comparison src/eval.c @ 1772:42ac369bd824 v7.2.070

updated for version 7.2-070
author vimboss
date Tue, 23 Dec 2008 22:52:58 +0000
parents 2a11407a5a8f
children 54d5eb36689f
comparison
equal deleted inserted replaced
1771:1f90fab89ce3 1772:42ac369bd824
29 #if defined(FEAT_FLOAT) && defined(HAVE_MATH_H) 29 #if defined(FEAT_FLOAT) && defined(HAVE_MATH_H)
30 # include <math.h> 30 # include <math.h>
31 #endif 31 #endif
32 32
33 #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */ 33 #define DICT_MAXNEST 100 /* maximum nesting of lists and dicts */
34
35 #define DO_NOT_FREE_CNT 99999 /* refcount for dict or list that should not
36 be freed. */
34 37
35 /* 38 /*
36 * In a hashtab item "hi_key" points to "di_key" in a dictitem. 39 * In a hashtab item "hi_key" points to "di_key" in a dictitem.
37 * This avoids adding a pointer to the hashtab item. 40 * This avoids adding a pointer to the hashtab item.
38 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer. 41 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
787 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); 790 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
788 static void func_free __ARGS((ufunc_T *fp)); 791 static void func_free __ARGS((ufunc_T *fp));
789 static void func_unref __ARGS((char_u *name)); 792 static void func_unref __ARGS((char_u *name));
790 static void func_ref __ARGS((char_u *name)); 793 static void func_ref __ARGS((char_u *name));
791 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict)); 794 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
795 static int can_free_funccal __ARGS((funccall_T *fc, int copyID)) ;
796 static void free_funccal __ARGS((funccall_T *fc, int free_val));
792 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr)); 797 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
793 static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp)); 798 static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp));
794 static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off)); 799 static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
795 static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos)); 800 static int searchpair_cmn __ARGS((typval_T *argvars, pos_T *match_pos));
796 static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp)); 801 static int search_cmn __ARGS((typval_T *argvars, pos_T *match_pos, int *flagsp));
920 return ((funccall_T *)cookie)->level; 925 return ((funccall_T *)cookie)->level;
921 } 926 }
922 927
923 /* pointer to funccal for currently active function */ 928 /* pointer to funccal for currently active function */
924 funccall_T *current_funccal = NULL; 929 funccall_T *current_funccal = NULL;
930
931 /* pointer to list of previously used funccal, still around because some
932 * item in it is still being used. */
933 funccall_T *previous_funccal = NULL;
925 934
926 /* 935 /*
927 * Return TRUE when a function was ended by a ":return" command. 936 * Return TRUE when a function was ended by a ":return" command.
928 */ 937 */
929 int 938 int
6488 list_T *ll; 6497 list_T *ll;
6489 int copyID = ++current_copyID; 6498 int copyID = ++current_copyID;
6490 buf_T *buf; 6499 buf_T *buf;
6491 win_T *wp; 6500 win_T *wp;
6492 int i; 6501 int i;
6493 funccall_T *fc; 6502 funccall_T *fc, **pfc;
6494 int did_free = FALSE; 6503 int did_free = FALSE;
6495 #ifdef FEAT_WINDOWS 6504 #ifdef FEAT_WINDOWS
6496 tabpage_T *tp; 6505 tabpage_T *tp;
6497 #endif 6506 #endif
6498 6507
6571 /* restart, next list may also have been freed */ 6580 /* restart, next list may also have been freed */
6572 ll = first_list; 6581 ll = first_list;
6573 } 6582 }
6574 else 6583 else
6575 ll = ll->lv_used_next; 6584 ll = ll->lv_used_next;
6585
6586 /* check if any funccal can be freed now */
6587 for (pfc = &previous_funccal; *pfc != NULL; )
6588 {
6589 if (can_free_funccal(*pfc, copyID))
6590 {
6591 fc = *pfc;
6592 *pfc = fc->caller;
6593 free_funccal(fc, TRUE);
6594 did_free = TRUE;
6595 }
6596 else
6597 pfc = &(*pfc)->caller;
6598 }
6576 6599
6577 return did_free; 6600 return did_free;
6578 } 6601 }
6579 6602
6580 /* 6603 /*
18960 init_var_dict(dict, dict_var) 18983 init_var_dict(dict, dict_var)
18961 dict_T *dict; 18984 dict_T *dict;
18962 dictitem_T *dict_var; 18985 dictitem_T *dict_var;
18963 { 18986 {
18964 hash_init(&dict->dv_hashtab); 18987 hash_init(&dict->dv_hashtab);
18965 dict->dv_refcount = 99999; 18988 dict->dv_refcount = DO_NOT_FREE_CNT;
18966 dict_var->di_tv.vval.v_dict = dict; 18989 dict_var->di_tv.vval.v_dict = dict;
18967 dict_var->di_tv.v_type = VAR_DICT; 18990 dict_var->di_tv.v_type = VAR_DICT;
18968 dict_var->di_tv.v_lock = VAR_FIXED; 18991 dict_var->di_tv.v_lock = VAR_FIXED;
18969 dict_var->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; 18992 dict_var->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
18970 dict_var->di_key[0] = NUL; 18993 dict_var->di_key[0] = NUL;
19297 19320
19298 /* 19321 /*
19299 * Copy the values from typval_T "from" to typval_T "to". 19322 * Copy the values from typval_T "from" to typval_T "to".
19300 * When needed allocates string or increases reference count. 19323 * When needed allocates string or increases reference count.
19301 * Does not make a copy of a list or dict but copies the reference! 19324 * Does not make a copy of a list or dict but copies the reference!
19325 * It is OK for "from" and "to" to point to the same item. This is used to
19326 * make a copy later.
19302 */ 19327 */
19303 static void 19328 static void
19304 copy_tv(from, to) 19329 copy_tv(from, to)
19305 typval_T *from; 19330 typval_T *from;
19306 typval_T *to; 19331 typval_T *to;
21109 dict_T *selfdict; /* Dictionary for "self" */ 21134 dict_T *selfdict; /* Dictionary for "self" */
21110 { 21135 {
21111 char_u *save_sourcing_name; 21136 char_u *save_sourcing_name;
21112 linenr_T save_sourcing_lnum; 21137 linenr_T save_sourcing_lnum;
21113 scid_T save_current_SID; 21138 scid_T save_current_SID;
21114 funccall_T fc; 21139 funccall_T *fc;
21115 int save_did_emsg; 21140 int save_did_emsg;
21116 static int depth = 0; 21141 static int depth = 0;
21117 dictitem_T *v; 21142 dictitem_T *v;
21118 int fixvar_idx = 0; /* index in fixvar[] */ 21143 int fixvar_idx = 0; /* index in fixvar[] */
21119 int i; 21144 int i;
21135 } 21160 }
21136 ++depth; 21161 ++depth;
21137 21162
21138 line_breakcheck(); /* check for CTRL-C hit */ 21163 line_breakcheck(); /* check for CTRL-C hit */
21139 21164
21140 fc.caller = current_funccal; 21165 fc = (funccall_T *)alloc(sizeof(funccall_T));
21141 current_funccal = &fc; 21166 fc->caller = current_funccal;
21142 fc.func = fp; 21167 current_funccal = fc;
21143 fc.rettv = rettv; 21168 fc->func = fp;
21169 fc->rettv = rettv;
21144 rettv->vval.v_number = 0; 21170 rettv->vval.v_number = 0;
21145 fc.linenr = 0; 21171 fc->linenr = 0;
21146 fc.returned = FALSE; 21172 fc->returned = FALSE;
21147 fc.level = ex_nesting_level; 21173 fc->level = ex_nesting_level;
21148 /* Check if this function has a breakpoint. */ 21174 /* Check if this function has a breakpoint. */
21149 fc.breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0); 21175 fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
21150 fc.dbg_tick = debug_tick; 21176 fc->dbg_tick = debug_tick;
21151 21177
21152 /* 21178 /*
21153 * Note about using fc.fixvar[]: This is an array of FIXVAR_CNT variables 21179 * Note about using fc->fixvar[]: This is an array of FIXVAR_CNT variables
21154 * with names up to VAR_SHORT_LEN long. This avoids having to alloc/free 21180 * with names up to VAR_SHORT_LEN long. This avoids having to alloc/free
21155 * each argument variable and saves a lot of time. 21181 * each argument variable and saves a lot of time.
21156 */ 21182 */
21157 /* 21183 /*
21158 * Init l: variables. 21184 * Init l: variables.
21159 */ 21185 */
21160 init_var_dict(&fc.l_vars, &fc.l_vars_var); 21186 init_var_dict(&fc->l_vars, &fc->l_vars_var);
21161 if (selfdict != NULL) 21187 if (selfdict != NULL)
21162 { 21188 {
21163 /* Set l:self to "selfdict". Use "name" to avoid a warning from 21189 /* Set l:self to "selfdict". Use "name" to avoid a warning from
21164 * some compiler that checks the destination size. */ 21190 * some compiler that checks the destination size. */
21165 v = &fc.fixvar[fixvar_idx++].var; 21191 v = &fc->fixvar[fixvar_idx++].var;
21166 name = v->di_key; 21192 name = v->di_key;
21167 STRCPY(name, "self"); 21193 STRCPY(name, "self");
21168 v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX; 21194 v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
21169 hash_add(&fc.l_vars.dv_hashtab, DI2HIKEY(v)); 21195 hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
21170 v->di_tv.v_type = VAR_DICT; 21196 v->di_tv.v_type = VAR_DICT;
21171 v->di_tv.v_lock = 0; 21197 v->di_tv.v_lock = 0;
21172 v->di_tv.vval.v_dict = selfdict; 21198 v->di_tv.vval.v_dict = selfdict;
21173 ++selfdict->dv_refcount; 21199 ++selfdict->dv_refcount;
21174 } 21200 }
21176 /* 21202 /*
21177 * Init a: variables. 21203 * Init a: variables.
21178 * Set a:0 to "argcount". 21204 * Set a:0 to "argcount".
21179 * Set a:000 to a list with room for the "..." arguments. 21205 * Set a:000 to a list with room for the "..." arguments.
21180 */ 21206 */
21181 init_var_dict(&fc.l_avars, &fc.l_avars_var); 21207 init_var_dict(&fc->l_avars, &fc->l_avars_var);
21182 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "0", 21208 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
21183 (varnumber_T)(argcount - fp->uf_args.ga_len)); 21209 (varnumber_T)(argcount - fp->uf_args.ga_len));
21184 /* Use "name" to avoid a warning from some compiler that checks the 21210 /* Use "name" to avoid a warning from some compiler that checks the
21185 * destination size. */ 21211 * destination size. */
21186 v = &fc.fixvar[fixvar_idx++].var; 21212 v = &fc->fixvar[fixvar_idx++].var;
21187 name = v->di_key; 21213 name = v->di_key;
21188 STRCPY(name, "000"); 21214 STRCPY(name, "000");
21189 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; 21215 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
21190 hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v)); 21216 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21191 v->di_tv.v_type = VAR_LIST; 21217 v->di_tv.v_type = VAR_LIST;
21192 v->di_tv.v_lock = VAR_FIXED; 21218 v->di_tv.v_lock = VAR_FIXED;
21193 v->di_tv.vval.v_list = &fc.l_varlist; 21219 v->di_tv.vval.v_list = &fc->l_varlist;
21194 vim_memset(&fc.l_varlist, 0, sizeof(list_T)); 21220 vim_memset(&fc->l_varlist, 0, sizeof(list_T));
21195 fc.l_varlist.lv_refcount = 99999; 21221 fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
21196 fc.l_varlist.lv_lock = VAR_FIXED; 21222 fc->l_varlist.lv_lock = VAR_FIXED;
21197 21223
21198 /* 21224 /*
21199 * Set a:firstline to "firstline" and a:lastline to "lastline". 21225 * Set a:firstline to "firstline" and a:lastline to "lastline".
21200 * Set a:name to named arguments. 21226 * Set a:name to named arguments.
21201 * Set a:N to the "..." arguments. 21227 * Set a:N to the "..." arguments.
21202 */ 21228 */
21203 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "firstline", 21229 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline",
21204 (varnumber_T)firstline); 21230 (varnumber_T)firstline);
21205 add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "lastline", 21231 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
21206 (varnumber_T)lastline); 21232 (varnumber_T)lastline);
21207 for (i = 0; i < argcount; ++i) 21233 for (i = 0; i < argcount; ++i)
21208 { 21234 {
21209 ai = i - fp->uf_args.ga_len; 21235 ai = i - fp->uf_args.ga_len;
21210 if (ai < 0) 21236 if (ai < 0)
21216 sprintf((char *)numbuf, "%d", ai + 1); 21242 sprintf((char *)numbuf, "%d", ai + 1);
21217 name = numbuf; 21243 name = numbuf;
21218 } 21244 }
21219 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN) 21245 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
21220 { 21246 {
21221 v = &fc.fixvar[fixvar_idx++].var; 21247 v = &fc->fixvar[fixvar_idx++].var;
21222 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; 21248 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
21223 } 21249 }
21224 else 21250 else
21225 { 21251 {
21226 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T) 21252 v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
21228 if (v == NULL) 21254 if (v == NULL)
21229 break; 21255 break;
21230 v->di_flags = DI_FLAGS_RO; 21256 v->di_flags = DI_FLAGS_RO;
21231 } 21257 }
21232 STRCPY(v->di_key, name); 21258 STRCPY(v->di_key, name);
21233 hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v)); 21259 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21234 21260
21235 /* Note: the values are copied directly to avoid alloc/free. 21261 /* Note: the values are copied directly to avoid alloc/free.
21236 * "argvars" must have VAR_FIXED for v_lock. */ 21262 * "argvars" must have VAR_FIXED for v_lock. */
21237 v->di_tv = argvars[i]; 21263 v->di_tv = argvars[i];
21238 v->di_tv.v_lock = VAR_FIXED; 21264 v->di_tv.v_lock = VAR_FIXED;
21239 21265
21240 if (ai >= 0 && ai < MAX_FUNC_ARGS) 21266 if (ai >= 0 && ai < MAX_FUNC_ARGS)
21241 { 21267 {
21242 list_append(&fc.l_varlist, &fc.l_listitems[ai]); 21268 list_append(&fc->l_varlist, &fc->l_listitems[ai]);
21243 fc.l_listitems[ai].li_tv = argvars[i]; 21269 fc->l_listitems[ai].li_tv = argvars[i];
21244 fc.l_listitems[ai].li_tv.v_lock = VAR_FIXED; 21270 fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
21245 } 21271 }
21246 } 21272 }
21247 21273
21248 /* Don't redraw while executing the function. */ 21274 /* Don't redraw while executing the function. */
21249 ++RedrawingDisabled; 21275 ++RedrawingDisabled;
21304 if (do_profiling == PROF_YES) 21330 if (do_profiling == PROF_YES)
21305 { 21331 {
21306 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL)) 21332 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
21307 func_do_profile(fp); 21333 func_do_profile(fp);
21308 if (fp->uf_profiling 21334 if (fp->uf_profiling
21309 || (fc.caller != NULL && fc.caller->func->uf_profiling)) 21335 || (fc->caller != NULL && fc->caller->func->uf_profiling))
21310 { 21336 {
21311 ++fp->uf_tm_count; 21337 ++fp->uf_tm_count;
21312 profile_start(&call_start); 21338 profile_start(&call_start);
21313 profile_zero(&fp->uf_tm_children); 21339 profile_zero(&fp->uf_tm_children);
21314 } 21340 }
21320 current_SID = fp->uf_script_ID; 21346 current_SID = fp->uf_script_ID;
21321 save_did_emsg = did_emsg; 21347 save_did_emsg = did_emsg;
21322 did_emsg = FALSE; 21348 did_emsg = FALSE;
21323 21349
21324 /* call do_cmdline() to execute the lines */ 21350 /* call do_cmdline() to execute the lines */
21325 do_cmdline(NULL, get_func_line, (void *)&fc, 21351 do_cmdline(NULL, get_func_line, (void *)fc,
21326 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); 21352 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
21327 21353
21328 --RedrawingDisabled; 21354 --RedrawingDisabled;
21329 21355
21330 /* when the function was aborted because of an error, return -1 */ 21356 /* when the function was aborted because of an error, return -1 */
21335 rettv->vval.v_number = -1; 21361 rettv->vval.v_number = -1;
21336 } 21362 }
21337 21363
21338 #ifdef FEAT_PROFILE 21364 #ifdef FEAT_PROFILE
21339 if (do_profiling == PROF_YES && (fp->uf_profiling 21365 if (do_profiling == PROF_YES && (fp->uf_profiling
21340 || (fc.caller != NULL && fc.caller->func->uf_profiling))) 21366 || (fc->caller != NULL && fc->caller->func->uf_profiling)))
21341 { 21367 {
21342 profile_end(&call_start); 21368 profile_end(&call_start);
21343 profile_sub_wait(&wait_start, &call_start); 21369 profile_sub_wait(&wait_start, &call_start);
21344 profile_add(&fp->uf_tm_total, &call_start); 21370 profile_add(&fp->uf_tm_total, &call_start);
21345 profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children); 21371 profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
21346 if (fc.caller != NULL && fc.caller->func->uf_profiling) 21372 if (fc->caller != NULL && fc->caller->func->uf_profiling)
21347 { 21373 {
21348 profile_add(&fc.caller->func->uf_tm_children, &call_start); 21374 profile_add(&fc->caller->func->uf_tm_children, &call_start);
21349 profile_add(&fc.caller->func->uf_tml_children, &call_start); 21375 profile_add(&fc->caller->func->uf_tml_children, &call_start);
21350 } 21376 }
21351 } 21377 }
21352 #endif 21378 #endif
21353 21379
21354 /* when being verbose, mention the return value */ 21380 /* when being verbose, mention the return value */
21357 ++no_wait_return; 21383 ++no_wait_return;
21358 verbose_enter_scroll(); 21384 verbose_enter_scroll();
21359 21385
21360 if (aborting()) 21386 if (aborting())
21361 smsg((char_u *)_("%s aborted"), sourcing_name); 21387 smsg((char_u *)_("%s aborted"), sourcing_name);
21362 else if (fc.rettv->v_type == VAR_NUMBER) 21388 else if (fc->rettv->v_type == VAR_NUMBER)
21363 smsg((char_u *)_("%s returning #%ld"), sourcing_name, 21389 smsg((char_u *)_("%s returning #%ld"), sourcing_name,
21364 (long)fc.rettv->vval.v_number); 21390 (long)fc->rettv->vval.v_number);
21365 else 21391 else
21366 { 21392 {
21367 char_u buf[MSG_BUF_LEN]; 21393 char_u buf[MSG_BUF_LEN];
21368 char_u numbuf2[NUMBUFLEN]; 21394 char_u numbuf2[NUMBUFLEN];
21369 char_u *tofree; 21395 char_u *tofree;
21370 char_u *s; 21396 char_u *s;
21371 21397
21372 /* The value may be very long. Skip the middle part, so that we 21398 /* The value may be very long. Skip the middle part, so that we
21373 * have some idea how it starts and ends. smsg() would always 21399 * have some idea how it starts and ends. smsg() would always
21374 * truncate it at the end. */ 21400 * truncate it at the end. */
21375 s = tv2string(fc.rettv, &tofree, numbuf2, 0); 21401 s = tv2string(fc->rettv, &tofree, numbuf2, 0);
21376 if (s != NULL) 21402 if (s != NULL)
21377 { 21403 {
21378 trunc_string(s, buf, MSG_BUF_CLEN); 21404 trunc_string(s, buf, MSG_BUF_CLEN);
21379 smsg((char_u *)_("%s returning %s"), sourcing_name, buf); 21405 smsg((char_u *)_("%s returning %s"), sourcing_name, buf);
21380 vim_free(tofree); 21406 vim_free(tofree);
21406 verbose_leave_scroll(); 21432 verbose_leave_scroll();
21407 --no_wait_return; 21433 --no_wait_return;
21408 } 21434 }
21409 21435
21410 did_emsg |= save_did_emsg; 21436 did_emsg |= save_did_emsg;
21411 current_funccal = fc.caller; 21437 current_funccal = fc->caller;
21412
21413 /* The a: variables typevals were not allocated, only free the allocated
21414 * variables. */
21415 vars_clear_ext(&fc.l_avars.dv_hashtab, FALSE);
21416
21417 vars_clear(&fc.l_vars.dv_hashtab); /* free all l: variables */
21418 --depth; 21438 --depth;
21439
21440 /* if the a:000 list and the a: dict are not referenced we can free the
21441 * funccall_T and what's in it. */
21442 if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
21443 && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
21444 && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
21445 {
21446 free_funccal(fc, FALSE);
21447 }
21448 else
21449 {
21450 hashitem_T *hi;
21451 listitem_T *li;
21452 int todo;
21453
21454 /* "fc" is still in use. This can happen when returning "a:000" or
21455 * assigning "l:" to a global variable.
21456 * Link "fc" in the list for garbage collection later. */
21457 fc->caller = previous_funccal;
21458 previous_funccal = fc;
21459
21460 /* Make a copy of the a: variables, since we didn't do that above. */
21461 todo = (int)fc->l_avars.dv_hashtab.ht_used;
21462 for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
21463 {
21464 if (!HASHITEM_EMPTY(hi))
21465 {
21466 --todo;
21467 v = HI2DI(hi);
21468 copy_tv(&v->di_tv, &v->di_tv);
21469 }
21470 }
21471
21472 /* Make a copy of the a:000 items, since we didn't do that above. */
21473 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
21474 copy_tv(&li->li_tv, &li->li_tv);
21475 }
21476 }
21477
21478 /*
21479 * Return TRUE if items in "fc" do not have "copyID". That means they are not
21480 * referenced from anywyere.
21481 */
21482 static int
21483 can_free_funccal(fc, copyID)
21484 funccall_T *fc;
21485 int copyID;
21486 {
21487 return (fc->l_varlist.lv_copyID != copyID
21488 && fc->l_vars.dv_copyID != copyID
21489 && fc->l_avars.dv_copyID != copyID);
21490 }
21491
21492 /*
21493 * Free "fc" and what it contains.
21494 */
21495 static void
21496 free_funccal(fc, free_val)
21497 funccall_T *fc;
21498 int free_val; /* a: vars were allocated */
21499 {
21500 listitem_T *li;
21501
21502 /* The a: variables typevals may not have been allocated, only free the
21503 * allocated variables. */
21504 vars_clear_ext(&fc->l_avars.dv_hashtab, free_val);
21505
21506 /* free all l: variables */
21507 vars_clear(&fc->l_vars.dv_hashtab);
21508
21509 /* Free the a:000 variables if they were allocated. */
21510 if (free_val)
21511 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
21512 clear_tv(&li->li_tv);
21513
21514 vim_free(fc);
21419 } 21515 }
21420 21516
21421 /* 21517 /*
21422 * Add a number variable "name" to dict "dp" with value "nr". 21518 * Add a number variable "name" to dict "dp" with value "nr".
21423 */ 21519 */