diff options
author | Bram Moolenaar <Bram@vim.org> | 2019-05-11 18:37:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2019-05-11 18:37:44 +0200 |
commit | 6ed8819822994512c160006bd1204aa11ae3c494 (patch) | |
tree | 171487d99e5cf0a6c7e5333159d98c821064e93e | |
parent | ec28d1516eb8bb5dcaa42de145953a6d49aebb6f (diff) |
patch 8.1.1319: computing function length name in many placesv8.1.1319
Problem: Computing function length name in many places.
Solution: compute name length in call_func().
-rw-r--r-- | src/channel.c | 12 | ||||
-rw-r--r-- | src/eval.c | 8 | ||||
-rw-r--r-- | src/evalfunc.c | 9 | ||||
-rw-r--r-- | src/ex_cmds2.c | 2 | ||||
-rw-r--r-- | src/regexp.c | 4 | ||||
-rw-r--r-- | src/terminal.c | 2 | ||||
-rw-r--r-- | src/userfunc.c | 50 | ||||
-rw-r--r-- | src/version.c | 4 |
8 files changed, 47 insertions, 44 deletions
diff --git a/src/channel.c b/src/channel.c index a29414f69f..31c9bbe229 100644 --- a/src/channel.c +++ b/src/channel.c @@ -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); diff --git a/src/eval.c b/src/eval.c index fe8a8efe77..7df5455849 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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); diff --git a/src/evalfunc.c b/src/evalfunc.c index ff51d1210a..02ca1ae828 100644 --- a/src/evalfunc.c +++ b/src/evalfunc.c @@ -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]); diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c index 8bab8536b3..18c438ce0c 100644 --- a/src/ex_cmds2.c +++ b/src/ex_cmds2.c @@ -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); diff --git a/src/regexp.c b/src/regexp.c index ceeb899ad2..ee485a3ab5 100644 --- a/src/regexp.c +++ b/src/regexp.c @@ -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); } diff --git a/src/terminal.c b/src/terminal.c index f007bf23ae..bc57d641fa 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -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, diff --git a/src/userfunc.c b/src/userfunc.c index d8cbe635ee..4959b0d6a5 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -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) { diff --git a/src/version.c b/src/version.c index ea97befd37..7bcb8c8735 100644 --- a/src/version.c +++ b/src/version.c @@ -768,6 +768,10 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1319, +/**/ + 1318, +/**/ 1317, /**/ 1316, |