Merge pull request #5550 from jamessan/big-endian-fixes

Making nvim big-endian friendly
This commit is contained in:
James McCoy
2016-11-02 20:04:10 -04:00
committed by GitHub
9 changed files with 91 additions and 89 deletions

View File

@@ -232,8 +232,14 @@ for i = 1, #functions do
converted = 'arg_'..j converted = 'arg_'..j
local rt = real_type(param[1]) local rt = real_type(param[1])
if rt ~= 'Object' then if rt ~= 'Object' then
if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') then
-- Buffer, Window, and Tabpage have a specific type, but are stored in integer
output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..' && args.items['..(j - 1)..'].data.integer >= 0) {')
output:write('\n '..converted..' = (handle_T)args.items['..(j - 1)..'].data.integer;')
else
output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {') output:write('\n if (args.items['..(j - 1)..'].type == kObjectType'..rt..') {')
output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';') output:write('\n '..converted..' = args.items['..(j - 1)..'].data.'..rt:lower()..';')
end
if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then if rt:match('^Buffer$') or rt:match('^Window$') or rt:match('^Tabpage$') or rt:match('^Boolean$') then
-- accept nonnegative integers for Booleans, Buffers, Windows and Tabpages -- accept nonnegative integers for Booleans, Buffers, Windows and Tabpages
output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer >= 0) {') output:write('\n } else if (args.items['..(j - 1)..'].type == kObjectTypeInteger && args.items['..(j - 1)..'].data.integer >= 0) {')

View File

@@ -91,9 +91,6 @@ typedef enum {
struct object { struct object {
ObjectType type; ObjectType type;
union { union {
Buffer buffer;
Window window;
Tabpage tabpage;
Boolean boolean; Boolean boolean;
Integer integer; Integer integer;
Float floating; Float floating;

View File

@@ -616,13 +616,14 @@ bool object_to_vim(Object obj, typval_T *tv, Error *err)
case kObjectTypeWindow: case kObjectTypeWindow:
case kObjectTypeTabpage: case kObjectTypeTabpage:
case kObjectTypeInteger: case kObjectTypeInteger:
if (obj.data.integer > INT_MAX || obj.data.integer < INT_MIN) { if (obj.data.integer > VARNUMBER_MAX
|| obj.data.integer < VARNUMBER_MIN) {
api_set_error(err, Validation, _("Integer value outside range")); api_set_error(err, Validation, _("Integer value outside range"));
return false; return false;
} }
tv->v_type = VAR_NUMBER; tv->v_type = VAR_NUMBER;
tv->vval.v_number = (int)obj.data.integer; tv->vval.v_number = (varnumber_T)obj.data.integer;
break; break;
case kObjectTypeFloat: case kObjectTypeFloat:

View File

@@ -37,15 +37,15 @@
#define BUFFER_OBJ(s) ((Object) { \ #define BUFFER_OBJ(s) ((Object) { \
.type = kObjectTypeBuffer, \ .type = kObjectTypeBuffer, \
.data.buffer = s }) .data.integer = s })
#define WINDOW_OBJ(s) ((Object) { \ #define WINDOW_OBJ(s) ((Object) { \
.type = kObjectTypeWindow, \ .type = kObjectTypeWindow, \
.data.window = s }) .data.integer = s })
#define TABPAGE_OBJ(s) ((Object) { \ #define TABPAGE_OBJ(s) ((Object) { \
.type = kObjectTypeTabpage, \ .type = kObjectTypeTabpage, \
.data.tabpage = s }) .data.integer = s })
#define ARRAY_OBJ(a) ((Object) { \ #define ARRAY_OBJ(a) ((Object) { \
.type = kObjectTypeArray, \ .type = kObjectTypeArray, \

View File

@@ -348,7 +348,7 @@ Tabpage nvim_win_get_tabpage(Window window, Error *err)
/// @return Window number /// @return Window number
Integer nvim_win_get_number(Window window, Error *err) Integer nvim_win_get_number(Window window, Error *err)
{ {
Integer rv = 0; int rv = 0;
win_T *win = find_window_by_handle(window, err); win_T *win = find_window_by_handle(window, err);
if (!win) { if (!win) {
@@ -356,7 +356,7 @@ Integer nvim_win_get_number(Window window, Error *err)
} }
int tabnr; int tabnr;
win_get_tabwin(window, &tabnr, (int *)&rv); win_get_tabwin(window, &tabnr, &rv);
return rv; return rv;
} }

