]> granicus.if.org Git - vim/commitdiff
patch 8.1.1319: computing function length name in many places v8.1.1319
authorBram Moolenaar <Bram@vim.org>
Sat, 11 May 2019 16:37:44 +0000 (18:37 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 11 May 2019 16:37:44 +0000 (18:37 +0200)
Problem:    Computing function length name in many places.
Solution:   compute name length in call_func().

src/channel.c
src/eval.c
src/evalfunc.c
src/ex_cmds2.c
src/regexp.c
src/terminal.c
src/userfunc.c
src/version.c

index a29414f69f3b043e91f443f8a9d1774454a86fd4..31c9bbe229db286e02777e0e4ea541c87dbf7447 100644 (file)
@@ -1650,7 +1650,7 @@ invoke_callback(channel_T *channel, char_u *callback, partial_T *partial,
     argv[0].v_type = VAR_CHANNEL;
     argv[0].vval.v_channel = channel;
 
-    call_func(callback, (int)STRLEN(callback), &rettv, 2, argv, NULL,
+    call_func(callback, -1, &rettv, 2, argv, NULL,
                                          0L, 0L, &dummy, TRUE, partial, NULL);
     clear_tv(&rettv);
     channel_need_redraw = TRUE;
@@ -2989,7 +2989,7 @@ channel_close(channel_T *channel, int invoke_close_cb)
                                                (char *)channel->ch_close_cb);
              argv[0].v_type = VAR_CHANNEL;
              argv[0].vval.v_channel = channel;
-             call_func(channel->ch_close_cb, (int)STRLEN(channel->ch_close_cb),
+             call_func(channel->ch_close_cb, -1,
                           &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE,
                           channel->ch_close_partial, NULL);
              clear_tv(&rettv);
@@ -5478,7 +5478,7 @@ job_cleanup(job_T *job)
        argv[0].vval.v_job = job;
        argv[1].v_type = VAR_NUMBER;
        argv[1].vval.v_number = job->jv_exitval;
-       call_func(job->jv_exit_cb, (int)STRLEN(job->jv_exit_cb),
+       call_func(job->jv_exit_cb, -1,
            &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE,
            job->jv_exit_partial, NULL);
        clear_tv(&rettv);
@@ -6069,8 +6069,7 @@ invoke_prompt_callback(void)
     argv[0].vval.v_string = vim_strsave(text);
     argv[1].v_type = VAR_UNKNOWN;
 
-    call_func(curbuf->b_prompt_callback,
-             (int)STRLEN(curbuf->b_prompt_callback),
+    call_func(curbuf->b_prompt_callback, -1,
              &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE,
              curbuf->b_prompt_partial, NULL);
     clear_tv(&argv[0]);
@@ -6093,8 +6092,7 @@ invoke_prompt_interrupt(void)
     argv[0].v_type = VAR_UNKNOWN;
 
     got_int = FALSE; // don't skip executing commands
-    call_func(curbuf->b_prompt_interrupt,
-             (int)STRLEN(curbuf->b_prompt_interrupt),
+    call_func(curbuf->b_prompt_interrupt, -1,
              &rettv, 0, argv, NULL, 0L, 0L, &dummy, TRUE,
              curbuf->b_prompt_int_partial, NULL);
     clear_tv(&rettv);
index fe8a8efe771f8848f663e9eff8d7b94b2433c4ff..7df5455849a45a2d480bd62f2a77f48ec485567b 100644 (file)
@@ -765,7 +765,7 @@ eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
        s = expr->vval.v_string;
        if (s == NULL || *s == NUL)
            return FAIL;
-       if (call_func(s, (int)STRLEN(s), rettv, argc, argv, NULL,
+       if (call_func(s, -1, rettv, argc, argv, NULL,
                                     0L, 0L, &dummy, TRUE, NULL, NULL) == FAIL)
            return FAIL;
     }
@@ -776,7 +776,7 @@ eval_expr_typval(typval_T *expr, typval_T *argv, int argc, typval_T *rettv)
        s = partial_name(partial);
        if (s == NULL || *s == NUL)
            return FAIL;
-       if (call_func(s, (int)STRLEN(s), rettv, argc, argv, NULL,
+       if (call_func(s, -1, rettv, argc, argv, NULL,
                                  0L, 0L, &dummy, TRUE, partial, NULL) == FAIL)
            return FAIL;
     }
@@ -1088,7 +1088,7 @@ call_vim_function(
     int                ret;
 
     rettv->v_type = VAR_UNKNOWN;               /* clear_tv() uses this */
-    ret = call_func(func, (int)STRLEN(func), rettv, argc, argv, NULL,
+    ret = call_func(func, -1, rettv, argc, argv, NULL,
                    curwin->w_cursor.lnum, curwin->w_cursor.lnum,
                    &doesrange, TRUE, NULL, NULL);
     if (ret == FAIL)
@@ -7109,7 +7109,7 @@ handle_subscript(
            }
            else
                s = (char_u *)"";
-           ret = get_func_tv(s, (int)STRLEN(s), rettv, arg,
+           ret = get_func_tv(s, -1, rettv, arg,
                        curwin->w_cursor.lnum, curwin->w_cursor.lnum,
                        &len, evaluate, pt, selfdict);
 
index ff51d1210a1efce2a866036d55b4316f962f5c94..02ca1ae8289d8f17497ab853a7f2e1b7f8a70a97 100644 (file)
@@ -767,6 +767,8 @@ static struct fst
     {"line2byte",      1, 1, f_line2byte},
     {"lispindent",     1, 1, f_lispindent},
     {"list2str",       1, 2, f_list2str},
+    {"listener_add",   1, 2, f_listener_add},
+    {"listener_remove",        1, 1, f_listener_remove},
     {"localtime",      0, 0, f_localtime},
 #ifdef FEAT_FLOAT
     {"log",            1, 1, f_log},
@@ -9746,9 +9748,9 @@ f_readfile(typval_T *argvars, typval_T *rettv)
 
     if (failed)
     {
+       // an empty list is returned on error
        list_free(rettv->vval.v_list);
-       /* readfile doc says an empty list is returned on error */
-       rettv->vval.v_list = list_alloc();
+       rettv_list_alloc(rettv);
     }
 
     vim_free(prev);
@@ -12644,8 +12646,7 @@ item_compare2(const void *s1, const void *s2)
     copy_tv(&si2->item->li_tv, &argv[1]);
 
     rettv.v_type = VAR_UNKNOWN;                /* clear_tv() uses this */
-    res = call_func(func_name, (int)STRLEN(func_name),
-                                &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE,
+    res = call_func(func_name, -1, &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE,
                                 partial, sortinfo->item_compare_selfdict);
     clear_tv(&argv[0]);
     clear_tv(&argv[1]);
index 8bab8536b39742c9e7f4500f44b80363bf15b574..18c438ce0cb66bbd20a8021cafba4bbe0e1dec60 100644 (file)
@@ -325,7 +325,7 @@ timer_callback(timer_T *timer)
     argv[0].vval.v_number = (varnumber_T)timer->tr_id;
     argv[1].v_type = VAR_UNKNOWN;
 
-    call_func(timer->tr_callback, (int)STRLEN(timer->tr_callback),
+    call_func(timer->tr_callback, -1,
                        &rettv, 1, argv, NULL, 0L, 0L, &dummy, TRUE,
                        timer->tr_partial, NULL);
     clear_tv(&rettv);
index ceeb899ad2a030d39793b4c2883a63778abfa899..ee485a3ab574ba1478d1907c61ffe968065a82ad 100644 (file)
@@ -7423,7 +7423,7 @@ vim_regsub_both(
                if (expr->v_type == VAR_FUNC)
                {
                    s = expr->vval.v_string;
-                   call_func(s, (int)STRLEN(s), &rettv,
+                   call_func(s, -1, &rettv,
                                    1, argv, fill_submatch_list,
                                         0L, 0L, &dummy, TRUE, NULL, NULL);
                }
@@ -7432,7 +7432,7 @@ vim_regsub_both(
                    partial_T   *partial = expr->vval.v_partial;
 
                    s = partial_name(partial);
-                   call_func(s, (int)STRLEN(s), &rettv,
+                   call_func(s, -1, &rettv,
                                    1, argv, fill_submatch_list,
                                      0L, 0L, &dummy, TRUE, partial, NULL);
                }
index f007bf23ae97f4664b6b25dc48fa8032069c9001..bc57d641fad55b08c9f373b19430f18e92608c9c 100644 (file)
@@ -3779,7 +3779,7 @@ handle_call_command(term_T *term, channel_T *channel, listitem_T *item)
     argvars[0].v_type = VAR_NUMBER;
     argvars[0].vval.v_number = term->tl_buffer->b_fnum;
     argvars[1] = item->li_next->li_tv;
-    if (call_func(func, (int)STRLEN(func), &rettv,
+    if (call_func(func, -1, &rettv,
                2, argvars, /* argv_func */ NULL,
                /* firstline */ 1, /* lastline */ 1,
                &doesrange, /* evaluate */ TRUE,
index d8cbe635ee619d4e7096a05887ccb67ffccc5bda..4959b0d6a530b28ced738a5ddcca425988ca2382 100644 (file)
@@ -432,16 +432,16 @@ emsg_funcname(char *ermsg, char_u *name)
  */
     int
 get_func_tv(
-    char_u     *name,          /* name of the function */
-    int                len,            /* length of "name" */
+    char_u     *name,          // name of the function
+    int                len,            // length of "name" or -1 to use strlen()
     typval_T   *rettv,
-    char_u     **arg,          /* argument, pointing to the '(' */
-    linenr_T   firstline,      /* first line of range */
-    linenr_T   lastline,       /* last line of range */
-    int                *doesrange,     /* return: function handled range */
+    char_u     **arg,          // argument, pointing to the '('
+    linenr_T   firstline,      // first line of range
+    linenr_T   lastline,       // last line of range
+    int                *doesrange,     // return: function handled range
     int                evaluate,
-    partial_T  *partial,       /* for extra arguments */
-    dict_T     *selfdict)      /* Dictionary for "self" */
+    partial_T  *partial,       // for extra arguments
+    dict_T     *selfdict)      // Dictionary for "self"
 {
     char_u     *argp;
     int                ret = OK;
@@ -1435,7 +1435,7 @@ func_call(
     }
 
     if (item == NULL)
-       r = call_func(name, (int)STRLEN(name), rettv, argc, argv, NULL,
+       r = call_func(name, -1, rettv, argc, argv, NULL,
                                 curwin->w_cursor.lnum, curwin->w_cursor.lnum,
                                             &dummy, TRUE, partial, selfdict);
 
@@ -1458,20 +1458,20 @@ func_call(
  */
     int
 call_func(
-    char_u     *funcname,      /* name of the function */
-    int                len,            /* length of "name" */
-    typval_T   *rettv,         /* return value goes here */
-    int                argcount_in,    /* number of "argvars" */
-    typval_T   *argvars_in,    /* vars for arguments, must have "argcount"
-                                  PLUS ONE elements! */
+    char_u     *funcname,      // name of the function
+    int                len,            // length of "name" or -1 to use strlen()
+    typval_T   *rettv,         // return value goes here
+    int                argcount_in,    // number of "argvars"
+    typval_T   *argvars_in,    // vars for arguments, must have "argcount"
+                               // PLUS ONE elements!
     int                (* argv_func)(int, typval_T *, int),
-                               /* function to fill in argvars */
-    linenr_T   firstline,      /* first line of range */
-    linenr_T   lastline,       /* last line of range */
-    int                *doesrange,     /* return: function handled range */
+                               // function to fill in argvars
+    linenr_T   firstline,      // first line of range
+    linenr_T   lastline,       // last line of range
+    int                *doesrange,     // return: function handled range
     int                evaluate,
-    partial_T  *partial,       /* optional, can be NULL */
-    dict_T     *selfdict_in)   /* Dictionary for "self" */
+    partial_T  *partial,       // optional, can be NULL
+    dict_T     *selfdict_in)   // Dictionary for "self"
 {
     int                ret = FAIL;
     int                error = ERROR_NONE;
@@ -1487,9 +1487,9 @@ call_func(
     typval_T   argv[MAX_FUNC_ARGS + 1]; /* used when "partial" is not NULL */
     int                argv_clear = 0;
 
-    /* Make a copy of the name, if it comes from a funcref variable it could
-     * be changed or deleted in the called function. */
-    name = vim_strnsave(funcname, len);
+    // Make a copy of the name, if it comes from a funcref variable it could
+    // be changed or deleted in the called function.
+    name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname);
     if (name == NULL)
        return ret;
 
@@ -3285,7 +3285,7 @@ ex_call(exarg_T *eap)
            curwin->w_cursor.coladd = 0;
        }
        arg = startarg;
-       if (get_func_tv(name, (int)STRLEN(name), &rettv, &arg,
+       if (get_func_tv(name, -1, &rettv, &arg,
                    eap->line1, eap->line2, &doesrange,
                                   !eap->skip, partial, fudi.fd_dict) == FAIL)
        {
index ea97befd374d654bb6068598e560d70a9fccd3d4..7bcb8c87350922eb0756c09c88cbe3c607a047e3 100644 (file)
@@ -767,6 +767,10 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1319,
+/**/
+    1318,
 /**/
     1317,
 /**/