diff options
| author | Michal Nazarewicz | 2016-07-27 22:39:04 +0200 |
|---|---|---|
| committer | Michal Nazarewicz | 2016-08-02 15:39:10 +0200 |
| commit | 04d96eca08ff797c0cd93c33fe8589f4623fc449 (patch) | |
| tree | adc46050fff677705e5be6400502495e3943dd1f | |
| parent | 9a418e0f98a6ee14d9984e597038168ebe0a7a03 (diff) | |
| download | emacs-04d96eca08ff797c0cd93c33fe8589f4623fc449.tar.gz emacs-04d96eca08ff797c0cd93c33fe8589f4623fc449.zip | |
Get rid of re_set_syntax
Instead of using a global variable for storing regex syntax, pass it
to re_compile_pattern. This is only enabled when compiling Emacs (i.e.
‘#ifdef emacs’).
* src/regex.h (re_set_syntax): Declare only #ifndef emacs.
(re_compile_pattern): Now takes syntax argument #ifdef emacs.
* src/regex.c (re_syntax_options): Define only #ifndef emacs.
(re_compile_pattern): Use the new syntax argument #ifdef emacs.
* src/search.c (compile_pattern_1): Don’t use re_set_syntax and
instead pass syntax to re_compile_pattern directly.
| -rw-r--r-- | src/regex.c | 12 | ||||
| -rw-r--r-- | src/regex.h | 14 | ||||
| -rw-r--r-- | src/search.c | 10 |
3 files changed, 29 insertions, 7 deletions
diff --git a/src/regex.c b/src/regex.c index 261d2997c32..4edc064d6b8 100644 --- a/src/regex.c +++ b/src/regex.c | |||
| @@ -1149,6 +1149,8 @@ print_double_string (re_char *where, re_char *string1, ssize_t size1, | |||
| 1149 | 1149 | ||
| 1150 | #endif /* not DEBUG */ | 1150 | #endif /* not DEBUG */ |
| 1151 | 1151 | ||
| 1152 | #ifndef emacs | ||
| 1153 | |||
| 1152 | /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can | 1154 | /* Set by `re_set_syntax' to the current regexp syntax to recognize. Can |
| 1153 | also be assigned to arbitrarily: each pattern buffer stores its own | 1155 | also be assigned to arbitrarily: each pattern buffer stores its own |
| 1154 | syntax, so it can be changed between regex compilations. */ | 1156 | syntax, so it can be changed between regex compilations. */ |
| @@ -1174,6 +1176,8 @@ re_set_syntax (reg_syntax_t syntax) | |||
| 1174 | } | 1176 | } |
| 1175 | WEAK_ALIAS (__re_set_syntax, re_set_syntax) | 1177 | WEAK_ALIAS (__re_set_syntax, re_set_syntax) |
| 1176 | 1178 | ||
| 1179 | #endif | ||
| 1180 | |||
| 1177 | /* Regexp to use to replace spaces, or NULL meaning don't. */ | 1181 | /* Regexp to use to replace spaces, or NULL meaning don't. */ |
| 1178 | static const_re_char *whitespace_regexp; | 1182 | static const_re_char *whitespace_regexp; |
| 1179 | 1183 | ||
| @@ -6271,8 +6275,14 @@ bcmp_translate (const_re_char *s1, const_re_char *s2, register ssize_t len, | |||
| 6271 | 6275 | ||
| 6272 | const char * | 6276 | const char * |
| 6273 | re_compile_pattern (const char *pattern, size_t length, | 6277 | re_compile_pattern (const char *pattern, size_t length, |
| 6278 | #ifdef emacs | ||
| 6279 | reg_syntax_t syntax, | ||
| 6280 | #endif | ||
| 6274 | struct re_pattern_buffer *bufp) | 6281 | struct re_pattern_buffer *bufp) |
| 6275 | { | 6282 | { |
| 6283 | #ifndef emacs | ||
| 6284 | const reg_syntax_t syntax = re_syntax_options; | ||
| 6285 | #endif | ||
| 6276 | reg_errcode_t ret; | 6286 | reg_errcode_t ret; |
| 6277 | 6287 | ||
| 6278 | /* GNU code is written to assume at least RE_NREGS registers will be set | 6288 | /* GNU code is written to assume at least RE_NREGS registers will be set |
| @@ -6284,7 +6294,7 @@ re_compile_pattern (const char *pattern, size_t length, | |||
| 6284 | setting no_sub. */ | 6294 | setting no_sub. */ |
| 6285 | bufp->no_sub = 0; | 6295 | bufp->no_sub = 0; |
| 6286 | 6296 | ||
| 6287 | ret = regex_compile ((re_char*) pattern, length, re_syntax_options, bufp); | 6297 | ret = regex_compile ((re_char*) pattern, length, syntax, bufp); |
| 6288 | 6298 | ||
| 6289 | if (!ret) | 6299 | if (!ret) |
| 6290 | return NULL; | 6300 | return NULL; |
diff --git a/src/regex.h b/src/regex.h index 01b659addbb..4497333500a 100644 --- a/src/regex.h +++ b/src/regex.h | |||
| @@ -20,6 +20,13 @@ | |||
| 20 | #ifndef _REGEX_H | 20 | #ifndef _REGEX_H |
| 21 | #define _REGEX_H 1 | 21 | #define _REGEX_H 1 |
| 22 | 22 | ||
| 23 | #if defined emacs && (defined _REGEX_RE_COMP || defined _LIBC) | ||
| 24 | /* We’re not defining re_set_syntax and using a different prototype of | ||
| 25 | re_compile_pattern when building Emacs so fail compilation early with | ||
| 26 | a (somewhat helpful) error message when conflict is detected. */ | ||
| 27 | # error "_REGEX_RE_COMP nor _LIBC can be defined if emacs is defined." | ||
| 28 | #endif | ||
| 29 | |||
| 23 | /* Allow the use in C++ code. */ | 30 | /* Allow the use in C++ code. */ |
| 24 | #ifdef __cplusplus | 31 | #ifdef __cplusplus |
| 25 | extern "C" { | 32 | extern "C" { |
| @@ -453,14 +460,21 @@ typedef struct | |||
| 453 | 460 | ||
| 454 | /* Declarations for routines. */ | 461 | /* Declarations for routines. */ |
| 455 | 462 | ||
| 463 | #ifndef emacs | ||
| 464 | |||
| 456 | /* Sets the current default syntax to SYNTAX, and return the old syntax. | 465 | /* Sets the current default syntax to SYNTAX, and return the old syntax. |
| 457 | You can also simply assign to the `re_syntax_options' variable. */ | 466 | You can also simply assign to the `re_syntax_options' variable. */ |
| 458 | extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); | 467 | extern reg_syntax_t re_set_syntax (reg_syntax_t __syntax); |
| 459 | 468 | ||
| 469 | #endif | ||
| 470 | |||
| 460 | /* Compile the regular expression PATTERN, with length LENGTH | 471 | /* Compile the regular expression PATTERN, with length LENGTH |
| 461 | and syntax given by the global `re_syntax_options', into the buffer | 472 | and syntax given by the global `re_syntax_options', into the buffer |
| 462 | BUFFER. Return NULL if successful, and an error string if not. */ | 473 | BUFFER. Return NULL if successful, and an error string if not. */ |
| 463 | extern const char *re_compile_pattern (const char *__pattern, size_t __length, | 474 | extern const char *re_compile_pattern (const char *__pattern, size_t __length, |
| 475 | #ifdef emacs | ||
| 476 | reg_syntax_t syntax, | ||
| 477 | #endif | ||
| 464 | struct re_pattern_buffer *__buffer); | 478 | struct re_pattern_buffer *__buffer); |
| 465 | 479 | ||
| 466 | 480 | ||
diff --git a/src/search.c b/src/search.c index 7cb18a2059a..f0419522df2 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -113,8 +113,8 @@ static void | |||
| 113 | compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, | 113 | compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, |
| 114 | Lisp_Object translate, bool posix) | 114 | Lisp_Object translate, bool posix) |
| 115 | { | 115 | { |
| 116 | reg_syntax_t syntax; | ||
| 116 | char *val; | 117 | char *val; |
| 117 | reg_syntax_t old; | ||
| 118 | 118 | ||
| 119 | cp->regexp = Qnil; | 119 | cp->regexp = Qnil; |
| 120 | cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); | 120 | cp->buf.translate = (! NILP (translate) ? translate : make_number (0)); |
| @@ -131,16 +131,15 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, | |||
| 131 | Using BLOCK_INPUT here means the debugger won't run if an error occurs. | 131 | Using BLOCK_INPUT here means the debugger won't run if an error occurs. |
| 132 | So let's turn it off. */ | 132 | So let's turn it off. */ |
| 133 | /* BLOCK_INPUT; */ | 133 | /* BLOCK_INPUT; */ |
| 134 | old = re_set_syntax (RE_SYNTAX_EMACS | ||
| 135 | | (posix ? 0 : RE_NO_POSIX_BACKTRACKING)); | ||
| 136 | 134 | ||
| 137 | if (STRINGP (Vsearch_spaces_regexp)) | 135 | if (STRINGP (Vsearch_spaces_regexp)) |
| 138 | re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp)); | 136 | re_set_whitespace_regexp (SSDATA (Vsearch_spaces_regexp)); |
| 139 | else | 137 | else |
| 140 | re_set_whitespace_regexp (NULL); | 138 | re_set_whitespace_regexp (NULL); |
| 141 | 139 | ||
| 142 | val = (char *) re_compile_pattern (SSDATA (pattern), | 140 | syntax = RE_SYNTAX_EMACS | (posix ? 0 : RE_NO_POSIX_BACKTRACKING); |
| 143 | SBYTES (pattern), &cp->buf); | 141 | val = (char *) re_compile_pattern (SSDATA (pattern), SBYTES (pattern), |
| 142 | syntax, &cp->buf); | ||
| 144 | 143 | ||
| 145 | /* If the compiled pattern hard codes some of the contents of the | 144 | /* If the compiled pattern hard codes some of the contents of the |
| 146 | syntax-table, it can only be reused with *this* syntax table. */ | 145 | syntax-table, it can only be reused with *this* syntax table. */ |
| @@ -148,7 +147,6 @@ compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, | |||
| 148 | 147 | ||
| 149 | re_set_whitespace_regexp (NULL); | 148 | re_set_whitespace_regexp (NULL); |
| 150 | 149 | ||
| 151 | re_set_syntax (old); | ||
| 152 | /* unblock_input (); */ | 150 | /* unblock_input (); */ |
| 153 | if (val) | 151 | if (val) |
| 154 | xsignal1 (Qinvalid_regexp, build_string (val)); | 152 | xsignal1 (Qinvalid_regexp, build_string (val)); |