diff options
Diffstat (limited to 'src/regex.c')
| -rw-r--r-- | src/regex.c | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/regex.c b/src/regex.c index 1c1164da57d..9e9018bff88 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -457,11 +457,17 @@ init_syntax_once (void) | |||
| 457 | 457 | ||
| 458 | # endif /* not alloca */ | 458 | # endif /* not alloca */ |
| 459 | 459 | ||
| 460 | # define REGEX_ALLOCATE alloca | 460 | # ifdef emacs |
| 461 | # define REGEX_USE_SAFE_ALLOCA USE_SAFE_ALLOCA | ||
| 462 | # define REGEX_SAFE_FREE() SAFE_FREE () | ||
| 463 | # define REGEX_ALLOCATE SAFE_ALLOCA | ||
| 464 | # else | ||
| 465 | # define REGEX_ALLOCATE alloca | ||
| 466 | # endif | ||
| 461 | 467 | ||
| 462 | /* Assumes a `char *destination' variable. */ | 468 | /* Assumes a `char *destination' variable. */ |
| 463 | # define REGEX_REALLOCATE(source, osize, nsize) \ | 469 | # define REGEX_REALLOCATE(source, osize, nsize) \ |
| 464 | (destination = alloca (nsize), \ | 470 | (destination = REGEX_ALLOCATE (nsize), \ |
| 465 | memcpy (destination, source, osize)) | 471 | memcpy (destination, source, osize)) |
| 466 | 472 | ||
| 467 | /* No need to do anything to free, after alloca. */ | 473 | /* No need to do anything to free, after alloca. */ |
| @@ -469,6 +475,11 @@ init_syntax_once (void) | |||
| 469 | 475 | ||
| 470 | #endif /* not REGEX_MALLOC */ | 476 | #endif /* not REGEX_MALLOC */ |
| 471 | 477 | ||
| 478 | #ifndef REGEX_USE_SAFE_ALLOCA | ||
| 479 | # define REGEX_USE_SAFE_ALLOCA ((void) 0) | ||
| 480 | # define REGEX_SAFE_FREE() ((void) 0) | ||
| 481 | #endif | ||
| 482 | |||
| 472 | /* Define how to allocate the failure stack. */ | 483 | /* Define how to allocate the failure stack. */ |
| 473 | 484 | ||
| 474 | #if defined REL_ALLOC && defined REGEX_MALLOC | 485 | #if defined REL_ALLOC && defined REGEX_MALLOC |
| @@ -482,22 +493,10 @@ init_syntax_once (void) | |||
| 482 | 493 | ||
| 483 | #else /* not using relocating allocator */ | 494 | #else /* not using relocating allocator */ |
| 484 | 495 | ||
| 485 | # ifdef REGEX_MALLOC | 496 | # define REGEX_ALLOCATE_STACK(size) REGEX_ALLOCATE (size) |
| 497 | # define REGEX_REALLOCATE_STACK(source, o, n) REGEX_REALLOCATE (source, o, n) | ||
| 498 | # define REGEX_FREE_STACK(ptr) REGEX_FREE (ptr) | ||
| 486 | 499 | ||
| 487 | # define REGEX_ALLOCATE_STACK malloc | ||
| 488 | # define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize) | ||
| 489 | # define REGEX_FREE_STACK free | ||
| 490 | |||
| 491 | # else /* not REGEX_MALLOC */ | ||
| 492 | |||
| 493 | # define REGEX_ALLOCATE_STACK alloca | ||
| 494 | |||
| 495 | # define REGEX_REALLOCATE_STACK(source, osize, nsize) \ | ||
| 496 | REGEX_REALLOCATE (source, osize, nsize) | ||
| 497 | /* No need to explicitly free anything. */ | ||
| 498 | # define REGEX_FREE_STACK(arg) ((void)0) | ||
| 499 | |||
| 500 | # endif /* not REGEX_MALLOC */ | ||
| 501 | #endif /* not using relocating allocator */ | 500 | #endif /* not using relocating allocator */ |
| 502 | 501 | ||
| 503 | 502 | ||
| @@ -4579,6 +4578,7 @@ static int bcmp_translate (re_char *s1, re_char *s2, | |||
| 4579 | FREE_VAR (regend); \ | 4578 | FREE_VAR (regend); \ |
| 4580 | FREE_VAR (best_regstart); \ | 4579 | FREE_VAR (best_regstart); \ |
| 4581 | FREE_VAR (best_regend); \ | 4580 | FREE_VAR (best_regend); \ |
| 4581 | REGEX_SAFE_FREE (); \ | ||
| 4582 | } while (0) | 4582 | } while (0) |
| 4583 | #else | 4583 | #else |
| 4584 | # define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */ | 4584 | # define FREE_VARIABLES() ((void)0) /* Do nothing! But inhibit gcc warning. */ |
| @@ -5018,6 +5018,8 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1, | |||
| 5018 | 5018 | ||
| 5019 | DEBUG_PRINT ("\n\nEntering re_match_2.\n"); | 5019 | DEBUG_PRINT ("\n\nEntering re_match_2.\n"); |
| 5020 | 5020 | ||
| 5021 | REGEX_USE_SAFE_ALLOCA; | ||
| 5022 | |||
| 5021 | INIT_FAIL_STACK (); | 5023 | INIT_FAIL_STACK (); |
| 5022 | 5024 | ||
| 5023 | #ifdef MATCH_MAY_ALLOCATE | 5025 | #ifdef MATCH_MAY_ALLOCATE |