~ubuntu-branches/ubuntu/maverick/vim/maverick

« back to all changes in this revision

Viewing changes to src/eval.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2009-01-13 18:39:18 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090113183918-kgq1jzdwsbbex4pq
Tags: 2:7.2.079-1ubuntu1
* Resynchronise with Debian (diversions fix closes LP: #296324). Remaining
  changes:
  - runtime/syntax/debcontrol.vim:
    + Add "metapackages" to the list of valid sections.
  - runtime/syntax/debchangelog.vim:
    + Add "jaunty" to the list of valid suites.
  - Drop vim-lesstif package and lesstif2-dev build-dependency.
  - Enable Python interpreter on basic builds.
  - Create a .pot file for translations.
  - Disable autoindent, line-wrapping, and backup files by default.
  - runtime/syntax/debsources.vim:
    + Add "jaunty" to debsourcesDistrKeyword
  - runtime/syntax/grub.vim:
    + Add Ubuntu-specific 'quiet' keyword.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
#define DICT_MAXNEST 100        /* maximum nesting of lists and dicts */
34
34
 
 
35
#define DO_NOT_FREE_CNT 99999   /* refcount for dict or list that should not
 
36
                                   be freed. */
 
37
 
35
38
/*
36
39
 * In a hashtab item "hi_key" points to "di_key" in a dictitem.
37
40
 * This avoids adding a pointer to the hashtab item.
348
351
    {VV_NAME("mouse_col",        VAR_NUMBER), 0},
349
352
    {VV_NAME("operator",         VAR_STRING), VV_RO},
350
353
    {VV_NAME("searchforward",    VAR_NUMBER), 0},
 
354
    {VV_NAME("oldfiles",         VAR_LIST), 0},
351
355
};
352
356
 
353
357
/* shorthand */
355
359
#define vv_nr           vv_di.di_tv.vval.v_number
356
360
#define vv_float        vv_di.di_tv.vval.v_float
357
361
#define vv_str          vv_di.di_tv.vval.v_string
 
362
#define vv_list         vv_di.di_tv.vval.v_list
358
363
#define vv_tv           vv_di.di_tv
359
364
 
360
365
/*
426
431
static long list_idx_of_item __ARGS((list_T *l, listitem_T *item));
427
432
static void list_append __ARGS((list_T *l, listitem_T *item));
428
433
static int list_append_tv __ARGS((list_T *l, typval_T *tv));
429
 
static int list_append_string __ARGS((list_T *l, char_u *str, int len));
430
434
static int list_append_number __ARGS((list_T *l, varnumber_T n));
431
435
static int list_insert_tv __ARGS((list_T *l, typval_T *tv, listitem_T *item));
432
436
static int list_extend __ARGS((list_T   *l1, list_T *l2, listitem_T *bef));
788
792
static void func_unref __ARGS((char_u *name));
789
793
static void func_ref __ARGS((char_u *name));
790
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));
791
797
static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
792
798
static win_T *find_win_by_nr __ARGS((typval_T *vp, tabpage_T *tp));
793
799
static void getwinvar __ARGS((typval_T *argvars, typval_T *rettv, int off));
845
851
        p = &vimvars[i];
846
852
        if (p->vv_di.di_tv.v_type == VAR_STRING)
847
853
        {
848
 
            vim_free(p->vv_di.di_tv.vval.v_string);
849
 
            p->vv_di.di_tv.vval.v_string = NULL;
 
854
            vim_free(p->vv_str);
 
855
            p->vv_str = NULL;
 
856
        }
 
857
        else if (p->vv_di.di_tv.v_type == VAR_LIST)
 
858
        {
 
859
            list_unref(p->vv_list);
 
860
            p->vv_list = NULL;
850
861
        }
851
862
    }
852
863
    hash_clear(&vimvarht);
 
864
    hash_init(&vimvarht);  /* garbage_collect() will access it */
853
865
    hash_clear(&compat_hashtab);
854
866
 
855
867
    /* script-local variables */
916
928
/* pointer to funccal for currently active function */
917
929
funccall_T *current_funccal = NULL;
918
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;
 
934
 
919
935
/*
920
936
 * Return TRUE when a function was ended by a ":return" command.
921
937
 */
3287
3303
 
3288
3304
    if (*startarg != '(')
3289
3305
    {
3290
 
        EMSG2(_("E107: Missing braces: %s"), eap->arg);
 
3306
        EMSG2(_("E107: Missing parentheses: %s"), eap->arg);
3291
3307
        goto end;
3292
3308
    }
3293
3309
 
6057
6073
}
6058
6074
 
