To: vim_dev@googlegroups.com Subject: Patch 8.2.5114 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.5114 Problem: Time limit on searchpair() does not work properly. Solution: Set the time limit once instead of for each regexp. (closes #10562) Files: src/search.c, src/evalfunc.c, src/testdir/test_search.vim *** ../vim-8.2.5113/src/search.c 2022-06-05 16:55:50.702774344 +0100 --- src/search.c 2022-06-16 20:53:41.296852873 +0100 *************** *** 674,683 **** stop_lnum = extra_arg->sa_stop_lnum; #ifdef FEAT_RELTIME if (extra_arg->sa_tm > 0) - { init_regexp_timeout(extra_arg->sa_tm); ! timed_out = &extra_arg->sa_timed_out; ! } #endif } --- 674,683 ---- stop_lnum = extra_arg->sa_stop_lnum; #ifdef FEAT_RELTIME if (extra_arg->sa_tm > 0) init_regexp_timeout(extra_arg->sa_tm); ! // Also set the pointer when sa_tm is zero, the caller may have set the ! // timeout. ! timed_out = &extra_arg->sa_timed_out; #endif } *************** *** 1105,1113 **** } while (--count > 0 && found); // stop after count matches or no match ! # ifdef FEAT_RELTIME ! disable_regexp_timeout(); ! # endif vim_regfree(regmatch.regprog); if (!found) // did not find it --- 1105,1114 ---- } while (--count > 0 && found); // stop after count matches or no match ! #ifdef FEAT_RELTIME ! if (extra_arg != NULL && extra_arg->sa_tm > 0) ! disable_regexp_timeout(); ! #endif vim_regfree(regmatch.regprog); if (!found) // did not find it *************** *** 4859,4865 **** // get the fuzzy matches ret = rettv_list_alloc(rettv); ! if (ret != OK) goto done; if (retmatchpos) { --- 4860,4866 ---- // get the fuzzy matches ret = rettv_list_alloc(rettv); ! if (ret == FAIL) goto done; if (retmatchpos) { *** ../vim-8.2.5113/src/evalfunc.c 2022-06-16 11:42:05.592034924 +0100 --- src/evalfunc.c 2022-06-16 21:11:03.267379234 +0100 *************** *** 8975,8980 **** --- 8975,8984 ---- if (skip != NULL) use_skip = eval_expr_valid_arg(skip); + #ifdef FEAT_RELTIME + if (time_limit > 0) + init_regexp_timeout(time_limit); + #endif save_cursor = curwin->w_cursor; pos = curwin->w_cursor; CLEAR_POS(&firstpos); *************** *** 8986,8994 **** CLEAR_FIELD(sia); sia.sa_stop_lnum = lnum_stop; - #ifdef FEAT_RELTIME - sia.sa_tm = time_limit; - #endif n = searchit(curwin, curbuf, &pos, NULL, dir, pat, 1L, options, RE_SEARCH, &sia); if (n == FAIL || (firstpos.lnum != 0 && EQUAL_POS(pos, firstpos))) --- 8990,8995 ---- *************** *** 9074,9079 **** --- 9075,9083 ---- curwin->w_cursor = save_cursor; theend: + #ifdef FEAT_RELTIME + disable_regexp_timeout(); + #endif vim_free(pat2); vim_free(pat3); if (p_cpo == empty_option) *** ../vim-8.2.5113/src/testdir/test_search.vim 2022-06-05 16:55:50.702774344 +0100 --- src/testdir/test_search.vim 2022-06-16 21:10:18.459734723 +0100 *************** *** 328,334 **** call assert_equal(3, searchpair('\', '\', '\', 'W')) call assert_equal([0, 3, 3, 0], getpos('.')) ! q! endfunc func Test_searchpairpos() --- 328,358 ---- call assert_equal(3, searchpair('\', '\', '\', 'W')) call assert_equal([0, 3, 3, 0], getpos('.')) ! bwipe! ! endfunc ! ! func Test_searchpair_timeout() ! CheckFeature reltime ! ! func Waitabit() ! sleep 20m ! return 1 " skip match ! endfunc ! ! new ! call setline(1, range(100)) ! call setline(1, "(start here") ! call setline(100, "end here)") ! let starttime = reltime() ! ! " A timeout of 100 msec should happen after about five times of 20 msec wait ! " in Waitabit(). When the timeout applies to each search the elapsed time ! " will be much longer. ! call assert_equal(0, searchpair('(', '\d', ')', '', "Waitabit()", 0, 100)) ! let elapsed = reltime(starttime)->reltimefloat() ! call assert_inrange(0.09, 0.300, elapsed) ! ! bwipe! endfunc func Test_searchpairpos() *** ../vim-8.2.5113/src/version.c 2022-06-16 18:47:16.921378694 +0100 --- src/version.c 2022-06-16 20:49:45.136596792 +0100 *************** *** 736,737 **** --- 736,739 ---- { /* Add new patch number below this line */ + /**/ + 5114, /**/ -- To keep milk from turning sour: Keep it in the cow. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///