aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/regex.c47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/regex.c b/src/regex.c
index 2977cb4ecda..bf3e96855d4 100644
--- a/src/regex.c
+++ b/src/regex.c
@@ -875,17 +875,20 @@ static const char *re_error_msg[] =
875 875
876/* Avoiding alloca during matching, to placate r_alloc. */ 876/* Avoiding alloca during matching, to placate r_alloc. */
877 877
878/* Define MATCH_SHOULD_NOT_ALLOCA if we need to make sure that the 878/* Define MATCH_MAY_ALLOCATE if we need to make sure that the
879 searching and matching functions should not call alloca. On some 879 searching and matching functions should not call alloca. On some
880 systems, alloca is implemented in terms of malloc, and if we're 880 systems, alloca is implemented in terms of malloc, and if we're
881 using the relocating allocator routines, then malloc could cause a 881 using the relocating allocator routines, then malloc could cause a
882 relocation, which might (if the strings being searched are in the 882 relocation, which might (if the strings being searched are in the
883 ralloc heap) shift the data out from underneath the regexp 883 ralloc heap) shift the data out from underneath the regexp
884 routines. */ 884 routines. */
885#if defined (REL_ALLOC) 885
886#if defined (C_ALLOCA) 886/* Normally, this is fine. */
887#define MATCH_SHOULD_NOT_ALLOCA 887#define MATCH_MAY_ALLOCATE
888#endif 888
889/* But under some circumstances, it's not. */
890#if defined (REL_ALLOC) && defined (C_ALLOCA)
891#undef MATCH_MAY_ALLOCATE
889#endif 892#endif
890 893
891 894
@@ -924,7 +927,7 @@ typedef struct
924 927
925/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */ 928/* Initialize `fail_stack'. Do `return -2' if the alloc fails. */
926 929
927#ifndef MATCH_SHOULD_NOT_ALLOCA 930#ifdef MATCH_MAY_ALLOCATE
928#define INIT_FAIL_STACK() \ 931#define INIT_FAIL_STACK() \
929 do { \ 932 do { \
930 fail_stack.stack = (fail_stack_elt_t *) \ 933 fail_stack.stack = (fail_stack_elt_t *) \
@@ -1227,10 +1230,10 @@ typedef union
1227 1230
1228 1231
1229 1232
1230/* How do we implement MATCH_SHOULD_NOT_ALLOCA? 1233/* How do we implement a missing MATCH_MAY_ALLOCATE?
1231 We make the fail stack a global thing, and then grow it to 1234 We make the fail stack a global thing, and then grow it to
1232 re_max_failures when we compile. */ 1235 re_max_failures when we compile. */
1233#ifdef MATCH_SHOULD_NOT_ALLOCA 1236#ifndef MATCH_MAY_ALLOCATE
1234static fail_stack_type fail_stack; 1237static fail_stack_type fail_stack;
1235 1238
1236static const char ** regstart, ** regend; 1239static const char ** regstart, ** regend;
@@ -2457,7 +2460,7 @@ regex_compile (pattern, size, syntax, bufp)
2457 } 2460 }
2458#endif /* DEBUG */ 2461#endif /* DEBUG */
2459 2462
2460#ifdef MATCH_SHOULD_NOT_ALLOCA 2463#ifndef MATCH_MAY_ALLOCATE
2461 /* Initialize the failure stack to the largest possible stack. This 2464 /* Initialize the failure stack to the largest possible stack. This
2462 isn't necessary unless we're trying to avoid calling alloca in 2465 isn't necessary unless we're trying to avoid calling alloca in
2463 the search and match routines. */ 2466 the search and match routines. */
@@ -2698,7 +2701,7 @@ re_compile_fastmap (bufp)
2698 struct re_pattern_buffer *bufp; 2701 struct re_pattern_buffer *bufp;
2699{ 2702{
2700 int j, k; 2703 int j, k;
2701#ifndef MATCH_SHOULD_NOT_ALLOCA 2704#ifdef MATCH_MAY_ALLOCATE
2702 fail_stack_type fail_stack; 2705 fail_stack_type fail_stack;
2703#endif 2706#endif
2704#ifndef REGEX_MALLOC 2707#ifndef REGEX_MALLOC
@@ -3209,9 +3212,7 @@ static boolean alt_match_null_string_p (),
3209 3212
3210 3213
3211/* Free everything we malloc. */ 3214/* Free everything we malloc. */
3212#ifdef MATCH_SHOULD_NOT_ALLOCA 3215#ifdef MATCH_MAY_ALLOCATE
3213#define FREE_VARIABLES() /* Do nothing! */
3214#else
3215#ifdef REGEX_MALLOC 3216#ifdef REGEX_MALLOC
3216#define FREE_VAR(var) if (var) free (var); var = NULL 3217#define FREE_VAR(var) if (var) free (var); var = NULL
3217#define FREE_VARIABLES() \ 3218#define FREE_VARIABLES() \
@@ -3231,7 +3232,9 @@ static boolean alt_match_null_string_p (),
3231/* Some MIPS systems (at least) want this to free alloca'd storage. */ 3232/* Some MIPS systems (at least) want this to free alloca'd storage. */
3232#define FREE_VARIABLES() alloca (0) 3233#define FREE_VARIABLES() alloca (0)
3233#endif /* not REGEX_MALLOC */ 3234#endif /* not REGEX_MALLOC */
3234#endif /* not MATCH_SHOULD_NOT_ALLOCA */ 3235#else
3236#define FREE_VARIABLES() /* Do nothing! */
3237#endif /* not MATCH_MAY_ALLOCATE */
3235 3238
3236/* These values must meet several constraints. They must not be valid 3239/* These values must meet several constraints. They must not be valid
3237 register values; since we have a limit of 255 registers (because 3240 register values; since we have a limit of 255 registers (because
@@ -3312,7 +3315,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3312 scanning the strings. If the latter is zero, the failure point is 3315 scanning the strings. If the latter is zero, the failure point is
3313 a ``dummy''; if a failure happens and the failure point is a dummy, 3316 a ``dummy''; if a failure happens and the failure point is a dummy,
3314 it gets discarded and the next next one is tried. */ 3317 it gets discarded and the next next one is tried. */
3315#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, this is global. */ 3318#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3316 fail_stack_type fail_stack; 3319 fail_stack_type fail_stack;
3317#endif 3320#endif
3318#ifdef DEBUG 3321#ifdef DEBUG
@@ -3336,7 +3339,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3336 matching and the regnum-th regend points to right after where we 3339 matching and the regnum-th regend points to right after where we
3337 stopped matching the regnum-th subexpression. (The zeroth register 3340 stopped matching the regnum-th subexpression. (The zeroth register
3338 keeps track of what the whole pattern matches.) */ 3341 keeps track of what the whole pattern matches.) */
3339#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, these are global. */ 3342#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
3340 const char **regstart, **regend; 3343 const char **regstart, **regend;
3341#endif 3344#endif
3342 3345
@@ -3345,7 +3348,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3345 restored because it will have been set to wherever in the string we 3348 restored because it will have been set to wherever in the string we
3346 are when we last see its open-group operator. Similarly for a 3349 are when we last see its open-group operator. Similarly for a
3347 register's end. */ 3350 register's end. */
3348#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, these are global. */ 3351#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
3349 const char **old_regstart, **old_regend; 3352 const char **old_regstart, **old_regend;
3350#endif 3353#endif
3351 3354
@@ -3355,7 +3358,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3355 matched any of the pattern so far this time through the reg_num-th 3358 matched any of the pattern so far this time through the reg_num-th
3356 subexpression. These two fields get reset each time through any 3359 subexpression. These two fields get reset each time through any
3357 loop their register is in. */ 3360 loop their register is in. */
3358#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, this is global. */ 3361#ifdef MATCH_MAY_ALLOCATE /* otherwise, this is global. */
3359 register_info_type *reg_info; 3362 register_info_type *reg_info;
3360#endif 3363#endif
3361 3364
@@ -3364,7 +3367,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3364 This happens as we backtrack through the failure points, which in 3367 This happens as we backtrack through the failure points, which in
3365 turn happens only if we have not yet matched the entire string. */ 3368 turn happens only if we have not yet matched the entire string. */
3366 unsigned best_regs_set = false; 3369 unsigned best_regs_set = false;
3367#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, these are global. */ 3370#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
3368 const char **best_regstart, **best_regend; 3371 const char **best_regstart, **best_regend;
3369#endif 3372#endif
3370 3373
@@ -3379,7 +3382,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3379 const char *match_end = NULL; 3382 const char *match_end = NULL;
3380 3383
3381 /* Used when we pop values we don't care about. */ 3384 /* Used when we pop values we don't care about. */
3382#ifndef MATCH_SHOULD_NOT_ALLOCA /* otherwise, these are global. */ 3385#ifdef MATCH_MAY_ALLOCATE /* otherwise, these are global. */
3383 const char **reg_dummy; 3386 const char **reg_dummy;
3384 register_info_type *reg_info_dummy; 3387 register_info_type *reg_info_dummy;
3385#endif 3388#endif
@@ -3393,7 +3396,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3393 3396
3394 INIT_FAIL_STACK (); 3397 INIT_FAIL_STACK ();
3395 3398
3396#ifndef MATCH_SHOULD_NOT_ALLOCA 3399#ifdef MATCH_MAY_ALLOCATE
3397 /* Do not bother to initialize all the register variables if there are 3400 /* Do not bother to initialize all the register variables if there are
3398 no groups in the pattern, as it takes a fair amount of time. If 3401 no groups in the pattern, as it takes a fair amount of time. If
3399 there are groups, we include space for register 0 (the whole 3402 there are groups, we include space for register 0 (the whole
@@ -3428,7 +3431,7 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
3428 reg_info = reg_info_dummy = (register_info_type *) NULL; 3431 reg_info = reg_info_dummy = (register_info_type *) NULL;
3429 } 3432 }
3430#endif /* REGEX_MALLOC */ 3433#endif /* REGEX_MALLOC */
3431#endif /* MATCH_SHOULD_NOT_ALLOCA */ 3434#endif /* MATCH_MAY_ALLOCATE */
3432 3435
3433 /* The starting position is bogus. */ 3436 /* The starting position is bogus. */
3434 if (pos < 0 || pos > size1 + size2) 3437 if (pos < 0 || pos > size1 + size2)