6059
6075
/*
 
6076
 * Get list item "l[idx - 1]" as a string.  Returns NULL for failure.
 
6077
 */
 
6078
    char_u *
 
6079
list_find_str(l, idx)
 
6080
    list_T      *l;
 
6081
    long        idx;
 
6082
{
 
6083
    listitem_T  *li;
 
6084
 
 
6085
    li = list_find(l, idx - 1);
 
6086
    if (li == NULL)
 
6087
    {
 
6088
        EMSGN(_(e_listidx), idx);
 
6089
        return NULL;
 
6090
    }
 
6091
    return get_tv_string(&li->li_tv);
 
6092
}
 
6093
 
 
6094
/*
6060
6095
 * Locate "item" list "l" and return its index.
6061
6096
 * Returns -1 when "item" is not in the list.
6062
6097
 */
6147
6182
 * When "len" >= 0 use "str[len]".
6148
6183
 * Returns FAIL when out of memory.
6149
6184
 */
6150
 
    static int
 
6185
    int
6151
6186
list_append_string(l, str, len)
6152
6187
    list_T      *l;
6153
6188
    char_u      *str;
6464
6499
    buf_T       *buf;
6465
6500
    win_T       *wp;
6466
6501
    int         i;
6467
 
    funccall_T  *fc;
 
6502
    funccall_T  *fc, **pfc;
6468
6503
    int         did_free = FALSE;
6469
6504
#ifdef FEAT_WINDOWS
6470
6505
    tabpage_T   *tp;
6507
6542
        set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID);
6508
6543
    }
6509
6544
 
 
6545
    /* v: vars */
 
6546
    set_ref_in_ht(&vimvarht, copyID);
 
6547
 
6510
6548
    /*
6511
6549
     * 2. Go through the list of dicts and free items without the copyID.
6512
6550
     */
6545
6583
        else
6546
6584
            ll = ll->lv_used_next;
6547
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
    }
 
6599
 
6548
6600
    return did_free;
6549
6601
}
6550
6602
 
