Mercurial > vim
comparison src/testdir/test_quickfix.vim @ 26518:13ba00ef7687 v8.2.3788
patch 8.2.3788: lambda for option that is a function may be freed
Commit: https://github.com/vim/vim/commit/6ae8fae8696623b527c7fb22567f6a3705b2f0dd
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sun Dec 12 16:26:44 2021 +0000
patch 8.2.3788: lambda for option that is a function may be freed
Problem: Lambda for option that is a function may be garbage collected.
Solution: Set a reference in the funcref. (Yegappan Lakshmanan,
closes #9330)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 12 Dec 2021 17:30:04 +0100 |
parents | c0cb28384dc2 |
children | 33d680d372aa |
comparison
equal
deleted
inserted
replaced
26517:7dfc4c45f698 | 26518:13ba00ef7687 |
---|---|
1 " Test for the quickfix feature. | 1 " Test for the quickfix feature. |
2 | 2 |
3 source check.vim | 3 source check.vim |
4 source vim9.vim | |
4 CheckFeature quickfix | 5 CheckFeature quickfix |
5 | 6 |
6 source screendump.vim | 7 source screendump.vim |
7 | 8 |
8 set encoding=utf-8 | 9 set encoding=utf-8 |
5280 func Test_qftextfunc() | 5281 func Test_qftextfunc() |
5281 call Xtest_qftextfunc('c') | 5282 call Xtest_qftextfunc('c') |
5282 call Xtest_qftextfunc('l') | 5283 call Xtest_qftextfunc('l') |
5283 endfunc | 5284 endfunc |
5284 | 5285 |
5286 func Test_qftextfunc_callback() | |
5287 let lines =<< trim END | |
5288 set efm=%f:%l:%c:%m | |
5289 | |
5290 #" Test for using a function() | |
5291 set qftf=function('g:Tqfexpr') | |
5292 cexpr "F1:1:1:L1" | |
5293 copen | |
5294 call assert_equal('F1-L1C1-L1', getline(1)) | |
5295 cclose | |
5296 | |
5297 #" Using a funcref variable to set 'quickfixtextfunc' | |
5298 VAR Fn = function('g:Tqfexpr') | |
5299 LET &qftf = Fn | |
5300 cexpr "F2:2:2:L2" | |
5301 copen | |
5302 call assert_equal('F2-L2C2-L2', getline(1)) | |
5303 cclose | |
5304 | |
5305 #" Using string(funcref_variable) to set 'quickfixtextfunc' | |
5306 LET Fn = function('g:Tqfexpr') | |
5307 LET &qftf = string(Fn) | |
5308 cexpr "F3:3:3:L3" | |
5309 copen | |
5310 call assert_equal('F3-L3C3-L3', getline(1)) | |
5311 cclose | |
5312 | |
5313 #" Test for using a funcref() | |
5314 set qftf=funcref('g:Tqfexpr') | |
5315 cexpr "F4:4:4:L4" | |
5316 copen | |
5317 call assert_equal('F4-L4C4-L4', getline(1)) | |
5318 cclose | |
5319 | |
5320 #" Using a funcref variable to set 'quickfixtextfunc' | |
5321 LET Fn = funcref('g:Tqfexpr') | |
5322 LET &qftf = Fn | |
5323 cexpr "F5:5:5:L5" | |
5324 copen | |
5325 call assert_equal('F5-L5C5-L5', getline(1)) | |
5326 cclose | |
5327 | |
5328 #" Using a string(funcref_variable) to set 'quickfixtextfunc' | |
5329 LET Fn = funcref('g:Tqfexpr') | |
5330 LET &qftf = string(Fn) | |
5331 cexpr "F5:5:5:L5" | |
5332 copen | |
5333 call assert_equal('F5-L5C5-L5', getline(1)) | |
5334 cclose | |
5335 | |
5336 #" Test for using a lambda function with set | |
5337 VAR optval = "LSTART a LMIDDLE Tqfexpr(a) LEND" | |
5338 LET optval = substitute(optval, ' ', '\\ ', 'g') | |
5339 exe "set qftf=" .. optval | |
5340 cexpr "F6:6:6:L6" | |
5341 copen | |
5342 call assert_equal('F6-L6C6-L6', getline(1)) | |
5343 cclose | |
5344 | |
5345 #" Set 'quickfixtextfunc' to a lambda expression | |
5346 LET &qftf = LSTART a LMIDDLE Tqfexpr(a) LEND | |
5347 cexpr "F7:7:7:L7" | |
5348 copen | |
5349 call assert_equal('F7-L7C7-L7', getline(1)) | |
5350 cclose | |
5351 | |
5352 #" Set 'quickfixtextfunc' to string(lambda_expression) | |
5353 LET &qftf = "LSTART a LMIDDLE Tqfexpr(a) LEND" | |
5354 cexpr "F8:8:8:L8" | |
5355 copen | |
5356 call assert_equal('F8-L8C8-L8', getline(1)) | |
5357 cclose | |
5358 | |
5359 #" Set 'quickfixtextfunc' to a variable with a lambda expression | |
5360 VAR Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND | |
5361 LET &qftf = Lambda | |
5362 cexpr "F9:9:9:L9" | |
5363 copen | |
5364 call assert_equal('F9-L9C9-L9', getline(1)) | |
5365 cclose | |
5366 | |
5367 #" Set 'quickfixtextfunc' to a string(variable with a lambda expression) | |
5368 LET Lambda = LSTART a LMIDDLE Tqfexpr(a) LEND | |
5369 LET &qftf = string(Lambda) | |
5370 cexpr "F9:9:9:L9" | |
5371 copen | |
5372 call assert_equal('F9-L9C9-L9', getline(1)) | |
5373 cclose | |
5374 END | |
5375 call CheckLegacyAndVim9Success(lines) | |
5376 | |
5377 " set 'quickfixtextfunc' to a partial with dict. This used to cause a crash. | |
5378 func SetQftfFunc() | |
5379 let params = {'qftf': function('g:DictQftfFunc')} | |
5380 let &quickfixtextfunc = params.qftf | |
5381 endfunc | |
5382 func g:DictQftfFunc(_) dict | |
5383 endfunc | |
5384 call SetQftfFunc() | |
5385 new | |
5386 call SetQftfFunc() | |
5387 bw | |
5388 call test_garbagecollect_now() | |
5389 new | |
5390 set qftf= | |
5391 wincmd w | |
5392 set qftf= | |
5393 :%bw! | |
5394 | |
5395 " set per-quickfix list 'quickfixtextfunc' to a partial with dict. This used | |
5396 " to cause a crash. | |
5397 let &qftf = '' | |
5398 func SetLocalQftfFunc() | |
5399 let params = {'qftf': function('g:DictQftfFunc')} | |
5400 call setqflist([], 'a', {'quickfixtextfunc' : params.qftf}) | |
5401 endfunc | |
5402 call SetLocalQftfFunc() | |
5403 call test_garbagecollect_now() | |
5404 call setqflist([], 'a', {'quickfixtextfunc' : ''}) | |
5405 delfunc g:DictQftfFunc | |
5406 delfunc SetQftfFunc | |
5407 delfunc SetLocalQftfFunc | |
5408 set efm& | |
5409 endfunc | |
5410 | |
5285 " Test for updating a location list for some other window and check that | 5411 " Test for updating a location list for some other window and check that |
5286 " 'qftextfunc' uses the correct location list. | 5412 " 'qftextfunc' uses the correct location list. |
5287 func Test_qftextfunc_other_loclist() | 5413 func Test_qftextfunc_other_loclist() |
5288 %bw! | 5414 %bw! |
5289 call setloclist(0, [], 'f') | 5415 call setloclist(0, [], 'f') |