X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=regex.c;h=591d6f14e12bf1094376b66b8943aa351e07b9fc;hb=0ab8a118f1d2e4648c24a10ab0b57f6d07239be4;hp=ffc791236d73e3ac989acc9dbea239f7217208de;hpb=7a34afe4329f7eeb95b51d60a3d5887ede83abb8;p=gnulib.git diff --git a/regex.c b/regex.c index ffc791236..591d6f14e 100644 --- a/regex.c +++ b/regex.c @@ -49,8 +49,12 @@ /* Whether to use ISO C Amendment 1 wide char functions. Those should not be used for Emacs since it uses its own. */ +#if defined _LIBC +#define WIDE_CHAR_SUPPORT 1 +#else #define WIDE_CHAR_SUPPORT \ - (defined _LIBC || HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC && !emacs) + (HAVE_WCTYPE_H && HAVE_WCHAR_H && HAVE_BTOWC && !emacs) +#endif /* For platform which support the ISO C amendement 1 functionality we support user defined character classes. */ @@ -124,8 +128,17 @@ # include "charset.h" # include "category.h" +# ifdef malloc +# undef malloc +# endif # define malloc xmalloc +# ifdef realloc +# undef realloc +# endif # define realloc xrealloc +# ifdef free +# undef free +# endif # define free xfree /* Converts the pointer to the char to BEG-based offset from the start. */ @@ -1314,7 +1327,8 @@ static const char *re_error_msgid[] = /* Roughly the maximum number of failure points on the stack. Would be exactly that if always used TYPICAL_FAILURE_SIZE items each time we failed. This is a variable only so users of regex can assign to it; we never - change it ourselves. */ + change it ourselves. We always multiply it by TYPICAL_FAILURE_SIZE + before using it, so it should probably be a byte-count instead. */ # if defined MATCH_MAY_ALLOCATE /* Note that 4400 was enough to cause a crash on Alpha OSF/1, whose default stack limit is 2mb. In order for a larger @@ -1504,19 +1518,43 @@ do { \ } \ } while (0) +/* Discard a saved register off the stack. */ +#define DISCARD_FAILURE_REG_OR_COUNT() \ +do { \ + int reg = POP_FAILURE_INT (); \ + if (reg == -1) \ + { \ + /* It's a counter. */ \ + POP_FAILURE_POINTER (); \ + reg = POP_FAILURE_INT (); \ + DEBUG_PRINT3 (" Discard counter %p = %d\n", ptr, reg); \ + } \ + else \ + { \ + POP_FAILURE_POINTER (); \ + POP_FAILURE_POINTER (); \ + DEBUG_PRINT4 (" Discard reg %d (spanning %p -> %p)\n", \ + reg, regstart[reg], regend[reg]); \ + } \ +} while (0) + /* Check that we are not stuck in an infinite loop. */ #define CHECK_INFINITE_LOOP(pat_cur, string_place) \ do { \ - int failure = TOP_FAILURE_HANDLE(); \ + int failure = TOP_FAILURE_HANDLE (); \ /* Check for infinite matching loops */ \ - while (failure > 0 && \ - (FAILURE_STR (failure) == string_place \ - || FAILURE_STR (failure) == NULL)) \ + while (failure > 0 \ + && (FAILURE_STR (failure) == string_place \ + || FAILURE_STR (failure) == NULL)) \ { \ assert (FAILURE_PAT (failure) >= bufp->buffer \ && FAILURE_PAT (failure) <= bufp->buffer + bufp->used); \ if (FAILURE_PAT (failure) == pat_cur) \ - goto fail; \ + { \ + while (fail_stack.frame < fail_stack.avail) \ + DISCARD_FAILURE_REG_OR_COUNT (); \ + goto fail; \ + } \ DEBUG_PRINT2 (" Other pattern: %p\n", FAILURE_PAT (failure)); \ failure = NEXT_FAILURE_HANDLE(failure); \ } \ @@ -1566,7 +1604,7 @@ do { \ /* Estimate the size of data pushed by a typical failure stack entry. An estimate is all we need, because all we use this for is to choose a limit for how big to make the failure stack. */ - +/* BEWARE, the value `20' is hard-coded in emacs.c:main(). */ #define TYPICAL_FAILURE_SIZE 20 /* How many items can still be added to the stack without overflowing it. */ @@ -1906,15 +1944,23 @@ struct range_table_work_area do { if (p != pend) \ { \ PATFETCH (c); \ + if (c == ' ') \ + FREE_STACK_RETURN (REG_BADBR); \ while ('0' <= c && c <= '9') \ { \ + int prev; \ if (num < 0) \ - num = 0; \ + num = 0; \ + prev = num; \ num = num * 10 + c - '0'; \ + if (num / 10 != prev) \ + FREE_STACK_RETURN (REG_BADBR); \ if (p == pend) \ - break; \ + break; \ PATFETCH (c); \ } \ + if (c == ' ') \ + FREE_STACK_RETURN (REG_BADBR); \ } \ } while (0) @@ -1953,9 +1999,10 @@ typedef int re_wchar_t; /* Map a string to the char class it names (if any). */ static re_wctype_t -re_wctype (string) - re_char *string; +re_wctype (str) + re_char *str; { + const char *string = str; if (STREQ (string, "alnum")) return RECC_ALNUM; else if (STREQ (string, "alpha")) return RECC_ALPHA; else if (STREQ (string, "word")) return RECC_WORD; @@ -4366,6 +4413,7 @@ mutually_exclusive_p (bufp, p1, p2) } } } + break; case charset_not: switch (SWITCH_ENUM_CAST (*p1)) @@ -5823,8 +5871,8 @@ re_exec (s) int regcomp (preg, pattern, cflags) - regex_t *preg; - const char *pattern; + regex_t *__restrict preg; + const char *__restrict pattern; int cflags; { reg_errcode_t ret; @@ -5908,8 +5956,8 @@ WEAK_ALIAS (__regcomp, regcomp) int regexec (preg, string, nmatch, pmatch, eflags) - const regex_t *preg; - const char *string; + const regex_t *__restrict preg; + const char *__restrict string; size_t nmatch; regmatch_t pmatch[]; int eflags;