To: vim_dev@googlegroups.com Subject: Patch 7.4.1860 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 7.4.1860 Problem: Using a partial for timer_start() may cause a crash. Solution: Set the copyID in timer objects. (Ozaki Kiichi) Files: src/testdir/test_timers.vim, src/eval.c, src/ex_cmds2.c, src/proto/ex_cmds2.pro *** ../vim-7.4.1859/src/testdir/test_timers.vim 2016-03-26 18:20:36.949052940 +0100 --- src/testdir/test_timers.vim 2016-05-31 21:08:09.066709407 +0200 *************** *** 8,13 **** --- 8,17 ---- let s:val += 1 endfunc + func MyHandlerWithLists(lists, timer) + let x = string(a:lists) + endfunc + func Test_oneshot() let s:val = 0 let timer = timer_start(50, 'MyHandler') *************** *** 42,45 **** --- 46,55 ---- sleep 200m call assert_equal(1, s:val) endfunc + + func Test_retain_partial() + call timer_start(100, function('MyHandlerWithLists', [['a']])) + call test_garbagecollect_now() + sleep 200m + endfunc " vim: ts=2 sw=0 et *** ../vim-7.4.1859/src/eval.c 2016-05-25 22:51:13.385755343 +0200 --- src/eval.c 2016-05-31 21:09:37.726708187 +0200 *************** *** 7046,7051 **** --- 7046,7055 ---- abort = abort || set_ref_in_nb_channel(copyID); #endif + #ifdef FEAT_TIMERS + abort = abort || set_ref_in_timer(copyID); + #endif + if (!abort) { /* *** ../vim-7.4.1859/src/ex_cmds2.c 2016-05-24 19:37:25.051103801 +0200 --- src/ex_cmds2.c 2016-05-31 21:09:37.726708187 +0200 *************** *** 1252,1257 **** --- 1252,1276 ---- remove_timer(timer); free_timer(timer); } + + /* + * Mark references in partials of timers. + */ + int + set_ref_in_timer(int copyID) + { + int abort = FALSE; + timer_T *timer; + typval_T tv; + + for (timer = first_timer; timer != NULL; timer = timer->tr_next) + { + tv.v_type = VAR_PARTIAL; + tv.vval.v_partial = timer->tr_partial; + abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL); + } + return abort; + } # endif #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT) *** ../vim-7.4.1859/src/proto/ex_cmds2.pro 2016-03-15 23:10:26.412712095 +0100 --- src/proto/ex_cmds2.pro 2016-05-31 21:09:37.730708187 +0200 *************** *** 22,27 **** --- 22,28 ---- long check_due_timer(void); timer_T *find_timer(int id); void stop_timer(timer_T *timer); + int set_ref_in_timer(int copyID); void profile_divide(proftime_T *tm, int count, proftime_T *tm2); void profile_add(proftime_T *tm, proftime_T *tm2); void profile_self(proftime_T *self, proftime_T *total, proftime_T *children); *** ../vim-7.4.1859/src/version.c 2016-05-29 16:44:22.157304121 +0200 --- src/version.c 2016-05-31 21:10:02.222707850 +0200 *************** *** 755,756 **** --- 755,758 ---- { /* Add new patch number below this line */ + /**/ + 1860, /**/ -- The History of every major Galactic Civilization tends to pass through three distinct and recognizable phases, those of Survival, Inquiry and Sophistication, otherwise known as the How, Why and Where phases. For instance, the first phase is characterized by the question 'How can we eat?' the second by the question 'Why do we eat?' and the third by the question 'Where shall we have lunch?' -- Douglas Adams, "The Hitchhiker's Guide to the Galaxy" /// 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 ///