Skip to content

Commit 9a78d37

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents b8b35c8 + b4c5572 commit 9a78d37

File tree

14 files changed

+609
-50
lines changed

14 files changed

+609
-50
lines changed

src/fileio.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9071,6 +9071,11 @@ aucmd_restbuf(
90719071
win_remove(curwin, NULL);
90729072
aucmd_win_used = FALSE;
90739073
last_status(FALSE); /* may need to remove last status line */
9074+
9075+
if (!valid_tabpage_win(curtab))
9076+
/* no valid window in current tabpage */
9077+
close_tabpage(curtab);
9078+
90749079
restore_snapshot(SNAP_AUCMD_IDX, FALSE);
90759080
(void)win_comp_pos(); /* recompute window positions */
90769081
unblock_autocmds();

src/proto/window.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ int win_new_tabpage(int after);
2626
int may_open_tabpage(void);
2727
int make_tabpages(int maxcount);
2828
int valid_tabpage(tabpage_T *tpc);
29+
int valid_tabpage_win(tabpage_T *tpc);
30+
void close_tabpage(tabpage_T *tpc);
2931
tabpage_T *find_tabpage(int n);
3032
int tabpage_index(tabpage_T *ftp);
3133
void goto_tabpage(int n);

src/quickfix.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5077,6 +5077,7 @@ ex_helpgrep(exarg_T *eap)
50775077
char_u *lang;
50785078
#endif
50795079
qf_info_T *qi = &ql_info;
5080+
qf_info_T *save_qi;
50805081
int new_qi = FALSE;
50815082
win_T *wp;
50825083
#ifdef FEAT_AUTOCMD
@@ -5130,6 +5131,9 @@ ex_helpgrep(exarg_T *eap)
51305131
}
51315132
}
51325133

5134+
/* Autocommands may change the list. Save it for later comparison */
5135+
save_qi = qi;
5136+
51335137
regmatch.regprog = vim_regcomp(eap->arg, RE_MAGIC + RE_STRING);
51345138
regmatch.rm_ic = FALSE;
51355139
if (regmatch.regprog != NULL)
@@ -5262,7 +5266,7 @@ ex_helpgrep(exarg_T *eap)
52625266
{
52635267
apply_autocmds(EVENT_QUICKFIXCMDPOST, au_name,
52645268
curbuf->b_fname, TRUE, curbuf);
5265-
if (!new_qi && qi != &ql_info && qf_find_buf(qi) == NULL)
5269+
if (!new_qi && qi != save_qi && qf_find_buf(qi) == NULL)
52665270
/* autocommands made "qi" invalid */
52675271
return;
52685272
}

src/testdir/Make_all.mak

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ NEW_TESTS = test_arabic.res \
137137
test_arglist.res \
138138
test_assert.res \
139139
test_autochdir.res \
140+
test_autocmd.res \
140141
test_backspace_opt.res \
141142
test_breakindent.res \
142143
test_bufwintabinfo.res \

src/testdir/gen_opt_test.vim

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ while 1
180180
for val in a[0]
181181
call add(script, 'set ' . name . '=' . val)
182182
call add(script, 'set ' . shortname . '=' . val)
183-
184-
if name == 'verbosefile' && !empty(val)
185-
call add(script, 'call delete("'. val. '")')
186-
endif
187183
endfor
188184

189185
" setting an option can only fail when it's implemented.
@@ -197,6 +193,9 @@ while 1
197193

198194
call add(script, 'set ' . name . '&')
199195
call add(script, 'set ' . shortname . '&')
196+
if name == 'verbosefile'
197+
call add(script, 'call delete("xxx")')
198+
endif
200199

201200
if name == 'more'
202201
call add(script, 'set nomore')

src/testdir/test_alot.vim

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
set belloff=all
55
source test_assign.vim
6-
source test_autocmd.vim
76
source test_changedtick.vim
87
source test_cursor_func.vim
98
source test_delete.vim

src/testdir/test_autocmd.vim

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
" Tests for autocommands
22

3+
set belloff=all
4+
35
function! s:cleanup_buffers() abort
46
for bnr in range(1, bufnr('$'))
57
if bufloaded(bnr) && bufnr('%') != bnr
@@ -318,6 +320,8 @@ func Test_three_windows()
318320
call assert_equal('Xanother', expand('%'))
319321