6597
6649
    {
6598
6650
        case VAR_DICT:
6599
6651
            dd = tv->vval.v_dict;
6600
 
            if (dd->dv_copyID != copyID)
 
6652
            if (dd != NULL && dd->dv_copyID != copyID)
6601
6653
            {
6602
6654
                /* Didn't see this dict yet. */
6603
6655
                dd->dv_copyID = copyID;
6607
6659
 
6608
6660
        case VAR_LIST:
6609
6661
            ll = tv->vval.v_list;
6610
 
            if (ll->lv_copyID != copyID)
 
6662
            if (ll != NULL && ll->lv_copyID != copyID)
6611
6663
            {
6612
6664
                /* Didn't see this list yet. */
6613
6665
                ll->lv_copyID = copyID;
7535
7587
    {"getwinposx",      0, 0, f_getwinposx},
7536
7588
    {"getwinposy",      0, 0, f_getwinposy},
7537
7589
    {"getwinvar",       2, 2, f_getwinvar},
7538
 
    {"glob",            1, 1, f_glob},
7539
 
    {"globpath",        2, 2, f_globpath},
 
7590
    {"glob",            1, 2, f_glob},
 
7591
    {"globpath",        2, 3, f_globpath},
7540
7592
    {"has",             1, 1, f_has},
7541
7593
    {"has_key",         2, 2, f_has_key},
7542
7594
    {"haslocaldir",     0, 0, f_haslocaldir},
9528
9580
    else
9529
9581
    {
9530
9582
        /* When the optional second argument is non-zero, don't remove matches
9531
 
         * for 'suffixes' and 'wildignore' */
 
9583
         * for 'wildignore' and don't put matches for 'suffixes' at the end. */
9532
9584
        if (argvars[1].v_type != VAR_UNKNOWN
9533
9585
                                    && get_tv_number_chk(&argvars[1], &error))
9534
9586
            flags |= WILD_KEEP_ALL;
10310
10362
    s = get_tv_string(&argvars[0]);
10311
10363
    if (s == NULL || *s == NUL || VIM_ISDIGIT(*s))
10312
10364
        EMSG2(_(e_invarg2), s);
10313
 
    else if (!function_exists(s))
 
10365
    /* Don't check an autoload name for existence here. */
 
10366
    else if (vim_strchr(s, AUTOLOAD_CHAR) == NULL && !function_exists(s))
10314
10367
        EMSG2(_("E700: Unknown function: %s"), s);
10315
10368
    else
10316
10369
    {
10612
10665
# ifdef FEAT_WINDOWS
10613
10666
            win_T       *wp;
10614
10667
# endif
10615
 
            int         n = 1;
 
10668
            int         winnr = 1;
10616
10669
 
10617
10670
            if (row >= 0 && col >= 0)
10618
10671
            {
10622
10675
                (void)mouse_comp_pos(win, &row, &col, &lnum);
10623
10676
# ifdef FEAT_WINDOWS
10624
10677
                for (wp = firstwin; wp != win; wp = wp->w_next)
10625
 
                    ++n;
 
10678
                    ++winnr;
10626
10679
# endif
10627
 
                vimvars[VV_MOUSE_WIN].vv_nr = n;
 
10680
                vimvars[VV_MOUSE_WIN].vv_nr = winnr;
10628
10681
                vimvars[VV_MOUSE_LNUM].vv_nr = lnum;
10629
10682
                vimvars[VV_MOUSE_COL].vv_nr = col + 1;
10630
10683
            }
11294
11347
    typval_T    *argvars;
11295
11348
    typval_T    *rettv;
11296
11349
{
 
11350
    int         flags = WILD_SILENT|WILD_USE_NL;
11297
11351
    expand_T    xpc;
 
11352
    int         error = FALSE;
11298
11353
 
11299
 
    ExpandInit(&xpc);
11300
 
    xpc.xp_context = EXPAND_FILES;
 
11354
    /* When the optional second argument is non-zero, don't remove matches
 
11355
    * for 'wildignore' and don't put matches for 'suffixes' at the end. */
 
11356
    if (argvars[1].v_type != VAR_UNKNOWN
 
11357
                                && get_tv_number_chk(&argvars[1], &error))
 
11358
        flags |= WILD_KEEP_ALL;
11301
11359
    rettv->v_type = VAR_STRING;
11302
 
    rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
11303
 
                                     NULL, WILD_USE_NL|WILD_SILENT, WILD_ALL);
 
11360
    if (!error)
 
11361
    {
 
11362
        ExpandInit(&xpc);
 
11363
        xpc.xp_context = EXPAND_FILES;
 
11364
        rettv->vval.v_string = ExpandOne(&xpc, get_tv_string(&argvars[0]),
 
11365
                                                       NULL, flags, WILD_ALL);
 
11366
    }
 
11367
    else
 
11368
        rettv->vval.v_string = NULL;
11304
11369
}
11305
11370
 
11306
11371
/*
11311
11376
    typval_T    *argvars;
11312
11377
    typval_T    *rettv;
11313
11378
{
 
11379
    int         flags = 0;
11314
11380
    char_u      buf1[NUMBUFLEN];
11315
11381
    char_u      *file = get_tv_string_buf_chk(&argvars[1], buf1);
 
11382
    int         error = FALSE;
11316
11383
 
 
11384
    /* When the optional second argument is non-zero, don't remove matches
 
11385
    * for 'wildignore' and don't put matches for 'suffixes' at the end. */
 
11386
    if (argvars[2].v_type != VAR_UNKNOWN
 
11387
                                && get_tv_number_chk(&argvars[2], &error))
 
11388
        flags |= WILD_KEEP_ALL;
11317
11389
    rettv->v_type = VAR_STRING;
11318
 
    if (file == NULL)
 
11390
    if (file == NULL || error)
11319
11391
        rettv->vval.v_string = NULL;
11320
11392
    else
11321
 
        rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file);
 
11393
        rettv->vval.v_string = globpath(get_tv_string(&argvars[0]), file,
 
11394
                                                                       flags);
11322
11395
}
11323
11396
 
11324
11397
/*
11792
11865
            n = has_patch(atoi((char *)name + 5));
11793
11866
        else if (STRICMP(name, "vim_starting") == 0)
11794
11867
            n = (starting != 0);
 
11868
#ifdef FEAT_MBYTE
 
11869
        else if (STRICMP(name, "multi_byte_encoding") == 0)
 
11870
            n = has_mbyte;
 
11871
#endif
11795
11872
#if defined(FEAT_BEVAL) && defined(FEAT_GUI_W32)
11796
11873
        else if (STRICMP(name, "balloon_multiline") == 0)
11797
11874
            n = multiline_balloon_available();
16599
16676
                p = highlight_has_attr(id, HL_INVERSE, modec);
16600
16677
                break;
16601
16678
 
16602
 
        case 's':                                       /* standout */
16603
 
                p = highlight_has_attr(id, HL_STANDOUT, modec);
 
16679
        case 's':
 
16680
                if (TOLOWER_ASC(what[1]) == 'p')        /* sp[#] */
 
16681
                    p = highlight_color(id, what, modec);
 
16682
                else                                    /* standout */
 
16683
                    p = highlight_has_attr(id, HL_STANDOUT, modec);
16604
16684
                break;
16605
16685
 
16606
16686
        case 'u':
18106
18186
}
18107
18187
 
18108
18188
/*
18109
 
 * Set v:count, v:count1 and v:prevcount.
 
18189
 * Get List v: variable value.  Caller must take care of reference count when
 
18190
 * needed.
 
18191
 */
 
18192
    list_T *
 
18193
get_vim_var_list(idx)
 
18194
    int         idx;
 
18195
{
 
18196
    return vimvars[idx].vv_list;
 
18197
}
 
18198
 
 
18199
/*
 
18200
 * Set v:count to "count" and v:count1 to "count1".
 
18201
 * When "set_prevcount" is TRUE first set v:prevcount from v:count.
18110
18202
 */
18111
18203
    void
18112
 
set_vcount(count, count1)
 
18204
set_vcount(count, count1, set_prevcount)
18113
18205
    long        count;
18114
18206
    long        count1;
 
18207
    int         set_prevcount;
18115
18208
{
18116
 
    vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
 
18209
    if (set_prevcount)
 
18210
        vimvars[VV_PREVCOUNT].vv_nr = vimvars[VV_COUNT].vv_nr;
18117
18211
    vimvars[VV_COUNT].vv_nr = count;
18118
18212
    vimvars[VV_COUNT1].vv_nr = count1;
18119
18213
}
18141
18235
}
18142
18236
 
