X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/ecb21060d5c1752d41d7a742be565c59b5fcb855..cb711556008291dc0d1425b8f0f0837b37ae8368:/src/regex.c diff --git a/src/regex.c b/src/regex.c index 0858378c6e..91259dc779 100644 --- a/src/regex.c +++ b/src/regex.c @@ -3,7 +3,7 @@ internationalization features.) Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007 + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -153,10 +153,7 @@ # define RE_CHAR_TO_MULTIBYTE(c) unibyte_to_multibyte_table[(c)] -# define RE_CHAR_TO_UNIBYTE(c) \ - (ASCII_CHAR_P (c) ? (c) \ - : CHAR_BYTE8_P (c) ? CHAR_TO_BYTE8 (c) \ - : multibyte_char_to_unibyte_safe (c)) +# define RE_CHAR_TO_UNIBYTE(c) CHAR_TO_BYTE_SAFE (c) /* Set C a (possibly converted to multibyte) character before P. P points into a string which is the virtual concatenation of STR1 @@ -289,11 +286,7 @@ xrealloc (block, size) /* Sword must be nonzero for the wordchar pattern commands in re_match_2. */ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 }; -# ifdef SWITCH_ENUM_BUG -# define SWITCH_ENUM_CAST(x) ((int)(x)) -# else # define SWITCH_ENUM_CAST(x) (x) -# endif /* Dummy macros for non-Emacs environments. */ # define BASE_LEADING_CODE_P(c) (0) @@ -1398,18 +1391,12 @@ static const char *re_error_msgid[] = /* Normally, this is fine. */ #define MATCH_MAY_ALLOCATE -/* When using GNU C, we are not REALLY using the C alloca, no matter - what config.h may say. So don't take precautions for it. */ -#ifdef __GNUC__ -# undef C_ALLOCA -#endif - /* The match routines may not allocate if (1) they would do it with malloc and (2) it's not safe for them to use malloc. Note that if REL_ALLOC is defined, matching would not use malloc for the failure stack, but we would still use it for the register vectors; so REL_ALLOC should not affect this. */ -#if (defined C_ALLOCA || defined REGEX_MALLOC) && defined emacs +#if defined REGEX_MALLOC && defined emacs # undef MATCH_MAY_ALLOCATE #endif @@ -1864,8 +1851,10 @@ static int analyse_first _RE_ARGS ((re_char *p, re_char *pend, being larger than MAX_BUF_SIZE, then flag memory exhausted. */ #if __BOUNDED_POINTERS__ # define SET_HIGH_BOUND(P) (__ptrhigh (P) = __ptrlow (P) + bufp->allocated) -# define MOVE_BUFFER_POINTER(P) \ - (__ptrlow (P) += incr, SET_HIGH_BOUND (P), __ptrvalue (P) += incr) +# define MOVE_BUFFER_POINTER(P) \ + (__ptrlow (P) = new_buffer + (__ptrlow (P) - old_buffer), \ + SET_HIGH_BOUND (P), \ + __ptrvalue (P) = new_buffer + (__ptrvalue (P) - old_buffer)) # define ELSE_EXTEND_BUFFER_HIGH_BOUND \ else \ { \ @@ -1879,12 +1868,12 @@ static int analyse_first _RE_ARGS ((re_char *p, re_char *pend, SET_HIGH_BOUND (pending_exact); \ } #else -# define MOVE_BUFFER_POINTER(P) (P) += incr +# define MOVE_BUFFER_POINTER(P) ((P) = new_buffer + ((P) - old_buffer)) # define ELSE_EXTEND_BUFFER_HIGH_BOUND #endif #define EXTEND_BUFFER() \ do { \ - re_char *old_buffer = bufp->buffer; \ + unsigned char *old_buffer = bufp->buffer; \ if (bufp->allocated == MAX_BUF_SIZE) \ return REG_ESIZE; \ bufp->allocated <<= 1; \ @@ -1896,7 +1885,7 @@ static int analyse_first _RE_ARGS ((re_char *p, re_char *pend, /* If the buffer moved, move all the pointers into it. */ \ if (old_buffer != bufp->buffer) \ { \ - int incr = bufp->buffer - old_buffer; \ + unsigned char *new_buffer = bufp->buffer; \ MOVE_BUFFER_POINTER (b); \ MOVE_BUFFER_POINTER (begalt); \ if (fixup_alt_jump) \ @@ -4635,11 +4624,6 @@ re_search_2 (bufp, str1, size1, str2, size2, startpos, range, regs, stop) val = re_match_2_internal (bufp, string1, size1, string2, size2, startpos, regs, stop); -#ifndef REGEX_MALLOC -# ifdef C_ALLOCA - alloca (0); -# endif -#endif if (val >= 0) return startpos; @@ -5076,9 +5060,6 @@ re_match (bufp, string, size, pos, regs) { int result = re_match_2_internal (bufp, NULL, 0, (re_char*) string, size, pos, regs, size); -# if defined C_ALLOCA && !defined REGEX_MALLOC - alloca (0); -# endif return result; } WEAK_ALIAS (__re_match, re_match) @@ -5124,9 +5105,6 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop) result = re_match_2_internal (bufp, (re_char*) string1, size1, (re_char*) string2, size2, pos, regs, stop); -#if defined C_ALLOCA && !defined REGEX_MALLOC - alloca (0); -#endif return result; } WEAK_ALIAS (__re_match_2, re_match_2) @@ -5593,10 +5571,7 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) if (multibyte) { pat_ch = STRING_CHAR_AND_LENGTH (p, pend - p, pat_charlen); - if (CHAR_BYTE8_P (pat_ch)) - pat_ch = CHAR_TO_BYTE8 (pat_ch); - else - pat_ch = RE_CHAR_TO_UNIBYTE (pat_ch); + pat_ch = RE_CHAR_TO_UNIBYTE (pat_ch); } else { @@ -5611,6 +5586,8 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) if (buf_ch < 0) buf_ch = *d; } + else + buf_ch = *d; if (buf_ch != pat_ch) { d = dfail; @@ -5667,6 +5644,9 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) in the initial byte-length of the command. */ int count = 0; + /* Whether matching against a unibyte character. */ + boolean unibyte_char = false; + DEBUG_PRINT2 ("EXECUTING charset%s.\n", not ? "_not" : ""); range_table_exists = CHARSET_RANGE_TABLE_EXISTS_P (&p[-1]); @@ -5686,7 +5666,10 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) c = TRANSLATE (c); c1 = RE_CHAR_TO_UNIBYTE (c); if (c1 >= 0) - c = c1; + { + unibyte_char = true; + c = c1; + } } else { @@ -5697,11 +5680,16 @@ re_match_2_internal (bufp, string1, size1, string2, size2, pos, regs, stop) c1 = TRANSLATE (c1); c1 = RE_CHAR_TO_UNIBYTE (c1); if (c1 >= 0) - c = c1; + { + unibyte_char = true; + c = c1; + } } + else + unibyte_char = true; } - if (c < (1 << BYTEWIDTH)) + if (unibyte_char && c < (1 << BYTEWIDTH)) { /* Lookup bitmap. */ /* Cast to `unsigned' instead of `unsigned char' in case the bit list is a full 32 bytes long. */ @@ -6847,20 +6835,17 @@ void regfree (preg) regex_t *preg; { - if (preg->buffer != NULL) - free (preg->buffer); + free (preg->buffer); preg->buffer = NULL; preg->allocated = 0; preg->used = 0; - if (preg->fastmap != NULL) - free (preg->fastmap); + free (preg->fastmap); preg->fastmap = NULL; preg->fastmap_accurate = 0; - if (preg->translate != NULL) - free (preg->translate); + free (preg->translate); preg->translate = NULL; } WEAK_ALIAS (__regfree, regfree)