320322
au!
323+
enew
324+
bwipe! Xtestje1
321325
call delete('Xtestje1')
322326
call delete('Xtestje2')
323327
call delete('Xtestje3')
@@ -341,3 +345,72 @@ func Test_BufEnter()
341345
call delete('Xdir', 'd')
342346
au! BufEnter
343347
endfunc
348+
349+
" Closing a window might cause an endless loop
350+
" E814 for older Vims
351+
function Test_autocmd_bufwipe_in_SessLoadPost()
352+
if has('win32')
353+
throw 'Skipped: test hangs on MS-Windows'
354+
endif
355+
tabnew
356+
set noswapfile
357+
let g:bufnr=bufnr('%')
358+
mksession!
359+
360+
let content=['set nocp noswapfile',
361+
\ 'let v:swapchoice="e"',
362+
\ 'augroup test_autocmd_sessionload',
363+
\ 'autocmd!',
364+
\ 'autocmd SessionLoadPost * 4bw!',
365+
\ 'augroup END'
366+
\ ]
367+
call writefile(content, 'Xvimrc')
368+
let a=system(v:progpath. ' -u Xvimrc --noplugins -S Session.vim')
369+
call assert_match('E814', a)
370+
371+
unlet! g:bufnr
372+
set swapfile
373+
for file in ['Session.vim', 'Xvimrc']
374+
call delete(file)
375+
endfor
376+
endfunc
377+
378+
" SEGV occurs in older versions.
379+
function Test_autocmd_bufwipe_in_SessLoadPost2()
380+
if has('win32')
381+
throw 'Skipped: test hangs on MS-Windows'
382+
endif
383+
tabnew
384+
set noswapfile
385+
let g:bufnr=bufnr('%')
386+
mksession!
387+
388+
let content = ['set nocp noswapfile',
389+
\ 'function! DeleteInactiveBufs()',
390+
\ ' tabfirst',
391+
\ ' let tabblist = []',
392+
\ ' for i in range(1, tabpagenr(''$''))',
393+
\ ' call extend(tabblist, tabpagebuflist(i))',
394+
\ ' endfor',
395+
\ ' for b in range(1, bufnr(''$''))',
396+
\ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')',
397+
\ ' exec ''bwipeout '' . b',
398+
\ ' endif',
399+
\ ' endfor',
400+
\ 'call append("1", "SessionLoadPost DONE")',
401+
\ 'endfunction',
402+
\ 'au SessionLoadPost * call DeleteInactiveBufs()']
403+
call writefile(content, 'Xvimrc')
404+
let a=system(v:progpath. ' -u Xvimrc --noplugins -S Session.vim')
405+
" this probably only matches on unix
406+
if has("unix")
407+
call assert_notmatch('Caught deadly signal SEGV', a)
408+
endif
409+
call assert_match('SessionLoadPost DONE', a)
410+
411+
unlet! g:bufnr
412+
set swapfile
413+
for file in ['Session.vim', 'Xvimrc']
414+
call delete(file)
415+
endfor
416+
endfunc

src/testdir/test_delete.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func Test_file_delete()
88
call assert_equal(0, delete('Xfile'))
99
call assert_fails('call readfile("Xfile")', 'E484:')
1010
call assert_equal(-1, delete('Xfile'))
11+
bwipe Xfile
1112
endfunc
1213

1314
func Test_dir_delete()
@@ -35,6 +36,8 @@ func Test_recursive_delete()
3536
call assert_equal(0, delete('Xdir1', 'rf'))
3637
call assert_false(isdirectory('Xdir1'))
3738
call assert_equal(-1, delete('Xdir1', 'd'))
39+
bwipe Xdir1/Xfile
40+
bwipe Xdir1/subdir/Xfile
3841
endfunc
3942

4043
func Test_symlink_delete()
@@ -49,6 +52,7 @@ func Test_symlink_delete()
4952
call assert_equal(0, delete('Xlink'))
5053
call assert_equal(-1, delete('Xlink'))
5154
call assert_equal(0, delete('Xfile'))
55+
bwipe Xfile
5256
endfunc
5357

5458
func Test_symlink_dir_delete()
@@ -96,4 +100,8 @@ func Test_symlink_recursive_delete()
96100
call assert_equal(['a', 'b'], readfile('Xdir4/Xfile'))
97101
call assert_equal(0, delete('Xdir4/Xfile'))
98102
call assert_equal(0, delete('Xdir4', 'd'))
103+
104+
bwipe Xdir3/Xfile
105+
bwipe Xdir3/subdir/Xfile
106+
bwipe Xdir4/Xfile
99107
endfunc

src/testdir/test_fnamemodify.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ func Test_fnamemodify()
3333
call assert_equal('''abc"%"def''', fnamemodify('abc"%"def', ':S'))
3434
call assert_equal('''abc''\'''' ''\''''def''', fnamemodify('abc'' ''def', ':S'))
3535
call assert_equal('''abc''\''''%''\''''def''', fnamemodify('abc''%''def', ':S'))
36-
call assert_equal(expand('%:r:S'), shellescape(expand('%:r')))
3736
sp test_alot.vim
37+
call assert_equal(expand('%:r:S'), shellescape(expand('%:r')))
3838
call assert_equal('test_alot,''test_alot'',test_alot.vim', join([expand('%:r'), expand('%:r:S'), expand('%')], ','))
3939
quit
4040

src/testdir/test_functions.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ func Test_getbufvar()
460460
let bd = getbufvar(bnr, '',def_num)
461461
call assert_equal(1, len(bd))
462462

463-
call assert_equal('', getbufvar(9, ''))
464-
call assert_equal(def_num, getbufvar(9, '', def_num))
463+
call assert_equal('', getbufvar(9999, ''))
464+
call assert_equal(def_num, getbufvar(9999, '', def_num))
465465
unlet def_num
466466

467467
call assert_equal(0, getbufvar(bnr, '&autoindent'))

0 commit comments

Comments
 (0)