diff options
author | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-01-05 10:40:02 -0500 |
---|---|---|
committer | Jan Edmund Lazo <jan.lazo@mail.utoronto.ca> | 2020-01-05 10:40:53 -0500 |
commit | 1aacab49ea0e5cff94bd89595737b6af677f4490 (patch) | |
tree | 3d917be003cb49e95a3ea021145701f44cfb39b9 | |
parent | 3a3fb0860248b42e05de6591d4b7727453efdef2 (diff) | |
download | rneovim-1aacab49ea0e5cff94bd89595737b6af677f4490.tar.gz rneovim-1aacab49ea0e5cff94bd89595737b6af677f4490.tar.bz2 rneovim-1aacab49ea0e5cff94bd89595737b6af677f4490.zip |
vim-patch:8.1.1579: dict and list could be GC'ed while displaying error
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 vim/vim#4571)
https://github.com/vim/vim/commit/adc6714aac20f5462a0ecec50ab4806b2f3ab0db
-rw-r--r-- | src/nvim/eval.c | 2 | ||||
-rw-r--r-- | src/nvim/eval/typval.c | 2 | ||||
-rw-r--r-- | src/nvim/getchar.c | 2 | ||||
-rw-r--r-- | src/nvim/globals.h | 2 | ||||
-rw-r--r-- | src/nvim/testdir/test_timers.vim | 26 | ||||
-rw-r--r-- | test/unit/eval/helpers.lua | 2 |
6 files changed, 31 insertions, 5 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index cf4d3af232..5c19ce4047 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -5920,7 +5920,7 @@ static int dict_get_tv(char_u **arg, typval_T *rettv, int evaluate) if (**arg != '}') { EMSG2(_("E723: Missing end of Dictionary '}': %s"), *arg); failret: - if (evaluate) { + if (d != NULL) { tv_dict_free(d); } return FAIL; diff --git a/src/nvim/eval/typval.c b/src/nvim/eval/typval.c index 728e3a7fa3..da97eccc65 100644 --- a/src/nvim/eval/typval.c +++ b/src/nvim/eval/typval.c @@ -1306,7 +1306,7 @@ void tv_dict_item_remove(dict_T *const dict, dictitem_T *const item) dict_T *tv_dict_alloc(void) FUNC_ATTR_NONNULL_RET FUNC_ATTR_WARN_UNUSED_RESULT { - dict_T *const d = xmalloc(sizeof(dict_T)); + dict_T *const d = xcalloc(1, sizeof(dict_T)); // Add the dict to the list of dicts for garbage collection. if (gc_first_dict != NULL) { diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index b82839103f..81666bf5d6 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -1518,7 +1518,7 @@ int vgetc(void) * collection in the first next vgetc(). It's disabled after that to * avoid internally used Lists and Dicts to be freed. */ - may_garbage_collect = FALSE; + may_garbage_collect = false; return c; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 148ab0a02b..4741778c14 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -325,7 +325,7 @@ EXTERN except_T *caught_stack INIT(= NULL); /// we do garbage collection before waiting for a char at the toplevel. /// "garbage_collect_at_exit" indicates garbagecollect(1) was called. /// -EXTERN int may_garbage_collect INIT(= false); +EXTERN bool may_garbage_collect INIT(= false); EXTERN int want_garbage_collect INIT(= false); EXTERN int garbage_collect_at_exit INIT(= false); diff --git a/src/nvim/testdir/test_timers.vim b/src/nvim/testdir/test_timers.vim index c4d74222a4..3043103270 100644 --- a/src/nvim/testdir/test_timers.vim +++ b/src/nvim/testdir/test_timers.vim @@ -313,4 +313,30 @@ 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() + " skipped: Nvim does not support test_garbagecollect_soon(), test_override() + return + " '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/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 3d1c42c3a0..bcd7c750c5 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -406,7 +406,7 @@ end local alloc_logging_helpers = { list = function(l) return {func='calloc', args={1, ffi.sizeof('list_T')}, ret=void(l)} end, li = function(li) return {func='malloc', args={ffi.sizeof('listitem_T')}, ret=void(li)} end, - dict = function(d) return {func='malloc', args={ffi.sizeof('dict_T')}, ret=void(d)} end, + dict = function(d) return {func='calloc', args={1, ffi.sizeof('dict_T')}, ret=void(d)} end, di = function(di, size) size = alloc_len(size, function() return di.di_key end) return {func='malloc', args={ffi.offsetof('dictitem_T', 'di_key') + size + 1}, ret=void(di)} |