18143
18237
/*
 
18238
 * Set List v: variable to "val".
 
18239
 */
 
18240
    void
 
18241
set_vim_var_list(idx, val)
 
18242
    int         idx;
 
18243
    list_T      *val;
 
18244
{
 
18245
    list_unref(vimvars[idx].vv_list);
 
18246
    vimvars[idx].vv_list = val;
 
18247
    if (val != NULL)
 
18248
        ++val->lv_refcount;
 
18249
}
 
18250
 
 
18251
/*
18144
18252
 * Set v:register if needed.
18145
18253
 */
18146
18254
    void
18877
18985
    dictitem_T  *dict_var;
18878
18986
{
18879
18987
    hash_init(&dict->dv_hashtab);
18880
 
    dict->dv_refcount = 99999;
 
18988
    dict->dv_refcount = DO_NOT_FREE_CNT;
18881
18989
    dict_var->di_tv.vval.v_dict = dict;
18882
18990
    dict_var->di_tv.v_type = VAR_DICT;
18883
18991
    dict_var->di_tv.v_lock = VAR_FIXED;
19214
19322
 * Copy the values from typval_T "from" to typval_T "to".
19215
19323
 * When needed allocates string or increases reference count.
19216
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.
19217
19327
 */
19218
19328
    static void
19219
19329
copy_tv(from, to)
21026
21136
    char_u      *save_sourcing_name;
21027
21137
    linenr_T    save_sourcing_lnum;
21028
21138
    scid_T      save_current_SID;
21029
 
    funccall_T  fc;
 
21139
    funccall_T  *fc;
21030
21140
    int         save_did_emsg;
21031
21141
    static int  depth = 0;
21032
21142
    dictitem_T  *v;
21052
21162
 
21053
21163
    line_breakcheck();          /* check for CTRL-C hit */
21054
21164
 
21055
 
    fc.caller = current_funccal;
21056
 
    current_funccal = &fc;
21057
 
    fc.func = fp;
21058
 
    fc.rettv = rettv;
 
21165
    fc = (funccall_T *)alloc(sizeof(funccall_T));
 
21166
    fc->caller = current_funccal;
 
21167
    current_funccal = fc;
 
21168
    fc->func = fp;
 
21169
    fc->rettv = rettv;
21059
21170
    rettv->vval.v_number = 0;
21060
 
    fc.linenr = 0;
21061
 
    fc.returned = FALSE;
21062
 
    fc.level = ex_nesting_level;
 
21171
    fc->linenr = 0;
 
21172
    fc->returned = FALSE;
 
21173
    fc->level = ex_nesting_level;
21063
21174
    /* Check if this function has a breakpoint. */
21064
 
    fc.breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
21065
 
    fc.dbg_tick = debug_tick;
 
21175
    fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
 
21176
    fc->dbg_tick = debug_tick;
21066
21177
 
21067
21178
    /*
21068
 
     * 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
21069
21180
     * with names up to VAR_SHORT_LEN long.  This avoids having to alloc/free
21070
21181
     * each argument variable and saves a lot of time.
21071
21182
     */
21072
21183
    /*
21073
21184
     * Init l: variables.
21074
21185
     */
21075
 
    init_var_dict(&fc.l_vars, &fc.l_vars_var);
 
21186
    init_var_dict(&fc->l_vars, &fc->l_vars_var);
21076
21187
    if (selfdict != NULL)
21077
21188
    {
21078
21189
        /* Set l:self to "selfdict".  Use "name" to avoid a warning from
21079
21190
         * some compiler that checks the destination size. */
21080
 
        v = &fc.fixvar[fixvar_idx++].var;
 
21191
        v = &fc->fixvar[fixvar_idx++].var;
21081
21192
        name = v->di_key;
21082
21193
        STRCPY(name, "self");
21083
21194
        v->di_flags = DI_FLAGS_RO + DI_FLAGS_FIX;
21084
 
        hash_add(&fc.l_vars.dv_hashtab, DI2HIKEY(v));
 
21195
        hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
21085
21196
        v->di_tv.v_type = VAR_DICT;
21086
21197
        v->di_tv.v_lock = 0;
21087
21198
        v->di_tv.vval.v_dict = selfdict;
21093
21204
     * Set a:0 to "argcount".
21094
21205
     * Set a:000 to a list with room for the "..." arguments.
21095
21206
     */
21096
 
    init_var_dict(&fc.l_avars, &fc.l_avars_var);
21097
 
    add_nr_var(&fc.l_avars, &fc.fixvar[fixvar_idx++].var, "0",
 
21207
    init_var_dict(&fc->l_avars, &fc->l_avars_var);
 
21208
    add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
21098
21209
                                (varnumber_T)(argcount - fp->uf_args.ga_len));
21099
 
    v = &fc.fixvar[fixvar_idx++].var;
21100
 
    STRCPY(v->di_key, "000");
 
21210
    /* Use "name" to avoid a warning from some compiler that checks the
 
21211
     * destination size. */
 
21212
    v = &fc->fixvar[fixvar_idx++].var;
 
21213
    name = v->di_key;
 
21214
    STRCPY(name, "000");
21101
21215
    v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
21102
 
    hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
 
21216
    hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21103
21217
    v->di_tv.v_type = VAR_LIST;
21104
21218
    v->di_tv.v_lock = VAR_FIXED;
21105
 
    v->di_tv.vval.v_list = &fc.l_varlist;
21106
 
    vim_memset(&fc.l_varlist, 0, sizeof(list_T));
21107
 
    fc.l_varlist.lv_refcount = 99999;
21108
 
    fc.l_varlist.lv_lock = VAR_FIXED;
 
21219
    v->di_tv.vval.v_list = &fc->l_varlist;
 
21220
    vim_memset(&fc->l_varlist, 0, sizeof(list_T));
 
21221
    fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
 
21222
    fc->l_varlist.lv_lock = VAR_FIXED;
21109
21223
 
21110
21224
    /*
21111
21225
     * Set a:firstline to "firstline" and a:lastline to "lastline".
21112
21226
     * Set a:name to named arguments.
21113
21227
     * Set a:N to the "..." arguments.
21114
21228
     */
21115
 
    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",
21116
21230
                                                      (varnumber_T)firstline);
21117
 
    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",
21118
21232
                                                       (varnumber_T)lastline);
