summaryrefslogtreecommitdiff
path: root/src/search.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2012-05-23 20:32:28 +0300
committerEli Zaretskii <eliz@gnu.org>2012-05-23 20:32:28 +0300
commit52c55cc7d2bec9795533f58e15c61f7a7b51d1b0 (patch)
tree91855df41e7cbffb713b6b8c4ee570082e0b8d0d /src/search.c
parent1b7e0ab8c77f6a6fdb9758adc7297ac907fee3c5 (diff)
downloademacs-52c55cc7d2bec9795533f58e15c61f7a7b51d1b0.tar.gz
emacs-52c55cc7d2bec9795533f58e15c61f7a7b51d1b0.tar.bz2
emacs-52c55cc7d2bec9795533f58e15c61f7a7b51d1b0.zip
Fix bug #11519 with relocation of buffer text during regex search.
src/lisp.h [REL_ALLOC]: Add prototypes for external functions defined on ralloc.c. src/buffer.c [REL_ALLOC]: Remove prototypes of r_alloc_reset_variable, r_alloc, r_re_alloc, and r_alloc_free, they are now on lisp.h. src/ralloc.c (r_alloc_inhibit_buffer_relocation): New function. src/search.c (search_buffer): Use it to inhibit relocation of buffer text while re_search_2 is doing its job, because re_search_2 is passed C pointers to buffer text.
Diffstat (limited to 'src/search.c')
-rw-r--r--src/search.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/search.c b/src/search.c
index 1f3ccc25dc8..67f9e505fad 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1158,12 +1158,25 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
while (n < 0)
{
EMACS_INT val;
+
+#ifdef REL_ALLOC
+ /* re_search_2 below is passed C pointers to buffer text.
+ If some code called by it causes memory (re)allocation,
+ buffer text could be relocated on platforms that use
+ REL_ALLOC, which invalidates those C pointers. So we
+ inhibit relocation of buffer text for as long as
+ re_search_2 runs. */
+ r_alloc_inhibit_buffer_relocation (1);
+#endif
val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
pos_byte - BEGV_BYTE, lim_byte - pos_byte,
(NILP (Vinhibit_changing_match_data)
? &search_regs : &search_regs_1),
/* Don't allow match past current point */
pos_byte - BEGV_BYTE);
+#ifdef REL_ALLOC
+ r_alloc_inhibit_buffer_relocation (0);
+#endif
if (val == -2)
{
matcher_overflow ();
@@ -1202,11 +1215,20 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte,
while (n > 0)
{
EMACS_INT val;
+
+#ifdef REL_ALLOC
+ /* See commentary above for the reasons for inhibiting
+ buffer text relocation here. */
+ r_alloc_inhibit_buffer_relocation (1);
+#endif
val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2,
pos_byte - BEGV_BYTE, lim_byte - pos_byte,
(NILP (Vinhibit_changing_match_data)
? &search_regs : &search_regs_1),
lim_byte - BEGV_BYTE);
+#ifdef REL_ALLOC
+ r_alloc_inhibit_buffer_relocation (0);
+#endif
if (val == -2)
{
matcher_overflow ();