summaryrefslogtreecommitdiff
path: root/src/regex-emacs.c
diff options
context:
space:
mode:
authorGlenn Morris <rgm@gnu.org>2020-04-18 07:50:22 -0700
committerGlenn Morris <rgm@gnu.org>2020-04-18 07:50:22 -0700
commit4819bea6900348f923e0de58995ec41760993b6c (patch)
treedf5ba765ab0270a215671959a099a65e9f2a2f58 /src/regex-emacs.c
parent9dac60b1bf449cc42fe77bc4f3a85bad55afa00f (diff)
parentf3b62b6c62c41d2e5d15418ea940bce6b11bdf7d (diff)
downloademacs-4819bea6900348f923e0de58995ec41760993b6c.tar.gz
Merge from origin/emacs-27
f3b62b6c62 (origin/emacs-27) Avoid crashes in regex-emacs.c due to GC 175c61c18b Fix "C-u M-!" when 'shell-command-dont-erase-buffer' is no... 6b297519b5 Fix cl-most-positive-float doc typo c36c5a3ded ; lisp/ldefs-boot.el: Update. 3876a60569 Fix a typo in calculator.el 9e832ba91b * lisp/erc/erc.el: Add URL to the new ERC page on the Emac... # Conflicts: # etc/NEWS
Diffstat (limited to 'src/regex-emacs.c')
-rw-r--r--src/regex-emacs.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/regex-emacs.c b/src/regex-emacs.c
index 9fd23943402..9cade11c9fb 100644
--- a/src/regex-emacs.c
+++ b/src/regex-emacs.c
@@ -3848,6 +3848,12 @@ re_match_2 (struct re_pattern_buffer *bufp,
return result;
}
+static void
+unwind_re_match (void *ptr)
+{
+ struct buffer *b = (struct buffer *) ptr;
+ b->text->inhibit_shrinking = 0;
+}
/* This is a separate function so that we can force an alloca cleanup
afterwards. */
@@ -3944,6 +3950,19 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
INIT_FAIL_STACK ();
+ ptrdiff_t count = SPECPDL_INDEX ();
+
+ /* Prevent shrinking and relocation of buffer text if GC happens
+ while we are inside this function. The calls to
+ UPDATE_SYNTAX_TABLE_* macros can trigger GC if they call Lisp,
+ and we have C pointers to buffer text that must not become
+ invalid as result of GC. */
+ if (!current_buffer->text->inhibit_shrinking)
+ {
+ record_unwind_protect_ptr (unwind_re_match, current_buffer);
+ current_buffer->text->inhibit_shrinking = 1;
+ }
+
/* Do not bother to initialize all the register variables if there are
no groups in the pattern, as it takes a fair amount of time. If
there are groups, we include space for register 0 (the whole
@@ -3960,6 +3979,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
/* The starting position is bogus. */
if (pos < 0 || pos > size1 + size2)
{
+ unbind_to (count, Qnil);
SAFE_FREE ();
return -1;
}
@@ -4174,6 +4194,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
DEBUG_PRINT ("Returning %td from re_match_2.\n", dcnt);
+ unbind_to (count, Qnil);
SAFE_FREE ();
return dcnt;
}
@@ -5020,6 +5041,7 @@ re_match_2_internal (struct re_pattern_buffer *bufp,
if (best_regs_set)
goto restore_best_regs;
+ unbind_to (count, Qnil);
SAFE_FREE ();
return -1; /* Failure to match. */