21119
21233
    for (i = 0; i < argcount; ++i)
21120
21234
    {
21130
21244
        }
21131
21245
        if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
21132
21246
        {
21133
 
            v = &fc.fixvar[fixvar_idx++].var;
 
21247
            v = &fc->fixvar[fixvar_idx++].var;
21134
21248
            v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
21135
21249
        }
21136
21250
        else
21142
21256
            v->di_flags = DI_FLAGS_RO;
21143
21257
        }
21144
21258
        STRCPY(v->di_key, name);
21145
 
        hash_add(&fc.l_avars.dv_hashtab, DI2HIKEY(v));
 
21259
        hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
21146
21260
 
21147
21261
        /* Note: the values are copied directly to avoid alloc/free.
21148
21262
         * "argvars" must have VAR_FIXED for v_lock. */
21151
21265
 
21152
21266
        if (ai >= 0 && ai < MAX_FUNC_ARGS)
21153
21267
        {
21154
 
            list_append(&fc.l_varlist, &fc.l_listitems[ai]);
21155
 
            fc.l_listitems[ai].li_tv = argvars[i];
21156
 
            fc.l_listitems[ai].li_tv.v_lock = VAR_FIXED;
 
21268
            list_append(&fc->l_varlist, &fc->l_listitems[ai]);
 
21269
            fc->l_listitems[ai].li_tv = argvars[i];
 
21270
            fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
21157
21271
        }
