comparison src/userfunc.c @ 27114:98a01021e465 v8.2.4086

patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused Commit: https://github.com/vim/vim/commit/d9d2fd0aa33dd9f7460d6f1e403505a60f7ce2fc Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jan 13 21:15:21 2022 +0000 patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused Problem: "cctx" argument of find_func_even_dead() is unused. Solution: Remove the argument.
author Bram Moolenaar <Bram@vim.org>
date Thu, 13 Jan 2022 22:30:05 +0100
parents 6d063974af23
children 374c7d5a096a
comparison
equal deleted inserted replaced
27113:93194ce58678 27114:98a01021e465
1932 * Find a function by name, return pointer to it in ufuncs. 1932 * Find a function by name, return pointer to it in ufuncs.
1933 * When "is_global" is true don't find script-local or imported functions. 1933 * When "is_global" is true don't find script-local or imported functions.
1934 * Return NULL for unknown function. 1934 * Return NULL for unknown function.
1935 */ 1935 */
1936 ufunc_T * 1936 ufunc_T *
1937 find_func_even_dead(char_u *name, int is_global, cctx_T *cctx UNUSED) 1937 find_func_even_dead(char_u *name, int is_global)
1938 { 1938 {
1939 hashitem_T *hi; 1939 hashitem_T *hi;
1940 ufunc_T *func; 1940 ufunc_T *func;
1941 1941
1942 if (!is_global) 1942 if (!is_global)
1968 * Find a function by name, return pointer to it in ufuncs. 1968 * Find a function by name, return pointer to it in ufuncs.
1969 * "cctx" is passed in a :def function to find imported functions. 1969 * "cctx" is passed in a :def function to find imported functions.
1970 * Return NULL for unknown or dead function. 1970 * Return NULL for unknown or dead function.
1971 */ 1971 */
1972 ufunc_T * 1972 ufunc_T *
1973 find_func(char_u *name, int is_global, cctx_T *cctx) 1973 find_func(char_u *name, int is_global)
1974 { 1974 {
1975 ufunc_T *fp = find_func_even_dead(name, is_global, cctx); 1975 ufunc_T *fp = find_func_even_dead(name, is_global);
1976 1976
1977 if (fp != NULL && (fp->uf_flags & FC_DEAD) == 0) 1977 if (fp != NULL && (fp->uf_flags & FC_DEAD) == 0)
1978 return fp; 1978 return fp;
1979 return NULL; 1979 return NULL;
1980 } 1980 }
2341 * This is for when a compiled function defines a global function. 2341 * This is for when a compiled function defines a global function.
2342 */ 2342 */
2343 int 2343 int
2344 copy_func(char_u *lambda, char_u *global, ectx_T *ectx) 2344 copy_func(char_u *lambda, char_u *global, ectx_T *ectx)
2345 { 2345 {
2346 ufunc_T *ufunc = find_func_even_dead(lambda, TRUE, NULL); 2346 ufunc_T *ufunc = find_func_even_dead(lambda, TRUE);
2347 ufunc_T *fp = NULL; 2347 ufunc_T *fp = NULL;
2348 2348
2349 if (ufunc == NULL) 2349 if (ufunc == NULL)
2350 { 2350 {
2351 semsg(_(e_lambda_function_not_found_str), lambda); 2351 semsg(_(e_lambda_function_not_found_str), lambda);
2352 return FAIL; 2352 return FAIL;
2353 } 2353 }
2354 2354
2355 fp = find_func(global, TRUE, NULL); 2355 fp = find_func(global, TRUE);
2356 if (fp != NULL) 2356 if (fp != NULL)
2357 { 2357 {
2358 // TODO: handle ! to overwrite 2358 // TODO: handle ! to overwrite
2359 semsg(_(e_function_str_already_exists_add_bang_to_replace), global); 2359 semsg(_(e_function_str_already_exists_add_bang_to_replace), global);
2360 return FAIL; 2360 return FAIL;
3411 { 3411 {
3412 /* 3412 /*
3413 * User defined function. 3413 * User defined function.
3414 */ 3414 */
3415 if (fp == NULL) 3415 if (fp == NULL)
3416 fp = find_func(rfname, is_global, NULL); 3416 fp = find_func(rfname, is_global);
3417 3417
3418 // Trigger FuncUndefined event, may load the function. 3418 // Trigger FuncUndefined event, may load the function.
3419 if (fp == NULL 3419 if (fp == NULL
3420 && apply_autocmds(EVENT_FUNCUNDEFINED, 3420 && apply_autocmds(EVENT_FUNCUNDEFINED,
3421 rfname, rfname, TRUE, NULL) 3421 rfname, rfname, TRUE, NULL)
3422 && !aborting()) 3422 && !aborting())
3423 { 3423 {
3424 // executed an autocommand, search for the function again 3424 // executed an autocommand, search for the function again
3425 fp = find_func(rfname, is_global, NULL); 3425 fp = find_func(rfname, is_global);
3426 } 3426 }
3427 // Try loading a package. 3427 // Try loading a package.
3428 if (fp == NULL && script_autoload(rfname, TRUE) && !aborting()) 3428 if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
3429 { 3429 {
3430 // loaded a package, search for the function again 3430 // loaded a package, search for the function again
3431 fp = find_func(rfname, is_global, NULL); 3431 fp = find_func(rfname, is_global);
3432 } 3432 }
3433 if (fp == NULL) 3433 if (fp == NULL)
3434 { 3434 {
3435 char_u *p = untrans_function_name(rfname); 3435 char_u *p = untrans_function_name(rfname);
3436 3436
3437 // If using Vim9 script try not local to the script. 3437 // If using Vim9 script try not local to the script.
3438 // Don't do this if the name starts with "s:". 3438 // Don't do this if the name starts with "s:".
3439 if (p != NULL && (funcname[0] != 's' || funcname[1] != ':')) 3439 if (p != NULL && (funcname[0] != 's' || funcname[1] != ':'))
3440 fp = find_func(p, is_global, NULL); 3440 fp = find_func(p, is_global);
3441 } 3441 }
3442 3442
3443 if (fp != NULL && (fp->uf_flags & FC_DELETED)) 3443 if (fp != NULL && (fp->uf_flags & FC_DELETED))
3444 error = FCERR_DELETED; 3444 error = FCERR_DELETED;
3445 #ifdef FEAT_LUA 3445 #ifdef FEAT_LUA
4178 set_nextcmd(eap, p); 4178 set_nextcmd(eap, p);
4179 if (eap->nextcmd != NULL) 4179 if (eap->nextcmd != NULL)
4180 *p = NUL; 4180 *p = NUL;
4181 if (!eap->skip && !got_int) 4181 if (!eap->skip && !got_int)
4182 { 4182 {
4183 fp = find_func(name, is_global, NULL); 4183 fp = find_func(name, is_global);
4184 if (fp == NULL && ASCII_ISUPPER(*eap->arg)) 4184 if (fp == NULL && ASCII_ISUPPER(*eap->arg))
4185 { 4185 {
4186 char_u *up = untrans_function_name(name); 4186 char_u *up = untrans_function_name(name);
4187 4187
4188 // With Vim9 script the name was made script-local, if not 4188 // With Vim9 script the name was made script-local, if not
4189 // found try again with the original name. 4189 // found try again with the original name.
4190 if (up != NULL) 4190 if (up != NULL)
4191 fp = find_func(up, FALSE, NULL); 4191 fp = find_func(up, FALSE);
4192 } 4192 }
4193 4193
4194 if (fp != NULL) 4194 if (fp != NULL)
4195 { 4195 {
4196 list_func_head(fp, TRUE); 4196 list_func_head(fp, TRUE);
4401 // need to skip the body to be able to find what follows. 4401 // need to skip the body to be able to find what follows.
4402 if (!eap->skip && !eap->forceit) 4402 if (!eap->skip && !eap->forceit)
4403 { 4403 {
4404 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) 4404 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL)
4405 emsg(_(e_dictionary_entry_already_exists)); 4405 emsg(_(e_dictionary_entry_already_exists));
4406 else if (name != NULL && find_func(name, is_global, NULL) != NULL) 4406 else if (name != NULL && find_func(name, is_global) != NULL)
4407 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name); 4407 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name);
4408 } 4408 }
4409 4409
4410 if (!eap->skip && did_emsg) 4410 if (!eap->skip && did_emsg)
4411 goto erret; 4411 goto erret;
4435 { 4435 {
4436 emsg_funcname(e_function_name_conflicts_with_variable_str, name); 4436 emsg_funcname(e_function_name_conflicts_with_variable_str, name);
4437 goto erret; 4437 goto erret;
4438 } 4438 }
4439 4439
4440 fp = find_func_even_dead(name, is_global, NULL); 4440 fp = find_func_even_dead(name, is_global);
4441 if (vim9script) 4441 if (vim9script)
4442 { 4442 {
4443 char_u *uname = untrans_function_name(name); 4443 char_u *uname = untrans_function_name(name);
4444 4444
4445 import = find_imported(uname == NULL ? name : uname, 0, FALSE, NULL); 4445 import = find_imported(uname == NULL ? name : uname, 0, FALSE, NULL);
4790 int 4790 int
4791 translated_function_exists(char_u *name, int is_global) 4791 translated_function_exists(char_u *name, int is_global)
4792 { 4792 {
4793 if (builtin_function(name, -1)) 4793 if (builtin_function(name, -1))
4794 return has_internal_func(name); 4794 return has_internal_func(name);
4795 return find_func(name, is_global, NULL) != NULL; 4795 return find_func(name, is_global) != NULL;
4796 } 4796 }
4797 4797
4798 /* 4798 /*
4799 * Return TRUE when "ufunc" has old-style "..." varargs 4799 * Return TRUE when "ufunc" has old-style "..." varargs
4800 * or named varargs "...name: type". 4800 * or named varargs "...name: type".
4937 semsg(_(e_invalid_argument_str), eap->arg); 4937 semsg(_(e_invalid_argument_str), eap->arg);
4938 vim_free(name); 4938 vim_free(name);
4939 return; 4939 return;
4940 } 4940 }
4941 if (!eap->skip) 4941 if (!eap->skip)
4942 fp = find_func(name, is_global, NULL); 4942 fp = find_func(name, is_global);
4943 vim_free(name); 4943 vim_free(name);
4944 4944
4945 if (!eap->skip) 4945 if (!eap->skip)
4946 { 4946 {
4947 if (fp == NULL) 4947 if (fp == NULL)
4996 { 4996 {
4997 ufunc_T *fp = NULL; 4997 ufunc_T *fp = NULL;
4998 4998
4999 if (name == NULL || !func_name_refcount(name)) 4999 if (name == NULL || !func_name_refcount(name))
5000 return; 5000 return;
5001 fp = find_func(name, FALSE, NULL); 5001 fp = find_func(name, FALSE);
5002 if (fp == NULL && numbered_function(name)) 5002 if (fp == NULL && numbered_function(name))
5003 { 5003 {
5004 #ifdef EXITFREE 5004 #ifdef EXITFREE
5005 if (!entered_free_all_mem) 5005 if (!entered_free_all_mem)
5006 #endif 5006 #endif
5037 { 5037 {
5038 ufunc_T *fp; 5038 ufunc_T *fp;
5039 5039
5040 if (name == NULL || !func_name_refcount(name)) 5040 if (name == NULL || !func_name_refcount(name))
5041 return; 5041 return;
5042 fp = find_func(name, FALSE, NULL); 5042 fp = find_func(name, FALSE);
5043 if (fp != NULL) 5043 if (fp != NULL)
5044 ++fp->uf_refcount; 5044 ++fp->uf_refcount;
5045 else if (numbered_function(name)) 5045 else if (numbered_function(name))
5046 // Only give an error for a numbered function. 5046 // Only give an error for a numbered function.
5047 // Fail silently, when named or lambda function isn't found. 5047 // Fail silently, when named or lambda function isn't found.
5532 { 5532 {
5533 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string 5533 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
5534 : rettv->vval.v_partial->pt_name; 5534 : rettv->vval.v_partial->pt_name;
5535 // Translate "s:func" to the stored function name. 5535 // Translate "s:func" to the stored function name.
5536 fname = fname_trans_sid(fname, fname_buf, &tofree, &error); 5536 fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
5537 fp = find_func(fname, FALSE, NULL); 5537 fp = find_func(fname, FALSE);
5538 vim_free(tofree); 5538 vim_free(tofree);
5539 } 5539 }
5540 5540
5541 if (fp != NULL && (fp->uf_flags & FC_DICT)) 5541 if (fp != NULL && (fp->uf_flags & FC_DICT))
5542 { 5542 {
5951 return FALSE; 5951 return FALSE;
5952 5952
5953 if (fp_in == NULL) 5953 if (fp_in == NULL)
5954 { 5954 {
5955 fname = fname_trans_sid(name, fname_buf, &tofree, &error); 5955 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
5956 fp = find_func(fname, FALSE, NULL); 5956 fp = find_func(fname, FALSE);
5957 } 5957 }
5958 if (fp != NULL) 5958 if (fp != NULL)
5959 { 5959 {
5960 for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped) 5960 for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped)
5961 abort = abort || set_ref_in_funccal(fc, copyID); 5961 abort = abort || set_ref_in_funccal(fc, copyID);