Compare commits

...

13 Commits

Author SHA1 Message Date
Bram Moolenaar
713bf9e996 patch 8.1.1010: Lua interface leaks memory
Problem:    Lua interface leaks memory.
Solution:   Clear typeval after copying it.
2019-03-16 16:38:41 +01:00
Bram Moolenaar
1f271efbbb patch 8.1.1009: MS-Windows: some text is not baseline aligned
Problem:    MS-Windows: some text is not baseline aligned.
Solution:   Use bottom alignment. (Taro Muraoka, closes #4116, closes #1520)
2019-03-16 15:24:42 +01:00
Bram Moolenaar
0251d2d811 patch 8.1.1008: MS-Windows: HAVE_STDINT_H only defined for non-debug version
Problem:    MS-Windows: HAVE_STDINT_H only defined for non-debug version.
Solution:   Move definition of HAVE_STDINT_H up. (Taro Muraoka, closes #4109)
2019-03-14 21:37:19 +01:00
Bram Moolenaar
209b8e3e3b patch 8.1.1007: using closure may consume a lot of memory
Problem:    Using closure may consume a lot of memory.
Solution:   unreference items that are no longer needed. Add a test. (Ozaki
            Kiichi, closes #3961)
2019-03-14 13:43:24 +01:00
Bram Moolenaar
4aa47b28f4 patch 8.1.1006: repeated code in quickfix support
Problem:    Repeated code in quickfix support.
Solution:   Move code to functions. (Yegappan Lakshmanan, closes #4091)
2019-03-13 06:51:53 +01:00
Bram Moolenaar
55d81cd2a1 patch 8.1.1005: test fails because t_F2 is not set
Problem:    Test fails because t_F2 is not set.
Solution:   Add try-catch.
2019-03-11 08:05:50 +01:00
Bram Moolenaar
e165f63598 patch 8.1.1004: function "luaV_setref()" not covered with tests
Problem:    Function "luaV_setref()" not covered with tests.
Solution:   Add a test. (Dominique Pelle, closes #4089)
2019-03-10 09:48:59 +01:00
Bram Moolenaar
6edbbd8114 patch 8.1.1003: playing back recorded key sequence mistakes key code
Problem:    Playing back recorded key sequence mistakes key code.
Solution:   Insert a <Nop> after the <Esc>. (closes #4068)
2019-03-10 09:41:51 +01:00
Bram Moolenaar
cbef8e1aa1 patch 8.1.1002: "gf" does not always work when URL has a port number
Problem:    "gf" does not always work when URL has a port number. (Jakob
            Schöttl)
Solution:   When a URL is recognized also accept ":". (closes #4082)
2019-03-09 12:32:56 +01:00
Bram Moolenaar
8156ed3755 patch 8.1.1001: Visual area not correct when using 'cursorline'
Problem:    Visual area not correct when using 'cursorline'.
Solution:   Update w_last_cursorline also in Visual mode. (Hirohito Higashi,
            closes #4086)
2019-03-09 11:46:15 +01:00
Bram Moolenaar
fd731b0e31 patch 8.1.1000: indenting is off
Problem:    Indenting is off.
Solution:   Make indenting consistent and update comments. (Ozaki Kiichi,
            closes #4079)
2019-03-09 11:23:58 +01:00
Bram Moolenaar
9d7fdd403a patch 8.1.0999: use register one too often and not properly tested
Problem:    Use register one too often and not properly tested.
Solution:   Do not always use register one when specifying a register.
            (closes #4085)  Add more tests.
2019-03-08 09:50:52 +01:00
Bram Moolenaar
19a66858a5 patch 8.1.0998: getcurpos() unexpectedly changes "curswant"
Problem:    getcurpos() unexpectedly changes "curswant".
Solution:   Save and restore "curswant". (closes #4069)
2019-03-07 11:25:32 +01:00
19 changed files with 686 additions and 296 deletions

View File

@@ -626,6 +626,10 @@ CFLAGS = $(CFLAGS) /MP
!endif
!endif
# VC10 or later has stdint.h.
!if $(MSVC_MAJOR) >= 10
CFLAGS = $(CFLAGS) -DHAVE_STDINT_H
!endif
!ifdef NODEBUG
VIM = vim
@@ -649,11 +653,6 @@ OPTFLAG = $(OPTFLAG) /GL
CFLAGS=$(CFLAGS) $(WP64CHECK)
!endif
# VC10 or later has stdint.h.
!if $(MSVC_MAJOR) >= 10
CFLAGS = $(CFLAGS) -DHAVE_STDINT_H
!endif
# Static code analysis generally available starting with VS2012 (VC11) or
# Windows SDK 7.1 (VC10)
!if ("$(ANALYZE)" == "yes") && ($(MSVC_MAJOR) >= 10)

View File

@@ -5474,9 +5474,23 @@ getpos_both(
(varnumber_T)0);
if (getcurpos)
{
int save_set_curswant = curwin->w_set_curswant;
colnr_T save_curswant = curwin->w_curswant;
colnr_T save_virtcol = curwin->w_virtcol;
update_curswant();
list_append_number(l, curwin->w_curswant == MAXCOL ?
(varnumber_T)MAXCOL : (varnumber_T)curwin->w_curswant + 1);
// Do not change "curswant", as it is unexpected that a get
// function has a side effect.
if (save_set_curswant)
{
curwin->w_set_curswant = save_set_curswant;
curwin->w_curswant = save_curswant;
curwin->w_virtcol = save_virtcol;
curwin->w_valid &= ~VALID_VIRTCOL;
}
}
}
else

View File

@@ -2017,10 +2017,10 @@ file_name_in_line(
len = 0;
while (vim_isfilec(ptr[len]) || (ptr[len] == '\\' && ptr[len + 1] == ' ')
|| ((options & FNAME_HYP) && path_is_url(ptr + len))
|| (is_url && vim_strchr((char_u *)"?&=", ptr[len]) != NULL))
|| (is_url && vim_strchr((char_u *)":?&=", ptr[len]) != NULL))
{
// After type:// we also include ?, & and = as valid characters, so that
// http://google.com?q=this&that=ok works.
// After type:// we also include :, ?, & and = as valid characters, so that
// http://google.com:8080?q=this&that=ok works.
if ((ptr[len] >= 'A' && ptr[len] <= 'Z') || (ptr[len] >= 'a' && ptr[len] <= 'z'))
{
if (in_type && path_is_url(ptr + len + 1))

View File

@@ -1577,108 +1577,109 @@ vgetc(void)
}
else
{
mod_mask = 0x0;
last_recorded_len = 0;
for (;;) /* this is done twice if there are modifiers */
{
int did_inc = FALSE;
mod_mask = 0x0;
last_recorded_len = 0;
for (;;) // this is done twice if there are modifiers
{
int did_inc = FALSE;
if (mod_mask
if (mod_mask
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
|| im_is_preediting()
|| im_is_preediting()
#endif
)
{
/* no mapping after modifier has been read */
++no_mapping;
++allow_keys;
did_inc = TRUE; /* mod_mask may change value */
}
c = vgetorpeek(TRUE);
if (did_inc)
{
--no_mapping;
--allow_keys;
}
/* Get two extra bytes for special keys */
if (c == K_SPECIAL
#ifdef FEAT_GUI
|| c == CSI
#endif
)
{
int save_allow_keys = allow_keys;
++no_mapping;
allow_keys = 0; /* make sure BS is not found */
c2 = vgetorpeek(TRUE); /* no mapping for these chars */
c = vgetorpeek(TRUE);
--no_mapping;
allow_keys = save_allow_keys;
if (c2 == KS_MODIFIER)
)
{
mod_mask = c;
continue;
// no mapping after modifier has been read
++no_mapping;
++allow_keys;
did_inc = TRUE; // mod_mask may change value
}
c = TO_SPECIAL(c2, c);
c = vgetorpeek(TRUE);
if (did_inc)
{
--no_mapping;
--allow_keys;
}
// Get two extra bytes for special keys
if (c == K_SPECIAL
#ifdef FEAT_GUI
|| c == CSI
#endif
)
{
int save_allow_keys = allow_keys;
++no_mapping;
allow_keys = 0; // make sure BS is not found
c2 = vgetorpeek(TRUE); // no mapping for these chars
c = vgetorpeek(TRUE);
--no_mapping;
allow_keys = save_allow_keys;
if (c2 == KS_MODIFIER)
{
mod_mask = c;
continue;
}
c = TO_SPECIAL(c2, c);
#if defined(FEAT_GUI_MSWIN) && defined(FEAT_MENU) && defined(FEAT_TEAROFF)
/* Handle K_TEAROFF here, the caller of vgetc() doesn't need to
* know that a menu was torn off */
if (c == K_TEAROFF)
{
char_u name[200];
int i;
/* get menu path, it ends with a <CR> */
for (i = 0; (c = vgetorpeek(TRUE)) != '\r'; )
// Handle K_TEAROFF here, the caller of vgetc() doesn't need to
// know that a menu was torn off
if (c == K_TEAROFF)
{
name[i] = c;
if (i < 199)
++i;
char_u name[200];
int i;
// get menu path, it ends with a <CR>
for (i = 0; (c = vgetorpeek(TRUE)) != '\r'; )
{
name[i] = c;
if (i < 199)
++i;
}
name[i] = NUL;
gui_make_tearoff(name);
continue;
}
name[i] = NUL;
gui_make_tearoff(name);
continue;
}
#endif
#if defined(FEAT_GUI) && defined(FEAT_GUI_GTK) && defined(FEAT_MENU)
/* GTK: <F10> normally selects the menu, but it's passed until
* here to allow mapping it. Intercept and invoke the GTK
* behavior if it's not mapped. */
if (c == K_F10 && gui.menubar != NULL)
{
gtk_menu_shell_select_first(GTK_MENU_SHELL(gui.menubar), FALSE);
continue;
}
// GTK: <F10> normally selects the menu, but it's passed until
// here to allow mapping it. Intercept and invoke the GTK
// behavior if it's not mapped.
if (c == K_F10 && gui.menubar != NULL)
{
gtk_menu_shell_select_first(
GTK_MENU_SHELL(gui.menubar), FALSE);
continue;
}
#endif
#ifdef FEAT_GUI
/* Handle focus event here, so that the caller doesn't need to
* know about it. Return K_IGNORE so that we loop once (needed if
* 'lazyredraw' is set). */
if (c == K_FOCUSGAINED || c == K_FOCUSLOST)
{
ui_focus_change(c == K_FOCUSGAINED);
c = K_IGNORE;
}
// Handle focus event here, so that the caller doesn't need to
// know about it. Return K_IGNORE so that we loop once (needed
// if 'lazyredraw' is set).
if (c == K_FOCUSGAINED || c == K_FOCUSLOST)
{
ui_focus_change(c == K_FOCUSGAINED);
c = K_IGNORE;
}
/* Translate K_CSI to CSI. The special key is only used to avoid
* it being recognized as the start of a special key. */
if (c == K_CSI)
c = CSI;
// Translate K_CSI to CSI. The special key is only used to
// avoid it being recognized as the start of a special key.
if (c == K_CSI)
c = CSI;
#endif
}
/* a keypad or special function key was not mapped, use it like
* its ASCII equivalent */
switch (c)
{
case K_KPLUS: c = '+'; break;
case K_KMINUS: c = '-'; break;
case K_KDIVIDE: c = '/'; break;
case K_KMULTIPLY: c = '*'; break;
case K_KENTER: c = CAR; break;
case K_KPOINT:
}
// a keypad or special function key was not mapped, use it like
// its ASCII equivalent
switch (c)
{
case K_KPLUS: c = '+'; break;
case K_KMINUS: c = '-'; break;
case K_KDIVIDE: c = '/'; break;
case K_KMULTIPLY: c = '*'; break;
case K_KENTER: c = CAR; break;
case K_KPOINT:
#ifdef MSWIN
// Can be either '.' or a ',',
// depending on the type of keypad.
@@ -1686,19 +1687,19 @@ vgetc(void)
#else
c = '.'; break;
#endif
case K_K0: c = '0'; break;
case K_K1: c = '1'; break;
case K_K2: c = '2'; break;
case K_K3: c = '3'; break;
case K_K4: c = '4'; break;
case K_K5: c = '5'; break;
case K_K6: c = '6'; break;
case K_K7: c = '7'; break;
case K_K8: c = '8'; break;
case K_K9: c = '9'; break;
case K_K0: c = '0'; break;
case K_K1: c = '1'; break;
case K_K2: c = '2'; break;
case K_K3: c = '3'; break;
case K_K4: c = '4'; break;
case K_K5: c = '5'; break;
case K_K6: c = '6'; break;
case K_K7: c = '7'; break;
case K_K8: c = '8'; break;
case K_K9: c = '9'; break;
case K_XHOME:
case K_ZHOME: if (mod_mask == MOD_MASK_SHIFT)
case K_XHOME:
case K_ZHOME: if (mod_mask == MOD_MASK_SHIFT)
{
c = K_S_HOME;
mod_mask = 0;
@@ -1711,8 +1712,8 @@ vgetc(void)
else
c = K_HOME;
break;
case K_XEND:
case K_ZEND: if (mod_mask == MOD_MASK_SHIFT)
case K_XEND:
case K_ZEND: if (mod_mask == MOD_MASK_SHIFT)
{
c = K_S_END;
mod_mask = 0;
@@ -1726,45 +1727,45 @@ vgetc(void)
c = K_END;
break;
case K_XUP: c = K_UP; break;
case K_XDOWN: c = K_DOWN; break;
case K_XLEFT: c = K_LEFT; break;
case K_XRIGHT: c = K_RIGHT; break;
}
/* For a multi-byte character get all the bytes and return the
* converted character.
* Note: This will loop until enough bytes are received!
*/
if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1)
{
++no_mapping;
buf[0] = c;
for (i = 1; i < n; ++i)
{
buf[i] = vgetorpeek(TRUE);
if (buf[i] == K_SPECIAL
#ifdef FEAT_GUI
|| buf[i] == CSI
#endif
)
{
/* Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER sequence,
* which represents a K_SPECIAL (0x80),
* or a CSI - KS_EXTRA - KE_CSI sequence, which represents
* a CSI (0x9B),
* of a K_SPECIAL - KS_EXTRA - KE_CSI, which is CSI too. */
c = vgetorpeek(TRUE);
if (vgetorpeek(TRUE) == (int)KE_CSI && c == KS_EXTRA)
buf[i] = CSI;
}
case K_XUP: c = K_UP; break;
case K_XDOWN: c = K_DOWN; break;
case K_XLEFT: c = K_LEFT; break;
case K_XRIGHT: c = K_RIGHT; break;
}
--no_mapping;
c = (*mb_ptr2char)(buf);
}
break;
}
// For a multi-byte character get all the bytes and return the
// converted character.
// Note: This will loop until enough bytes are received!
if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1)
{
++no_mapping;
buf[0] = c;
for (i = 1; i < n; ++i)
{
buf[i] = vgetorpeek(TRUE);
if (buf[i] == K_SPECIAL
#ifdef FEAT_GUI
|| buf[i] == CSI
#endif
)
{
// Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER
// sequence, which represents a K_SPECIAL (0x80),
// or a CSI - KS_EXTRA - KE_CSI sequence, which
// represents a CSI (0x9B),
// or a K_SPECIAL - KS_EXTRA - KE_CSI, which is CSI
// too.
c = vgetorpeek(TRUE);
if (vgetorpeek(TRUE) == (int)KE_CSI && c == KS_EXTRA)
buf[i] = CSI;
}
}
--no_mapping;
c = (*mb_ptr2char)(buf);
}
break;
}
}
#ifdef FEAT_EVAL
@@ -2912,6 +2913,17 @@ vgetorpeek(int advance)
if (gui.in_use && shape_changed)
gui_update_cursor(TRUE, FALSE);
#endif
if (timedout && c == ESC)
{
char_u nop_buf[3];
// When recording there will be no timeout. Add a <Nop> after the ESC
// to avoid that it forms a key code with following characters.
nop_buf[0] = K_SPECIAL;
nop_buf[1] = KS_EXTRA;
nop_buf[2] = KE_NOP;
gotchars(nop_buf, 3);
}
--vgetc_busy;

View File

@@ -822,7 +822,7 @@ DWriteContext::CreateTextFormatFromLOGFONT(const LOGFONTW &logFont,
if (SUCCEEDED(hr))
hr = pTextFormat->SetParagraphAlignment(
DWRITE_PARAGRAPH_ALIGNMENT_CENTER);
DWRITE_PARAGRAPH_ALIGNMENT_FAR);
if (SUCCEEDED(hr))
hr = pTextFormat->SetWordWrapping(DWRITE_WORD_WRAPPING_NO_WRAP);

View File

@@ -844,10 +844,7 @@ luaV_list_add (lua_State *L)
lua_settop(L, 2);
luaV_checktypval(L, 2, &v, "adding list item");
if (list_append_tv(l, &v) == FAIL)
{
clear_tv(&v);
luaL_error(L, "failed to add item to list");
}
clear_tv(&v);
lua_settop(L, 1);
return 1;
@@ -872,10 +869,7 @@ luaV_list_insert (lua_State *L)
lua_settop(L, 2);
luaV_checktypval(L, 2, &v, "inserting list item");
if (list_insert_tv(l, &v, li) == FAIL)
{
clear_tv(&v);
luaL_error(L, "failed to add item to list");
}
clear_tv(&v);
lua_settop(L, 1);
return 1;
@@ -981,6 +975,7 @@ luaV_dict_newindex(lua_State *L)
char_u *key = (char_u *) luaL_checkstring(L, 2);
dictitem_T *di;
typval_T v;
if (d->dv_lock)
luaL_error(L, "dict is locked");
if (key == NULL)
@@ -1104,6 +1099,7 @@ luaV_funcref_call(lua_State *L)
{
luaV_checktypval(L, i + 2, &v, "calling funcref");
list_append_tv(f->args.vval.v_list, &v);
clear_tv(&v);
}
status = func_call(f->tv.vval.v_string, &f->args,
NULL, f->self, &rettv);
@@ -1571,6 +1567,7 @@ luaV_list(lua_State *L)
{
luaV_checktypval(L, -1, &v, "vim.list");
list_append_tv(l, &v);
clear_tv(&v);
}
lua_pop(L, 1); /* value */
} while (notnil);

View File

@@ -1245,10 +1245,15 @@ do_execreg(
emsg(_(e_nolastcmd));
return FAIL;
}
VIM_CLEAR(new_last_cmdline); /* don't keep the cmdline containing @: */
/* Escape all control characters with a CTRL-V */
// don't keep the cmdline containing @:
VIM_CLEAR(new_last_cmdline);
// Escape all control characters with a CTRL-V
p = vim_strsave_escaped_ext(last_cmdline,
(char_u *)"\001\002\003\004\005\006\007\010\011\012\013\014\015\016\017\020\021\022\023\024\025\026\027\030\031\032\033\034\035\036\037", Ctrl_V, FALSE);
(char_u *)"\001\002\003\004\005\006\007"
"\010\011\012\013\014\015\016\017"
"\020\021\022\023\024\025\026\027"
"\030\031\032\033\034\035\036\037",
Ctrl_V, FALSE);
if (p != NULL)
{
/* When in Visual mode "'<,'>" will be prepended to the command.
@@ -1747,7 +1752,6 @@ op_delete(oparg_T *oap)
struct block_def bd;
linenr_T old_lcount = curbuf->b_ml.ml_line_count;
int did_yank = FALSE;
int orig_regname = oap->regname;
if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to do */
return OK;
@@ -1833,12 +1837,13 @@ op_delete(oparg_T *oap)
/*
* Put deleted text into register 1 and shift number registers if the
* delete contains a line break, or when a regname has been specified.
* delete contains a line break, or when using a specific operator (Vi
* compatible)
* Use the register name from before adjust_clip_reg() may have
* changed it.
*/
if (orig_regname != 0 || oap->motion_type == MLINE
|| oap->line_count > 1 || oap->use_reg_one)
if (oap->motion_type == MLINE || oap->line_count > 1
|| oap->use_reg_one)
{
shift_delete_registers();
if (op_yank(oap, TRUE, FALSE) == OK)

View File

@@ -172,7 +172,7 @@ static int qf_win_pos_update(qf_info_T *qi, int old_qf_index);
static win_T *qf_find_win(qf_info_T *qi);
static buf_T *qf_find_buf(qf_info_T *qi);
static void qf_update_buffer(qf_info_T *qi, qfline_T *old_last);
static void qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last);
static void qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last);
static buf_T *load_dummy_buffer(char_u *fname, char_u *dirname_start, char_u *resulting_dir);
static void wipe_dummy_buffer(buf_T *buf, char_u *dirname_start);
static void unload_dummy_buffer(buf_T *buf, char_u *dirname_start);
@@ -1802,6 +1802,15 @@ qf_cmdtitle(char_u *cmd)
return qftitle_str;
}
/*
* Return a pointer to the current list in the specified quickfix stack
*/
static qf_list_T *
qf_get_curlist(qf_info_T *qi)
{
return &qi->qf_lists[qi->qf_curlist];
}
/*
* Prepare for adding a new quickfix list. If the current list is in the
* middle of the stack, then all the following lists are freed and then
@@ -1830,7 +1839,7 @@ qf_new_list(qf_info_T *qi, char_u *qf_title)
}
else
qi->qf_curlist = qi->qf_listcount++;
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
vim_memset(qfl, 0, (size_t)(sizeof(qf_list_T)));
qf_store_title(qfl, qf_title);
qfl->qfl_type = qi->qfl_type;
@@ -2725,6 +2734,16 @@ qf_find_help_win(void)
return NULL;
}
/*
* Set the location list for the specified window to 'qi'.
*/
static void
win_set_loclist(win_T *wp, qf_info_T *qi)
{
wp->w_llist = qi;
qi->qf_refcount++;
}
/*
* Find a help window or open one. If 'newwin' is TRUE, then open a new help
* window.
@@ -2766,10 +2785,7 @@ jump_to_help_window(qf_info_T *qi, int newwin, int *opened_window)
// location list. If the user asks to open a new window, then the new
// window will get a copy of the location list.
if (IS_LL_STACK(qi) && !newwin)
{
curwin->w_llist = qi;
qi->qf_refcount++;
}
win_set_loclist(curwin, qi);
}
if (!p_im)
@@ -2848,12 +2864,9 @@ qf_open_new_file_win(qf_info_T *ll_ref)
swb_flags = 0;
RESET_BINDING(curwin);
if (ll_ref != NULL)
{
// The new window should use the location list from the
// location list window
curwin->w_llist = ll_ref;
ll_ref->qf_refcount++;
}
win_set_loclist(curwin, ll_ref);
return OK;
}
@@ -2894,11 +2907,7 @@ qf_goto_win_with_ll_file(win_T *use_win, int qf_fnum, qf_info_T *ll_ref)
// If the location list for the window is not set, then set it
// to the location list from the location window
if (win->w_llist == NULL)
{
win->w_llist = ll_ref;
if (ll_ref != NULL)
ll_ref->qf_refcount++;
}
win_set_loclist(win, ll_ref);
}
/*
@@ -3022,7 +3031,7 @@ qf_jump_edit_buffer(
int prev_winid,
int *opened_window)
{
qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
qf_list_T *qfl = qf_get_curlist(qi);
qfltype_T qfl_type = qfl->qfl_type;
int retval = OK;
int old_qf_curlist = qi->qf_curlist;
@@ -3146,7 +3155,7 @@ qf_jump_print_msg(
if (!msg_scrolled)
update_topline_redraw();
sprintf((char *)IObuff, _("(%d of %d)%s%s: "), qf_index,
qi->qf_lists[qi->qf_curlist].qf_count,
qf_get_curlist(qi)->qf_count,
qf_ptr->qf_cleared ? _(" (line deleted)") : "",
(char *)qf_types(qf_ptr->qf_type, qf_ptr->qf_nr));
// Add the message, skipping leading whitespace and newlines.
@@ -3311,7 +3320,7 @@ qf_jump_newwin(qf_info_T *qi,
incr_quickfix_busy();
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
qf_ptr = qfl->qf_ptr;
old_qf_ptr = qf_ptr;
@@ -3512,7 +3521,7 @@ qf_list(exarg_T *eap)
emsg(_(e_trailing));
return;
}
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
if (plus)
{
i = qfl->qf_index;
@@ -3900,7 +3909,7 @@ ex_cwindow(exarg_T *eap)
return;
}
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
// Look for an existing quickfix window.
win = qf_find_win(qi);
@@ -4120,14 +4129,14 @@ ex_copen(exarg_T *eap)
return;
}
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
qf_set_title_var(qfl);
// Save the current index here, as updating the quickfix buffer may free
// the quickfix list
lnum = qfl->qf_index;
// Fill the buffer with the quickfix list.
qf_fill_buffer(qi, curbuf, NULL);
qf_fill_buffer(qfl, curbuf, NULL);
decr_quickfix_busy();
@@ -4195,7 +4204,7 @@ qf_current_entry(win_T *wp)
// In the location list window, use the referenced location list
qi = wp->w_llist_ref;
return qi->qf_lists[qi->qf_curlist].qf_index;
return qf_get_curlist(qi)->qf_index;
}
/*
@@ -4208,7 +4217,7 @@ qf_win_pos_update(
int old_qf_index) // previous qf_index or zero
{
win_T *win;
int qf_index = qi->qf_lists[qi->qf_curlist].qf_index;
int qf_index = qf_get_curlist(qi)->qf_index;
// Put the cursor on the current error in the quickfix window, so that
// it's viewable.
@@ -4306,7 +4315,7 @@ qf_update_win_titlevar(qf_info_T *qi)
{
curwin_save = curwin;
curwin = win;
qf_set_title_var(&qi->qf_lists[qi->qf_curlist]);
qf_set_title_var(qf_get_curlist(qi));
curwin = curwin_save;
}
}
@@ -4333,7 +4342,7 @@ qf_update_buffer(qf_info_T *qi, qfline_T *old_last)
qf_update_win_titlevar(qi);
qf_fill_buffer(qi, buf, old_last);
qf_fill_buffer(qf_get_curlist(qi), buf, old_last);
++CHANGEDTICK(buf);
if (old_last == NULL)
@@ -4433,7 +4442,7 @@ qf_buf_add_line(buf_T *buf, linenr_T lnum, qfline_T *qfp, char_u *dirname)
* ml_delete() is used and autocommands will be triggered.
*/
static void
qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
qf_fill_buffer(qf_list_T *qfl, buf_T *buf, qfline_T *old_last)
{
linenr_T lnum;
qfline_T *qfp;
@@ -4453,9 +4462,8 @@ qf_fill_buffer(qf_info_T *qi, buf_T *buf, qfline_T *old_last)
}
// Check if there is anything to display
if (!qf_stack_empty(qi))
if (qfl != NULL)
{
qf_list_T *qfl = &qi->qf_lists[qi->qf_curlist];
char_u dirname[MAXPATHL];
*dirname = NUL;
@@ -4551,7 +4559,7 @@ qf_restore_list(qf_info_T *qi, int_u save_qfid)
{
int curlist;
if (qi->qf_lists[qi->qf_curlist].qf_id != save_qfid)
if (qf_get_curlist(qi)->qf_id != save_qfid)
{
curlist = qf_id2nr(qi, save_qfid);
if (curlist < 0)
@@ -4769,11 +4777,11 @@ ex_make(exarg_T *eap)
goto cleanup;
}
if (res >= 0)
qf_list_changed(&qi->qf_lists[qi->qf_curlist]);
qf_list_changed(qf_get_curlist(qi));
// Remember the current quickfix list identifier, so that we can
// check for autocommands changing the current quickfix list.
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
save_qfid = qf_get_curlist(qi)->qf_id;
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
@@ -4808,7 +4816,7 @@ qf_get_size(exarg_T *eap)
return 0;
}
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
for (i = 0, qfp = qfl->qf_start; i < qfl->qf_count && qfp != NULL;
++i, qfp = qfp->qf_next)
{
@@ -4845,7 +4853,7 @@ qf_get_cur_idx(exarg_T *eap)
return 0;
}
return qi->qf_lists[qi->qf_curlist].qf_index;
return qf_get_curlist(qi)->qf_index;
}
/*
@@ -4869,7 +4877,7 @@ qf_get_cur_valid_idx(exarg_T *eap)
return 1;
}
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
qfp = qfl->qf_start;
// check if the list has valid errors
@@ -4985,7 +4993,7 @@ ex_cc(exarg_T *eap)
// For cfdo and lfdo commands, jump to the nth valid file entry.
if (eap->cmdidx == CMD_cdo || eap->cmdidx == CMD_ldo
|| eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo)
errornr = qf_get_nth_valid_entry(&qi->qf_lists[qi->qf_curlist],
errornr = qf_get_nth_valid_entry(qf_get_curlist(qi),
eap->addr_count > 0 ? (int)eap->line1 : 1,
eap->cmdidx == CMD_cfdo || eap->cmdidx == CMD_lfdo);
@@ -5114,8 +5122,8 @@ ex_cfile(exarg_T *eap)
}
}
if (res >= 0)
qf_list_changed(&qi->qf_lists[qi->qf_curlist]);
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
qf_list_changed(qf_get_curlist(qi));
save_qfid = qf_get_curlist(qi)->qf_id;
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name, NULL, FALSE, curbuf);
@@ -5236,9 +5244,9 @@ vgr_load_dummy_buf(
}
/*
* Check whether a quickfix/location list valid. Autocmds may remove or change
* a quickfix list when vimgrep is running. If the list is not found, create a
* new list.
* Check whether a quickfix/location list is valid. Autocmds may remove or
* change a quickfix list when vimgrep is running. If the list is not found,
* create a new list.
*/
static int
vgr_qflist_valid(
@@ -5479,7 +5487,7 @@ ex_vimgrep(exarg_T *eap)
// Remember the current quickfix list identifier, so that we can check for
// autocommands changing the current quickfix list.
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
save_qfid = qf_get_curlist(qi)->qf_id;
seconds = (time_t)0;
for (fi = 0; fi < fcount && !got_int && tomatch > 0; ++fi)
@@ -5515,7 +5523,7 @@ ex_vimgrep(exarg_T *eap)
decr_quickfix_busy();
goto theend;
}
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
save_qfid = qf_get_curlist(qi)->qf_id;
if (buf == NULL)
{
@@ -5595,7 +5603,7 @@ ex_vimgrep(exarg_T *eap)
FreeWild(fcount, fnames);
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
qfl->qf_nonevalid = FALSE;
qfl->qf_ptr = qfl->qf_start;
qfl->qf_index = 1;
@@ -6602,7 +6610,7 @@ qf_setprop_curidx(qf_info_T *qi, qf_list_T *qfl, dictitem_T *di)
// If the current list is modified and it is displayed in the quickfix
// window, then Update it.
if (qi->qf_lists[qi->qf_curlist].qf_id == qfl->qf_id)
if (qf_get_curlist(qi)->qf_id == qfl->qf_id)
qf_win_pos_update(qi, old_qfidx);
return OK;
@@ -6668,7 +6676,7 @@ qf_free_stack(win_T *wp, qf_info_T *qi)
{
// If the quickfix/location list window is open, then clear it
if (qi->qf_curlist < qi->qf_listcount)
qf_free(&qi->qf_lists[qi->qf_curlist]);
qf_free(qf_get_curlist(qi));
qf_update_buffer(qi, NULL);
}
@@ -6700,10 +6708,7 @@ qf_free_stack(win_T *wp, qf_info_T *qi)
qfwin->w_llist_ref = new_ll;
if (wp != qfwin)
{
wp->w_llist = new_ll;
new_ll->qf_refcount++;
}
win_set_loclist(wp, new_ll);
}
}
@@ -6745,7 +6750,7 @@ set_errorlist(
{
retval = qf_add_entries(qi, qi->qf_curlist, list, title, action);
if (retval == OK)
qf_list_changed(&qi->qf_lists[qi->qf_curlist]);
qf_list_changed(qf_get_curlist(qi));
}
decr_quickfix_busy();
@@ -6900,11 +6905,11 @@ ex_cbuffer(exarg_T *eap)
return;
}
if (res >= 0)
qf_list_changed(&qi->qf_lists[qi->qf_curlist]);
qf_list_changed(qf_get_curlist(qi));
// Remember the current quickfix list identifier, so that we can
// check for autocommands changing the current quickfix list.
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
save_qfid = qf_get_curlist(qi)->qf_id;
if (au_name != NULL)
{
buf_T *curbuf_old = curbuf;
@@ -6991,11 +6996,11 @@ ex_cexpr(exarg_T *eap)
goto cleanup;
}
if (res >= 0)
qf_list_changed(&qi->qf_lists[qi->qf_curlist]);
qf_list_changed(qf_get_curlist(qi));
// Remember the current quickfix list identifier, so that we can
// check for autocommands changing the current quickfix list.
save_qfid = qi->qf_lists[qi->qf_curlist].qf_id;
save_qfid = qf_get_curlist(qi)->qf_id;
if (au_name != NULL)
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
curbuf->b_fname, TRUE, curbuf);
@@ -7259,7 +7264,7 @@ ex_helpgrep(exarg_T *eap)
vim_regfree(regmatch.regprog);
qfl = &qi->qf_lists[qi->qf_curlist];
qfl = qf_get_curlist(qi);
qfl->qf_nonevalid = FALSE;
qfl->qf_ptr = qfl->qf_start;
qfl->qf_index = 1;

View File

@@ -3704,14 +3704,16 @@ win_line(
#endif
#ifdef FEAT_SYN_HL
/* Cursor line highlighting for 'cursorline' in the current window. Not
* when Visual mode is active, because it's not clear what is selected
* then. */
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
&& !(wp == curwin && VIsual_active))
// Cursor line highlighting for 'cursorline' in the current window.
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
{
line_attr = HL_ATTR(HLF_CUL);
area_highlighting = TRUE;
// Do not show the cursor line when Visual mode is active, because it's
// not clear what is selected then. Do update w_last_cursorline.
if (!(wp == curwin && VIsual_active))
{
line_attr = HL_ATTR(HLF_CUL);
area_highlighting = TRUE;
}
wp->w_last_cursorline = wp->w_cursor.lnum;
}
#endif

View File

@@ -63,8 +63,8 @@ SCRIPTS_GUI =
# Individual tests, including the ones part of test_alot.
# Please keep sorted up to test_alot.
NEW_TESTS = \
test_arglist \
test_arabic \
test_arglist \
test_assert \
test_assign \
test_autochdir \
@@ -108,11 +108,11 @@ NEW_TESTS = \
test_ex_equal \
test_ex_undo \
test_ex_z \
test_exit \
test_exec_while_if \
test_execute_func \
test_exists \
test_exists_autocmd \
test_exit \
test_expand \
test_expand_dllpath \
test_expand_func \
@@ -179,6 +179,7 @@ NEW_TESTS = \
test_match \
test_matchadd_conceal \
test_matchadd_conceal_utf8 \
test_memory_usage \
test_menu \
test_messages \
test_mksession \
@@ -355,6 +356,7 @@ NEW_TESTS_RES = \
test_maparg.res \
test_marks.res \
test_matchadd_conceal.res \
test_memory_usage.res \
test_mksession.res \
test_nested_function.res \
test_netbeans.res \

View File

@@ -0,0 +1,12 @@
|a+0&#e0e0e08|b|c| | +0&#ffffff0@70
|a+0&#e0e0e08|b|c| | +0&#ffffff0@70
|a+0&#e0e0e08|b|c| | +0&#ffffff0@70
|a+0&#e0e0e08|b|c| | +0&#ffffff0@70
|a+0&#e0e0e08|b|c| | +0&#ffffff0@70
>a|b+0&#e0e0e08|c| | +0&#ffffff0@70
|a|b|c| @71
|a|b|c| @71
|a|b|c| @71
|a|b|c| @71
|a|b|c| @71
|-+2&&@1| |V|I|S|U|A|L| |L|I|N|E| |-@1| +0&&@29|1|2| @7|1|2|,|1| @9|1|5|%|

View File

@@ -9,6 +9,7 @@ func Test_gf_url()
\ "third test for URL:\\\\machine.name\\vimtest2c and other text",
\ "fourth test for URL:\\\\machine.name\\tmp\\vimtest2d, and other text",
\ "fifth test for URL://machine.name/tmp?q=vim&opt=yes and other text",
\ "sixth test for URL://machine.name:1234?q=vim and other text",
\ ])
call cursor(1,1)
call search("^first")
@@ -20,7 +21,7 @@ func Test_gf_url()
if has("ebcdic")
set isf=@,240-249,/,.,-,_,+,,,$,:,~,\
else
set isf=@,48-57,/,.,-,_,+,,,$,:,~,\
set isf=@,48-57,/,.,-,_,+,,,$,~,\
endif
call search("^third")
call search("name")
@@ -33,6 +34,10 @@ func Test_gf_url()
call search("URL")
call assert_equal("URL://machine.name/tmp?q=vim&opt=yes", expand("<cfile>"))
call search("^sixth")
call search("URL")
call assert_equal("URL://machine.name:1234?q=vim", expand("<cfile>"))
set isf&vim
enew!
endfunc

View File

@@ -552,3 +552,23 @@ func Test_cursorline_after_yank()
call StopVimInTerminal(buf)
call delete('Xtest_cursorline_yank')
endfunc
func Test_cursorline_with_visualmode()
if !CanRunVimInTerminal()
return
endif
call writefile([
\ 'set cul',
\ 'call setline(1, repeat(["abc"], 50))',
\ ], 'Xtest_cursorline_with_visualmode')
let buf = RunVimInTerminal('-S Xtest_cursorline_with_visualmode', {'rows': 12})
call term_wait(buf)
call term_sendkeys(buf, "V\<C-f>kkkjk")
call VerifyScreenDump(buf, 'Test_cursorline_with_visualmode_01', {})
" clean up
call StopVimInTerminal(buf)
call delete('Xtest_cursorline_with_visualmode')
endfunc

View File

@@ -4,6 +4,11 @@ if !has('lua')
finish
endif
func TearDown()
" Run garbage collection after each test to exercise luaV_setref().
call test_garbagecollect_now()
endfunc
" Check that switching to another buffer does not trigger ml_get error.
func Test_command_new_no_ml_get_error()
new

View File

@@ -0,0 +1,144 @@
" Tests for memory usage.
if !has('terminal') || has('gui_running') || $ASAN_OPTIONS !=# ''
" Skip tests on Travis CI ASAN build because it's difficult to estimate
" memory usage.
finish
endif
source shared.vim
func s:pick_nr(str) abort
return substitute(a:str, '[^0-9]', '', 'g') * 1
endfunc
if has('win32')
if !executable('wmic')
finish
endif
func s:memory_usage(pid) abort
let cmd = printf('wmic process where processid=%d get WorkingSetSize', a:pid)
return s:pick_nr(system(cmd)) / 1024
endfunc
elseif has('unix')
if !executable('ps')
finish
endif
func s:memory_usage(pid) abort
return s:pick_nr(system('ps -o rss= -p ' . a:pid))
endfunc
else
finish
endif
" Wait for memory usage to level off.
func s:monitor_memory_usage(pid) abort
let proc = {}
let proc.pid = a:pid
let proc.hist = []
let proc.min = 0
let proc.max = 0
func proc.op() abort
" Check the last 200ms.
let val = s:memory_usage(self.pid)
if self.min > val
let self.min = val
elseif self.max < val
let self.max = val
endif
call add(self.hist, val)
if len(self.hist) < 20
return 0
endif
let sample = remove(self.hist, 0)
return len(uniq([sample] + self.hist)) == 1
endfunc
call WaitFor({-> proc.op()}, 10000)
return {'last': get(proc.hist, -1), 'min': proc.min, 'max': proc.max}
endfunc
let s:term_vim = {}
func s:term_vim.start(...) abort
let self.buf = term_start([GetVimProg()] + a:000)
let self.job = term_getjob(self.buf)
call WaitFor({-> job_status(self.job) ==# 'run'})
let self.pid = job_info(self.job).process
endfunc
func s:term_vim.stop() abort
call term_sendkeys(self.buf, ":qall!\<CR>")
call WaitFor({-> job_status(self.job) ==# 'dead'})
exe self.buf . 'bwipe!'
endfunc
func s:vim_new() abort
return copy(s:term_vim)
endfunc
func Test_memory_func_capture_vargs()
" Case: if a local variable captures a:000, funccall object will be free
" just after it finishes.
let testfile = 'Xtest.vim'
call writefile([
\ 'func s:f(...)',
\ ' let x = a:000',
\ 'endfunc',
\ 'for _ in range(10000)',
\ ' call s:f(0)',
\ 'endfor',
\ ], testfile)
let vim = s:vim_new()
call vim.start('--clean', '-c', 'set noswapfile', testfile)
let before = s:monitor_memory_usage(vim.pid).last
call term_sendkeys(vim.buf, ":so %\<CR>")
call WaitFor({-> term_getcursor(vim.buf)[0] == 1})
let after = s:monitor_memory_usage(vim.pid)
" Estimate the limit of max usage as 2x initial usage.
call assert_inrange(before, 2 * before, after.max)
" In this case, garbase collecting is not needed.
call assert_equal(after.last, after.max)
call vim.stop()
call delete(testfile)
endfunc
func Test_memory_func_capture_lvars()
" Case: if a local variable captures l: dict, funccall object will not be
" free until garbage collector runs, but after that memory usage doesn't
" increase so much even when rerun Xtest.vim since system memory caches.
let testfile = 'Xtest.vim'
call writefile([
\ 'func s:f()',
\ ' let x = l:',
\ 'endfunc',
\ 'for _ in range(10000)',
\ ' call s:f()',
\ 'endfor',
\ ], testfile)
let vim = s:vim_new()
call vim.start('--clean', '-c', 'set noswapfile', testfile)
let before = s:monitor_memory_usage(vim.pid).last
call term_sendkeys(vim.buf, ":so %\<CR>")
call WaitFor({-> term_getcursor(vim.buf)[0] == 1})
let after = s:monitor_memory_usage(vim.pid)
" Rerun Xtest.vim.
for _ in range(3)
call term_sendkeys(vim.buf, ":so %\<CR>")
call WaitFor({-> term_getcursor(vim.buf)[0] == 1})
let last = s:monitor_memory_usage(vim.pid).last
endfor
call assert_inrange(before, after.max + (after.last - before), last)
call vim.stop()
call delete(testfile)
endfunc

View File

@@ -42,7 +42,6 @@ func Test_display_registers()
call assert_match('^\n--- Registers ---\n'
\ . '"" a\n'
\ . '"0 ba\n'
\ . '"1 b\n'
\ . '"a b\n'
\ . '.*'
\ . '"- a\n'
@@ -63,3 +62,106 @@ func Test_display_registers()
bwipe!
endfunc
func Test_register_one()
" delete a line goes into register one
new
call setline(1, "one")
normal dd
call assert_equal("one\n", @1)
" delete a word does not change register one, does change "-
call setline(1, "two")
normal de
call assert_equal("one\n", @1)
call assert_equal("two", @-)
" delete a word with a register does not change register one
call setline(1, "three")
normal "ade
call assert_equal("three", @a)
call assert_equal("one\n", @1)
" delete a word with register DOES change register one with one of a list of
" operators
" %
call setline(1, ["(12)3"])
normal "ad%
call assert_equal("(12)", @a)
call assert_equal("(12)", @1)
" (
call setline(1, ["first second"])
normal $"ad(
call assert_equal("first secon", @a)
call assert_equal("first secon", @1)
" )
call setline(1, ["First Second."])
normal gg0"ad)
call assert_equal("First Second.", @a)
call assert_equal("First Second.", @1)
" `
call setline(1, ["start here."])
normal gg0fhmx0"ad`x
call assert_equal("start ", @a)
call assert_equal("start ", @1)
" /
call setline(1, ["searchX"])
exe "normal gg0\"ad/X\<CR>"
call assert_equal("search", @a)
call assert_equal("search", @1)
" ?
call setline(1, ["Ysearch"])
exe "normal gg$\"ad?Y\<CR>"
call assert_equal("Ysearc", @a)
call assert_equal("Ysearc", @1)
" n
call setline(1, ["Ynext"])
normal gg$"adn
call assert_equal("Ynex", @a)
call assert_equal("Ynex", @1)
" N
call setline(1, ["prevY"])
normal gg0"adN
call assert_equal("prev", @a)
call assert_equal("prev", @1)
" }
call setline(1, ["one", ""])
normal gg0"ad}
call assert_equal("one\n", @a)
call assert_equal("one\n", @1)
" {
call setline(1, ["", "two"])
normal 2G$"ad{
call assert_equal("\ntw", @a)
call assert_equal("\ntw", @1)
bwipe!
endfunc
" Check that replaying a typed sequence does not use an Esc and following
" characters as an escape sequence.
func Test_recording_esc_sequence()
new
try
let save_F2 = &t_F2
catch
endtry
let t_F2 = "\<Esc>OQ"
call feedkeys("qqiTest\<Esc>", "xt")
call feedkeys("OQuirk\<Esc>q", "xt")
call feedkeys("Go\<Esc>@q", "xt")
call assert_equal(['Quirk', 'Test', 'Quirk', 'Test'], getline(1, 4))
bwipe!
if exists('save_F2')
let t_F2 = save_F2
endif
endfunc

View File

@@ -1,8 +1,4 @@
" Tests for various Visual mode.
if !has('visual')
finish
endif
func Test_block_shift_multibyte()
" Uses double-wide character.
@@ -397,3 +393,14 @@ func Test_Visual_paragraph_textobject()
bwipe!
endfunc
func Test_curswant_not_changed()
new
call setline(1, ['one', 'two'])
au InsertLeave * call getcurpos()
call feedkeys("gg0\<C-V>jI123 \<Esc>j", 'xt')
call assert_equal([0, 2, 1, 0, 1], getcurpos())
bwipe!
au! InsertLeave
endfunc

View File

@@ -39,12 +39,12 @@ static hashtab_T func_hashtab;
/* Used by get_func_tv() */
static garray_T funcargs = GA_EMPTY;
/* pointer to funccal for currently active function */
funccall_T *current_funccal = NULL;
// pointer to funccal for currently active function
static funccall_T *current_funccal = NULL;
/* Pointer to list of previously used funccal, still around because some
* item in it is still being used. */
funccall_T *previous_funccal = NULL;
// Pointer to list of previously used funccal, still around because some
// item in it is still being used.
static funccall_T *previous_funccal = NULL;
static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it");
static char *e_funcdict = N_("E717: Dictionary entry already exists");
@@ -586,45 +586,53 @@ add_nr_var(
}
/*
* Free "fc" and what it contains.
* Free "fc".
*/
static void
free_funccal(
funccall_T *fc,
int free_val) /* a: vars were allocated */
static void
free_funccal(funccall_T *fc)
{
listitem_T *li;
int i;
int i;
for (i = 0; i < fc->fc_funcs.ga_len; ++i)
{
ufunc_T *fp = ((ufunc_T **)(fc->fc_funcs.ga_data))[i];
ufunc_T *fp = ((ufunc_T **)(fc->fc_funcs.ga_data))[i];
/* When garbage collecting a funccall_T may be freed before the
* function that references it, clear its uf_scoped field.
* The function may have been redefined and point to another
* funccall_T, don't clear it then. */
// When garbage collecting a funccall_T may be freed before the
// function that references it, clear its uf_scoped field.
// The function may have been redefined and point to another
// funccall_T, don't clear it then.
if (fp != NULL && fp->uf_scoped == fc)
fp->uf_scoped = NULL;
}
ga_clear(&fc->fc_funcs);
/* The a: variables typevals may not have been allocated, only free the
* allocated variables. */
vars_clear_ext(&fc->l_avars.dv_hashtab, free_val);
/* free all l: variables */
vars_clear(&fc->l_vars.dv_hashtab);
/* Free the a:000 variables if they were allocated. */
if (free_val)
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
clear_tv(&li->li_tv);
func_ptr_unref(fc->func);
vim_free(fc);
}
/*
* Free "fc" and what it contains.
* Can be called only when "fc" is kept beyond the period of it called,
* i.e. after cleanup_function_call(fc).
*/
static void
free_funccal_contents(funccall_T *fc)
{
listitem_T *li;
// Free all l: variables.
vars_clear(&fc->l_vars.dv_hashtab);
// Free all a: variables.
vars_clear(&fc->l_avars.dv_hashtab);
// Free the a:000 variables.
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
clear_tv(&li->li_tv);
free_funccal(fc);
}
/*
* Handle the last part of returning from a function: free the local hashtable.
* Unless it is still in use by a closure.
@@ -632,51 +640,75 @@ free_funccal(
static void
cleanup_function_call(funccall_T *fc)
{
int may_free_fc = fc->fc_refcount <= 0;
int free_fc = TRUE;
current_funccal = fc->caller;
/* If the a:000 list and the l: and a: dicts are not referenced and there
* is no closure using it, we can free the funccall_T and what's in it. */
if (fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
&& fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
&& fc->l_avars.dv_refcount == DO_NOT_FREE_CNT
&& fc->fc_refcount <= 0)
{
free_funccal(fc, FALSE);
}
// Free all l: variables if not referred.
if (may_free_fc && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT)
vars_clear(&fc->l_vars.dv_hashtab);
else
free_fc = FALSE;
// If the a:000 list and the l: and a: dicts are not referenced and
// there is no closure using it, we can free the funccall_T and what's
// in it.
if (may_free_fc && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
vars_clear_ext(&fc->l_avars.dv_hashtab, FALSE);
else
{
hashitem_T *hi;
listitem_T *li;
int todo;
dictitem_T *v;
static int made_copy = 0;
int todo;
hashitem_T *hi;
dictitem_T *di;
/* "fc" is still in use. This can happen when returning "a:000",
* assigning "l:" to a global variable or defining a closure.
* Link "fc" in the list for garbage collection later. */
fc->caller = previous_funccal;
previous_funccal = fc;
free_fc = FALSE;
/* Make a copy of the a: variables, since we didn't do that above. */
// Make a copy of the a: variables, since we didn't do that above.
todo = (int)fc->l_avars.dv_hashtab.ht_used;
for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
{
if (!HASHITEM_EMPTY(hi))
{
--todo;
v = HI2DI(hi);
copy_tv(&v->di_tv, &v->di_tv);
di = HI2DI(hi);
copy_tv(&di->di_tv, &di->di_tv);
}
}
}
/* Make a copy of the a:000 items, since we didn't do that above. */
if (may_free_fc && fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT)
fc->l_varlist.lv_first = NULL;
else
{
listitem_T *li;
free_fc = FALSE;
// Make a copy of the a:000 items, since we didn't do that above.
for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
copy_tv(&li->li_tv, &li->li_tv);
}
if (++made_copy == 10000)
if (free_fc)
free_funccal(fc);
else
{
static int made_copy = 0;
// "fc" is still in use. This can happen when returning "a:000",
// assigning "l:" to a global variable or defining a closure.
// Link "fc" in the list for garbage collection later.
fc->caller = previous_funccal;
previous_funccal = fc;
if (want_garbage_collect)
// If garbage collector is ready, clear count.
made_copy = 0;
else if (++made_copy >= (int)((4096 * 1024) / sizeof(*fc)))
{
// We have made a lot of copies. This can happen when
// repetitively calling a function that creates a reference to
// We have made a lot of copies, worth 4 Mbyte. This can happen
// when repetitively calling a function that creates a reference to
// itself somehow. Call the garbage collector soon to avoid using
// too much memory.
made_copy = 0;
@@ -731,7 +763,7 @@ call_user_func(
line_breakcheck(); /* check for CTRL-C hit */
fc = (funccall_T *)alloc(sizeof(funccall_T));
fc = (funccall_T *)alloc_clear(sizeof(funccall_T));
if (fc == NULL)
return;
fc->caller = current_funccal;
@@ -832,16 +864,15 @@ call_user_func(
{
v = &fc->fixvar[fixvar_idx++].var;
v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
STRCPY(v->di_key, name);
}
else
{
v = (dictitem_T *)alloc((unsigned)(sizeof(dictitem_T)
+ STRLEN(name)));
v = dictitem_alloc(name);
if (v == NULL)
break;
v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX | DI_FLAGS_ALLOC;
v->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX;
}
STRCPY(v->di_key, name);
/* Note: the values are copied directly to avoid alloc/free.
* "argvars" must have VAR_FIXED for v_lock. */
@@ -860,9 +891,11 @@ call_user_func(
if (ai >= 0 && ai < MAX_FUNC_ARGS)
{
list_append(&fc->l_varlist, &fc->l_listitems[ai]);
fc->l_listitems[ai].li_tv = argvars[i];
fc->l_listitems[ai].li_tv.v_lock = VAR_FIXED;
listitem_T *li = &fc->l_listitems[ai];
li->li_tv = argvars[i];
li->li_tv.v_lock = VAR_FIXED;
list_append(&fc->l_varlist, li);
}
}
@@ -1088,7 +1121,7 @@ funccal_unref(funccall_T *fc, ufunc_T *fp, int force)
if (fc == *pfc)
{
*pfc = fc->caller;
free_funccal(fc, TRUE);
free_funccal_contents(fc);
return;
}
}
@@ -3646,7 +3679,7 @@ free_unref_funccal(int copyID, int testing)
{
fc = *pfc;
*pfc = fc->caller;
free_funccal(fc, TRUE);
free_funccal_contents(fc);
did_free = TRUE;
did_free_funccal = TRUE;
}

View File

@@ -779,6 +779,32 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1010,
/**/
1009,
/**/
1008,
/**/
1007,
/**/
1006,
/**/
1005,
/**/
1004,
/**/
1003,
/**/
1002,
/**/
1001,
/**/
1000,
/**/
999,
/**/
998,
/**/
997,
/**/