To: vim_dev@googlegroups.com Subject: Patch 7.4.1826 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1826 Problem: Callbacks are invoked when it's not safe. (Andrew Stewart) Solution: When a channel is to be closed don't invoke callbacks right away, wait for a safe moment. Files: src/structs.h, src/channel.c *** ../vim-7.4.1825/src/structs.h 2016-04-29 22:58:25.622876633 +0200 --- src/structs.h 2016-05-09 17:07:32.120714293 +0200 *************** *** 1416,1421 **** --- 1416,1424 ---- char *ch_hostname; /* only for socket, allocated */ int ch_port; /* only for socket */ + int ch_to_be_closed; /* When TRUE reading or writing failed and + * the channel must be closed when it's safe + * to invoke callbacks. */ int ch_error; /* When TRUE an error was reported. Avoids * giving pages full of error messages when * the other side has exited, only mention the *** ../vim-7.4.1825/src/channel.c 2016-05-08 21:46:56.168690797 +0200 --- src/channel.c 2016-05-09 17:13:27.844763619 +0200 *************** *** 2782,2788 **** channel_close_on_error(channel_T *channel, char *func) { /* Do not call emsg(), most likely the other end just exited. */ ! ch_errors(channel, "%s(): Cannot read from channel", func); /* Queue a "DETACH" netbeans message in the command queue in order to * terminate the netbeans session later. Do not end the session here --- 2782,2789 ---- channel_close_on_error(channel_T *channel, char *func) { /* Do not call emsg(), most likely the other end just exited. */ ! ch_errors(channel, "%s(): Cannot read from channel, will close it soon", ! func); /* Queue a "DETACH" netbeans message in the command queue in order to * terminate the netbeans session later. Do not end the session here *************** *** 2800,2806 **** (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); /* When reading from stdout is not possible, assume the other side has ! * died. */ channel_close(channel, TRUE); if (channel->ch_nb_close_cb != NULL) (*channel->ch_nb_close_cb)(); --- 2801,2815 ---- (int)STRLEN(DETACH_MSG_RAW), FALSE, "PUT "); /* When reading from stdout is not possible, assume the other side has ! * died. Don't close the channel right away, it may be the wrong moment ! * to invoke callbacks. */ ! channel->ch_to_be_closed = TRUE; ! } ! ! static void ! channel_close_now(channel_T *channel) ! { ! ch_log(channel, "Closing channel because of previous read error"); channel_close(channel, TRUE); if (channel->ch_nb_close_cb != NULL) (*channel->ch_nb_close_cb)(); *************** *** 3515,3520 **** --- 3524,3537 ---- } while (channel != NULL) { + if (channel->ch_to_be_closed) + { + channel->ch_to_be_closed = FALSE; + channel_close_now(channel); + /* channel may have been freed, start over */ + channel = first_channel; + continue; + } if (channel->ch_refcount == 0 && !channel_still_useful(channel)) { /* channel is no longer useful, free it */ *** ../vim-7.4.1825/src/version.c 2016-05-08 21:46:56.172690753 +0200 --- src/version.c 2016-05-09 17:08:44.071915308 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1826, /**/ -- ARTHUR: It is I, Arthur, son of Uther Pendragon, from the castle of Camelot. King of all Britons, defeator of the Saxons, sovereign of all England! [Pause] SOLDIER: Get away! "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// 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 ///