21158
21272
    }
21159
21273
 
21218
21332
        if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
21219
21333
            func_do_profile(fp);
21220
21334
        if (fp->uf_profiling
21221
 
                       || (fc.caller != NULL && fc.caller->func->uf_profiling))
 
21335
                    || (fc->caller != NULL && fc->caller->func->uf_profiling))
21222
21336
        {
21223
21337
            ++fp->uf_tm_count;
21224
21338
            profile_start(&call_start);
21234
21348
    did_emsg = FALSE;
21235
21349
 
21236
21350
    /* call do_cmdline() to execute the lines */
21237
 
    do_cmdline(NULL, get_func_line, (void *)&fc,
 
21351
    do_cmdline(NULL, get_func_line, (void *)fc,
21238
21352
                                     DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
21239
21353
 
21240
21354
    --RedrawingDisabled;
21249
21363
 
21250
21364
#ifdef FEAT_PROFILE
21251
21365
    if (do_profiling == PROF_YES && (fp->uf_profiling
21252
 
                    || (fc.caller != NULL && fc.caller->func->uf_profiling)))
 
21366
                    || (fc->caller != NULL && fc->caller->func->uf_profiling)))
21253
21367
    {
21254
21368
        profile_end(&call_start);
21255
21369
        profile_sub_wait(&wait_start, &call_start);
21256
21370
        profile_add(&fp->uf_tm_total, &call_start);
21257
21371
        profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
21258
 
        if (fc.caller != NULL && fc.caller->func->uf_profiling)
 
21372
        if (fc->caller != NULL && fc->caller->func->uf_profiling)
21259
21373
        {
21260
 
            profile_add(&fc.caller->func->uf_tm_children, &call_start);
21261
 
            profile_add(&fc.caller->func->uf_tml_children, &call_start);
 
21374
            profile_add(&fc->caller->func->uf_tm_children, &call_start);
 
21375
            profile_add(&fc->caller->func->uf_tml_children, &call_start);
21262
21376
        }
21263
21377
    }
21264
21378
#endif
21271
21385
 
21272
21386
        if (aborting())
21273
21387
            smsg((char_u *)_("%s aborted"), sourcing_name);
21274
 
        else if (fc.rettv->v_type == VAR_NUMBER)
 
21388
        else if (fc->rettv->v_type == VAR_NUMBER)
21275
21389
            smsg((char_u *)_("%s returning #%ld"), sourcing_name,
21276
 
                                               (long)fc.rettv->vval.v_number);
 
21390
                                               (long)fc->rettv->vval.v_number);
