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.
This commit is contained in:
Paul Eggert 2016-10-22 21:12:54 -07:00
parent b2ba630739
commit f6134bbda2

View file

@ -1439,21 +1439,22 @@ typedef struct
#define TOP_FAILURE_HANDLE() fail_stack.frame #define TOP_FAILURE_HANDLE() fail_stack.frame
#ifdef emacs #ifdef emacs
#define STR_BASE_PTR(obj) \ # define STR_BASE_PTR(obj) \
(NILP (obj) ? current_buffer->text->beg : \ (NILP (obj) ? current_buffer->text->beg \
STRINGP (obj) ? SDATA (obj) : \ : STRINGP (obj) ? SDATA (obj) \
NULL) : NULL)
#else #else
#define STR_BASE_PTR(obj) NULL # define STR_BASE_PTR(obj) NULL
#endif #endif
#define ENSURE_FAIL_STACK(space) \ #define ENSURE_FAIL_STACK(space) \
while (REMAINING_AVAIL_SLOTS <= 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 string1_off, end1_off, end_match_1_off; \
ptrdiff_t string2_off, end2_off, end_match_2_off; \ ptrdiff_t string2_off, end2_off, end_match_2_off; \
ptrdiff_t d_off, dend_off, dfail_off; \ ptrdiff_t d_off, dend_off, dfail_off; \
if (orig_base) \ if (might_relocate) \
{ \ { \
if (string1) \ if (string1) \
{ \ { \
@ -1472,12 +1473,11 @@ while (REMAINING_AVAIL_SLOTS <= space) { \
dfail_off = dfail - orig_base; \ dfail_off = dfail - orig_base; \
} \ } \
if (!GROW_FAIL_STACK (fail_stack)) \ if (!GROW_FAIL_STACK (fail_stack)) \
return -2; \ return -2; \
/* GROW_FAIL_STACK may call malloc and relocate the string */ \ /* In Emacs, GROW_FAIL_STACK might relocate string pointers. */ \
/* pointers. */ \ if (might_relocate) \
re_char* new_base = STR_BASE_PTR (re_match_object); \
if (new_base && new_base != orig_base) \
{ \ { \
re_char *new_base = STR_BASE_PTR (re_match_object); \
if (string1) \ if (string1) \
{ \ { \
string1 = new_base + string1_off; \ 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) && !bufp->can_be_null)
return -1; return -1;
/* re_match_2_internal may allocate, causing a relocation of the /* re_match_2_internal may allocate, relocating the Lisp text
lisp text object that we're searching. */ object that we're searching. */
ptrdiff_t offset1, offset2; ptrdiff_t offset1, offset2;
IF_LINT (offset2 = 0); /* Work around GCC bug 78081. */
re_char *orig_base = STR_BASE_PTR (re_match_object); 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 (string1) offset1 = string1 - orig_base;
if (string2) offset2 = string2 - 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) if (val == -2)
return -2; return -2;
re_char *new_base = STR_BASE_PTR (re_match_object); if (might_relocate)
if (new_base && new_base != orig_base)
{ {
re_char *new_base = STR_BASE_PTR (re_match_object);
if (string1) string1 = offset1 + new_base; if (string1) string1 = offset1 + new_base;
if (string2) string2 = offset2 + new_base; if (string2) string2 = offset2 + new_base;
} }