To: vim_dev@googlegroups.com Subject: Patch 7.4.1827 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1827 Problem: No error when invoking a callback when it's not safe. Solution: Add an error message. Avoid the error when freeing a channel. Files: src/structs.h, src/channel.c *** ../vim-7.4.1826/src/structs.h 2016-05-09 17:20:08.492312468 +0200 --- src/structs.h 2016-05-09 17:46:44.442422193 +0200 *************** *** 1419,1424 **** --- 1419,1426 ---- 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_to_be_freed; /* When TRUE channel must be freed 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.1826/src/channel.c 2016-05-09 17:20:08.496312424 +0200 --- src/channel.c 2016-05-09 17:51:57.102860175 +0200 *************** *** 59,64 **** --- 59,67 ---- /* Whether a redraw is needed for appending a line to a buffer. */ static int channel_need_redraw = FALSE; + /* Whether we are inside channel_parse_messages() or another situation where it + * is safe to invoke callbacks. */ + static int safe_to_invoke_callback = 0; #ifdef WIN32 static int *************** *** 403,410 **** { if (!in_free_unref_items) { ! channel_free_contents(channel); ! channel_free_channel(channel); } } --- 406,420 ---- { if (!in_free_unref_items) { ! if (safe_to_invoke_callback == 0) ! { ! channel->ch_to_be_freed = TRUE; ! } ! else ! { ! channel_free_contents(channel); ! channel_free_channel(channel); ! } } } *************** *** 444,449 **** --- 454,463 ---- int did_free = FALSE; channel_T *ch; + /* This is invoked from the garbage collector, which only runs at a safe + * point. */ + ++safe_to_invoke_callback; + for (ch = first_channel; ch != NULL; ch = ch->ch_next) if (!channel_still_useful(ch) && (ch->ch_copyID & mask) != (copyID & mask)) *************** *** 453,458 **** --- 467,474 ---- channel_free_contents(ch); did_free = TRUE; } + + --safe_to_invoke_callback; return did_free; } *************** *** 1450,1455 **** --- 1466,1474 ---- typval_T rettv; int dummy; + if (safe_to_invoke_callback == 0) + EMSG("INTERNAL: Invoking callback when it is not safe"); + argv[0].v_type = VAR_CHANNEL; argv[0].vval.v_channel = channel; *************** *** 3515,3520 **** --- 3534,3541 ---- int r; int part = PART_SOCK; + ++safe_to_invoke_callback; + /* Only do this message when another message was given, otherwise we get * lots of them. */ if (did_log_msg) *************** *** 3532,3537 **** --- 3553,3565 ---- channel = first_channel; continue; } + if (channel->ch_to_be_freed) + { + channel_free(channel); + /* channel has been freed, start over */ + channel = first_channel; + continue; + } if (channel->ch_refcount == 0 && !channel_still_useful(channel)) { /* channel is no longer useful, free it */ *************** *** 3572,3577 **** --- 3600,3607 ---- redraw_after_callback(); } + --safe_to_invoke_callback; + return ret; } *** ../vim-7.4.1826/src/version.c 2016-05-09 17:20:08.496312424 +0200 --- src/version.c 2016-05-09 17:37:26.784701922 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1827, /**/ -- Computers make very fast, very accurate, mistakes. /// 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 ///