To: vim_dev@googlegroups.com Subject: Patch 8.0.0646 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.0646 Problem: The hlsearch test fails on fast systems. Solution: Make the search pattern slower. Fix that the old regexp engine doesn't timeout properly. Files: src/regexp.c, src/testdir/test_hlsearch.vim *** ../vim-8.0.0645/src/regexp.c 2017-06-17 20:08:16.312896717 +0200 --- src/regexp.c 2017-06-17 20:43:07.997399263 +0200 *************** *** 3492,3498 **** static char_u *reg_getline(linenr_T lnum); static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm, int *timed_out); ! static long regtry(bt_regprog_T *prog, colnr_T col); static void cleanup_subexpr(void); #ifdef FEAT_SYN_HL static void cleanup_zsubexpr(void); --- 3492,3498 ---- static char_u *reg_getline(linenr_T lnum); static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm, int *timed_out); ! static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out); static void cleanup_subexpr(void); #ifdef FEAT_SYN_HL static void cleanup_zsubexpr(void); *************** *** 3519,3525 **** static int re_num_cmp(long_u val, char_u *scan); static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen); ! static int regmatch(char_u *prog); static int regrepeat(char_u *p, long maxcount); #ifdef DEBUG --- 3519,3525 ---- static int re_num_cmp(long_u val, char_u *scan); static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen); ! static int regmatch(char_u *prog, proftime_T *tm, int *timed_out); static int regrepeat(char_u *p, long maxcount); #ifdef DEBUG *************** *** 3780,3787 **** bt_regexec_both( char_u *line, colnr_T col, /* column to start looking for match */ ! proftime_T *tm UNUSED, /* timeout limit or NULL */ ! int *timed_out UNUSED) /* flag set on timeout or NULL */ { bt_regprog_T *prog; char_u *s; --- 3780,3787 ---- bt_regexec_both( char_u *line, colnr_T col, /* column to start looking for match */ ! proftime_T *tm, /* timeout limit or NULL */ ! int *timed_out) /* flag set on timeout or NULL */ { bt_regprog_T *prog; char_u *s; *************** *** 3919,3925 **** || (c < 255 && prog->regstart < 255 && #endif MB_TOLOWER(prog->regstart) == MB_TOLOWER(c))))) ! retval = regtry(prog, col); else retval = 0; } --- 3919,3925 ---- || (c < 255 && prog->regstart < 255 && #endif MB_TOLOWER(prog->regstart) == MB_TOLOWER(c))))) ! retval = regtry(prog, col, tm, timed_out); else retval = 0; } *************** *** 3958,3964 **** break; } ! retval = regtry(prog, col); if (retval > 0) break; --- 3958,3964 ---- break; } ! retval = regtry(prog, col, tm, timed_out); if (retval > 0) break; *************** *** 4059,4065 **** * Returns 0 for failure, number of lines contained in the match otherwise. */ static long ! regtry(bt_regprog_T *prog, colnr_T col) { reginput = regline + col; need_clear_subexpr = TRUE; --- 4059,4069 ---- * Returns 0 for failure, number of lines contained in the match otherwise. */ static long ! regtry( ! bt_regprog_T *prog, ! colnr_T col, ! proftime_T *tm, /* timeout limit or NULL */ ! int *timed_out) /* flag set on timeout or NULL */ { reginput = regline + col; need_clear_subexpr = TRUE; *************** *** 4069,4075 **** need_clear_zsubexpr = TRUE; #endif ! if (regmatch(prog->program + 1) == 0) return 0; cleanup_subexpr(); --- 4073,4079 ---- need_clear_zsubexpr = TRUE; #endif ! if (regmatch(prog->program + 1, tm, timed_out) == 0) return 0; cleanup_subexpr(); *************** *** 4253,4259 **** */ static int regmatch( ! char_u *scan) /* Current node. */ { char_u *next; /* Next node. */ int op; --- 4257,4265 ---- */ static int regmatch( ! char_u *scan, /* Current node. */ ! proftime_T *tm UNUSED, /* timeout limit or NULL */ ! int *timed_out UNUSED) /* flag set on timeout or NULL */ { char_u *next; /* Next node. */ int op; *************** *** 4266,4271 **** --- 4272,4280 ---- #define RA_BREAK 3 /* break inner loop */ #define RA_MATCH 4 /* successful match */ #define RA_NOMATCH 5 /* didn't match */ + #ifdef FEAT_RELTIME + int tm_count = 0; + #endif /* Make "regstack" and "backpos" empty. They are allocated and freed in * bt_regexec_both() to reduce malloc()/free() calls. */ *************** *** 4300,4305 **** --- 4309,4328 ---- status = RA_FAIL; break; } + #ifdef FEAT_RELTIME + /* Check for timeout once in a 100 times to avoid overhead. */ + if (tm != NULL && ++tm_count == 100) + { + tm_count = 0; + if (profile_passed_limit(tm)) + { + if (timed_out != NULL) + *timed_out = TRUE; + status = RA_FAIL; + break; + } + } + #endif status = RA_CONT; #ifdef DEBUG *** ../vim-8.0.0645/src/testdir/test_hlsearch.vim 2017-06-17 20:08:16.312896717 +0200 --- src/testdir/test_hlsearch.vim 2017-06-17 20:28:35.815901559 +0200 *************** *** 39,45 **** endif " This pattern takes a long time to match, it should timeout. ! help let start = reltime() set hlsearch nolazyredraw redrawtime=101 let @/ = '\%#=1a*.*X\@<=b*' --- 39,46 ---- endif " This pattern takes a long time to match, it should timeout. ! new ! call setline(1, ['aaa', repeat('abc ', 1000), 'ccc']) let start = reltime() set hlsearch nolazyredraw redrawtime=101 let @/ = '\%#=1a*.*X\@<=b*' *************** *** 48,52 **** call assert_true(elapsed > 0.1) call assert_true(elapsed < 1.0) set nohlsearch redrawtime& ! quit endfunc --- 49,53 ---- call assert_true(elapsed > 0.1) call assert_true(elapsed < 1.0) set nohlsearch redrawtime& ! bwipe! endfunc *** ../vim-8.0.0645/src/version.c 2017-06-17 20:08:16.316896687 +0200 --- src/version.c 2017-06-17 20:46:14.975996328 +0200 *************** *** 766,767 **** --- 766,769 ---- { /* Add new patch number below this line */ + /**/ + 646, /**/ -- Don't read everything you believe. /// 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 ///