mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
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)
adc6714aac
This commit is contained in:
parent
3a3fb08602
commit
1aacab49ea
@ -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;
|
||||
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)}
|
||||
|
Loading…
Reference in New Issue
Block a user