diff options
| author | Richard M. Stallman | 1995-04-29 20:21:41 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1995-04-29 20:21:41 +0000 |
| commit | c823611d96abfee4f6abbd697c5b8a98f80a727f (patch) | |
| tree | ce4888ad0b183cf9904979d19e8a8a17a46270cf /src/regex.c | |
| parent | ae849784b436145eccbde502c152720b9164788e (diff) | |
| download | emacs-c823611d96abfee4f6abbd697c5b8a98f80a727f.tar.gz emacs-c823611d96abfee4f6abbd697c5b8a98f80a727f.zip | |
(PUSH_FAILURE_INT, POP_FAILURE_INT): Use WIDE_INT.
(WIDE_INT): Defined (two alternate definitions).
(C_ALLOCA): Undef it, if __GNUC__.
(REGEX_ALLOCATE_STACK, REGEX_REALLOCATE_STACK)
(REGEX_FREE_STACK): New macros.
(INIT_FAIL_STACK, DOUBLE_FAIL_STACK, FREE_VARIABLES): Use them.
(re_max_failures) [REL_ALLOC]: Alternative larger initial value.
(re_compile_fastmap): Use REGEX_FREE_STACK.
(re_match_2_internal): Always call FREE_VARIABLES before returning.
Always init regstart, old_regstart, etc. whenever MATCH_MAY_ALLOCATE
is defined.
(FREE_VARIABLES) [REL_ALLOC]: Define non-trivially.
Diffstat (limited to 'src/regex.c')
| -rw-r--r-- | src/regex.c | 191 |
1 files changed, 138 insertions, 53 deletions
diff --git a/src/regex.c b/src/regex.c index fc370b351f7..c17ff8cd0b7 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -49,6 +49,8 @@ | |||
| 49 | #include "buffer.h" | 49 | #include "buffer.h" |
| 50 | #include "syntax.h" | 50 | #include "syntax.h" |
| 51 | 51 | ||
| 52 | #define WIDE_INT EMACS_INT | ||
| 53 | |||
| 52 | #else /* not emacs */ | 54 | #else /* not emacs */ |
| 53 | 55 | ||
| 54 | #ifdef STDC_HEADERS | 56 | #ifdef STDC_HEADERS |
| @@ -58,6 +60,10 @@ char *malloc (); | |||
| 58 | char *realloc (); | 60 | char *realloc (); |
| 59 | #endif | 61 | #endif |
| 60 | 62 | ||
| 63 | /* This isn't right--it needs to check for machines with 64-bit pointers | ||
| 64 | and do something different. But I don't know what, and I don't | ||
| 65 | need to deal with it right now. -- rms. */ | ||
| 66 | #define WIDE_INT int | ||
| 61 | 67 | ||
| 62 | /* We used to test for `BSTRING' here, but only GCC and Emacs define | 68 | /* We used to test for `BSTRING' here, but only GCC and Emacs define |
| 63 | `BSTRING', as far as I know, and neither of them use this code. */ | 69 | `BSTRING', as far as I know, and neither of them use this code. */ |
| @@ -209,6 +215,7 @@ init_syntax_once () | |||
| 209 | 215 | ||
| 210 | #define REGEX_ALLOCATE malloc | 216 | #define REGEX_ALLOCATE malloc |
| 211 | #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) | 217 | #define REGEX_REALLOCATE(source, osize, nsize) realloc (source, nsize) |
| 218 | #define REGEX_FREE free | ||
| 212 | 219 | ||
| 213 | #else /* not REGEX_MALLOC */ | 220 | #else /* not REGEX_MALLOC */ |
| 214 | 221 | ||
| @@ -238,7 +245,40 @@ char *alloca (); | |||
| 238 | bcopy (source, destination, osize), \ | 245 | bcopy (source, destination, osize), \ |
| 239 | destination) | 246 | destination) |
| 240 | 247 | ||
| 248 | /* No need to do anything to free, after alloca. */ | ||
| 249 | #define REGEX_FREE(arg) (0) | ||
| 250 | |||
| 251 | #endif /* not REGEX_MALLOC */ | ||
| 252 | |||
| 253 | /* Define how to allocate the failure stack. */ | ||
| 254 | |||
| 255 | #ifdef REL_ALLOC | ||
| 256 | #define REGEX_ALLOCATE_STACK(size) \ | ||
| 257 | r_alloc (&failure_stack_ptr, (size)) | ||
| 258 | #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ | ||
| 259 | r_re_alloc (&failure_stack_ptr, (nsize)) | ||
| 260 | #define REGEX_FREE_STACK(ptr) \ | ||
| 261 | r_alloc_free (&failure_stack_ptr) | ||
| 262 | |||
| 263 | #else /* not REL_ALLOC */ | ||
| 264 | |||
| 265 | #ifdef REGEX_MALLOC | ||
| 266 | |||
| 267 | #define REGEX_ALLOCATE_STACK malloc | ||
| 268 | #define REGEX_REALLOCATE_STACK(source, osize, nsize) realloc (source, nsize) | ||
| 269 | #define REGEX_FREE_STACK free | ||
| 270 | |||
| 271 | #else /* not REGEX_MALLOC */ | ||
| 272 | |||
| 273 | #define REGEX_ALLOCATE_STACK alloca | ||
| 274 | |||
| 275 | #define REGEX_REALLOCATE_STACK(source, osize, nsize) \ | ||
| 276 | REGEX_REALLOCATE (source, osize, nsize) | ||
| 277 | /* No need to explicitly free anything. */ | ||
| 278 | #define REGEX_FREE_STACK(arg) | ||
| 279 | |||
| 241 | #endif /* not REGEX_MALLOC */ | 280 | #endif /* not REGEX_MALLOC */ |
| 281 | #endif /* not REL_ALLOC */ | ||
| 242 | 282 | ||
| 243 | 283 | ||
| 244 | /* True if `size1' is non-NULL and PTR is pointing anywhere inside | 284 | /* True if `size1' is non-NULL and PTR is pointing anywhere inside |
| @@ -915,6 +955,12 @@ static const char *re_error_msgid[] = | |||
| 915 | /* Normally, this is fine. */ | 955 | /* Normally, this is fine. */ |
| 916 | #define MATCH_MAY_ALLOCATE | 956 | #define MATCH_MAY_ALLOCATE |
| 917 | 957 | ||
| 958 | /* When using GNU C, we are not REALLY using the C alloca, no matter | ||
| 959 | what config.h may say. So don't take precautions for it. */ | ||
| 960 | #ifdef __GNUC__ | ||
| 961 | #undef C_ALLOCA | ||
| 962 | #endif | ||
| 963 | |||
| 918 | /* The match routines may not allocate if (1) they would do it with malloc | 964 | /* The match routines may not allocate if (1) they would do it with malloc |
| 919 | and (2) it's not safe for them to use malloc. */ | 965 | and (2) it's not safe for them to use malloc. */ |
| 920 | #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && (defined (emacs) || defined (REL_ALLOC)) | 966 | #if (defined (C_ALLOCA) || defined (REGEX_MALLOC)) && (defined (emacs) || defined (REL_ALLOC)) |
| @@ -924,7 +970,7 @@ static const char *re_error_msgid[] = | |||
| 924 | 970 | ||
| 925 | /* Failure stack declarations and macros; both re_compile_fastmap and | 971 | /* Failure stack declarations and macros; both re_compile_fastmap and |
| 926 | re_match_2 use a failure stack. These have to be macros because of | 972 | re_match_2 use a failure stack. These have to be macros because of |
| 927 | REGEX_ALLOCATE. */ | 973 | REGEX_ALLOCATE_STACK. */ |
| 928 | 974 | ||
| 929 | 975 | ||
| 930 | /* Number of failure points for which to initially allocate space | 976 | /* Number of failure points for which to initially allocate space |
| @@ -938,7 +984,11 @@ static const char *re_error_msgid[] = | |||
| 938 | exactly that if always used MAX_FAILURE_SPACE each time we failed. | 984 | exactly that if always used MAX_FAILURE_SPACE each time we failed. |
| 939 | This is a variable only so users of regex can assign to it; we never | 985 | This is a variable only so users of regex can assign to it; we never |
| 940 | change it ourselves. */ | 986 | change it ourselves. */ |
| 987 | #ifdef REL_ALLOC | ||
| 988 | int re_max_failures = 20000000; | ||
| 989 | #else | ||
| 941 | int re_max_failures = 2000; | 990 | int re_max_failures = 2000; |
| 991 | #endif | ||
| 942 | 992 | ||
| 943 | typedef unsigned char *fail_stack_elt_t; | 993 | typedef unsigned char *fail_stack_elt_t; |
| 944 | 994 | ||
| @@ -961,7 +1011,7 @@ typedef struct | |||
| 961 | #define INIT_FAIL_STACK() \ | 1011 | #define INIT_FAIL_STACK() \ |
| 962 | do { \ | 1012 | do { \ |
| 963 | fail_stack.stack = (fail_stack_elt_t *) \ | 1013 | fail_stack.stack = (fail_stack_elt_t *) \ |
| 964 | REGEX_ALLOCATE (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ | 1014 | REGEX_ALLOCATE_STACK (INIT_FAILURE_ALLOC * sizeof (fail_stack_elt_t)); \ |
| 965 | \ | 1015 | \ |
| 966 | if (fail_stack.stack == NULL) \ | 1016 | if (fail_stack.stack == NULL) \ |
| 967 | return -2; \ | 1017 | return -2; \ |
| @@ -982,13 +1032,13 @@ typedef struct | |||
| 982 | Return 1 if succeeds, and 0 if either ran out of memory | 1032 | Return 1 if succeeds, and 0 if either ran out of memory |
| 983 | allocating space for it or it was already too large. | 1033 | allocating space for it or it was already too large. |
| 984 | 1034 | ||
| 985 | REGEX_REALLOCATE requires `destination' be declared. */ | 1035 | REGEX_REALLOCATE_STACK requires `destination' be declared. */ |
| 986 | 1036 | ||
| 987 | #define DOUBLE_FAIL_STACK(fail_stack) \ | 1037 | #define DOUBLE_FAIL_STACK(fail_stack) \ |
| 988 | ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ | 1038 | ((fail_stack).size > re_max_failures * MAX_FAILURE_ITEMS \ |
| 989 | ? 0 \ | 1039 | ? 0 \ |
| 990 | : ((fail_stack).stack = (fail_stack_elt_t *) \ | 1040 | : ((fail_stack).stack = (fail_stack_elt_t *) \ |
| 991 | REGEX_REALLOCATE ((fail_stack).stack, \ | 1041 | REGEX_REALLOCATE_STACK ((fail_stack).stack, \ |
| 992 | (fail_stack).size * sizeof (fail_stack_elt_t), \ | 1042 | (fail_stack).size * sizeof (fail_stack_elt_t), \ |
| 993 | ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ | 1043 | ((fail_stack).size << 1) * sizeof (fail_stack_elt_t)), \ |
| 994 | \ | 1044 | \ |
| @@ -1005,9 +1055,9 @@ typedef struct | |||
| 1005 | #define PUSH_PATTERN_OP(pattern_op, fail_stack) \ | 1055 | #define PUSH_PATTERN_OP(pattern_op, fail_stack) \ |
| 1006 | ((FAIL_STACK_FULL () \ | 1056 | ((FAIL_STACK_FULL () \ |
| 1007 | && !DOUBLE_FAIL_STACK (fail_stack)) \ | 1057 | && !DOUBLE_FAIL_STACK (fail_stack)) \ |
| 1008 | ? 0 \ | 1058 | ? 0 \ |
| 1009 | : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ | 1059 | : ((fail_stack).stack[(fail_stack).avail++] = pattern_op, \ |
| 1010 | 1)) | 1060 | 1)) |
| 1011 | 1061 | ||
| 1012 | /* Push a pointer value onto the failure stack. | 1062 | /* Push a pointer value onto the failure stack. |
| 1013 | Assumes the variable `fail_stack'. Probably should only | 1063 | Assumes the variable `fail_stack'. Probably should only |
| @@ -1019,13 +1069,13 @@ typedef struct | |||
| 1019 | Assumes the variable `fail_stack'. Probably should only | 1069 | Assumes the variable `fail_stack'. Probably should only |
| 1020 | be called from within `PUSH_FAILURE_POINT'. */ | 1070 | be called from within `PUSH_FAILURE_POINT'. */ |
| 1021 | #define PUSH_FAILURE_INT(item) \ | 1071 | #define PUSH_FAILURE_INT(item) \ |
| 1022 | fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) (EMACS_INT) (item) | 1072 | fail_stack.stack[fail_stack.avail++] = (fail_stack_elt_t) (WIDE_INT) (item) |
| 1023 | 1073 | ||
| 1024 | /* The complement operation. Assumes `fail_stack' is nonempty. */ | 1074 | /* The complement operation. Assumes `fail_stack' is nonempty. */ |
| 1025 | #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail] | 1075 | #define POP_FAILURE_POINTER() fail_stack.stack[--fail_stack.avail] |
| 1026 | 1076 | ||
| 1027 | /* The complement operation. Assumes `fail_stack' is nonempty. */ | 1077 | /* The complement operation. Assumes `fail_stack' is nonempty. */ |
| 1028 | #define POP_FAILURE_INT() (EMACS_INT) fail_stack.stack[--fail_stack.avail] | 1078 | #define POP_FAILURE_INT() (WIDE_INT) fail_stack.stack[--fail_stack.avail] |
| 1029 | 1079 | ||
| 1030 | /* Used to omit pushing failure point id's when we're not debugging. */ | 1080 | /* Used to omit pushing failure point id's when we're not debugging. */ |
| 1031 | #ifdef DEBUG | 1081 | #ifdef DEBUG |
| @@ -1065,7 +1115,7 @@ typedef struct | |||
| 1065 | /* Ensure we have enough space allocated for what we will push. */ \ | 1115 | /* Ensure we have enough space allocated for what we will push. */ \ |
| 1066 | while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ | 1116 | while (REMAINING_AVAIL_SLOTS < NUM_FAILURE_ITEMS) \ |
| 1067 | { \ | 1117 | { \ |
| 1068 | if (!DOUBLE_FAIL_STACK (fail_stack)) \ | 1118 | if (!DOUBLE_FAIL_STACK (fail_stack)) \ |
| 1069 | return failure_code; \ | 1119 | return failure_code; \ |
| 1070 | \ | 1120 | \ |
| 1071 | DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ | 1121 | DEBUG_PRINT2 ("\n Doubled stack; size now: %d\n", \ |
| @@ -1271,23 +1321,6 @@ typedef union | |||
| 1271 | static char reg_unset_dummy; | 1321 | static char reg_unset_dummy; |
| 1272 | #define REG_UNSET_VALUE (®_unset_dummy) | 1322 | #define REG_UNSET_VALUE (®_unset_dummy) |
| 1273 | #define REG_UNSET(e) ((e) == REG_UNSET_VALUE) | 1323 | #define REG_UNSET(e) ((e) == REG_UNSET_VALUE) |
| 1274 | |||
| 1275 | |||
| 1276 | |||
| 1277 | /* How do we implement a missing MATCH_MAY_ALLOCATE? | ||
| 1278 | We make the fail stack a global thing, and then grow it to | ||
| 1279 | re_max_failures when we compile. */ | ||
| 1280 | #ifndef MATCH_MAY_ALLOCATE | ||
| 1281 | static fail_stack_type fail_stack; | ||
| 1282 | |||
| 1283 | static const char ** regstart, ** regend; | ||
| 1284 | static const char ** old_regstart, ** old_regend; | ||
| 1285 | static const char **best_regstart, **best_regend; | ||
| 1286 | static register_info_type *reg_info; | ||
| 1287 | static const char **reg_dummy; | ||
| 1288 | static register_info_type *reg_info_dummy; | ||
| 1289 | #endif | ||
| 1290 | |||
| 1291 | 1324 | ||
| 1292 | /* Subroutine declarations and macros for regex_compile. */ | 1325 | /* Subroutine declarations and macros for regex_compile. */ |
| 1293 | 1326 | ||
| @@ -1492,6 +1525,54 @@ typedef struct | |||
| 1492 | || STREQ (string, "punct") || STREQ (string, "graph") \ | 1525 | || STREQ (string, "punct") || STREQ (string, "graph") \ |
| 1493 | || STREQ (string, "cntrl") || STREQ (string, "blank")) | 1526 | || STREQ (string, "cntrl") || STREQ (string, "blank")) |
| 1494 | 1527 | ||
| 1528 | #ifndef MATCH_MAY_ALLOCATE | ||
| 1529 | |||
| 1530 | /* If we cannot allocate large objects within re_match_2_internal, | ||
| 1531 | we make the fail stack and register vectors global. | ||
| 1532 | The fail stack, we grow to the maximum size when a regexp | ||
| 1533 | is compiled. | ||
| 1534 | The register vectors, we adjust in size each time we | ||
| 1535 | compile a regexp, according to the number of registers it needs. */ | ||
| 1536 | |||
| 1537 | static fail_stack_type fail_stack; | ||
| 1538 | |||
| 1539 | /* Size with which the following vectors are currently allocated. | ||
| 1540 | That is so we can make them bigger as needed, | ||
| 1541 | but never make them smaller. */ | ||
| 1542 | static int regs_allocated_size; | ||
| 1543 | |||
| 1544 | static const char ** regstart, ** regend; | ||
| 1545 | static const char ** old_regstart, ** old_regend; | ||
| 1546 | static const char **best_regstart, **best_regend; | ||
| 1547 | static register_info_type *reg_info; | ||
| 1548 | static const char **reg_dummy; | ||
| 1549 | static register_info_type *reg_info_dummy; | ||
| 1550 | |||
| 1551 | /* Make the register vectors big enough for NUM_REGS registers, | ||
| 1552 | but don't make them smaller. */ | ||
| 1553 | |||
| 1554 | static | ||
| 1555 | regex_grow_registers (num_regs) | ||
| 1556 | int num_regs; | ||
| 1557 | { | ||
| 1558 | if (num_regs > regs_allocated_size) | ||
| 1559 | { | ||
| 1560 | RETALLOC_IF (regstart, num_regs, const char *); | ||
| 1561 | RETALLOC_IF (regend, num_regs, const char *); | ||
| 1562 | RETALLOC_IF (old_regstart, num_regs, const char *); | ||
| 1563 | RETALLOC_IF (old_regend, num_regs, const char *); | ||
| 1564 | RETALLOC_IF (best_regstart, num_regs, const char *); | ||
| 1565 | RETALLOC_IF (best_regend, num_regs, const char *); | ||
| 1566 | RETALLOC_IF (reg_info, num_regs, register_info_type); | ||
| 1567 | RETALLOC_IF (reg_dummy, num_regs, const char *); | ||
| 1568 | RETALLOC_IF (reg_info_dummy, num_regs, register_info_type); | ||
| 1569 | |||
| 1570 | regs_allocated_size = num_regs; | ||
| 1571 | } | ||
| 1572 | } | ||
| 1573 | |||
| 1574 | #endif /* not MATCH_MAY_ALLOCATE */ | ||
| 1575 | |||
| 1495 | /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. | 1576 | /* `regex_compile' compiles PATTERN (of length SIZE) according to SYNTAX. |
| 1496 | Returns one of error codes defined in `regex.h', or zero for success. | 1577 | Returns one of error codes defined in `regex.h', or zero for success. |
| 1497 | 1578 | ||
| @@ -2555,18 +2636,9 @@ regex_compile (pattern, size, syntax, bufp) | |||
| 2555 | #endif /* not emacs */ | 2636 | #endif /* not emacs */ |
| 2556 | } | 2637 | } |
| 2557 | 2638 | ||
| 2558 | /* Initialize some other variables the matcher uses. */ | 2639 | regex_grow_registers (num_regs); |
| 2559 | RETALLOC_IF (regstart, num_regs, const char *); | ||
| 2560 | RETALLOC_IF (regend, num_regs, const char *); | ||
| 2561 | RETALLOC_IF (old_regstart, num_regs, const char *); | ||
| 2562 | RETALLOC_IF (old_regend, num_regs, const char *); | ||
| 2563 | RETALLOC_IF (best_regstart, num_regs, const char *); | ||
| 2564 | RETALLOC_IF (best_regend, num_regs, const char *); | ||
| 2565 | RETALLOC_IF (reg_info, num_regs, register_info_type); | ||
| 2566 | RETALLOC_IF (reg_dummy, num_regs, const char *); | ||
| 2567 | RETALLOC_IF (reg_info_dummy, num_regs, register_info_type); | ||
| 2568 | } | 2640 | } |
| 2569 | #endif | 2641 | #endif /* not MATCH_MAY_ALLOCATE */ |
| 2570 | 2642 | ||
| 2571 | return REG_NOERROR; | 2643 | return REG_NOERROR; |
| 2572 | } /* regex_compile */ | 2644 | } /* regex_compile */ |
| @@ -2791,6 +2863,10 @@ re_compile_fastmap (bufp) | |||
| 2791 | unsigned char *p = pattern; | 2863 | unsigned char *p = pattern; |
| 2792 | register unsigned char *pend = pattern + size; | 2864 | register unsigned char *pend = pattern + size; |
| 2793 | 2865 | ||
| 2866 | /* This holds the pointer to the failure stack, when | ||
| 2867 | it is allocated relocatably. */ | ||
| 2868 | fail_stack_elt_t *failure_stack_ptr; | ||
| 2869 | |||
| 2794 | /* Assume that each path through the pattern can be null until | 2870 | /* Assume that each path through the pattern can be null until |
| 2795 | proven otherwise. We set this false at the bottom of switch | 2871 | proven otherwise. We set this false at the bottom of switch |
| 2796 | statement, to which we get only if a particular path doesn't | 2872 | statement, to which we get only if a particular path doesn't |
| @@ -2840,7 +2916,7 @@ re_compile_fastmap (bufp) | |||
| 2840 | that is all we do. */ | 2916 | that is all we do. */ |
| 2841 | case duplicate: | 2917 | case duplicate: |
| 2842 | bufp->can_be_null = 1; | 2918 | bufp->can_be_null = 1; |
| 2843 | return 0; | 2919 | goto done; |
| 2844 | 2920 | ||
| 2845 | 2921 | ||
| 2846 | /* Following are the cases which match a character. These end | 2922 | /* Following are the cases which match a character. These end |
| @@ -2898,7 +2974,7 @@ re_compile_fastmap (bufp) | |||
| 2898 | /* Return if we have already set `can_be_null'; if we have, | 2974 | /* Return if we have already set `can_be_null'; if we have, |
| 2899 | then the fastmap is irrelevant. Something's wrong here. */ | 2975 | then the fastmap is irrelevant. Something's wrong here. */ |
| 2900 | else if (bufp->can_be_null) | 2976 | else if (bufp->can_be_null) |
| 2901 | return 0; | 2977 | goto done; |
| 2902 | 2978 | ||
| 2903 | /* Otherwise, have to check alternative paths. */ | 2979 | /* Otherwise, have to check alternative paths. */ |
| 2904 | break; | 2980 | break; |
| @@ -2992,7 +3068,10 @@ re_compile_fastmap (bufp) | |||
| 2992 | if (p + j < pend) | 3068 | if (p + j < pend) |
| 2993 | { | 3069 | { |
| 2994 | if (!PUSH_PATTERN_OP (p + j, fail_stack)) | 3070 | if (!PUSH_PATTERN_OP (p + j, fail_stack)) |
| 2995 | return -2; | 3071 | { |
| 3072 | REGEX_FREE_STACK (fail_stack.stack); | ||
| 3073 | return -2; | ||
| 3074 | } | ||
| 2996 | } | 3075 | } |
| 2997 | else | 3076 | else |
| 2998 | bufp->can_be_null = 1; | 3077 | bufp->can_be_null = 1; |
| @@ -3049,6 +3128,9 @@ re_compile_fastmap (bufp) | |||
| 3049 | /* Set `can_be_null' for the last path (also the first path, if the | 3128 | /* Set `can_be_null' for the last path (also the first path, if the |
| 3050 | pattern is empty). */ | 3129 | pattern is empty). */ |
| 3051 | bufp->can_be_null |= path_can_be_null; | 3130 | bufp->can_be_null |= path_can_be_null; |
| 3131 | |||
| 3132 | done: | ||
| 3133 | REGEX_FREE_STACK (fail_stack.stack); | ||
| 3052 | return 0; | 3134 | return 0; |
| 3053 | } /* re_compile_fastmap */ | 3135 | } /* re_compile_fastmap */ |
| 3054 | 3136 | ||
| @@ -3303,11 +3385,10 @@ static boolean alt_match_null_string_p (), | |||
| 3303 | 3385 | ||
| 3304 | /* Free everything we malloc. */ | 3386 | /* Free everything we malloc. */ |
| 3305 | #ifdef MATCH_MAY_ALLOCATE | 3387 | #ifdef MATCH_MAY_ALLOCATE |
| 3306 | #ifdef REGEX_MALLOC | 3388 | #define FREE_VAR(var) if (var) REGEX_FREE (var); var = NULL |
| 3307 | #define FREE_VAR(var) if (var) free (var); var = NULL | ||
| 3308 | #define FREE_VARIABLES() \ | 3389 | #define FREE_VARIABLES() \ |
| 3309 | do { \ | 3390 | do { \ |
| 3310 | FREE_VAR (fail_stack.stack); \ | 3391 | REGEX_FREE_STACK (fail_stack.stack); \ |
| 3311 | FREE_VAR (regstart); \ | 3392 | FREE_VAR (regstart); \ |
| 3312 | FREE_VAR (regend); \ | 3393 | FREE_VAR (regend); \ |
| 3313 | FREE_VAR (old_regstart); \ | 3394 | FREE_VAR (old_regstart); \ |
| @@ -3318,10 +3399,6 @@ static boolean alt_match_null_string_p (), | |||
| 3318 | FREE_VAR (reg_dummy); \ | 3399 | FREE_VAR (reg_dummy); \ |
| 3319 | FREE_VAR (reg_info_dummy); \ | 3400 | FREE_VAR (reg_info_dummy); \ |
| 3320 | } while (0) | 3401 | } while (0) |
| 3321 | #else /* not REGEX_MALLOC */ | ||
| 3322 | /* This used to do alloca (0), but now we do that in the caller. */ | ||
| 3323 | #define FREE_VARIABLES() /* Nothing */ | ||
| 3324 | #endif /* not REGEX_MALLOC */ | ||
| 3325 | #else | 3402 | #else |
| 3326 | #define FREE_VARIABLES() /* Do nothing! */ | 3403 | #define FREE_VARIABLES() /* Do nothing! */ |
| 3327 | #endif /* not MATCH_MAY_ALLOCATE */ | 3404 | #endif /* not MATCH_MAY_ALLOCATE */ |
| @@ -3437,6 +3514,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3437 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; | 3514 | unsigned nfailure_points_pushed = 0, nfailure_points_popped = 0; |
| 3438 | #endif | 3515 | #endif |
| 3439 | 3516 | ||
| 3517 | /* This holds the pointer to the failure stack, when | ||
| 3518 | it is allocated relocatably. */ | ||
| 3519 | fail_stack_elt_t *failure_stack_ptr; | ||
| 3520 | |||
| 3440 | /* We fill all the registers internally, independent of what we | 3521 | /* We fill all the registers internally, independent of what we |
| 3441 | return, for use in backreferences. The number here includes | 3522 | return, for use in backreferences. The number here includes |
| 3442 | an element for register zero. */ | 3523 | an element for register zero. */ |
| @@ -3538,7 +3619,6 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3538 | return -2; | 3619 | return -2; |
| 3539 | } | 3620 | } |
| 3540 | } | 3621 | } |
| 3541 | #if defined (REGEX_MALLOC) | ||
| 3542 | else | 3622 | else |
| 3543 | { | 3623 | { |
| 3544 | /* We must initialize all our variables to NULL, so that | 3624 | /* We must initialize all our variables to NULL, so that |
| @@ -3547,7 +3627,6 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3547 | = best_regend = reg_dummy = NULL; | 3627 | = best_regend = reg_dummy = NULL; |
| 3548 | reg_info = reg_info_dummy = (register_info_type *) NULL; | 3628 | reg_info = reg_info_dummy = (register_info_type *) NULL; |
| 3549 | } | 3629 | } |
| 3550 | #endif /* REGEX_MALLOC */ | ||
| 3551 | #endif /* MATCH_MAY_ALLOCATE */ | 3630 | #endif /* MATCH_MAY_ALLOCATE */ |
| 3552 | 3631 | ||
| 3553 | /* The starting position is bogus. */ | 3632 | /* The starting position is bogus. */ |
| @@ -3709,7 +3788,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3709 | regs->start = TALLOC (regs->num_regs, regoff_t); | 3788 | regs->start = TALLOC (regs->num_regs, regoff_t); |
| 3710 | regs->end = TALLOC (regs->num_regs, regoff_t); | 3789 | regs->end = TALLOC (regs->num_regs, regoff_t); |
| 3711 | if (regs->start == NULL || regs->end == NULL) | 3790 | if (regs->start == NULL || regs->end == NULL) |
| 3712 | return -2; | 3791 | { |
| 3792 | FREE_VARIABLES (); | ||
| 3793 | return -2; | ||
| 3794 | } | ||
| 3713 | bufp->regs_allocated = REGS_REALLOCATE; | 3795 | bufp->regs_allocated = REGS_REALLOCATE; |
| 3714 | } | 3796 | } |
| 3715 | else if (bufp->regs_allocated == REGS_REALLOCATE) | 3797 | else if (bufp->regs_allocated == REGS_REALLOCATE) |
| @@ -3722,7 +3804,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3722 | RETALLOC (regs->start, regs->num_regs, regoff_t); | 3804 | RETALLOC (regs->start, regs->num_regs, regoff_t); |
| 3723 | RETALLOC (regs->end, regs->num_regs, regoff_t); | 3805 | RETALLOC (regs->end, regs->num_regs, regoff_t); |
| 3724 | if (regs->start == NULL || regs->end == NULL) | 3806 | if (regs->start == NULL || regs->end == NULL) |
| 3725 | return -2; | 3807 | { |
| 3808 | FREE_VARIABLES (); | ||
| 3809 | return -2; | ||
| 3810 | } | ||
| 3726 | } | 3811 | } |
| 3727 | } | 3812 | } |
| 3728 | else | 3813 | else |
| @@ -3767,7 +3852,6 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3767 | regs->start[mcnt] = regs->end[mcnt] = -1; | 3852 | regs->start[mcnt] = regs->end[mcnt] = -1; |
| 3768 | } /* regs && !bufp->no_sub */ | 3853 | } /* regs && !bufp->no_sub */ |
| 3769 | 3854 | ||
| 3770 | FREE_VARIABLES (); | ||
| 3771 | DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", | 3855 | DEBUG_PRINT4 ("%u failure points pushed, %u popped (%u remain).\n", |
| 3772 | nfailure_points_pushed, nfailure_points_popped, | 3856 | nfailure_points_pushed, nfailure_points_popped, |
| 3773 | nfailure_points_pushed - nfailure_points_popped); | 3857 | nfailure_points_pushed - nfailure_points_popped); |
| @@ -3779,6 +3863,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) | |||
| 3779 | 3863 | ||
| 3780 | DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); | 3864 | DEBUG_PRINT2 ("Returning %d from re_match_2.\n", mcnt); |
| 3781 | 3865 | ||
| 3866 | FREE_VARIABLES (); | ||
| 3782 | return mcnt; | 3867 | return mcnt; |
| 3783 | } | 3868 | } |
| 3784 | 3869 | ||