To: vim_dev@googlegroups.com Subject: Patch 7.4.2304 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.2304 Problem: In a timer callback the timer itself can't be found or stopped. (Thinca) Solution: Do not remove the timer from the list, remember whether it was freed. Files: src/ex_cmds2.c, src/testdir/test_timers.vim *** ../vim-7.4.2303/src/ex_cmds2.c 2016-08-29 22:48:12.125106388 +0200 --- src/ex_cmds2.c 2016-09-01 21:09:54.394328936 +0200 *************** *** 1090,1095 **** --- 1090,1098 ---- static timer_T *first_timer = NULL; static int last_timer_id = 0; + static timer_T *current_timer = NULL; + static int free_current_timer = FALSE; + /* * Insert a timer in the list of timers. */ *************** *** 1121,1128 **** static void free_timer(timer_T *timer) { ! free_callback(timer->tr_callback, timer->tr_partial); ! vim_free(timer); } /* --- 1124,1136 ---- static void free_timer(timer_T *timer) { ! if (timer == current_timer) ! free_current_timer = TRUE; ! else ! { ! free_callback(timer->tr_callback, timer->tr_partial); ! vim_free(timer); ! } } /* *************** *** 1200,1217 **** # endif if (this_due <= 1) { ! remove_timer(timer); timer_callback(timer); did_one = TRUE; ! if (timer->tr_repeat != 0) { profile_setlimit(timer->tr_interval, &timer->tr_due); if (timer->tr_repeat > 0) --timer->tr_repeat; - insert_timer(timer); } else free_timer(timer); /* the callback may do anything, start all over */ break; } --- 1208,1230 ---- # endif if (this_due <= 1) { ! current_timer = timer; ! free_current_timer = FALSE; timer_callback(timer); + current_timer = NULL; + did_one = TRUE; ! if (timer->tr_repeat != 0 && !free_current_timer) { profile_setlimit(timer->tr_interval, &timer->tr_due); if (timer->tr_repeat > 0) --timer->tr_repeat; } else + { free_timer(timer); + remove_timer(timer); + } /* the callback may do anything, start all over */ break; } *** ../vim-7.4.2303/src/testdir/test_timers.vim 2016-08-28 16:06:01.407721837 +0200 --- src/testdir/test_timers.vim 2016-09-01 21:26:08.546370746 +0200 *************** *** 128,131 **** --- 128,146 ---- endif endfunc + func StopMyself(timer) + let g:called += 1 + if g:called == 2 + call timer_stop(a:timer) + endif + endfunc + + func Test_delete_myself() + let g:called = 0 + let t = timer_start(10, 'StopMyself', {'repeat': -1}) + call WaitFor('g:called == 2') + call assert_equal(2, g:called) + call assert_equal([], timer_info(t)) + endfunc + " vim: shiftwidth=2 sts=2 expandtab *** ../vim-7.4.2303/src/version.c 2016-09-01 20:58:17.640011363 +0200 --- src/version.c 2016-09-01 21:09:04.010740607 +0200 *************** *** 765,766 **** --- 765,768 ---- { /* Add new patch number below this line */ + /**/ + 2304, /**/ -- hundred-and-one symptoms of being an internet addict: 127. You bring your laptop and cellular phone to church. /// 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 ///