21277
21391
        else
21278
21392
        {
21279
21393
            char_u      buf[MSG_BUF_LEN];
21284
21398
            /* The value may be very long.  Skip the middle part, so that we
21285
21399
             * have some idea how it starts and ends. smsg() would always
21286
21400
             * truncate it at the end. */
21287
 
            s = tv2string(fc.rettv, &tofree, numbuf2, 0);
 
21401
            s = tv2string(fc->rettv, &tofree, numbuf2, 0);
21288
21402
            if (s != NULL)
21289
21403
            {
21290
21404
                trunc_string(s, buf, MSG_BUF_CLEN);
21320
21434
    }
21321
21435
 
21322
21436
    did_emsg |= save_did_emsg;
21323
 
    current_funccal = fc.caller;
21324
 
 
21325
 
    /* The a: variables typevals were not allocated, only free the allocated
21326
 
     * variables. */
21327
 
    vars_clear_ext(&fc.l_avars.dv_hashtab, FALSE);
21328
 
 
21329
 
    vars_clear(&fc.l_vars.dv_hashtab);          /* free all l: variables */
 
21437
    current_funccal = fc->caller;
21330
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);
21331
21515
}
21332
21516
 
21333
21517
/*
21900
22084
    }
21901
22085
}
21902
22086
 
 
22087
/*
 
22088
 * List v:oldfiles in a nice way.
 
22089
 */
 
22090
/*ARGSUSED*/
 
22091
    void
 
22092
ex_oldfiles(eap)
 
22093
    exarg_T     *eap;
 
22094
{
 
22095
    list_T      *l = vimvars[VV_OLDFILES].vv_list;
 
22096
    listitem_T  *li;
 
22097
    int         nr = 0;
 
22098
 
 
22099
    if (l == NULL)
 
22100
        msg((char_u *)_("No old files"));
 
22101
    else
 
22102
    {
 
22103
        msg_start();
 
22104
        msg_scroll = TRUE;
 
22105
        for (li = l->lv_first; li != NULL && !got_int; li = li->li_next)
 
22106
        {
 
22107
            msg_outnum((long)++nr);
 
22108
            MSG_PUTS(": ");
 
22109
            msg_outtrans(get_tv_string(&li->li_tv));
 
22110
            msg_putchar('\n');
 
22111
            out_flush();            /* output one line at a time */
 
22112
            ui_breakcheck();
 
22113
        }
 
22114
        /* Assume "got_int" was set to truncate the listing. */
 
22115
        got_int = FALSE;
 
22116
 
 
22117
#ifdef FEAT_BROWSE_CMD
 
22118
        if (cmdmod.browse)
 
22119
        {
 
22120
            quit_more = FALSE;
 
22121
            nr = prompt_for_number(FALSE);
 
22122
            msg_starthere();
 
22123
            if (nr > 0)
 
22124
            {
 
22125
                char_u *p = list_find_str(get_vim_var_list(VV_OLDFILES),
 
22126
                                                                    (long)nr);
 
22127
 
 
22128
                if (p != NULL)
 
22129
                {
 
22130
                    p = expand_env_save(p);
 
22131
                    eap->arg = p;
 
22132
                    eap->cmdidx = CMD_edit;
 
22133
                    cmdmod.browse = FALSE;
 
22134
                    do_exedit(eap, NULL);
 
22135
                    vim_free(p);
 
22136
                }
 
22137
            }
 
22138
        }
 
22139
#endif
 
22140
    }
 
22141
}
 
22142
 
21903
22143
#endif /* FEAT_EVAL */
21904
22144
 
21905
22145