Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 22541:7d6ba4204f66 v8.2.1819
patch 8.2.1819: Vim9: Memory leak when using a closure
Commit: https://github.com/vim/vim/commit/85d5e2b723e6fc233e53252dd5c523944146fbc2
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 10 14:13:01 2020 +0200
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 10 Oct 2020 14:15:04 +0200 |
parents | 9870e8b6ed78 |
children | c271498e03b2 |
comparison
equal
deleted
inserted
replaced
22540:f0fd5cb81663 | 22541:7d6ba4204f66 |
---|---|
1328 | 1328 |
1329 unlet g:UseArg | 1329 unlet g:UseArg |
1330 unlet g:UseVararg | 1330 unlet g:UseVararg |
1331 enddef | 1331 enddef |
1332 | 1332 |
1333 " TODO: reenable after fixing memory leak | 1333 def MakeGetAndAppendRefs() |
1334 "def MakeGetAndAppendRefs() | 1334 var local = 'a' |
1335 " var local = 'a' | 1335 |
1336 " | 1336 def Append(arg: string) |
1337 " def Append(arg: string) | 1337 local ..= arg |
1338 " local ..= arg | 1338 enddef |
1339 " enddef | 1339 g:Append = Append |
1340 " g:Append = Append | 1340 |
1341 " | 1341 def Get(): string |
1342 " def Get(): string | 1342 return local |
1343 " return local | 1343 enddef |
1344 " enddef | 1344 g:Get = Get |
1345 " g:Get = Get | 1345 enddef |
1346 "enddef | 1346 |
1347 " | 1347 def Test_closure_append_get() |
1348 "def Test_closure_append_get() | 1348 MakeGetAndAppendRefs() |
1349 " MakeGetAndAppendRefs() | 1349 g:Get()->assert_equal('a') |
1350 " g:Get()->assert_equal('a') | 1350 g:Append('-b') |
1351 " g:Append('-b') | 1351 g:Get()->assert_equal('a-b') |
1352 " g:Get()->assert_equal('a-b') | 1352 g:Append('-c') |
1353 " g:Append('-c') | 1353 g:Get()->assert_equal('a-b-c') |
1354 " g:Get()->assert_equal('a-b-c') | 1354 |
1355 " | 1355 unlet g:Append |
1356 " unlet g:Append | 1356 unlet g:Get |
1357 " unlet g:Get | 1357 enddef |
1358 "enddef | |
1359 | 1358 |
1360 def Test_nested_closure() | 1359 def Test_nested_closure() |
1361 var local = 'text' | 1360 var local = 'text' |
1362 def Closure(arg: string): string | 1361 def Closure(arg: string): string |
1363 return local .. arg | 1362 return local .. arg |
1387 Func() | 1386 Func() |
1388 END | 1387 END |
1389 CheckScriptSuccess(lines) | 1388 CheckScriptSuccess(lines) |
1390 enddef | 1389 enddef |
1391 | 1390 |
1392 " TODO: reenable after fixing memory leak | 1391 def Test_nested_closure_used() |
1393 "def Test_nested_closure_used() | 1392 var lines =<< trim END |
1394 " var lines =<< trim END | 1393 vim9script |
1395 " vim9script | 1394 def Func() |
1396 " def Func() | 1395 var x = 'hello' |
1397 " var x = 'hello' | 1396 var Closure = {-> x} |
1398 " var Closure = {-> x} | 1397 g:Myclosure = {-> Closure()} |
1399 " g:Myclosure = {-> Closure()} | 1398 enddef |
1400 " enddef | 1399 Func() |
1401 " Func() | 1400 assert_equal('hello', g:Myclosure()) |
1402 " assert_equal('hello', g:Myclosure()) | 1401 END |
1403 " END | 1402 CheckScriptSuccess(lines) |
1404 " CheckScriptSuccess(lines) | 1403 enddef |
1405 "enddef | |
1406 | 1404 |
1407 def Test_nested_closure_fails() | 1405 def Test_nested_closure_fails() |
1408 var lines =<< trim END | 1406 var lines =<< trim END |
1409 vim9script | 1407 vim9script |
1410 def FuncA() | 1408 def FuncA() |