]> granicus.if.org Git - vim/commitdiff
patch 9.0.0003: functions are global while they could be local v9.0.0003
authorYegappan Lakshmanan <yegappan@yahoo.com>
Wed, 29 Jun 2022 11:55:36 +0000 (12:55 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 29 Jun 2022 11:55:36 +0000 (12:55 +0100)
Problem:    Functions are global while they could be local.
Solution:   Add "static".  Add a few tests. (Yegappan Lakshmanan,
            closes #10612)

16 files changed:
src/crypt.c
src/evalvars.c
src/gui.c
src/highlight.c
src/proto/crypt.pro
src/proto/evalvars.pro
src/proto/gui.pro
src/proto/highlight.pro
src/proto/scriptfile.pro
src/proto/userfunc.pro
src/scriptfile.c
src/testdir/test_fold.vim
src/testdir/test_quickfix.vim
src/testdir/test_vim9_builtin.vim
src/userfunc.c
src/version.c

index bed76a96d465a9fd0a2a91537c1707f273a62758..b2b50d46323ced19b09a8c836278687867c7e43d 100644 (file)
@@ -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,
index f7939cbb7aedb0b61a7a4d437db5618c2225a0e8..779627c45a98d0031947780d787405a32c726a03 100644 (file)
@@ -648,7 +648,7 @@ eval_one_expr_in_str(char_u *p, garray_T *gap, int evaluate)
  * 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;
index 4408545db3b232a35f23d1245ed6a7f8d79f0b89..e708a27763265d15104b06f216332e7043d38ced 100644 (file)
--- a/src/gui.c
+++ b/src/gui.c
@@ -32,6 +32,7 @@ static void gui_do_scrollbar(win_T *wp, int which, int enable);
 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
index 75a310f53e962b6c406073c05b5c2746e5f584dc..bf876d16f117ce53a56fbadc5024c603c5d9d072 100644 (file)
@@ -566,7 +566,7 @@ static int color_numbers_8[28] = {0, 4, 2, 6,
  * "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];
index d6c7b7ffde906854da496081a6d72c37066ebfa1..7913694912bde6036d3b946bc3b1bf071bc4344c 100644 (file)
@@ -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 : */
index 4683c15ffa55923d667b0ceee7c2051fa4110cc1..253af6de6c779fe6c0a3f555503b86a09d25889e 100644 (file)
@@ -14,7 +14,6 @@ int get_spellword(list_T *list, char_u **pp);
 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);
index 2a0ac806f0e8496d00213db269392aeee21a3908..1a04248447f05f6e50ddb8e465bbf78faac98d15 100644 (file)
@@ -9,7 +9,6 @@ int gui_init_font(char_u *font_list, int fontset);
 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);
index 5635a17384b4b7e73fe48381a5c308ef29dead8f..33f90c65253f7b7d42f73b0389d49641c995efb6 100644 (file)
@@ -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);
index a38f258709c9bba18da9c1048f38a764798f02d1..205028d127e39cd731d10a4967a40e51608a60f7 100644 (file)
@@ -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);
index 537276013a57e8e2e9dfe44d1c3b4f3478699e52..427d47b241feb192f4afe63425bab5bcf1dbf97e 100644 (file)
@@ -38,7 +38,6 @@ void user_func_error(int error, char_u *name, funcexe_T *funcexe);
 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);
index f3a5783db510929386d3dbd80e6d70f7020187e5..952f2efd057cb748c0e508245dc67ccbc1b20a85 100644 (file)
@@ -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;
index 3bdd99fc0ede073f47999a5c7c3e3d0f91dc7c80..2618084025ce989ae914d6d20d622ca487270f35 100644 (file)
@@ -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
 
index 182d570474ba649689008e16420a443de273cb61..2a973754deef6142fa926e3da5b556be7936f08c 100644 (file)
@@ -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
 
index e83e320c730a015c34e1eba4a0d7e9314ffc5522..024359585367d649529b666c85ea934370a988e2 100644 (file)
@@ -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<string> =<< 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()
index 9b960b7752f3edfe3713c288a8c08bf5414a1bfe..9f8442277faf65aefde030fa26b67a6a1d860ff0 100644 (file)
@@ -32,6 +32,7 @@ static funccall_T *previous_funccal = NULL;
 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;
index 74e080ff3958da45d7c0e0a2ffc2497acd8594ee..2faf3bdfcca5bc5a195dc4955e1d67f6d62de6a9 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3,
 /**/
     2,
 /**/