aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2016-10-22 21:12:54 -0700
committerPaul Eggert2016-10-22 21:14:15 -0700
commitf6134bbda259c115c06d4a9a3ab5c39340a15949 (patch)
treef84ec5aafdfec9a88a0adc7c543c76a2c9f7317a /src
parentb2ba630739cf12db939cdcfe9cd19b6a7fdfbf97 (diff)
downloademacs-f6134bbda259c115c06d4a9a3ab5c39340a15949.tar.gz
emacs-f6134bbda259c115c06d4a9a3ab5c39340a15949.zip
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')
-rw-r--r--src/regex.c36
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
1439#define TOP_FAILURE_HANDLE() fail_stack.frame 1439#define TOP_FAILURE_HANDLE() fail_stack.frame
1440 1440
1441#ifdef emacs 1441#ifdef emacs
1442#define STR_BASE_PTR(obj) \ 1442# define STR_BASE_PTR(obj) \
1443 (NILP (obj) ? current_buffer->text->beg : \ 1443 (NILP (obj) ? current_buffer->text->beg \
1444 STRINGP (obj) ? SDATA (obj) : \ 1444 : STRINGP (obj) ? SDATA (obj) \
1445 NULL) 1445 : NULL)
1446#else 1446#else
1447#define STR_BASE_PTR(obj) NULL 1447# define STR_BASE_PTR(obj) NULL
1448#endif 1448#endif
1449 1449
1450#define ENSURE_FAIL_STACK(space) \ 1450#define ENSURE_FAIL_STACK(space) \
1451while (REMAINING_AVAIL_SLOTS <= space) { \ 1451while (REMAINING_AVAIL_SLOTS <= space) { \
1452 re_char* orig_base = STR_BASE_PTR (re_match_object); \ 1452 re_char *orig_base = STR_BASE_PTR (re_match_object); \
1453 bool might_relocate = orig_base != NULL; \
1453 ptrdiff_t string1_off, end1_off, end_match_1_off; \ 1454 ptrdiff_t string1_off, end1_off, end_match_1_off; \
1454 ptrdiff_t string2_off, end2_off, end_match_2_off; \ 1455 ptrdiff_t string2_off, end2_off, end_match_2_off; \
1455 ptrdiff_t d_off, dend_off, dfail_off; \ 1456 ptrdiff_t d_off, dend_off, dfail_off; \
1456 if (orig_base) \ 1457 if (might_relocate) \
1457 { \ 1458 { \
1458 if (string1) \ 1459 if (string1) \
1459 { \ 1460 { \
@@ -1472,12 +1473,11 @@ while (REMAINING_AVAIL_SLOTS <= space) { \
1472 dfail_off = dfail - orig_base; \ 1473 dfail_off = dfail - orig_base; \
1473 } \ 1474 } \
1474 if (!GROW_FAIL_STACK (fail_stack)) \ 1475 if (!GROW_FAIL_STACK (fail_stack)) \
1475 return -2; \ 1476 return -2; \
1476 /* GROW_FAIL_STACK may call malloc and relocate the string */ \ 1477 /* In Emacs, GROW_FAIL_STACK might relocate string pointers. */ \
1477 /* pointers. */ \ 1478 if (might_relocate) \
1478 re_char* new_base = STR_BASE_PTR (re_match_object); \
1479 if (new_base && new_base != orig_base) \
1480 { \ 1479 { \
1480 re_char *new_base = STR_BASE_PTR (re_match_object); \
1481 if (string1) \ 1481 if (string1) \
1482 { \ 1482 { \
1483 string1 = new_base + string1_off; \ 1483 string1 = new_base + string1_off; \
@@ -4496,11 +4496,13 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1,
4496 && !bufp->can_be_null) 4496 && !bufp->can_be_null)
4497 return -1; 4497 return -1;
4498 4498
4499 /* re_match_2_internal may allocate, causing a relocation of the 4499 /* re_match_2_internal may allocate, relocating the Lisp text
4500 lisp text object that we're searching. */ 4500 object that we're searching. */
4501 ptrdiff_t offset1, offset2; 4501 ptrdiff_t offset1, offset2;
4502 IF_LINT (offset2 = 0); /* Work around GCC bug 78081. */
4502 re_char *orig_base = STR_BASE_PTR (re_match_object); 4503 re_char *orig_base = STR_BASE_PTR (re_match_object);
4503 if (orig_base) 4504 bool might_relocate = orig_base != NULL;
4505 if (might_relocate)
4504 { 4506 {
4505 if (string1) offset1 = string1 - orig_base; 4507 if (string1) offset1 = string1 - orig_base;
4506 if (string2) offset2 = string2 - orig_base; 4508 if (string2) offset2 = string2 - orig_base;
@@ -4515,9 +4517,9 @@ re_search_2 (struct re_pattern_buffer *bufp, const char *str1, size_t size1,
4515 if (val == -2) 4517 if (val == -2)
4516 return -2; 4518 return -2;
4517 4519
4518 re_char *new_base = STR_BASE_PTR (re_match_object); 4520 if (might_relocate)
4519 if (new_base && new_base != orig_base)
4520 { 4521 {
4522 re_char *new_base = STR_BASE_PTR (re_match_object);
4521 if (string1) string1 = offset1 + new_base; 4523 if (string1) string1 = offset1 + new_base;
4522 if (string2) string2 = offset2 + new_base; 4524 if (string2) string2 = offset2 + new_base;
4523 } 4525 }