View File

@@ -488,9 +488,9 @@ struct file_buffer {
bool file_id_valid; bool file_id_valid;
FileID file_id; 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. */ // file has been changed and not written out.
int b_changedtick; /* incremented for each change, also for undo */ int b_changedtick; // incremented for each change, also for undo
bool b_saving; /* Set to true if we are in the middle of bool b_saving; /* Set to true if we are in the middle of
saving the buffer. */ saving the buffer. */
@@ -655,7 +655,7 @@ struct file_buffer {
long b_p_sts; ///< 'softtabstop' long b_p_sts; ///< 'softtabstop'
long b_p_sts_nopaste; ///< b_p_sts saved for paste mode long b_p_sts_nopaste; ///< b_p_sts saved for paste mode
char_u *b_p_sua; ///< 'suffixesadd' char_u *b_p_sua; ///< 'suffixesadd'
bool b_p_swf; ///< 'swapfile' int b_p_swf; ///< 'swapfile'
long b_p_smc; ///< 'synmaxcol' long b_p_smc; ///< 'synmaxcol'
char_u *b_p_syn; ///< 'syntax' char_u *b_p_syn; ///< 'syntax'
long b_p_ts; ///< 'tabstop' long b_p_ts; ///< 'tabstop'

View File

@@ -21,7 +21,8 @@ static msgpack_zone zone;
static msgpack_sbuffer sbuffer; static msgpack_sbuffer sbuffer;
#define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \ #define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \
bool msgpack_rpc_to_##lt(const msgpack_object *const obj, t *const arg) \ bool msgpack_rpc_to_##lt(const msgpack_object *const obj, \
Integer *const arg) \
FUNC_ATTR_NONNULL_ALL \ FUNC_ATTR_NONNULL_ALL \
{ \ { \
if (obj->type != MSGPACK_OBJECT_EXT \ if (obj->type != MSGPACK_OBJECT_EXT \
@@ -44,12 +45,12 @@ static msgpack_sbuffer sbuffer;
return true; \ return true; \
} \ } \
\ \
void msgpack_rpc_from_##lt(t o, msgpack_packer *res) \ void msgpack_rpc_from_##lt(Integer o, msgpack_packer *res) \
FUNC_ATTR_NONNULL_ARG(2) \ FUNC_ATTR_NONNULL_ARG(2) \
{ \ { \
msgpack_packer pac; \ msgpack_packer pac; \
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \ msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
msgpack_pack_int64(&pac, o); \ msgpack_pack_int64(&pac, (handle_T)o); \
msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \ msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \ msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
msgpack_sbuffer_clear(&sbuffer); \ msgpack_sbuffer_clear(&sbuffer); \
@@ -213,17 +214,17 @@ bool msgpack_rpc_to_object(const msgpack_object *const obj, Object *const arg)
switch (cur.mobj->via.ext.type) { switch (cur.mobj->via.ext.type) {
case kObjectTypeBuffer: { case kObjectTypeBuffer: {
cur.aobj->type = kObjectTypeBuffer; cur.aobj->type = kObjectTypeBuffer;
ret = msgpack_rpc_to_buffer(cur.mobj, &cur.aobj->data.buffer); ret = msgpack_rpc_to_buffer(cur.mobj, &cur.aobj->data.integer);
break; break;
} }
case kObjectTypeWindow: { case kObjectTypeWindow: {
cur.aobj->type = kObjectTypeWindow; cur.aobj->type = kObjectTypeWindow;
ret = msgpack_rpc_to_window(cur.mobj, &cur.aobj->data.window); ret = msgpack_rpc_to_window(cur.mobj, &cur.aobj->data.integer);
break; break;
} }
case kObjectTypeTabpage: { case kObjectTypeTabpage: {
cur.aobj->type = kObjectTypeTabpage; cur.aobj->type = kObjectTypeTabpage;
ret = msgpack_rpc_to_tabpage(cur.mobj, &cur.aobj->data.tabpage); ret = msgpack_rpc_to_tabpage(cur.mobj, &cur.aobj->data.integer);
break; break;
} }
} }
@@ -369,15 +370,15 @@ void msgpack_rpc_from_object(const Object result, msgpack_packer *const res)
break; break;
} }
case kObjectTypeBuffer: { case kObjectTypeBuffer: {
msgpack_rpc_from_buffer(cur.aobj->data.buffer, res); msgpack_rpc_from_buffer(cur.aobj->data.integer, res);
break; break;
} }
case kObjectTypeWindow: { case kObjectTypeWindow: {
msgpack_rpc_from_window(cur.aobj->data.window, res); msgpack_rpc_from_window(cur.aobj->data.integer, res);
break; break;
} }
case kObjectTypeTabpage: { case kObjectTypeTabpage: {
msgpack_rpc_from_tabpage(cur.aobj->data.tabpage, res); msgpack_rpc_from_tabpage(cur.aobj->data.integer, res);
break; break;
} }
case kObjectTypeArray: { case kObjectTypeArray: {

View File

@@ -2527,7 +2527,7 @@ did_set_string_option (
else if (varp == &p_sbo) { else if (varp == &p_sbo) {
if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK) if (check_opt_strings(p_sbo, p_scbopt_values, TRUE) != OK)
errmsg = e_invarg; errmsg = e_invarg;
} else if (varp == &p_ambw || (bool *)varp == &p_emoji) { } else if (varp == &p_ambw || (int *)varp == &p_emoji) {
// 'ambiwidth' // 'ambiwidth'
if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) { if (check_opt_strings(p_ambw, p_ambw_values, false) != OK) {
errmsg = e_invarg; errmsg = e_invarg;
@@ -3706,23 +3706,19 @@ set_bool_option (
} }
} }
} }
} } else if (varp == (char_u *)&(curbuf->b_p_lisp)) {
// When 'lisp' option changes include/exclude '-' in
/* // keyword characters.
* When 'lisp' option changes include/exclude '-' in (void)buf_init_chartab(curbuf, false); // ignore errors
* keyword characters. } else if ((int *)varp == &p_title) {
*/ // when 'title' changed, may need to change the title; same for 'icon'
else if (varp == (char_u *)&(curbuf->b_p_lisp)) { did_set_title(false);
(void)buf_init_chartab(curbuf, FALSE); /* ignore errors */
}
/* when 'title' changed, may need to change the title; same for 'icon' */
else if ((int *)varp == &p_title) {
did_set_title(FALSE);
} else if ((int *)varp == &p_icon) { } else if ((int *)varp == &p_icon) {
did_set_title(TRUE); did_set_title(true);
} else if ((bool *)varp == &curbuf->b_changed) { } else if ((int *)varp == &curbuf->b_changed) {
if (!value) if (!value) {
save_file_ff(curbuf); /* Buffer is unchanged */ save_file_ff(curbuf); // Buffer is unchanged
}
redraw_titles(); redraw_titles();
modified_was_set = value; modified_was_set = value;
} }
@@ -3750,11 +3746,12 @@ set_bool_option (
else if ((int *)varp == &curwin->w_p_wrap) { else if ((int *)varp == &curwin->w_p_wrap) {
if (curwin->w_p_wrap) if (curwin->w_p_wrap)
curwin->w_leftcol = 0; curwin->w_leftcol = 0;
} else if ((bool *)varp == &p_ea) { } else if ((int *)varp == &p_ea) {
if (p_ea && !old_value) if (p_ea && !old_value) {
win_equal(curwin, false, 0); win_equal(curwin, false, 0);
} else if ((bool *)varp == &p_acd) { }
/* Change directories when the 'acd' option is set now. */ } else if ((int *)varp == &p_acd) {
// Change directories when the 'acd' option is set now.
do_autochdir(); do_autochdir();
} }
/* 'diff' */ /* 'diff' */
@@ -4513,11 +4510,12 @@ get_option_value (
else { else {
/* Special case: 'modified' is b_changed, but we also want to consider /* Special case: 'modified' is b_changed, but we also want to consider
* it set when 'ff' or 'fenc' changed. */ * it set when 'ff' or 'fenc' changed. */
if ((bool *)varp == &curbuf->b_changed) if ((int *)varp == &curbuf->b_changed) {
*numval = curbufIsChanged(); *numval = curbufIsChanged();
else } else {
*numval = *(int *)varp; *numval = *(int *)varp;
} }
}
return 1; return 1;
} }
@@ -4884,14 +4882,15 @@ showoneopt (
varp = get_varp_scope(p, opt_flags); varp = get_varp_scope(p, opt_flags);
/* for 'modified' we also need to check if 'ff' or 'fenc' changed. */ // for 'modified' we also need to check if 'ff' or 'fenc' changed.
if ((p->flags & P_BOOL) && ((bool *)varp == &curbuf->b_changed if ((p->flags & P_BOOL) && ((int *)varp == &curbuf->b_changed
? !curbufIsChanged() : !*(bool *)varp)) ? !curbufIsChanged() : !*(int *)varp)) {
MSG_PUTS("no"); MSG_PUTS("no");
else if ((p->flags & P_BOOL) && *(int *)varp < 0) } else if ((p->flags & P_BOOL) && *(int *)varp < 0) {
MSG_PUTS("--"); MSG_PUTS("--");
else } else {
MSG_PUTS(" "); MSG_PUTS(" ");
}
MSG_PUTS(p->fullname); MSG_PUTS(p->fullname);
if (!(p->flags & P_BOOL)) { if (!(p->flags & P_BOOL)) {
msg_putchar('='); msg_putchar('=');

View File

@@ -1,8 +1,6 @@
#ifndef NVIM_OPTION_DEFS_H #ifndef NVIM_OPTION_DEFS_H
#define NVIM_OPTION_DEFS_H #define NVIM_OPTION_DEFS_H
#include <stdbool.h>
#include "nvim/types.h" #include "nvim/types.h"
#include "nvim/macros.h" // For EXTERN #include "nvim/macros.h" // For EXTERN
@@ -296,16 +294,16 @@ enum {
* The following are actual variables for the options * The following are actual variables for the options
*/ */
EXTERN long p_aleph; /* 'aleph' */ EXTERN long p_aleph; // 'aleph'
EXTERN bool p_acd; /* 'autochdir' */ EXTERN int p_acd; // 'autochdir'
EXTERN char_u *p_ambw; /* 'ambiwidth' */ EXTERN char_u *p_ambw; // 'ambiwidth'
EXTERN int p_ar; /* 'autoread' */ EXTERN int p_ar; // 'autoread'
EXTERN int p_aw; /* 'autowrite' */ EXTERN int p_aw; // 'autowrite'
EXTERN int p_awa; /* 'autowriteall' */ EXTERN int p_awa; // 'autowriteall'
EXTERN char_u *p_bs; /* 'backspace' */ EXTERN char_u *p_bs; // 'backspace'
EXTERN char_u *p_bg; /* 'background' */ EXTERN char_u *p_bg; // 'background'
EXTERN int p_bk; /* 'backup' */ EXTERN int p_bk; // 'backup'
EXTERN char_u *p_bkc; /* 'backupcopy' */ EXTERN char_u *p_bkc; // 'backupcopy'
EXTERN unsigned int bkc_flags; ///< flags from 'backupcopy' EXTERN unsigned int bkc_flags; ///< flags from 'backupcopy'
#ifdef IN_OPTION_C #ifdef IN_OPTION_C
static char *(p_bkc_values[]) = static char *(p_bkc_values[]) =
@@ -403,9 +401,9 @@ static char *(p_dy_values[]) = { "lastline", "truncate", "uhex", NULL };
#define DY_TRUNCATE 0x002 #define DY_TRUNCATE 0x002
#define DY_UHEX 0x004 #define DY_UHEX 0x004
EXTERN int p_ed; // 'edcompatible' EXTERN int p_ed; // 'edcompatible'
EXTERN bool p_emoji; // 'emoji' EXTERN int p_emoji; // 'emoji'
EXTERN char_u *p_ead; // 'eadirection' EXTERN char_u *p_ead; // 'eadirection'
EXTERN bool p_ea; // 'equalalways' EXTERN int p_ea; // 'equalalways'
EXTERN char_u *p_ep; // 'equalprg' EXTERN char_u *p_ep; // 'equalprg'
EXTERN int p_eb; // 'errorbells' EXTERN int p_eb; // 'errorbells'
EXTERN char_u *p_ef; // 'errorfile' EXTERN char_u *p_ef; // 'errorfile'
@@ -417,7 +415,7 @@ EXTERN int p_ek; // 'esckeys'
EXTERN int p_exrc; // 'exrc' EXTERN int p_exrc; // 'exrc'
EXTERN char_u *p_fencs; // 'fileencodings' EXTERN char_u *p_fencs; // 'fileencodings'
EXTERN char_u *p_ffs; // 'fileformats' EXTERN char_u *p_ffs; // 'fileformats'
EXTERN bool p_fic; // 'fileignorecase' EXTERN int p_fic; // 'fileignorecase'
EXTERN char_u *p_fcl; // 'foldclose' EXTERN char_u *p_fcl; // 'foldclose'
EXTERN long p_fdls; // 'foldlevelstart' EXTERN long p_fdls; // 'foldlevelstart'
EXTERN char_u *p_fdo; // 'foldopen' 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_titleold; ///< 'titleold'
EXTERN char_u *p_titlestring; ///< 'titlestring' EXTERN char_u *p_titlestring; ///< 'titlestring'
EXTERN char_u *p_tsr; ///< 'thesaurus' EXTERN char_u *p_tsr; ///< 'thesaurus'
EXTERN bool p_tgc; ///< 'termguicolors' EXTERN int p_tgc; ///< 'termguicolors'
EXTERN int p_ttimeout; ///< 'ttimeout' EXTERN int p_ttimeout; ///< 'ttimeout'
EXTERN long p_ttm; ///< 'ttimeoutlen' EXTERN long p_ttm; ///< 'ttimeoutlen'
EXTERN char_u *p_udir; ///< 'undodir' EXTERN char_u *p_udir; ///< 'undodir'
@@ -651,26 +649,26 @@ char_u *p_vfile = (char_u *)""; /* used before options are initialized */
#else #else
extern char_u *p_vfile; /* 'verbosefile' */ extern char_u *p_vfile; /* 'verbosefile' */
#endif #endif
EXTERN int p_warn; /* 'warn' */ EXTERN int p_warn; // 'warn'
EXTERN char_u *p_wop; /* 'wildoptions' */ EXTERN char_u *p_wop; // 'wildoptions'
EXTERN long p_window; /* 'window' */ EXTERN long p_window; // 'window'
EXTERN char_u *p_wak; /* 'winaltkeys' */ EXTERN char_u *p_wak; // 'winaltkeys'
EXTERN char_u *p_wig; /* 'wildignore' */ EXTERN char_u *p_wig; // 'wildignore'
EXTERN char_u *p_ww; /* 'whichwrap' */ EXTERN char_u *p_ww; // 'whichwrap'
EXTERN long p_wc; /* 'wildchar' */ EXTERN long p_wc; // 'wildchar'
EXTERN long p_wcm; /* 'wildcharm' */ EXTERN long p_wcm; // 'wildcharm'
EXTERN bool p_wic; ///< 'wildignorecase' EXTERN int p_wic; // 'wildignorecase'
EXTERN char_u *p_wim; /* 'wildmode' */ EXTERN char_u *p_wim; // 'wildmode'
EXTERN int p_wmnu; /* 'wildmenu' */ EXTERN int p_wmnu; // 'wildmenu'
EXTERN long p_wh; /* 'winheight' */ EXTERN long p_wh; // 'winheight'
EXTERN long p_wmh; /* 'winminheight' */ EXTERN long p_wmh; // 'winminheight'
EXTERN long p_wmw; /* 'winminwidth' */ EXTERN long p_wmw; // 'winminwidth'
EXTERN long p_wiw; /* 'winwidth' */ EXTERN long p_wiw; // 'winwidth'
EXTERN bool p_ws; /* 'wrapscan' */ EXTERN int p_ws; // 'wrapscan'
EXTERN int p_write; /* 'write' */ EXTERN int p_write; // 'write'
EXTERN int p_wa; /* 'writeany' */ EXTERN int p_wa; // 'writeany'
EXTERN int p_wb; /* 'writebackup' */ EXTERN int p_wb; // 'writebackup'
EXTERN long p_wd; /* 'writedelay' */ EXTERN long p_wd; // 'writedelay'
EXTERN int p_force_on; ///< options that cannot be turned off. EXTERN int p_force_on; ///< options that cannot be turned off.
EXTERN int p_force_off; ///< options that cannot be turned on. EXTERN int p_force_off; ///< options that cannot be turned on.