diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2016-10-22 21:12:54 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2016-10-22 21:14:15 -0700 |
commit | f6134bbda259c115c06d4a9a3ab5c39340a15949 (patch) | |
tree | f84ec5aafdfec9a88a0adc7c543c76a2c9f7317a /src/regex.c | |
parent | b2ba630739cf12db939cdcfe9cd19b6a7fdfbf97 (diff) | |
download | emacs-f6134bbda259c115c06d4a9a3ab5c39340a15949.tar.gz |
Port to GCC 6.2.1 + --enable-gcc-warnings
* src/regex.c (ENSURE_FAIL_STACK, re_search_2):
Redo recent regex changes to avoid complaints from GCC 6.2.1 when
Emacs is configured with --enable-gcc-warnings. Also, work around
GCC bug 78081, which was uncovered by this new code.
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 1346ef401cb..daa15ec5a8d 100644 --- a/src/regex.c +++ b/src/regex.c @@ -1439,21 +1439,22 @@ typedef struct #define TOP_FAILURE_HANDLE() fail_stack.frame #ifdef emacs -#define STR_BASE_PTR(obj) \ - (NILP (obj) ? current_buffer->text->beg : \ - STRINGP (obj) ? SDATA (obj) : \ - NULL) +# define STR_BASE_PTR(obj) \ + (NILP (obj) ? current_buffer->text->beg \ + : STRINGP (obj) ? SDATA (obj) \ + : NULL) #else -#define STR_BASE_PTR(obj) NULL +# define STR_BASE_PTR(obj) NULL #endif #define ENSURE_FAIL_STACK(space) \ while (REMAINING_AVAIL_SLOTS <= space) { \ - re_char* orig_base = STR_BASE_PTR (re_match_object); \ + re_char *orig_base = STR_BASE_PTR (re_match_object); \ + bool might_relocate = orig_base != NULL; \ ptrdiff_t string1_off, end1_off, end_match_1_off; \ ptrdiff_t string2_off, end2_off, end_match_2_off; \ ptrdiff_t d_off, dend_off, dfail_off; \ - if (orig_base) \ + if (might_relocate) \ { \ if (string1) \ { \ @@ -1472,12 +1473,11 @@ while (REMAINING_AVAIL_SLOTS <= space) { \ dfail_off = dfail - orig_base; \ } \ if (!GROW_FAIL_STACK (fail_stack)) \ - return -2; \ - /* GROW_FAIL_STACK may call malloc and relocate the string */ \ - /* pointers. */ \ - re_char* new_base = STR_BASE_PTR (re_match_object); \ - if (new_base && new_base != orig_base) \ + return -2; \ + /* In Emacs, GROW_FAIL_STACK might relocate string pointers. */ \ + if (might_relocate) \ { \ + re_char *new_base = STR_BASE_PTR (re_match_object); \ if (string1) \ { \ string1 = new_base + string1_off; \ @@ -4496,11 +4496,13 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, && !bufp->can_be_null) return -1; - /* re_match_2_internal may allocate, causing a relocation of the - lisp text object that we're searching. */ + /* re_match_2_internal may allocate, relocating the Lisp text + object that we're searching. */ ptrdiff_t offset1, offset2; + IF_LINT (offset2 = 0); /* Work around GCC bug 78081. */ re_char *orig_base = STR_BASE_PTR (re_match_object); - if (orig_base) + bool might_relocate = orig_base != NULL; + if (might_relocate) { if (string1) offset1 = string1 - orig_base; if (string2) offset2 = string2 - orig_base; @@ -4515,9 +4517,9 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1, if (val == -2) return -2; - re_char *new_base = STR_BASE_PTR (re_match_object); - if (new_base && new_base != orig_base) + if (might_relocate) { + re_char *new_base = STR_BASE_PTR (re_match_object); if (string1) string1 = offset1 + new_base; if (string2) string2 = offset2 + new_base; } |