# HG changeset patch # User Bram Moolenaar # Date 1656504003 -7200 # Node ID a74398c432a4a42ceee93e3b4679d6d425e1310a # Parent 0f3ce048146b129a0c0943a6cb6cb265ad778f06 patch 9.0.0003: functions are global while they could be local Commit: https://github.com/vim/vim/commit/ee47eaceaa148e07b566ff420f9a3c2edde2fa34 Author: Yegappan Lakshmanan Date: Wed Jun 29 12:55:36 2022 +0100 patch 9.0.0003: functions are global while they could be local Problem: Functions are global while they could be local. Solution: Add "static". Add a few tests. (Yegappan Lakshmanan, closes #10612) diff --git a/src/crypt.c b/src/crypt.c --- a/src/crypt.c +++ b/src/crypt.c @@ -73,6 +73,10 @@ typedef struct { char_u *p2, int last); } cryptmethod_T; +static int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); +static long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); +static long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); + // index is method_nr of cryptstate_T, CRYPT_M_* static cryptmethod_T cryptmethods[CRYPT_M_COUNT] = { // PK_Zip; very weak @@ -850,7 +854,7 @@ crypt_append_msg( } } - int + static int crypt_sodium_init( cryptstate_T *state UNUSED, char_u *key UNUSED, @@ -1030,7 +1034,7 @@ fail: * Encrypt "from[len]" into "to[len]". * "from" and "to" can be equal to encrypt in place. */ - long + static long crypt_sodium_buffer_encode( cryptstate_T *state UNUSED, char_u *from UNUSED, @@ -1080,7 +1084,7 @@ crypt_sodium_buffer_encode( * Decrypt "from[len]" into "to[len]". * "from" and "to" can be equal to encrypt in place. */ - long + static long crypt_sodium_buffer_decode( cryptstate_T *state UNUSED, char_u *from UNUSED, diff --git a/src/evalvars.c b/src/evalvars.c --- a/src/evalvars.c +++ b/src/evalvars.c @@ -648,7 +648,7 @@ eval_one_expr_in_str(char_u *p, garray_T * Used for a heredoc assignment. * Returns NULL for an error. */ - char_u * + static char_u * eval_all_expr_in_str(char_u *str) { garray_T ga; diff --git a/src/gui.c b/src/gui.c --- a/src/gui.c +++ b/src/gui.c @@ -32,6 +32,7 @@ static void gui_do_scrollbar(win_T *wp, static void gui_update_horiz_scrollbar(int); static void gui_set_fg_color(char_u *name); static void gui_set_bg_color(char_u *name); +static void init_gui_options(void); static win_T *xy2win(int x, int y, mouse_find_T popup); #ifdef GUI_MAY_FORK @@ -1395,7 +1396,7 @@ gui_update_cursor( } #if defined(FEAT_MENU) || defined(PROTO) - void + static void gui_position_menu(void) { # if !defined(FEAT_GUI_GTK) && !defined(FEAT_GUI_MOTIF) @@ -4815,7 +4816,7 @@ gui_bg_default(void) /* * Option initializations that can only be done after opening the GUI window. */ - void + static void init_gui_options(void) { // Set the 'background' option according to the lightness of the diff --git a/src/highlight.c b/src/highlight.c --- a/src/highlight.c +++ b/src/highlight.c @@ -566,7 +566,7 @@ static int color_numbers_8[28] = {0, 4, * "boldp" will be set to TRUE or FALSE for a foreground color when using 8 * colors, otherwise it will be unchanged. */ - int + static int lookup_color(int idx, int foreground, int *boldp) { int color = color_numbers_16[idx]; diff --git a/src/proto/crypt.pro b/src/proto/crypt.pro --- a/src/proto/crypt.pro +++ b/src/proto/crypt.pro @@ -24,9 +24,6 @@ void crypt_check_method(int method); void crypt_check_current_method(void); char_u *crypt_get_key(int store, int twice); void crypt_append_msg(buf_T *buf); -int crypt_sodium_init(cryptstate_T *state, char_u *key, char_u *salt, int salt_len, char_u *seed, int seed_len); -long crypt_sodium_buffer_encode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); -long crypt_sodium_buffer_decode(cryptstate_T *state, char_u *from, size_t len, char_u **buf_out, int last); int crypt_sodium_munlock(void *const addr, const size_t len); void crypt_sodium_randombytes_buf(void *const buf, const size_t size); /* vim: set ft=c : */ diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro --- a/src/proto/evalvars.pro +++ b/src/proto/evalvars.pro @@ -14,7 +14,6 @@ int get_spellword(list_T *list, char_u * void prepare_vimvar(int idx, typval_T *save_tv); void restore_vimvar(int idx, typval_T *save_tv); char_u *eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate); -char_u *eval_all_expr_in_str(char_u *str); list_T *heredoc_get(exarg_T *eap, char_u *cmd, int script_get, int vim9compile); void ex_var(exarg_T *eap); void ex_let(exarg_T *eap); diff --git a/src/proto/gui.pro b/src/proto/gui.pro --- a/src/proto/gui.pro +++ b/src/proto/gui.pro @@ -9,7 +9,6 @@ int gui_init_font(char_u *font_list, int int gui_get_wide_font(void); void gui_set_ligatures(void); void gui_update_cursor(int force, int clear_selection); -void gui_position_menu(void); int gui_get_base_width(void); int gui_get_base_height(void); void gui_resize_shell(int pixel_width, int pixel_height); @@ -51,7 +50,6 @@ void gui_check_colors(void); guicolor_T gui_get_color(char_u *name); int gui_get_lightness(guicolor_T pixel); char_u *gui_bg_default(void); -void init_gui_options(void); void gui_new_scrollbar_colors(void); void gui_focus_change(int in_focus); void gui_mouse_moved(int x, int y); diff --git a/src/proto/highlight.pro b/src/proto/highlight.pro --- a/src/proto/highlight.pro +++ b/src/proto/highlight.pro @@ -4,7 +4,6 @@ char_u *highlight_group_name(int id); int highlight_link_id(int id); void init_highlight(int both, int reset); int load_colors(char_u *name); -int lookup_color(int idx, int foreground, int *boldp); void do_highlight(char_u *line, int forceit, int init); void free_highlight(void); void restore_cterm_colors(void); diff --git a/src/proto/scriptfile.pro b/src/proto/scriptfile.pro --- a/src/proto/scriptfile.pro +++ b/src/proto/scriptfile.pro @@ -40,7 +40,6 @@ void ex_scriptversion(exarg_T *eap); void ex_finish(exarg_T *eap); void do_finish(exarg_T *eap, int reanimate); int source_finished(char_u *(*fgetline)(int, void *, int, getline_opt_T), void *cookie); -char_u *script_name_after_autoload(scriptitem_T *si); char_u *get_autoload_prefix(scriptitem_T *si); char_u *may_prefix_autoload(char_u *name); char_u *autoload_name(char_u *name); diff --git a/src/proto/userfunc.pro b/src/proto/userfunc.pro --- a/src/proto/userfunc.pro +++ b/src/proto/userfunc.pro @@ -38,7 +38,6 @@ void user_func_error(int error, char_u * int call_func(char_u *funcname, int len, typval_T *rettv, int argcount_in, typval_T *argvars_in, funcexe_T *funcexe); char_u *printable_func_name(ufunc_T *fp); char_u *trans_function_name(char_u **pp, int *is_global, int skip, int flags, funcdict_T *fdp, partial_T **partial, type_T **type); -char_u *untrans_function_name(char_u *name); char_u *get_scriptlocal_funcname(char_u *funcname); char_u *alloc_printable_func_name(char_u *fname); char_u *save_function_name(char_u **name, int *is_global, int skip, int flags, funcdict_T *fudi); diff --git a/src/scriptfile.c b/src/scriptfile.c --- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -2346,7 +2346,7 @@ source_finished( * Find the path of a script below the "autoload" directory. * Returns NULL if there is no "/autoload/" in the script name. */ - char_u * + static char_u * script_name_after_autoload(scriptitem_T *si) { char_u *p = si->sn_name; diff --git a/src/testdir/test_fold.vim b/src/testdir/test_fold.vim --- a/src/testdir/test_fold.vim +++ b/src/testdir/test_fold.vim @@ -1476,6 +1476,8 @@ func Test_fold_split() call assert_equal([0, 1, 1, 2, 2], range(1, 5)->map('foldlevel(v:val)')) call append(2, 'line 2.5') call assert_equal([0, 1, 0, 1, 2, 2], range(1, 6)->map('foldlevel(v:val)')) + 3d + call assert_equal([0, 1, 1, 2, 2], range(1, 5)->map('foldlevel(v:val)')) bw! endfunc diff --git a/src/testdir/test_quickfix.vim b/src/testdir/test_quickfix.vim --- a/src/testdir/test_quickfix.vim +++ b/src/testdir/test_quickfix.vim @@ -3363,8 +3363,11 @@ func Test_bufoverflow() cgetexpr ['Compiler: ' . repeat('a', 1015), 'File1:10:Hello World'] set efm=%DEntering\ directory\ %f,%f:%l:%m - cgetexpr ['Entering directory ' . repeat('a', 1006), - \ 'File1:10:Hello World'] + let lines =<< trim eval END + Entering directory $"{repeat('a', 1006)}" + File1:10:Hello World + END + cgetexpr lines set efm&vim endfunc diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim --- a/src/testdir/test_vim9_builtin.vim +++ b/src/testdir/test_vim9_builtin.vim @@ -3364,6 +3364,22 @@ def Test_searchdecl() v9.CheckDefAndScriptFailure(['searchdecl(1)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1']) v9.CheckDefAndScriptFailure(['searchdecl("a", 2)'], ['E1013: Argument 2: type mismatch, expected bool but got number', 'E1212: Bool required for argument 2']) v9.CheckDefAndScriptFailure(['searchdecl("a", true, 2)'], ['E1013: Argument 3: type mismatch, expected bool but got number', 'E1212: Bool required for argument 3']) + + # search for an empty string declaration + var lines: list =<< trim END + int var1; + + { + int var2; + var1 = 10; + } + END + new + setline(1, lines) + cursor(5, 4) + searchdecl('') + assert_equal([3, 1], [line('.'), col('.')]) + bw! enddef def Test_searchpair() diff --git a/src/userfunc.c b/src/userfunc.c --- a/src/userfunc.c +++ b/src/userfunc.c @@ -32,6 +32,7 @@ static funccall_T *previous_funccal = NU static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); static void func_clear(ufunc_T *fp, int force); static int func_free(ufunc_T *fp, int force); +static char_u *untrans_function_name(char_u *name); void func_init() @@ -4073,7 +4074,7 @@ theend: * This can be used to first search for a script-local function and fall back * to the global function if not found. */ - char_u * + static char_u * untrans_function_name(char_u *name) { char_u *p; diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -736,6 +736,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3, +/**/ 2, /**/ 1,