diff options
| author | Paul Eggert | 2017-02-01 15:18:44 -0800 |
|---|---|---|
| committer | Paul Eggert | 2017-02-01 15:23:19 -0800 |
| commit | b4c9f9120d8b0da0593f2fbde69b40374f56451d (patch) | |
| tree | 8f40be80730a41e83e58e0632ff539ac752eb453 /src/search.c | |
| parent | b01ac672be1277833964d2d53f6dd26560c70343 (diff) | |
| download | emacs-b4c9f9120d8b0da0593f2fbde69b40374f56451d.tar.gz emacs-b4c9f9120d8b0da0593f2fbde69b40374f56451d.zip | |
Fix quitting bug when buffers are frozen
Problem noted by Eli Zaretskii in:
http://lists.gnu.org/archive/html/emacs-devel/2017-01/msg00721.html
This patch also fixes some other issues in that report.
* src/lisp.h (incr_rarely_quit): Remove.
All callers changed to use rarely_quit directly.
* src/search.c (freeze_buffer_relocation)
(thaw_buffer_relocation): New functions.
(looking_at_1, fast_looking_at, search_buffer):
Use them to fix bug when quitting when buffers are frozen.
* src/sysdep.c (emacs_intr_read): Rename from emacs_nointr_read.
All uses changed.
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/src/search.c b/src/search.c index 084adda097b..33cb02aa7af 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -99,6 +99,25 @@ matcher_overflow (void) | |||
| 99 | error ("Stack overflow in regexp matcher"); | 99 | error ("Stack overflow in regexp matcher"); |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | static void | ||
| 103 | freeze_buffer_relocation (void) | ||
| 104 | { | ||
| 105 | #ifdef REL_ALLOC | ||
| 106 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 107 | searching it. */ | ||
| 108 | r_alloc_inhibit_buffer_relocation (1); | ||
| 109 | record_unwind_protect_int (r_alloc_inhibit_buffer_relocation, 0); | ||
| 110 | #endif | ||
| 111 | } | ||
| 112 | |||
| 113 | static void | ||
| 114 | thaw_buffer_relocation (void) | ||
| 115 | { | ||
| 116 | #ifdef REL_ALLOC | ||
| 117 | unbind_to (SPECPDL_INDEX () - 1, Qnil); | ||
| 118 | #endif | ||
| 119 | } | ||
| 120 | |||
| 102 | /* Compile a regexp and signal a Lisp error if anything goes wrong. | 121 | /* Compile a regexp and signal a Lisp error if anything goes wrong. |
| 103 | PATTERN is the pattern to compile. | 122 | PATTERN is the pattern to compile. |
| 104 | CP is the place to put the result. | 123 | CP is the place to put the result. |
| @@ -300,19 +319,13 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 300 | 319 | ||
| 301 | re_match_object = Qnil; | 320 | re_match_object = Qnil; |
| 302 | 321 | ||
| 303 | #ifdef REL_ALLOC | 322 | freeze_buffer_relocation (); |
| 304 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 305 | searching it. */ | ||
| 306 | r_alloc_inhibit_buffer_relocation (1); | ||
| 307 | #endif | ||
| 308 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 323 | i = re_match_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 309 | PT_BYTE - BEGV_BYTE, | 324 | PT_BYTE - BEGV_BYTE, |
| 310 | (NILP (Vinhibit_changing_match_data) | 325 | (NILP (Vinhibit_changing_match_data) |
| 311 | ? &search_regs : NULL), | 326 | ? &search_regs : NULL), |
| 312 | ZV_BYTE - BEGV_BYTE); | 327 | ZV_BYTE - BEGV_BYTE); |
| 313 | #ifdef REL_ALLOC | 328 | thaw_buffer_relocation (); |
| 314 | r_alloc_inhibit_buffer_relocation (0); | ||
| 315 | #endif | ||
| 316 | 329 | ||
| 317 | if (i == -2) | 330 | if (i == -2) |
| 318 | matcher_overflow (); | 331 | matcher_overflow (); |
| @@ -553,16 +566,10 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 553 | } | 566 | } |
| 554 | 567 | ||
| 555 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); | 568 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); |
| 556 | #ifdef REL_ALLOC | 569 | freeze_buffer_relocation (); |
| 557 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 558 | searching it. */ | ||
| 559 | r_alloc_inhibit_buffer_relocation (1); | ||
| 560 | #endif | ||
| 561 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | 570 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, |
| 562 | pos_byte, NULL, limit_byte); | 571 | pos_byte, NULL, limit_byte); |
| 563 | #ifdef REL_ALLOC | 572 | thaw_buffer_relocation (); |
| 564 | r_alloc_inhibit_buffer_relocation (0); | ||
| 565 | #endif | ||
| 566 | 573 | ||
| 567 | return len; | 574 | return len; |
| 568 | } | 575 | } |
| @@ -1204,11 +1211,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1204 | } | 1211 | } |
| 1205 | re_match_object = Qnil; | 1212 | re_match_object = Qnil; |
| 1206 | 1213 | ||
| 1207 | #ifdef REL_ALLOC | 1214 | freeze_buffer_relocation (); |
| 1208 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 1209 | searching it. */ | ||
| 1210 | r_alloc_inhibit_buffer_relocation (1); | ||
| 1211 | #endif | ||
| 1212 | 1215 | ||
| 1213 | while (n < 0) | 1216 | while (n < 0) |
| 1214 | { | 1217 | { |
| @@ -1250,9 +1253,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1250 | } | 1253 | } |
| 1251 | else | 1254 | else |
| 1252 | { | 1255 | { |
| 1253 | #ifdef REL_ALLOC | 1256 | thaw_buffer_relocation (); |
| 1254 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1255 | #endif | ||
| 1256 | return (n); | 1257 | return (n); |
| 1257 | } | 1258 | } |
| 1258 | n++; | 1259 | n++; |
| @@ -1295,17 +1296,13 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1295 | } | 1296 | } |
| 1296 | else | 1297 | else |
| 1297 | { | 1298 | { |
| 1298 | #ifdef REL_ALLOC | 1299 | thaw_buffer_relocation (); |
| 1299 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1300 | #endif | ||
| 1301 | return (0 - n); | 1300 | return (0 - n); |
| 1302 | } | 1301 | } |
| 1303 | n--; | 1302 | n--; |
| 1304 | maybe_quit (); | 1303 | maybe_quit (); |
| 1305 | } | 1304 | } |
| 1306 | #ifdef REL_ALLOC | 1305 | thaw_buffer_relocation (); |
| 1307 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1308 | #endif | ||
| 1309 | return (pos); | 1306 | return (pos); |
| 1310 | } | 1307 | } |
| 1311 | else /* non-RE case */ | 1308 | else /* non-RE case */ |