1
0
forked from aniani/vim

patch 8.2.1819: Vim9: Memory leak when using a closure

Problem:    Vim9: Memory leak when using a closure.
Solution:   Compute the mininal refcount in the funcstack.  Reenable disabled
            tests.
This commit is contained in:
Bram Moolenaar
2020-10-10 14:13:01 +02:00
parent 8956023920
commit 85d5e2b723
7 changed files with 143 additions and 110 deletions

View File

@@ -1330,32 +1330,31 @@ def Test_closure_using_argument()
unlet g:UseVararg
enddef
" TODO: reenable after fixing memory leak
"def MakeGetAndAppendRefs()
" var local = 'a'
"
" def Append(arg: string)
" local ..= arg
" enddef
" g:Append = Append
"
" def Get(): string
" return local
" enddef
" g:Get = Get
"enddef
"
"def Test_closure_append_get()
" MakeGetAndAppendRefs()
" g:Get()->assert_equal('a')
" g:Append('-b')
" g:Get()->assert_equal('a-b')
" g:Append('-c')
" g:Get()->assert_equal('a-b-c')
"
" unlet g:Append
" unlet g:Get
"enddef
def MakeGetAndAppendRefs()
var local = 'a'
def Append(arg: string)
local ..= arg
enddef
g:Append = Append
def Get(): string
return local
enddef
g:Get = Get
enddef
def Test_closure_append_get()
MakeGetAndAppendRefs()
g:Get()->assert_equal('a')
g:Append('-b')
g:Get()->assert_equal('a-b')
g:Append('-c')
g:Get()->assert_equal('a-b-c')
unlet g:Append
unlet g:Get
enddef
def Test_nested_closure()
var local = 'text'
@@ -1389,20 +1388,19 @@ def Test_double_closure_fails()
CheckScriptSuccess(lines)
enddef
" TODO: reenable after fixing memory leak
"def Test_nested_closure_used()
" var lines =<< trim END
" vim9script
" def Func()
" var x = 'hello'
" var Closure = {-> x}
" g:Myclosure = {-> Closure()}
" enddef
" Func()
" assert_equal('hello', g:Myclosure())
" END
" CheckScriptSuccess(lines)
"enddef
def Test_nested_closure_used()
var lines =<< trim END
vim9script
def Func()
var x = 'hello'
var Closure = {-> x}
g:Myclosure = {-> Closure()}
enddef
Func()
assert_equal('hello', g:Myclosure())
END
CheckScriptSuccess(lines)
enddef
def Test_nested_closure_fails()
var lines =<< trim END