summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2019-06-22 01:40:42 +0200
committerBram Moolenaar <Bram@vim.org>2019-06-22 01:40:42 +0200
commitadc6714aac20f5462a0ecec50ab4806b2f3ab0db (patch)
tree54650818f8664ba76e6cad1632d463ed6b9aec74
parentdfc145572813c5d3848feb4029ff8bfb127ab66a (diff)
downloadvim-git-adc6714aac20f5462a0ecec50ab4806b2f3ab0db.tar.gz
patch 8.1.1579: dict and list could be GC'ed while displaying errorv8.1.1579
Problem: Dict and list could be GC'ed while displaying error in a timer. (Yasuhiro Matsumoto) Solution: Block garbage collection when executing a timer. Add test_garbagecollect_soon(). Add "no_wait_return" to test_override(). (closes #4571)
-rw-r--r--runtime/doc/eval.txt7
-rw-r--r--src/dict.c4
-rw-r--r--src/evalfunc.c13
-rw-r--r--src/testdir/test_timers.vim24
-rw-r--r--src/version.c2
5 files changed, 48 insertions, 2 deletions
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index 80fbfba1d..8de2d8c29 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -2741,6 +2741,7 @@ test_alloc_fail({id}, {countdown}, {repeat})
test_autochdir() none enable 'autochdir' during startup
test_feedinput({string}) none add key sequence to input buffer
test_garbagecollect_now() none free memory right now for testing
+test_garbagecollect_soon() none free memory soon for testing
test_getvalue({string}) any get value of an internal variable
test_ignore_error({expr}) none ignore a specific error
test_null_blob() Blob null value for testing
@@ -10009,6 +10010,10 @@ test_garbagecollect_now() *test_garbagecollect_now()*
internally, and |v:testing| must have been set before calling
any function.
+test_garbagecollect_soon() *test_garbagecollect_soon()*
+ Set the flag to call the garbagecollector as if in the main
+ loop. Only to be used in tests.
+
test_getvalue({name}) *test_getvalue()*
Get the value of an internal variable. These values for
{name} are supported:
@@ -10072,6 +10077,8 @@ test_override({name}, {val}) *test_override()*
fallback to the old engine
no_query_mouse do not query the mouse position for "dec"
terminals
+ no_wait_return set the "no_wait_return" flag. Not restored
+ with "ALL".
ALL clear all overrides ({val} is not used)
"starting" is to be used when a test should behave like
diff --git a/src/dict.c b/src/dict.c
index ffcb10062..96c58c1f2 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -28,7 +28,7 @@ dict_alloc(void)
{
dict_T *d;
- d = ALLOC_ONE(dict_T);
+ d = ALLOC_CLEAR_ONE(dict_T);
if (d != NULL)
{
/* Add the dict to the list of dicts for garbage collection. */
@@ -811,7 +811,7 @@ dict_get_tv(char_u **arg, typval_T *rettv, int evaluate)
{
semsg(_("E723: Missing end of Dictionary '}': %s"), *arg);
failret:
- if (evaluate)
+ if (d != NULL)
dict_free(d);
return FAIL;
}
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 5c9400e17..7930eb982 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -448,6 +448,7 @@ static void f_test_option_not_set(typval_T *argvars, typval_T *rettv);
static void f_test_override(typval_T *argvars, typval_T *rettv);
static void f_test_refcount(typval_T *argvars, typval_T *rettv);
static void f_test_garbagecollect_now(typval_T *argvars, typval_T *rettv);
+static void f_test_garbagecollect_soon(typval_T *argvars, typval_T *rettv);
static void f_test_ignore_error(typval_T *argvars, typval_T *rettv);
static void f_test_null_blob(typval_T *argvars, typval_T *rettv);
#ifdef FEAT_JOB_CHANNEL
@@ -1019,6 +1020,7 @@ static struct fst
{"test_autochdir", 0, 0, f_test_autochdir},
{"test_feedinput", 1, 1, f_test_feedinput},
{"test_garbagecollect_now", 0, 0, f_test_garbagecollect_now},
+ {"test_garbagecollect_soon", 0, 0, f_test_garbagecollect_soon},
{"test_getvalue", 1, 1, f_test_getvalue},
{"test_ignore_error", 1, 1, f_test_ignore_error},
{"test_null_blob", 0, 0, f_test_null_blob},
@@ -14460,6 +14462,8 @@ f_test_override(typval_T *argvars, typval_T *rettv UNUSED)
nfa_fail_for_testing = val;
else if (STRCMP(name, (char_u *)"no_query_mouse") == 0)
no_query_mouse_for_testing = val;
+ else if (STRCMP(name, (char_u *)"no_wait_return") == 0)
+ no_wait_return = val;
else if (STRCMP(name, (char_u *)"ALL") == 0)
{
disable_char_avail_for_testing = FALSE;
@@ -14551,6 +14555,15 @@ f_test_garbagecollect_now(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
}
/*
+ * "test_garbagecollect_soon()" function
+ */
+ static void
+f_test_garbagecollect_soon(typval_T *argvars UNUSED, typval_T *rettv UNUSED)
+{
+ may_garbage_collect = TRUE;
+}
+
+/*
* "test_ignore_error()" function
*/
static void
diff --git a/src/testdir/test_timers.vim b/src/testdir/test_timers.vim
index 03391d8f5..e67da134b 100644
--- a/src/testdir/test_timers.vim
+++ b/src/testdir/test_timers.vim
@@ -309,4 +309,28 @@ func Test_restore_count()
call delete('Xtrctext')
endfunc
+" Test that the garbage collector isn't triggered if a timer callback invokes
+" vgetc().
+func Test_nocatch_garbage_collect()
+ " 'uptimetime. must be bigger than the timer timeout
+ set ut=200
+ call test_garbagecollect_soon()
+ call test_override('no_wait_return', 0)
+ func CauseAnError(id)
+ " This will show an error and wait for Enter.
+ let a = {'foo', 'bar'}
+ endfunc
+ func FeedChar(id)
+ call feedkeys('x', 't')
+ endfunc
+ call timer_start(300, 'FeedChar')
+ call timer_start(100, 'CauseAnError')
+ let x = getchar()
+
+ set ut&
+ call test_override('no_wait_return', 1)
+ delfunc CauseAnError
+ delfunc FeedChar
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index bc19c04f7..2b113afb8 100644
--- a/src/version.c
+++ b/src/version.c
@@ -778,6 +778,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 1579,
+/**/
1578,
/**/
1577,