To: vim_dev@googlegroups.com Subject: Patch 8.0.0923 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0923 Problem: Crash in GUI when terminal job exits. (Kazunobu Kuriyama) Solution: reset in_terminal_loop when a terminal is freed. Files: src/terminal.c, src/testdir/test_terminal.vim *** ../vim-8.0.0922/src/terminal.c 2017-08-12 22:55:54.217280907 +0200 --- src/terminal.c 2017-08-13 14:00:37.449571222 +0200 *************** *** 34,42 **** * * When the job ends the text is put in a buffer. Redrawing then happens from * that buffer, attributes come from the scrollback buffer tl_scrollback. * * TODO: - * - cursor shape/color/blink in the GUI * - Make argument list work on MS-Windows. #1954 * - MS-Windows: no redraw for 'updatetime' #1915 * - To set BS correctly, check get_stty(); Pass the fd of the pty. --- 34,43 ---- * * When the job ends the text is put in a buffer. Redrawing then happens from * that buffer, attributes come from the scrollback buffer tl_scrollback. + * When the buffer is changed it is turned into a normal buffer, the attributes + * in tl_scrollback are no longer used. * * TODO: * - Make argument list work on MS-Windows. #1954 * - MS-Windows: no redraw for 'updatetime' #1915 * - To set BS correctly, check get_stty(); Pass the fd of the pty. *************** *** 524,529 **** --- 525,532 ---- vim_free(term->tl_cursor_color); vim_free(term); buf->b_term = NULL; + if (in_terminal_loop == term) + in_terminal_loop = NULL; } /* *************** *** 1014,1019 **** --- 1017,1024 ---- /* * Get a key from the user without mapping. + * Note: while waiting a terminal may be closed and freed if the channel is + * closed and ++close was used. * TODO: use terminal mode mappings. */ static int *************** *** 1140,1149 **** --- 1145,1160 ---- #ifdef FEAT_CMDL_INFO clear_showcmd(); #endif + if (!term_use_loop()) + /* job finished while waiting for a character */ + return; /* CTRL-W "= prompt for expression to evaluate. */ if (c == '=' && get_expr_register() != '=') return; + if (!term_use_loop()) + /* job finished while waiting for a character */ + return; l = (list_T *)get_reg_contents(c, GREG_LIST); if (l != NULL) *************** *** 1272,1277 **** --- 1283,1292 ---- int termkey = 0; int ret; + /* Remember the terminal we are sending keys to. However, the terminal + * might be closed while waiting for a character, e.g. typing "exit" in a + * shell and ++close was used. Therefore use curbuf->b_term instead of a + * stored reference. */ in_terminal_loop = curbuf->b_term; if (*curwin->w_p_tk != NUL) *** ../vim-8.0.0922/src/testdir/test_terminal.vim 2017-08-12 16:01:00.690997000 +0200 --- src/testdir/test_terminal.vim 2017-08-13 14:10:20.669969512 +0200 *************** *** 414,416 **** --- 414,436 ---- exe buf . 'bwipe' endfunc + + " must be last, we can't go back from GUI to terminal + func Test_zz_terminal_in_gui() + if !has('gui') + return + endif + gui -f + + call assert_equal(1, winnr('$')) + let buf = Run_shell_in_terminal({'term_finish': 'close'}) + call Stop_shell_in_terminal(buf) + call term_wait(buf) + + " closing window wipes out the terminal buffer a with finished job + call WaitFor("winnr('$') == 1") + call assert_equal(1, winnr('$')) + call assert_equal("", bufname(buf)) + + unlet g:job + endfunc *** ../vim-8.0.0922/src/version.c 2017-08-13 13:41:57.176413216 +0200 --- src/version.c 2017-08-13 14:02:42.500795238 +0200 *************** *** 771,772 **** --- 771,774 ---- { /* Add new patch number below this line */ + /**/ + 923, /**/ -- A law to reduce crime states: "It is mandatory for a motorist with criminal intentions to stop at the city limits and telephone the chief of police as he is entering the town. [real standing law in Washington, United States of America] /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///