@@ -2580,6 +2580,40 @@ funcdepth_restore(int depth)
25802580 funcdepth = depth ;
25812581}
25822582
2583+ /*
2584+ * Allocate a funccall_T, link it in current_funccal and fill in "fp" and
2585+ * "rettv".
2586+ * Must be followed by one call to remove_funccal() or cleanup_function_call().
2587+ * Returns NULL when allocation fails.
2588+ */
2589+ funccall_T *
2590+ create_funccal (ufunc_T * fp , typval_T * rettv )
2591+ {
2592+ funccall_T * fc = ALLOC_CLEAR_ONE (funccall_T );
2593+
2594+ if (fc == NULL )
2595+ return NULL ;
2596+ fc -> fc_caller = current_funccal ;
2597+ current_funccal = fc ;
2598+ fc -> fc_func = fp ;
2599+ func_ptr_ref (fp );
2600+ fc -> fc_rettv = rettv ;
2601+ return fc ;
2602+ }
2603+
2604+ /*
2605+ * To be called when returning from a compiled function; restores
2606+ * current_funccal.
2607+ */
2608+ void
2609+ remove_funccal ()
2610+ {
2611+ funccall_T * fc = current_funccal ;
2612+
2613+ current_funccal = fc -> fc_caller ;
2614+ free_funccal (fc );
2615+ }
2616+
25832617/*
25842618 * Call a user function.
25852619 */
@@ -2627,20 +2661,15 @@ call_user_func(
26272661
26282662 line_breakcheck (); // check for CTRL-C hit
26292663
2630- fc = ALLOC_CLEAR_ONE ( funccall_T );
2664+ fc = create_funccal ( fp , rettv );
26312665 if (fc == NULL )
26322666 return ;
2633- fc -> fc_caller = current_funccal ;
2634- current_funccal = fc ;
2635- fc -> fc_func = fp ;
2636- fc -> fc_rettv = rettv ;
26372667 fc -> fc_level = ex_nesting_level ;
26382668 // Check if this function has a breakpoint.
26392669 fc -> fc_breakpoint = dbg_find_breakpoint (FALSE, fp -> uf_name , (linenr_T )0 );
26402670 fc -> fc_dbg_tick = debug_tick ;
26412671 // Set up fields for closure.
26422672 ga_init2 (& fc -> fc_ufuncs , sizeof (ufunc_T * ), 1 );
2643- func_ptr_ref (fp );
26442673
26452674 if (fp -> uf_def_status != UF_NOT_COMPILED )
26462675 {
@@ -2661,8 +2690,7 @@ call_user_func(
26612690 || (caller != NULL && caller -> uf_profiling )))
26622691 profile_may_end_func (& profile_info , fp , caller );
26632692#endif
2664- current_funccal = fc -> fc_caller ;
2665- free_funccal (fc );
2693+ remove_funccal ();
26662694 sticky_cmdmod_flags = save_sticky_cmdmod_flags ;
26672695 return ;
26682696 }
0 commit comments