Skip to content

Commit 0946326

Browse files
committed
patch 8.0.0646: the hlsearch test fails on fast systems
Problem: The hlsearch test fails on fast systems. Solution: Make the search pattern slower. Fix that the old regexp engine doesn't timeout properly.
1 parent 1ef9bbe commit 0946326

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

src/regexp.c

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3492,7 +3492,7 @@ typedef struct regbehind_S
34923492

34933493
static char_u *reg_getline(linenr_T lnum);
34943494
static long bt_regexec_both(char_u *line, colnr_T col, proftime_T *tm, int *timed_out);
3495-
static long regtry(bt_regprog_T *prog, colnr_T col);
3495+
static long regtry(bt_regprog_T *prog, colnr_T col, proftime_T *tm, int *timed_out);
34963496
static void cleanup_subexpr(void);
34973497
#ifdef FEAT_SYN_HL
34983498
static void cleanup_zsubexpr(void);
@@ -3519,7 +3519,7 @@ static void save_se_one(save_se_T *savep, char_u **pp);
35193519

35203520
static int re_num_cmp(long_u val, char_u *scan);
35213521
static int match_with_backref(linenr_T start_lnum, colnr_T start_col, linenr_T end_lnum, colnr_T end_col, int *bytelen);
3522-
static int regmatch(char_u *prog);
3522+
static int regmatch(char_u *prog, proftime_T *tm, int *timed_out);
35233523
static int regrepeat(char_u *p, long maxcount);
35243524

35253525
#ifdef DEBUG
@@ -3780,8 +3780,8 @@ bt_regexec_multi(
37803780
bt_regexec_both(
37813781
char_u *line,
37823782
colnr_T col, /* column to start looking for match */
3783-
proftime_T *tm UNUSED, /* timeout limit or NULL */
3784-
int *timed_out UNUSED) /* flag set on timeout or NULL */
3783+
proftime_T *tm, /* timeout limit or NULL */
3784+
int *timed_out) /* flag set on timeout or NULL */
37853785
{
37863786
bt_regprog_T *prog;
37873787
char_u *s;
@@ -3919,7 +3919,7 @@ bt_regexec_both(
39193919
|| (c < 255 && prog->regstart < 255 &&
39203920
#endif
39213921
MB_TOLOWER(prog->regstart) == MB_TOLOWER(c)))))
3922-
retval = regtry(prog, col);
3922+
retval = regtry(prog, col, tm, timed_out);
39233923
else
39243924
retval = 0;
39253925
}
@@ -3958,7 +3958,7 @@ bt_regexec_both(
39583958
break;
39593959
}
39603960

3961-
retval = regtry(prog, col);
3961+
retval = regtry(prog, col, tm, timed_out);
39623962
if (retval > 0)
39633963
break;
39643964

@@ -4059,7 +4059,11 @@ unref_extmatch(reg_extmatch_T *em)
40594059
* Returns 0 for failure, number of lines contained in the match otherwise.
40604060
*/
40614061
static long
4062-
regtry(bt_regprog_T *prog, colnr_T col)
4062+
regtry(
4063+
bt_regprog_T *prog,
4064+
colnr_T col,
4065+
proftime_T *tm, /* timeout limit or NULL */
4066+
int *timed_out) /* flag set on timeout or NULL */
40634067
{
40644068
reginput = regline + col;
40654069
need_clear_subexpr = TRUE;
@@ -4069,7 +4073,7 @@ regtry(bt_regprog_T *prog, colnr_T col)
40694073
need_clear_zsubexpr = TRUE;
40704074
#endif
40714075

4072-
if (regmatch(prog->program + 1) == 0)
4076+
if (regmatch(prog->program + 1, tm, timed_out) == 0)
40734077
return 0;
40744078

40754079
cleanup_subexpr();
@@ -4253,7 +4257,9 @@ static long bl_maxval;
42534257
*/
42544258
static int
42554259
regmatch(
4256-
char_u *scan) /* Current node. */
4260+
char_u *scan, /* Current node. */
4261+
proftime_T *tm UNUSED, /* timeout limit or NULL */
4262+
int *timed_out UNUSED) /* flag set on timeout or NULL */
42574263
{
42584264
char_u *next; /* Next node. */
42594265
int op;
@@ -4266,6 +4272,9 @@ regmatch(
42664272
#define RA_BREAK 3 /* break inner loop */
42674273
#define RA_MATCH 4 /* successful match */
42684274
#define RA_NOMATCH 5 /* didn't match */
4275+
#ifdef FEAT_RELTIME
4276+
int tm_count = 0;
4277+
#endif
42694278

42704279
/* Make "regstack" and "backpos" empty. They are allocated and freed in
42714280
* bt_regexec_both() to reduce malloc()/free() calls. */
@@ -4300,6 +4309,20 @@ regmatch(
43004309
status = RA_FAIL;
43014310
break;
43024311
}
4312+
#ifdef FEAT_RELTIME
4313+
/* Check for timeout once in a 100 times to avoid overhead. */
4314+
if (tm != NULL && ++tm_count == 100)
4315+
{
4316+
tm_count = 0;
4317+
if (profile_passed_limit(tm))
4318+
{
4319+
if (timed_out != NULL)
4320+
*timed_out = TRUE;
4321+
status = RA_FAIL;
4322+
break;
4323+
}
4324+
}
4325+
#endif
43034326
status = RA_CONT;
43044327

43054328
#ifdef DEBUG

src/testdir/test_hlsearch.vim

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func Test_hlsearch_hangs()
3939
endif
4040

4141
" This pattern takes a long time to match, it should timeout.
42-
help
42+
new
43+
call setline(1, ['aaa', repeat('abc ', 1000), 'ccc'])
4344
let start = reltime()
4445
set hlsearch nolazyredraw redrawtime=101
4546
let @/ = '\%#=1a*.*X\@<=b*'
@@ -48,5 +49,5 @@ func Test_hlsearch_hangs()
4849
call assert_true(elapsed > 0.1)
4950
call assert_true(elapsed < 1.0)
5051
set nohlsearch redrawtime&
51-
quit
52+
bwipe!
5253
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,8 @@ static char *(features[]) =
764764

765765
static int included_patches[] =
766766
{ /* Add new patch number below this line */
767+
/**/
768+
646,
767769
/**/
768770
645,
769771
/**/

0 commit comments

Comments
 (0)