mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Use int as the standard type for boolean options.
All options are accessed by passing char_u pointers around, casting the pointer to the right pointer type for the specific option, and then dereferencing that pointer. This dance works fine on little-endian systems when some bool options are int types (as in Vim) and some are bool types (as would make more sense), but on big-endian systems *(int *)varp when varp is pointing to a bool will read random memory. Therefore, all boolean options must remain a consistent type and int is currently the easiest to choose.
This commit is contained in:
parent
349fa0048b
commit
87ff2682d7
@ -488,7 +488,7 @@ struct file_buffer {
|
||||
bool file_id_valid;
|
||||
FileID file_id;
|
||||
|
||||
bool b_changed; /* 'modified': Set to true if something in the
|
||||
int b_changed; /* 'modified': Set to true if something in the
|
||||
file has been changed and not written out. */
|
||||
int b_changedtick; /* incremented for each change, also for undo */
|
||||
|
||||
@ -655,7 +655,7 @@ struct file_buffer {
|
||||
long b_p_sts; ///< 'softtabstop'
|
||||
long b_p_sts_nopaste; ///< b_p_sts saved for paste mode
|
||||
char_u *b_p_sua; ///< 'suffixesadd'
|
||||
bool b_p_swf; ///< 'swapfile'
|
||||
int b_p_swf; ///< 'swapfile'
|
||||
long b_p_smc; ///< 'synmaxcol'
|
||||
char_u *b_p_syn; ///< 'syntax'
|
||||
long b_p_ts; ///< 'tabstop'
|
||||
|
@ -2527,7 +2527,7 @@ did_set_string_option (
|
||||
else if (varp == &p_sbo) {
|
||||
if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
|
||||
errmsg = e_invarg;
|
||||
} else if (varp == &p_ambw || (bool *)varp == &p_emoji) {
|
||||
} else if (varp == &p_ambw || (int *)varp == &p_emoji) {
|
||||
// 'ambiwidth'
|
||||
if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) {
|
||||
errmsg = e_invarg;
|
||||
@ -3720,7 +3720,7 @@ set_bool_option (
|
||||
did_set_title(FALSE);
|
||||
} else if ((int *)varp == &p_icon) {
|
||||
did_set_title(TRUE);
|
||||
} else if ((bool *)varp == &curbuf->b_changed) {
|
||||
} else if ((int *)varp == &curbuf->b_changed) {
|
||||
if (!value)
|
||||
save_file_ff(curbuf); /* Buffer is unchanged */
|
||||
redraw_titles();
|
||||
@ -3750,10 +3750,10 @@ set_bool_option (
|
||||
else if ((int *)varp == &curwin->w_p_wrap) {
|
||||
if (curwin->w_p_wrap)
|
||||
curwin->w_leftcol = 0;
|
||||
} else if ((bool *)varp == &p_ea) {
|
||||
} else if ((int *)varp == &p_ea) {
|
||||
if (p_ea && !old_value)
|
||||
win_equal(curwin, false, 0);
|
||||
} else if ((bool *)varp == &p_acd) {
|
||||
} else if ((int *)varp == &p_acd) {
|
||||
/* Change directories when the 'acd' option is set now. */
|
||||
do_autochdir();
|
||||
}
|
||||
@ -4513,7 +4513,7 @@ get_option_value (
|
||||
else {
|
||||
/* Special case: 'modified' is b_changed, but we also want to consider
|
||||
* it set when 'ff' or 'fenc' changed. */
|
||||
if ((bool *)varp == &curbuf->b_changed)
|
||||
if ((int *)varp == &curbuf->b_changed)
|
||||
*numval = curbufIsChanged();
|
||||
else
|
||||
*numval = *(int *)varp;
|
||||
@ -4885,8 +4885,8 @@ showoneopt (
|
||||
varp = get_varp_scope(p, opt_flags);
|
||||
|
||||
/* for 'modified' we also need to check if 'ff' or 'fenc' changed. */
|
||||
if ((p->flags & P_BOOL) && ((bool *)varp == &curbuf->b_changed
|
||||
? !curbufIsChanged() : !*(bool *)varp))
|
||||
if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
|
||||
? !curbufIsChanged() : !*(int *)varp))
|
||||
MSG_PUTS("no");
|
||||
else if ((p->flags & P_BOOL) && *(int *)varp < 0)
|
||||
MSG_PUTS("--");
|
||||
|
@ -1,8 +1,6 @@
|
||||
#ifndef NVIM_OPTION_DEFS_H
|
||||
#define NVIM_OPTION_DEFS_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "nvim/types.h"
|
||||
#include "nvim/macros.h" // For EXTERN
|
||||
|
||||
@ -297,7 +295,7 @@ enum {
|
||||
*/
|
||||
|
||||
EXTERN long p_aleph; /* 'aleph' */
|
||||
EXTERN bool p_acd; /* 'autochdir' */
|
||||
EXTERN int p_acd; /* 'autochdir' */
|
||||
EXTERN char_u *p_ambw; /* 'ambiwidth' */
|
||||
EXTERN int p_ar; /* 'autoread' */
|
||||
EXTERN int p_aw; /* 'autowrite' */
|
||||
@ -403,9 +401,9 @@ static char *(p_dy_values[]) = { "lastline", "truncate", "uhex", NULL };
|
||||
#define DY_TRUNCATE 0x002
|
||||
#define DY_UHEX 0x004
|
||||
EXTERN int p_ed; // 'edcompatible'
|
||||
EXTERN bool p_emoji; // 'emoji'
|
||||
EXTERN int p_emoji; // 'emoji'
|
||||
EXTERN char_u *p_ead; // 'eadirection'
|
||||
EXTERN bool p_ea; // 'equalalways'
|
||||
EXTERN int p_ea; // 'equalalways'
|
||||
EXTERN char_u *p_ep; // 'equalprg'
|
||||
EXTERN int p_eb; // 'errorbells'
|
||||
EXTERN char_u *p_ef; // 'errorfile'
|
||||
@ -417,7 +415,7 @@ EXTERN int p_ek; // 'esckeys'
|
||||
EXTERN int p_exrc; // 'exrc'
|
||||
EXTERN char_u *p_fencs; // 'fileencodings'
|
||||
EXTERN char_u *p_ffs; // 'fileformats'
|
||||
EXTERN bool p_fic; // 'fileignorecase'
|
||||
EXTERN int p_fic; // 'fileignorecase'
|
||||
EXTERN char_u *p_fcl; // 'foldclose'
|
||||
EXTERN long p_fdls; // 'foldlevelstart'
|
||||
EXTERN char_u *p_fdo; // 'foldopen'
|
||||
@ -622,7 +620,7 @@ EXTERN long p_titlelen; ///< 'titlelen'
|
||||
EXTERN char_u *p_titleold; ///< 'titleold'
|
||||
EXTERN char_u *p_titlestring; ///< 'titlestring'
|
||||
EXTERN char_u *p_tsr; ///< 'thesaurus'
|
||||
EXTERN bool p_tgc; ///< 'termguicolors'
|
||||
EXTERN int p_tgc; ///< 'termguicolors'
|
||||
EXTERN int p_ttimeout; ///< 'ttimeout'
|
||||
EXTERN long p_ttm; ///< 'ttimeoutlen'
|
||||
EXTERN char_u *p_udir; ///< 'undodir'
|
||||
@ -659,14 +657,14 @@ EXTERN char_u *p_wig; /* 'wildignore' */
|
||||
EXTERN char_u *p_ww; /* 'whichwrap' */
|
||||
EXTERN long p_wc; /* 'wildchar' */
|
||||
EXTERN long p_wcm; /* 'wildcharm' */
|
||||
EXTERN bool p_wic; ///< 'wildignorecase'
|
||||
EXTERN int p_wic; ///< 'wildignorecase'
|
||||
EXTERN char_u *p_wim; /* 'wildmode' */
|
||||
EXTERN int p_wmnu; /* 'wildmenu' */
|
||||
EXTERN long p_wh; /* 'winheight' */
|
||||
EXTERN long p_wmh; /* 'winminheight' */
|
||||
EXTERN long p_wmw; /* 'winminwidth' */
|
||||
EXTERN long p_wiw; /* 'winwidth' */
|
||||
EXTERN bool p_ws; /* 'wrapscan' */
|
||||
EXTERN int p_ws; /* 'wrapscan' */
|
||||
EXTERN int p_write; /* 'write' */
|
||||
EXTERN int p_wa; /* 'writeany' */
|
||||
EXTERN int p_wb; /* 'writebackup' */
|
||||
|
Loading…
Reference in New Issue
Block a user