diff options
| author | Alan Mackenzie | 2017-02-12 10:59:03 +0000 |
|---|---|---|
| committer | Alan Mackenzie | 2017-02-12 10:59:03 +0000 |
| commit | f4d5b687150810129b7a1d5b006e31ccf82b691b (patch) | |
| tree | 4229b13800349032697daae3904dc3773e6b7a80 /src/search.c | |
| parent | d5514332d4a6092673ce1f78fadcae0c57f7be64 (diff) | |
| parent | 148100d98319499f0ac6f57b8be08cbd14884a5c (diff) | |
| download | emacs-comment-cache.tar.gz emacs-comment-cache.zip | |
Merge branch 'master' into comment-cachecomment-cache
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 105 |
1 files changed, 41 insertions, 64 deletions
diff --git a/src/search.c b/src/search.c index d3045108705..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. |
| @@ -276,8 +295,8 @@ looking_at_1 (Lisp_Object string, bool posix) | |||
| 276 | posix, | 295 | posix, |
| 277 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); | 296 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); |
| 278 | 297 | ||
| 279 | immediate_quit = 1; | 298 | /* Do a pending quit right away, to avoid paradoxical behavior */ |
| 280 | QUIT; /* Do a pending quit right away, to avoid paradoxical behavior */ | 299 | maybe_quit (); |
| 281 | 300 | ||
| 282 | /* Get pointers and sizes of the two strings | 301 | /* Get pointers and sizes of the two strings |
| 283 | that make up the visible portion of the buffer. */ | 302 | that make up the visible portion of the buffer. */ |
| @@ -300,20 +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 | immediate_quit = 0; | 328 | thaw_buffer_relocation (); |
| 314 | #ifdef REL_ALLOC | ||
| 315 | r_alloc_inhibit_buffer_relocation (0); | ||
| 316 | #endif | ||
| 317 | 329 | ||
| 318 | if (i == -2) | 330 | if (i == -2) |
| 319 | matcher_overflow (); | 331 | matcher_overflow (); |
| @@ -398,7 +410,6 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 398 | ? BVAR (current_buffer, case_canon_table) : Qnil), | 410 | ? BVAR (current_buffer, case_canon_table) : Qnil), |
| 399 | posix, | 411 | posix, |
| 400 | STRING_MULTIBYTE (string)); | 412 | STRING_MULTIBYTE (string)); |
| 401 | immediate_quit = 1; | ||
| 402 | re_match_object = string; | 413 | re_match_object = string; |
| 403 | 414 | ||
| 404 | val = re_search (bufp, SSDATA (string), | 415 | val = re_search (bufp, SSDATA (string), |
| @@ -406,7 +417,6 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, | |||
| 406 | SBYTES (string) - pos_byte, | 417 | SBYTES (string) - pos_byte, |
| 407 | (NILP (Vinhibit_changing_match_data) | 418 | (NILP (Vinhibit_changing_match_data) |
| 408 | ? &search_regs : NULL)); | 419 | ? &search_regs : NULL)); |
| 409 | immediate_quit = 0; | ||
| 410 | 420 | ||
| 411 | /* Set last_thing_searched only when match data is changed. */ | 421 | /* Set last_thing_searched only when match data is changed. */ |
| 412 | if (NILP (Vinhibit_changing_match_data)) | 422 | if (NILP (Vinhibit_changing_match_data)) |
| @@ -470,13 +480,11 @@ fast_string_match_internal (Lisp_Object regexp, Lisp_Object string, | |||
| 470 | 480 | ||
| 471 | bufp = compile_pattern (regexp, 0, table, | 481 | bufp = compile_pattern (regexp, 0, table, |
| 472 | 0, STRING_MULTIBYTE (string)); | 482 | 0, STRING_MULTIBYTE (string)); |
| 473 | immediate_quit = 1; | ||
| 474 | re_match_object = string; | 483 | re_match_object = string; |
| 475 | 484 | ||
| 476 | val = re_search (bufp, SSDATA (string), | 485 | val = re_search (bufp, SSDATA (string), |
| 477 | SBYTES (string), 0, | 486 | SBYTES (string), 0, |
| 478 | SBYTES (string), 0); | 487 | SBYTES (string), 0); |
| 479 | immediate_quit = 0; | ||
| 480 | return val; | 488 | return val; |
| 481 | } | 489 | } |
| 482 | 490 | ||
| @@ -497,9 +505,7 @@ fast_c_string_match_ignore_case (Lisp_Object regexp, | |||
| 497 | bufp = compile_pattern (regexp, 0, | 505 | bufp = compile_pattern (regexp, 0, |
| 498 | Vascii_canon_table, 0, | 506 | Vascii_canon_table, 0, |
| 499 | 0); | 507 | 0); |
| 500 | immediate_quit = 1; | ||
| 501 | val = re_search (bufp, string, len, 0, len, 0); | 508 | val = re_search (bufp, string, len, 0, len, 0); |
| 502 | immediate_quit = 0; | ||
| 503 | return val; | 509 | return val; |
| 504 | } | 510 | } |
| 505 | 511 | ||
| @@ -560,18 +566,10 @@ fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 560 | } | 566 | } |
| 561 | 567 | ||
| 562 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); | 568 | buf = compile_pattern (regexp, 0, Qnil, 0, multibyte); |
| 563 | immediate_quit = 1; | 569 | freeze_buffer_relocation (); |
| 564 | #ifdef REL_ALLOC | ||
| 565 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 566 | searching it. */ | ||
| 567 | r_alloc_inhibit_buffer_relocation (1); | ||
| 568 | #endif | ||
| 569 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, | 570 | len = re_match_2 (buf, (char *) p1, s1, (char *) p2, s2, |
| 570 | pos_byte, NULL, limit_byte); | 571 | pos_byte, NULL, limit_byte); |
| 571 | #ifdef REL_ALLOC | 572 | thaw_buffer_relocation (); |
| 572 | r_alloc_inhibit_buffer_relocation (0); | ||
| 573 | #endif | ||
| 574 | immediate_quit = 0; | ||
| 575 | 573 | ||
| 576 | return len; | 574 | return len; |
| 577 | } | 575 | } |
| @@ -648,7 +646,7 @@ newline_cache_on_off (struct buffer *buf) | |||
| 648 | If BYTEPOS is not NULL, set *BYTEPOS to the byte position corresponding | 646 | If BYTEPOS is not NULL, set *BYTEPOS to the byte position corresponding |
| 649 | to the returned character position. | 647 | to the returned character position. |
| 650 | 648 | ||
| 651 | If ALLOW_QUIT, set immediate_quit. That's good to do | 649 | If ALLOW_QUIT, check for quitting. That's good to do |
| 652 | except when inside redisplay. */ | 650 | except when inside redisplay. */ |
| 653 | 651 | ||
| 654 | ptrdiff_t | 652 | ptrdiff_t |
| @@ -684,8 +682,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 684 | if (shortage != 0) | 682 | if (shortage != 0) |
| 685 | *shortage = 0; | 683 | *shortage = 0; |
| 686 | 684 | ||
| 687 | immediate_quit = allow_quit; | ||
| 688 | |||
| 689 | if (count > 0) | 685 | if (count > 0) |
| 690 | while (start != end) | 686 | while (start != end) |
| 691 | { | 687 | { |
| @@ -703,7 +699,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 703 | ptrdiff_t next_change; | 699 | ptrdiff_t next_change; |
| 704 | int result = 1; | 700 | int result = 1; |
| 705 | 701 | ||
| 706 | immediate_quit = 0; | ||
| 707 | while (start < end && result) | 702 | while (start < end && result) |
| 708 | { | 703 | { |
| 709 | ptrdiff_t lim1; | 704 | ptrdiff_t lim1; |
| @@ -756,7 +751,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 756 | start_byte = end_byte; | 751 | start_byte = end_byte; |
| 757 | break; | 752 | break; |
| 758 | } | 753 | } |
| 759 | immediate_quit = allow_quit; | ||
| 760 | 754 | ||
| 761 | /* START should never be after END. */ | 755 | /* START should never be after END. */ |
| 762 | if (start_byte > ceiling_byte) | 756 | if (start_byte > ceiling_byte) |
| @@ -809,11 +803,12 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 809 | 803 | ||
| 810 | if (--count == 0) | 804 | if (--count == 0) |
| 811 | { | 805 | { |
| 812 | immediate_quit = 0; | ||
| 813 | if (bytepos) | 806 | if (bytepos) |
| 814 | *bytepos = lim_byte + next; | 807 | *bytepos = lim_byte + next; |
| 815 | return BYTE_TO_CHAR (lim_byte + next); | 808 | return BYTE_TO_CHAR (lim_byte + next); |
| 816 | } | 809 | } |
| 810 | if (allow_quit) | ||
| 811 | maybe_quit (); | ||
| 817 | } | 812 | } |
| 818 | 813 | ||
| 819 | start_byte = lim_byte; | 814 | start_byte = lim_byte; |
| @@ -832,7 +827,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 832 | ptrdiff_t next_change; | 827 | ptrdiff_t next_change; |
| 833 | int result = 1; | 828 | int result = 1; |
| 834 | 829 | ||
| 835 | immediate_quit = 0; | ||
| 836 | while (start > end && result) | 830 | while (start > end && result) |
| 837 | { | 831 | { |
| 838 | ptrdiff_t lim1; | 832 | ptrdiff_t lim1; |
| @@ -869,7 +863,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 869 | start_byte = end_byte; | 863 | start_byte = end_byte; |
| 870 | break; | 864 | break; |
| 871 | } | 865 | } |
| 872 | immediate_quit = allow_quit; | ||
| 873 | 866 | ||
| 874 | /* Start should never be at or before end. */ | 867 | /* Start should never be at or before end. */ |
| 875 | if (start_byte <= ceiling_byte) | 868 | if (start_byte <= ceiling_byte) |
| @@ -917,11 +910,12 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 917 | 910 | ||
| 918 | if (++count >= 0) | 911 | if (++count >= 0) |
| 919 | { | 912 | { |
| 920 | immediate_quit = 0; | ||
| 921 | if (bytepos) | 913 | if (bytepos) |
| 922 | *bytepos = ceiling_byte + prev + 1; | 914 | *bytepos = ceiling_byte + prev + 1; |
| 923 | return BYTE_TO_CHAR (ceiling_byte + prev + 1); | 915 | return BYTE_TO_CHAR (ceiling_byte + prev + 1); |
| 924 | } | 916 | } |
| 917 | if (allow_quit) | ||
| 918 | maybe_quit (); | ||
| 925 | } | 919 | } |
| 926 | 920 | ||
| 927 | start_byte = ceiling_byte; | 921 | start_byte = ceiling_byte; |
| @@ -929,7 +923,6 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 929 | } | 923 | } |
| 930 | } | 924 | } |
| 931 | 925 | ||
| 932 | immediate_quit = 0; | ||
| 933 | if (shortage) | 926 | if (shortage) |
| 934 | *shortage = count * direction; | 927 | *shortage = count * direction; |
| 935 | if (bytepos) | 928 | if (bytepos) |
| @@ -953,7 +946,7 @@ find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 953 | the number of line boundaries left unfound, and position at | 946 | the number of line boundaries left unfound, and position at |
| 954 | the limit we bumped up against. | 947 | the limit we bumped up against. |
| 955 | 948 | ||
| 956 | If ALLOW_QUIT, set immediate_quit. That's good to do | 949 | If ALLOW_QUIT, check for quitting. That's good to do |
| 957 | except in special cases. */ | 950 | except in special cases. */ |
| 958 | 951 | ||
| 959 | ptrdiff_t | 952 | ptrdiff_t |
| @@ -1196,10 +1189,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1196 | trt, posix, | 1189 | trt, posix, |
| 1197 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); | 1190 | !NILP (BVAR (current_buffer, enable_multibyte_characters))); |
| 1198 | 1191 | ||
| 1199 | immediate_quit = 1; /* Quit immediately if user types ^G, | 1192 | maybe_quit (); /* Do a pending quit right away, |
| 1200 | because letting this function finish | ||
| 1201 | can take too long. */ | ||
| 1202 | QUIT; /* Do a pending quit right away, | ||
| 1203 | to avoid paradoxical behavior */ | 1193 | to avoid paradoxical behavior */ |
| 1204 | /* Get pointers and sizes of the two strings | 1194 | /* Get pointers and sizes of the two strings |
| 1205 | that make up the visible portion of the buffer. */ | 1195 | that make up the visible portion of the buffer. */ |
| @@ -1221,11 +1211,7 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1221 | } | 1211 | } |
| 1222 | re_match_object = Qnil; | 1212 | re_match_object = Qnil; |
| 1223 | 1213 | ||
| 1224 | #ifdef REL_ALLOC | 1214 | freeze_buffer_relocation (); |
| 1225 | /* Prevent ralloc.c from relocating the current buffer while | ||
| 1226 | searching it. */ | ||
| 1227 | r_alloc_inhibit_buffer_relocation (1); | ||
| 1228 | #endif | ||
| 1229 | 1215 | ||
| 1230 | while (n < 0) | 1216 | while (n < 0) |
| 1231 | { | 1217 | { |
| @@ -1267,13 +1253,11 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1267 | } | 1253 | } |
| 1268 | else | 1254 | else |
| 1269 | { | 1255 | { |
| 1270 | immediate_quit = 0; | 1256 | thaw_buffer_relocation (); |
| 1271 | #ifdef REL_ALLOC | ||
| 1272 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1273 | #endif | ||
| 1274 | return (n); | 1257 | return (n); |
| 1275 | } | 1258 | } |
| 1276 | n++; | 1259 | n++; |
| 1260 | maybe_quit (); | ||
| 1277 | } | 1261 | } |
| 1278 | while (n > 0) | 1262 | while (n > 0) |
| 1279 | { | 1263 | { |
| @@ -1312,18 +1296,13 @@ search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, | |||
| 1312 | } | 1296 | } |
| 1313 | else | 1297 | else |
| 1314 | { | 1298 | { |
| 1315 | immediate_quit = 0; | 1299 | thaw_buffer_relocation (); |
| 1316 | #ifdef REL_ALLOC | ||
| 1317 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1318 | #endif | ||
| 1319 | return (0 - n); | 1300 | return (0 - n); |
| 1320 | } | 1301 | } |
| 1321 | n--; | 1302 | n--; |
| 1303 | maybe_quit (); | ||
| 1322 | } | 1304 | } |
| 1323 | immediate_quit = 0; | 1305 | thaw_buffer_relocation (); |
| 1324 | #ifdef REL_ALLOC | ||
| 1325 | r_alloc_inhibit_buffer_relocation (0); | ||
| 1326 | #endif | ||
| 1327 | return (pos); | 1306 | return (pos); |
| 1328 | } | 1307 | } |
| 1329 | else /* non-RE case */ | 1308 | else /* non-RE case */ |
| @@ -1927,7 +1906,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 1927 | < 0) | 1906 | < 0) |
| 1928 | return (n * (0 - direction)); | 1907 | return (n * (0 - direction)); |
| 1929 | /* First we do the part we can by pointers (maybe nothing) */ | 1908 | /* First we do the part we can by pointers (maybe nothing) */ |
| 1930 | QUIT; | 1909 | maybe_quit (); |
| 1931 | pat = base_pat; | 1910 | pat = base_pat; |
| 1932 | limit = pos_byte - dirlen + direction; | 1911 | limit = pos_byte - dirlen + direction; |
| 1933 | if (direction > 0) | 1912 | if (direction > 0) |
| @@ -3230,8 +3209,6 @@ find_newline1 (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 3230 | if (shortage != 0) | 3209 | if (shortage != 0) |
| 3231 | *shortage = 0; | 3210 | *shortage = 0; |
| 3232 | 3211 | ||
| 3233 | immediate_quit = allow_quit; | ||
| 3234 | |||
| 3235 | if (count > 0) | 3212 | if (count > 0) |
| 3236 | while (start != end) | 3213 | while (start != end) |
| 3237 | { | 3214 | { |
| @@ -3274,11 +3251,12 @@ find_newline1 (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 3274 | 3251 | ||
| 3275 | if (--count == 0) | 3252 | if (--count == 0) |
| 3276 | { | 3253 | { |
| 3277 | immediate_quit = 0; | ||
| 3278 | if (bytepos) | 3254 | if (bytepos) |
| 3279 | *bytepos = lim_byte + next; | 3255 | *bytepos = lim_byte + next; |
| 3280 | return BYTE_TO_CHAR (lim_byte + next); | 3256 | return BYTE_TO_CHAR (lim_byte + next); |
| 3281 | } | 3257 | } |
| 3258 | if (allow_quit) | ||
| 3259 | maybe_quit (); | ||
| 3282 | } | 3260 | } |
| 3283 | 3261 | ||
| 3284 | start_byte = lim_byte; | 3262 | start_byte = lim_byte; |
| @@ -3286,7 +3264,6 @@ find_newline1 (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end, | |||
| 3286 | } | 3264 | } |
| 3287 | } | 3265 | } |
| 3288 | 3266 | ||
| 3289 | immediate_quit = 0; | ||
| 3290 | if (shortage) | 3267 | if (shortage) |
| 3291 | *shortage = count; | 3268 | *shortage = count; |
| 3292 | if (bytepos) | 3269 | if (bytepos) |