diff options
Diffstat (limited to 'src/search.c')
| -rw-r--r-- | src/search.c | 243 |
1 files changed, 133 insertions, 110 deletions
diff --git a/src/search.c b/src/search.c index b3d67e6c431..7dc88268c76 100644 --- a/src/search.c +++ b/src/search.c | |||
| @@ -90,16 +90,16 @@ static Lisp_Object Qinvalid_regexp; | |||
| 90 | /* Error condition used for failing searches */ | 90 | /* Error condition used for failing searches */ |
| 91 | static Lisp_Object Qsearch_failed; | 91 | static Lisp_Object Qsearch_failed; |
| 92 | 92 | ||
| 93 | static void set_search_regs (EMACS_INT, EMACS_INT); | 93 | static void set_search_regs (ptrdiff_t, ptrdiff_t); |
| 94 | static void save_search_regs (void); | 94 | static void save_search_regs (void); |
| 95 | static EMACS_INT simple_search (EMACS_INT, unsigned char *, EMACS_INT, | 95 | static EMACS_INT simple_search (EMACS_INT, unsigned char *, ptrdiff_t, |
| 96 | EMACS_INT, Lisp_Object, EMACS_INT, EMACS_INT, | 96 | ptrdiff_t, Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 97 | EMACS_INT, EMACS_INT); | 97 | ptrdiff_t, ptrdiff_t); |
| 98 | static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, EMACS_INT, | 98 | static EMACS_INT boyer_moore (EMACS_INT, unsigned char *, ptrdiff_t, |
| 99 | Lisp_Object, Lisp_Object, EMACS_INT, | 99 | Lisp_Object, Lisp_Object, ptrdiff_t, |
| 100 | EMACS_INT, int); | 100 | ptrdiff_t, int); |
| 101 | static EMACS_INT search_buffer (Lisp_Object, EMACS_INT, EMACS_INT, | 101 | static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t, |
| 102 | EMACS_INT, EMACS_INT, EMACS_INT, int, | 102 | ptrdiff_t, ptrdiff_t, EMACS_INT, int, |
| 103 | Lisp_Object, Lisp_Object, int); | 103 | Lisp_Object, Lisp_Object, int); |
| 104 | static void matcher_overflow (void) NO_RETURN; | 104 | static void matcher_overflow (void) NO_RETURN; |
| 105 | 105 | ||
| @@ -272,8 +272,8 @@ looking_at_1 (Lisp_Object string, int posix) | |||
| 272 | { | 272 | { |
| 273 | Lisp_Object val; | 273 | Lisp_Object val; |
| 274 | unsigned char *p1, *p2; | 274 | unsigned char *p1, *p2; |
| 275 | EMACS_INT s1, s2; | 275 | ptrdiff_t s1, s2; |
| 276 | register EMACS_INT i; | 276 | register ptrdiff_t i; |
| 277 | struct re_pattern_buffer *bufp; | 277 | struct re_pattern_buffer *bufp; |
| 278 | 278 | ||
| 279 | if (running_asynch_code) | 279 | if (running_asynch_code) |
| @@ -368,10 +368,10 @@ data if you want to preserve them. */) | |||
| 368 | static Lisp_Object | 368 | static Lisp_Object |
| 369 | string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix) | 369 | string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix) |
| 370 | { | 370 | { |
| 371 | EMACS_INT val; | 371 | ptrdiff_t val; |
| 372 | struct re_pattern_buffer *bufp; | 372 | struct re_pattern_buffer *bufp; |
| 373 | EMACS_INT pos, pos_byte; | 373 | EMACS_INT pos; |
| 374 | int i; | 374 | ptrdiff_t pos_byte, i; |
| 375 | 375 | ||
| 376 | if (running_asynch_code) | 376 | if (running_asynch_code) |
| 377 | save_search_regs (); | 377 | save_search_regs (); |
| @@ -383,7 +383,7 @@ string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int p | |||
| 383 | pos = 0, pos_byte = 0; | 383 | pos = 0, pos_byte = 0; |
| 384 | else | 384 | else |
| 385 | { | 385 | { |
| 386 | EMACS_INT len = SCHARS (string); | 386 | ptrdiff_t len = SCHARS (string); |
| 387 | 387 | ||
| 388 | CHECK_NUMBER (start); | 388 | CHECK_NUMBER (start); |
| 389 | pos = XINT (start); | 389 | pos = XINT (start); |
| @@ -468,10 +468,10 @@ matched by parenthesis constructs in the pattern. */) | |||
| 468 | and return the index of the match, or negative on failure. | 468 | and return the index of the match, or negative on failure. |
| 469 | This does not clobber the match data. */ | 469 | This does not clobber the match data. */ |
| 470 | 470 | ||
| 471 | EMACS_INT | 471 | ptrdiff_t |
| 472 | fast_string_match (Lisp_Object regexp, Lisp_Object string) | 472 | fast_string_match (Lisp_Object regexp, Lisp_Object string) |
| 473 | { | 473 | { |
| 474 | EMACS_INT val; | 474 | ptrdiff_t val; |
| 475 | struct re_pattern_buffer *bufp; | 475 | struct re_pattern_buffer *bufp; |
| 476 | 476 | ||
| 477 | bufp = compile_pattern (regexp, 0, Qnil, | 477 | bufp = compile_pattern (regexp, 0, Qnil, |
| @@ -491,10 +491,10 @@ fast_string_match (Lisp_Object regexp, Lisp_Object string) | |||
| 491 | This does not clobber the match data. | 491 | This does not clobber the match data. |
| 492 | We assume that STRING contains single-byte characters. */ | 492 | We assume that STRING contains single-byte characters. */ |
| 493 | 493 | ||
| 494 | EMACS_INT | 494 | ptrdiff_t |
| 495 | fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string) | 495 | fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string) |
| 496 | { | 496 | { |
| 497 | EMACS_INT val; | 497 | ptrdiff_t val; |
| 498 | struct re_pattern_buffer *bufp; | 498 | struct re_pattern_buffer *bufp; |
| 499 | size_t len = strlen (string); | 499 | size_t len = strlen (string); |
| 500 | 500 | ||
| @@ -511,10 +511,10 @@ fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string) | |||
| 511 | 511 | ||
| 512 | /* Like fast_string_match but ignore case. */ | 512 | /* Like fast_string_match but ignore case. */ |
| 513 | 513 | ||
| 514 | EMACS_INT | 514 | ptrdiff_t |
| 515 | fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) | 515 | fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) |
| 516 | { | 516 | { |
| 517 | EMACS_INT val; | 517 | ptrdiff_t val; |
| 518 | struct re_pattern_buffer *bufp; | 518 | struct re_pattern_buffer *bufp; |
| 519 | 519 | ||
| 520 | bufp = compile_pattern (regexp, 0, Vascii_canon_table, | 520 | bufp = compile_pattern (regexp, 0, Vascii_canon_table, |
| @@ -535,14 +535,14 @@ fast_string_match_ignore_case (Lisp_Object regexp, Lisp_Object string) | |||
| 535 | indices into the string. This function doesn't modify the match | 535 | indices into the string. This function doesn't modify the match |
| 536 | data. */ | 536 | data. */ |
| 537 | 537 | ||
| 538 | EMACS_INT | 538 | ptrdiff_t |
| 539 | fast_looking_at (Lisp_Object regexp, EMACS_INT pos, EMACS_INT pos_byte, EMACS_INT limit, EMACS_INT limit_byte, Lisp_Object string) | 539 | fast_looking_at (Lisp_Object regexp, ptrdiff_t pos, ptrdiff_t pos_byte, ptrdiff_t limit, ptrdiff_t limit_byte, Lisp_Object string) |
| 540 | { | 540 | { |
| 541 | int multibyte; | 541 | int multibyte; |
| 542 | struct re_pattern_buffer *buf; | 542 | struct re_pattern_buffer *buf; |
| 543 | unsigned char *p1, *p2; | 543 | unsigned char *p1, *p2; |
| 544 | EMACS_INT s1, s2; | 544 | ptrdiff_t s1, s2; |
| 545 | EMACS_INT len; | 545 | ptrdiff_t len; |
| 546 | 546 | ||
| 547 | if (STRINGP (string)) | 547 | if (STRINGP (string)) |
| 548 | { | 548 | { |
| @@ -641,9 +641,9 @@ newline_cache_on_off (struct buffer *buf) | |||
| 641 | If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do | 641 | If ALLOW_QUIT is non-zero, set immediate_quit. That's good to do |
| 642 | except when inside redisplay. */ | 642 | except when inside redisplay. */ |
| 643 | 643 | ||
| 644 | EMACS_INT | 644 | ptrdiff_t |
| 645 | scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | 645 | scan_buffer (register int target, ptrdiff_t start, ptrdiff_t end, |
| 646 | EMACS_INT count, EMACS_INT *shortage, int allow_quit) | 646 | ptrdiff_t count, ptrdiff_t *shortage, int allow_quit) |
| 647 | { | 647 | { |
| 648 | struct region_cache *newline_cache; | 648 | struct region_cache *newline_cache; |
| 649 | int direction; | 649 | int direction; |
| @@ -675,9 +675,9 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | |||
| 675 | the position of the last character before the next such | 675 | the position of the last character before the next such |
| 676 | obstacle --- the last character the dumb search loop should | 676 | obstacle --- the last character the dumb search loop should |
| 677 | examine. */ | 677 | examine. */ |
| 678 | EMACS_INT ceiling_byte = CHAR_TO_BYTE (end) - 1; | 678 | ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end) - 1; |
| 679 | EMACS_INT start_byte = CHAR_TO_BYTE (start); | 679 | ptrdiff_t start_byte = CHAR_TO_BYTE (start); |
| 680 | EMACS_INT tem; | 680 | ptrdiff_t tem; |
| 681 | 681 | ||
| 682 | /* If we're looking for a newline, consult the newline cache | 682 | /* If we're looking for a newline, consult the newline cache |
| 683 | to see where we can avoid some scanning. */ | 683 | to see where we can avoid some scanning. */ |
| @@ -748,9 +748,9 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | |||
| 748 | while (start > end) | 748 | while (start > end) |
| 749 | { | 749 | { |
| 750 | /* The last character to check before the next obstacle. */ | 750 | /* The last character to check before the next obstacle. */ |
| 751 | EMACS_INT ceiling_byte = CHAR_TO_BYTE (end); | 751 | ptrdiff_t ceiling_byte = CHAR_TO_BYTE (end); |
| 752 | EMACS_INT start_byte = CHAR_TO_BYTE (start); | 752 | ptrdiff_t start_byte = CHAR_TO_BYTE (start); |
| 753 | EMACS_INT tem; | 753 | ptrdiff_t tem; |
| 754 | 754 | ||
| 755 | /* Consult the newline cache, if appropriate. */ | 755 | /* Consult the newline cache, if appropriate. */ |
| 756 | if (target == '\n' && newline_cache) | 756 | if (target == '\n' && newline_cache) |
| @@ -835,8 +835,8 @@ scan_buffer (register int target, EMACS_INT start, EMACS_INT end, | |||
| 835 | except in special cases. */ | 835 | except in special cases. */ |
| 836 | 836 | ||
| 837 | EMACS_INT | 837 | EMACS_INT |
| 838 | scan_newline (EMACS_INT start, EMACS_INT start_byte, | 838 | scan_newline (ptrdiff_t start, ptrdiff_t start_byte, |
| 839 | EMACS_INT limit, EMACS_INT limit_byte, | 839 | ptrdiff_t limit, ptrdiff_t limit_byte, |
| 840 | register EMACS_INT count, int allow_quit) | 840 | register EMACS_INT count, int allow_quit) |
| 841 | { | 841 | { |
| 842 | int direction = ((count > 0) ? 1 : -1); | 842 | int direction = ((count > 0) ? 1 : -1); |
| @@ -844,7 +844,7 @@ scan_newline (EMACS_INT start, EMACS_INT start_byte, | |||
| 844 | register unsigned char *cursor; | 844 | register unsigned char *cursor; |
| 845 | unsigned char *base; | 845 | unsigned char *base; |
| 846 | 846 | ||
| 847 | EMACS_INT ceiling; | 847 | ptrdiff_t ceiling; |
| 848 | register unsigned char *ceiling_addr; | 848 | register unsigned char *ceiling_addr; |
| 849 | 849 | ||
| 850 | int old_immediate_quit = immediate_quit; | 850 | int old_immediate_quit = immediate_quit; |
| @@ -930,21 +930,21 @@ scan_newline (EMACS_INT start, EMACS_INT start_byte, | |||
| 930 | return count * direction; | 930 | return count * direction; |
| 931 | } | 931 | } |
| 932 | 932 | ||
| 933 | EMACS_INT | 933 | ptrdiff_t |
| 934 | find_next_newline_no_quit (EMACS_INT from, EMACS_INT cnt) | 934 | find_next_newline_no_quit (ptrdiff_t from, ptrdiff_t cnt) |
| 935 | { | 935 | { |
| 936 | return scan_buffer ('\n', from, 0, cnt, (EMACS_INT *) 0, 0); | 936 | return scan_buffer ('\n', from, 0, cnt, (ptrdiff_t *) 0, 0); |
| 937 | } | 937 | } |
| 938 | 938 | ||
| 939 | /* Like find_next_newline, but returns position before the newline, | 939 | /* Like find_next_newline, but returns position before the newline, |
| 940 | not after, and only search up to TO. This isn't just | 940 | not after, and only search up to TO. This isn't just |
| 941 | find_next_newline (...)-1, because you might hit TO. */ | 941 | find_next_newline (...)-1, because you might hit TO. */ |
| 942 | 942 | ||
| 943 | EMACS_INT | 943 | ptrdiff_t |
| 944 | find_before_next_newline (EMACS_INT from, EMACS_INT to, EMACS_INT cnt) | 944 | find_before_next_newline (ptrdiff_t from, ptrdiff_t to, ptrdiff_t cnt) |
| 945 | { | 945 | { |
| 946 | EMACS_INT shortage; | 946 | ptrdiff_t shortage; |
| 947 | EMACS_INT pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); | 947 | ptrdiff_t pos = scan_buffer ('\n', from, to, cnt, &shortage, 1); |
| 948 | 948 | ||
| 949 | if (shortage == 0) | 949 | if (shortage == 0) |
| 950 | pos--; | 950 | pos--; |
| @@ -959,7 +959,8 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, | |||
| 959 | Lisp_Object count, int direction, int RE, int posix) | 959 | Lisp_Object count, int direction, int RE, int posix) |
| 960 | { | 960 | { |
| 961 | register EMACS_INT np; | 961 | register EMACS_INT np; |
| 962 | EMACS_INT lim, lim_byte; | 962 | EMACS_INT lim; |
| 963 | ptrdiff_t lim_byte; | ||
| 963 | EMACS_INT n = direction; | 964 | EMACS_INT n = direction; |
| 964 | 965 | ||
| 965 | if (!NILP (count)) | 966 | if (!NILP (count)) |
| @@ -1035,7 +1036,7 @@ search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror, | |||
| 1035 | static int | 1036 | static int |
| 1036 | trivial_regexp_p (Lisp_Object regexp) | 1037 | trivial_regexp_p (Lisp_Object regexp) |
| 1037 | { | 1038 | { |
| 1038 | EMACS_INT len = SBYTES (regexp); | 1039 | ptrdiff_t len = SBYTES (regexp); |
| 1039 | unsigned char *s = SDATA (regexp); | 1040 | unsigned char *s = SDATA (regexp); |
| 1040 | while (--len >= 0) | 1041 | while (--len >= 0) |
| 1041 | { | 1042 | { |
| @@ -1099,13 +1100,13 @@ while (0) | |||
| 1099 | static struct re_registers search_regs_1; | 1100 | static struct re_registers search_regs_1; |
| 1100 | 1101 | ||
| 1101 | static EMACS_INT | 1102 | static EMACS_INT |
| 1102 | search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | 1103 | search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte, |
| 1103 | EMACS_INT lim, EMACS_INT lim_byte, EMACS_INT n, | 1104 | ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n, |
| 1104 | int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix) | 1105 | int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix) |
| 1105 | { | 1106 | { |
| 1106 | EMACS_INT len = SCHARS (string); | 1107 | ptrdiff_t len = SCHARS (string); |
| 1107 | EMACS_INT len_byte = SBYTES (string); | 1108 | ptrdiff_t len_byte = SBYTES (string); |
| 1108 | register int i; | 1109 | register ptrdiff_t i; |
| 1109 | 1110 | ||
| 1110 | if (running_asynch_code) | 1111 | if (running_asynch_code) |
| 1111 | save_search_regs (); | 1112 | save_search_regs (); |
| @@ -1121,7 +1122,7 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | |||
| 1121 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) | 1122 | if (RE && !(trivial_regexp_p (string) && NILP (Vsearch_spaces_regexp))) |
| 1122 | { | 1123 | { |
| 1123 | unsigned char *p1, *p2; | 1124 | unsigned char *p1, *p2; |
| 1124 | EMACS_INT s1, s2; | 1125 | ptrdiff_t s1, s2; |
| 1125 | struct re_pattern_buffer *bufp; | 1126 | struct re_pattern_buffer *bufp; |
| 1126 | 1127 | ||
| 1127 | bufp = compile_pattern (string, | 1128 | bufp = compile_pattern (string, |
| @@ -1157,7 +1158,7 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | |||
| 1157 | 1158 | ||
| 1158 | while (n < 0) | 1159 | while (n < 0) |
| 1159 | { | 1160 | { |
| 1160 | EMACS_INT val; | 1161 | ptrdiff_t val; |
| 1161 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 1162 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 1162 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1163 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
| 1163 | (NILP (Vinhibit_changing_match_data) | 1164 | (NILP (Vinhibit_changing_match_data) |
| @@ -1201,7 +1202,7 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | |||
| 1201 | } | 1202 | } |
| 1202 | while (n > 0) | 1203 | while (n > 0) |
| 1203 | { | 1204 | { |
| 1204 | EMACS_INT val; | 1205 | ptrdiff_t val; |
| 1205 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, | 1206 | val = re_search_2 (bufp, (char *) p1, s1, (char *) p2, s2, |
| 1206 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, | 1207 | pos_byte - BEGV_BYTE, lim_byte - pos_byte, |
| 1207 | (NILP (Vinhibit_changing_match_data) | 1208 | (NILP (Vinhibit_changing_match_data) |
| @@ -1246,8 +1247,8 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | |||
| 1246 | else /* non-RE case */ | 1247 | else /* non-RE case */ |
| 1247 | { | 1248 | { |
| 1248 | unsigned char *raw_pattern, *pat; | 1249 | unsigned char *raw_pattern, *pat; |
| 1249 | EMACS_INT raw_pattern_size; | 1250 | ptrdiff_t raw_pattern_size; |
| 1250 | EMACS_INT raw_pattern_size_byte; | 1251 | ptrdiff_t raw_pattern_size_byte; |
| 1251 | unsigned char *patbuf; | 1252 | unsigned char *patbuf; |
| 1252 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); | 1253 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| 1253 | unsigned char *base_pat; | 1254 | unsigned char *base_pat; |
| @@ -1441,15 +1442,15 @@ search_buffer (Lisp_Object string, EMACS_INT pos, EMACS_INT pos_byte, | |||
| 1441 | 1442 | ||
| 1442 | static EMACS_INT | 1443 | static EMACS_INT |
| 1443 | simple_search (EMACS_INT n, unsigned char *pat, | 1444 | simple_search (EMACS_INT n, unsigned char *pat, |
| 1444 | EMACS_INT len, EMACS_INT len_byte, Lisp_Object trt, | 1445 | ptrdiff_t len, ptrdiff_t len_byte, Lisp_Object trt, |
| 1445 | EMACS_INT pos, EMACS_INT pos_byte, | 1446 | ptrdiff_t pos, ptrdiff_t pos_byte, |
| 1446 | EMACS_INT lim, EMACS_INT lim_byte) | 1447 | ptrdiff_t lim, ptrdiff_t lim_byte) |
| 1447 | { | 1448 | { |
| 1448 | int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); | 1449 | int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| 1449 | int forward = n > 0; | 1450 | int forward = n > 0; |
| 1450 | /* Number of buffer bytes matched. Note that this may be different | 1451 | /* Number of buffer bytes matched. Note that this may be different |
| 1451 | from len_byte in a multibyte buffer. */ | 1452 | from len_byte in a multibyte buffer. */ |
| 1452 | EMACS_INT match_byte; | 1453 | ptrdiff_t match_byte; |
| 1453 | 1454 | ||
| 1454 | if (lim > pos && multibyte) | 1455 | if (lim > pos && multibyte) |
| 1455 | while (n > 0) | 1456 | while (n > 0) |
| @@ -1457,9 +1458,9 @@ simple_search (EMACS_INT n, unsigned char *pat, | |||
| 1457 | while (1) | 1458 | while (1) |
| 1458 | { | 1459 | { |
| 1459 | /* Try matching at position POS. */ | 1460 | /* Try matching at position POS. */ |
| 1460 | EMACS_INT this_pos = pos; | 1461 | ptrdiff_t this_pos = pos; |
| 1461 | EMACS_INT this_pos_byte = pos_byte; | 1462 | ptrdiff_t this_pos_byte = pos_byte; |
| 1462 | EMACS_INT this_len = len; | 1463 | ptrdiff_t this_len = len; |
| 1463 | unsigned char *p = pat; | 1464 | unsigned char *p = pat; |
| 1464 | if (pos + len > lim || pos_byte + len_byte > lim_byte) | 1465 | if (pos + len > lim || pos_byte + len_byte > lim_byte) |
| 1465 | goto stop; | 1466 | goto stop; |
| @@ -1503,8 +1504,8 @@ simple_search (EMACS_INT n, unsigned char *pat, | |||
| 1503 | while (1) | 1504 | while (1) |
| 1504 | { | 1505 | { |
| 1505 | /* Try matching at position POS. */ | 1506 | /* Try matching at position POS. */ |
| 1506 | EMACS_INT this_pos = pos; | 1507 | ptrdiff_t this_pos = pos; |
| 1507 | EMACS_INT this_len = len; | 1508 | ptrdiff_t this_len = len; |
| 1508 | unsigned char *p = pat; | 1509 | unsigned char *p = pat; |
| 1509 | 1510 | ||
| 1510 | if (pos + len > lim) | 1511 | if (pos + len > lim) |
| @@ -1542,9 +1543,9 @@ simple_search (EMACS_INT n, unsigned char *pat, | |||
| 1542 | while (1) | 1543 | while (1) |
| 1543 | { | 1544 | { |
| 1544 | /* Try matching at position POS. */ | 1545 | /* Try matching at position POS. */ |
| 1545 | EMACS_INT this_pos = pos; | 1546 | ptrdiff_t this_pos = pos; |
| 1546 | EMACS_INT this_pos_byte = pos_byte; | 1547 | ptrdiff_t this_pos_byte = pos_byte; |
| 1547 | EMACS_INT this_len = len; | 1548 | ptrdiff_t this_len = len; |
| 1548 | const unsigned char *p = pat + len_byte; | 1549 | const unsigned char *p = pat + len_byte; |
| 1549 | 1550 | ||
| 1550 | if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte) | 1551 | if (this_pos - len < lim || (pos_byte - len_byte) < lim_byte) |
| @@ -1585,8 +1586,8 @@ simple_search (EMACS_INT n, unsigned char *pat, | |||
| 1585 | while (1) | 1586 | while (1) |
| 1586 | { | 1587 | { |
| 1587 | /* Try matching at position POS. */ | 1588 | /* Try matching at position POS. */ |
| 1588 | EMACS_INT this_pos = pos - len; | 1589 | ptrdiff_t this_pos = pos - len; |
| 1589 | EMACS_INT this_len = len; | 1590 | ptrdiff_t this_len = len; |
| 1590 | unsigned char *p = pat; | 1591 | unsigned char *p = pat; |
| 1591 | 1592 | ||
| 1592 | if (this_pos < lim) | 1593 | if (this_pos < lim) |
| @@ -1650,18 +1651,18 @@ simple_search (EMACS_INT n, unsigned char *pat, | |||
| 1650 | 1651 | ||
| 1651 | static EMACS_INT | 1652 | static EMACS_INT |
| 1652 | boyer_moore (EMACS_INT n, unsigned char *base_pat, | 1653 | boyer_moore (EMACS_INT n, unsigned char *base_pat, |
| 1653 | EMACS_INT len_byte, | 1654 | ptrdiff_t len_byte, |
| 1654 | Lisp_Object trt, Lisp_Object inverse_trt, | 1655 | Lisp_Object trt, Lisp_Object inverse_trt, |
| 1655 | EMACS_INT pos_byte, EMACS_INT lim_byte, | 1656 | ptrdiff_t pos_byte, ptrdiff_t lim_byte, |
| 1656 | int char_base) | 1657 | int char_base) |
| 1657 | { | 1658 | { |
| 1658 | int direction = ((n > 0) ? 1 : -1); | 1659 | int direction = ((n > 0) ? 1 : -1); |
| 1659 | register EMACS_INT dirlen; | 1660 | register ptrdiff_t dirlen; |
| 1660 | EMACS_INT limit; | 1661 | ptrdiff_t limit; |
| 1661 | int stride_for_teases = 0; | 1662 | int stride_for_teases = 0; |
| 1662 | int BM_tab[0400]; | 1663 | int BM_tab[0400]; |
| 1663 | register unsigned char *cursor, *p_limit; | 1664 | register unsigned char *cursor, *p_limit; |
| 1664 | register EMACS_INT i; | 1665 | register ptrdiff_t i; |
| 1665 | register int j; | 1666 | register int j; |
| 1666 | unsigned char *pat, *pat_end; | 1667 | unsigned char *pat, *pat_end; |
| 1667 | int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); | 1668 | int multibyte = ! NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| @@ -1813,7 +1814,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 1813 | char if reverse) of pattern would align in a possible match. */ | 1814 | char if reverse) of pattern would align in a possible match. */ |
| 1814 | while (n != 0) | 1815 | while (n != 0) |
| 1815 | { | 1816 | { |
| 1816 | EMACS_INT tail_end; | 1817 | ptrdiff_t tail_end; |
| 1817 | unsigned char *tail_end_ptr; | 1818 | unsigned char *tail_end_ptr; |
| 1818 | 1819 | ||
| 1819 | /* It's been reported that some (broken) compiler thinks that | 1820 | /* It's been reported that some (broken) compiler thinks that |
| @@ -1917,7 +1918,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 1917 | cursor += dirlen - i - direction; /* fix cursor */ | 1918 | cursor += dirlen - i - direction; /* fix cursor */ |
| 1918 | if (i + direction == 0) | 1919 | if (i + direction == 0) |
| 1919 | { | 1920 | { |
| 1920 | EMACS_INT position, start, end; | 1921 | ptrdiff_t position, start, end; |
| 1921 | 1922 | ||
| 1922 | cursor -= direction; | 1923 | cursor -= direction; |
| 1923 | 1924 | ||
| @@ -2009,7 +2010,7 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 2009 | pos_byte += dirlen - i - direction; | 2010 | pos_byte += dirlen - i - direction; |
| 2010 | if (i + direction == 0) | 2011 | if (i + direction == 0) |
| 2011 | { | 2012 | { |
| 2012 | EMACS_INT position, start, end; | 2013 | ptrdiff_t position, start, end; |
| 2013 | pos_byte -= direction; | 2014 | pos_byte -= direction; |
| 2014 | 2015 | ||
| 2015 | position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); | 2016 | position = pos_byte + ((direction > 0) ? 1 - len_byte : 0); |
| @@ -2050,9 +2051,9 @@ boyer_moore (EMACS_INT n, unsigned char *base_pat, | |||
| 2050 | Also clear out the match data for registers 1 and up. */ | 2051 | Also clear out the match data for registers 1 and up. */ |
| 2051 | 2052 | ||
| 2052 | static void | 2053 | static void |
| 2053 | set_search_regs (EMACS_INT beg_byte, EMACS_INT nbytes) | 2054 | set_search_regs (ptrdiff_t beg_byte, ptrdiff_t nbytes) |
| 2054 | { | 2055 | { |
| 2055 | int i; | 2056 | ptrdiff_t i; |
| 2056 | 2057 | ||
| 2057 | if (!NILP (Vinhibit_changing_match_data)) | 2058 | if (!NILP (Vinhibit_changing_match_data)) |
| 2058 | return; | 2059 | return; |
| @@ -2087,7 +2088,7 @@ static Lisp_Object | |||
| 2087 | wordify (Lisp_Object string, int lax) | 2088 | wordify (Lisp_Object string, int lax) |
| 2088 | { | 2089 | { |
| 2089 | register unsigned char *o; | 2090 | register unsigned char *o; |
| 2090 | register EMACS_INT i, i_byte, len, punct_count = 0, word_count = 0; | 2091 | register ptrdiff_t i, i_byte, len, punct_count = 0, word_count = 0; |
| 2091 | Lisp_Object val; | 2092 | Lisp_Object val; |
| 2092 | int prev_c = 0; | 2093 | int prev_c = 0; |
| 2093 | EMACS_INT adjust; | 2094 | EMACS_INT adjust; |
| @@ -2124,14 +2125,24 @@ wordify (Lisp_Object string, int lax) | |||
| 2124 | return empty_unibyte_string; | 2125 | return empty_unibyte_string; |
| 2125 | } | 2126 | } |
| 2126 | 2127 | ||
| 2127 | adjust = - punct_count + 5 * (word_count - 1) | 2128 | adjust = word_count - 1; |
| 2129 | if (INT_MULTIPLY_OVERFLOW (5, adjust)) | ||
| 2130 | memory_full (SIZE_MAX); | ||
| 2131 | adjust = - punct_count + 5 * adjust | ||
| 2128 | + ((lax && !whitespace_at_end) ? 2 : 4); | 2132 | + ((lax && !whitespace_at_end) ? 2 : 4); |
| 2129 | if (STRING_MULTIBYTE (string)) | 2133 | if (STRING_MULTIBYTE (string)) |
| 2130 | val = make_uninit_multibyte_string (len + adjust, | 2134 | { |
| 2131 | SBYTES (string) | 2135 | if (INT_ADD_OVERFLOW (SBYTES (string), adjust)) |
| 2132 | + adjust); | 2136 | memory_full (SIZE_MAX); |
| 2137 | val = make_uninit_multibyte_string (len + adjust, | ||
| 2138 | SBYTES (string) + adjust); | ||
| 2139 | } | ||
| 2133 | else | 2140 | else |
| 2134 | val = make_uninit_string (len + adjust); | 2141 | { |
| 2142 | if (INT_ADD_OVERFLOW (len, adjust)) | ||
| 2143 | memory_full (SIZE_MAX); | ||
| 2144 | val = make_uninit_string (len + adjust); | ||
| 2145 | } | ||
| 2135 | 2146 | ||
| 2136 | o = SDATA (val); | 2147 | o = SDATA (val); |
| 2137 | *o++ = '\\'; | 2148 | *o++ = '\\'; |
| @@ -2141,7 +2152,7 @@ wordify (Lisp_Object string, int lax) | |||
| 2141 | for (i = 0, i_byte = 0; i < len; ) | 2152 | for (i = 0, i_byte = 0; i < len; ) |
| 2142 | { | 2153 | { |
| 2143 | int c; | 2154 | int c; |
| 2144 | EMACS_INT i_byte_orig = i_byte; | 2155 | ptrdiff_t i_byte_orig = i_byte; |
| 2145 | 2156 | ||
| 2146 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); | 2157 | FETCH_STRING_CHAR_AS_MULTIBYTE_ADVANCE (c, string, i, i_byte); |
| 2147 | 2158 | ||
| @@ -2398,14 +2409,14 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2398 | (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp) | 2409 | (Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp) |
| 2399 | { | 2410 | { |
| 2400 | enum { nochange, all_caps, cap_initial } case_action; | 2411 | enum { nochange, all_caps, cap_initial } case_action; |
| 2401 | register EMACS_INT pos, pos_byte; | 2412 | register ptrdiff_t pos, pos_byte; |
| 2402 | int some_multiletter_word; | 2413 | int some_multiletter_word; |
| 2403 | int some_lowercase; | 2414 | int some_lowercase; |
| 2404 | int some_uppercase; | 2415 | int some_uppercase; |
| 2405 | int some_nonuppercase_initial; | 2416 | int some_nonuppercase_initial; |
| 2406 | register int c, prevc; | 2417 | register int c, prevc; |
| 2407 | ptrdiff_t sub; | 2418 | ptrdiff_t sub; |
| 2408 | EMACS_INT opoint, newpoint; | 2419 | ptrdiff_t opoint, newpoint; |
| 2409 | 2420 | ||
| 2410 | CHECK_STRING (newtext); | 2421 | CHECK_STRING (newtext); |
| 2411 | 2422 | ||
| @@ -2448,7 +2459,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2448 | if (NILP (fixedcase)) | 2459 | if (NILP (fixedcase)) |
| 2449 | { | 2460 | { |
| 2450 | /* Decide how to casify by examining the matched text. */ | 2461 | /* Decide how to casify by examining the matched text. */ |
| 2451 | EMACS_INT last; | 2462 | ptrdiff_t last; |
| 2452 | 2463 | ||
| 2453 | pos = search_regs.start[sub]; | 2464 | pos = search_regs.start[sub]; |
| 2454 | last = search_regs.end[sub]; | 2465 | last = search_regs.end[sub]; |
| @@ -2535,19 +2546,19 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2535 | if desired. */ | 2546 | if desired. */ |
| 2536 | if (NILP (literal)) | 2547 | if (NILP (literal)) |
| 2537 | { | 2548 | { |
| 2538 | EMACS_INT lastpos = 0; | 2549 | ptrdiff_t lastpos = 0; |
| 2539 | EMACS_INT lastpos_byte = 0; | 2550 | ptrdiff_t lastpos_byte = 0; |
| 2540 | /* We build up the substituted string in ACCUM. */ | 2551 | /* We build up the substituted string in ACCUM. */ |
| 2541 | Lisp_Object accum; | 2552 | Lisp_Object accum; |
| 2542 | Lisp_Object middle; | 2553 | Lisp_Object middle; |
| 2543 | EMACS_INT length = SBYTES (newtext); | 2554 | ptrdiff_t length = SBYTES (newtext); |
| 2544 | 2555 | ||
| 2545 | accum = Qnil; | 2556 | accum = Qnil; |
| 2546 | 2557 | ||
| 2547 | for (pos_byte = 0, pos = 0; pos_byte < length;) | 2558 | for (pos_byte = 0, pos = 0; pos_byte < length;) |
| 2548 | { | 2559 | { |
| 2549 | EMACS_INT substart = -1; | 2560 | ptrdiff_t substart = -1; |
| 2550 | EMACS_INT subend = 0; | 2561 | ptrdiff_t subend = 0; |
| 2551 | int delbackslash = 0; | 2562 | int delbackslash = 0; |
| 2552 | 2563 | ||
| 2553 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); | 2564 | FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte); |
| @@ -2563,8 +2574,8 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2563 | } | 2574 | } |
| 2564 | else if (c >= '1' && c <= '9') | 2575 | else if (c >= '1' && c <= '9') |
| 2565 | { | 2576 | { |
| 2566 | if (search_regs.start[c - '0'] >= 0 | 2577 | if (c - '0' < search_regs.num_regs |
| 2567 | && c <= search_regs.num_regs + '0') | 2578 | && 0 <= search_regs.start[c - '0']) |
| 2568 | { | 2579 | { |
| 2569 | substart = search_regs.start[c - '0']; | 2580 | substart = search_regs.start[c - '0']; |
| 2570 | subend = search_regs.end[c - '0']; | 2581 | subend = search_regs.end[c - '0']; |
| @@ -2702,7 +2713,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2702 | 2713 | ||
| 2703 | if (c == '&') | 2714 | if (c == '&') |
| 2704 | idx = sub; | 2715 | idx = sub; |
| 2705 | else if (c >= '1' && c <= '9' && c <= search_regs.num_regs + '0') | 2716 | else if (c >= '1' && c <= '9' && c - '0' < search_regs.num_regs) |
| 2706 | { | 2717 | { |
| 2707 | if (search_regs.start[c - '0'] >= 1) | 2718 | if (search_regs.start[c - '0'] >= 1) |
| 2708 | idx = c - '0'; | 2719 | idx = c - '0'; |
| @@ -2754,7 +2765,7 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2754 | { | 2765 | { |
| 2755 | if (buf_multibyte) | 2766 | if (buf_multibyte) |
| 2756 | { | 2767 | { |
| 2757 | EMACS_INT nchars = | 2768 | ptrdiff_t nchars = |
| 2758 | multibyte_chars_in_text (substed, substed_len); | 2769 | multibyte_chars_in_text (substed, substed_len); |
| 2759 | 2770 | ||
| 2760 | newtext = make_multibyte_string ((char *) substed, nchars, | 2771 | newtext = make_multibyte_string ((char *) substed, nchars, |
| @@ -2780,10 +2791,10 @@ since only regular expressions have distinguished subexpressions. */) | |||
| 2780 | 2791 | ||
| 2781 | /* Adjust search data for this change. */ | 2792 | /* Adjust search data for this change. */ |
| 2782 | { | 2793 | { |
| 2783 | EMACS_INT oldend = search_regs.end[sub]; | 2794 | ptrdiff_t oldend = search_regs.end[sub]; |
| 2784 | EMACS_INT oldstart = search_regs.start[sub]; | 2795 | ptrdiff_t oldstart = search_regs.start[sub]; |
| 2785 | EMACS_INT change = newpoint - search_regs.end[sub]; | 2796 | ptrdiff_t change = newpoint - search_regs.end[sub]; |
| 2786 | int i; | 2797 | ptrdiff_t i; |
| 2787 | 2798 | ||
| 2788 | for (i = 0; i < search_regs.num_regs; i++) | 2799 | for (i = 0; i < search_regs.num_regs; i++) |
| 2789 | { | 2800 | { |
| @@ -2876,7 +2887,7 @@ Return value is undefined if the last search failed. */) | |||
| 2876 | { | 2887 | { |
| 2877 | Lisp_Object tail, prev; | 2888 | Lisp_Object tail, prev; |
| 2878 | Lisp_Object *data; | 2889 | Lisp_Object *data; |
| 2879 | int i, len; | 2890 | ptrdiff_t i, len; |
| 2880 | 2891 | ||
| 2881 | if (!NILP (reseat)) | 2892 | if (!NILP (reseat)) |
| 2882 | for (tail = reuse; CONSP (tail); tail = XCDR (tail)) | 2893 | for (tail = reuse; CONSP (tail); tail = XCDR (tail)) |
| @@ -2897,7 +2908,7 @@ Return value is undefined if the last search failed. */) | |||
| 2897 | len = 0; | 2908 | len = 0; |
| 2898 | for (i = 0; i < search_regs.num_regs; i++) | 2909 | for (i = 0; i < search_regs.num_regs; i++) |
| 2899 | { | 2910 | { |
| 2900 | EMACS_INT start = search_regs.start[i]; | 2911 | ptrdiff_t start = search_regs.start[i]; |
| 2901 | if (start >= 0) | 2912 | if (start >= 0) |
| 2902 | { | 2913 | { |
| 2903 | if (EQ (last_thing_searched, Qt) | 2914 | if (EQ (last_thing_searched, Qt) |
| @@ -2988,11 +2999,13 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 2988 | 2999 | ||
| 2989 | /* Allocate registers if they don't already exist. */ | 3000 | /* Allocate registers if they don't already exist. */ |
| 2990 | { | 3001 | { |
| 2991 | ptrdiff_t length = XFASTINT (Flength (list)) / 2; | 3002 | EMACS_INT length = XFASTINT (Flength (list)) / 2; |
| 2992 | 3003 | ||
| 2993 | if (length > search_regs.num_regs) | 3004 | if (length > search_regs.num_regs) |
| 2994 | { | 3005 | { |
| 2995 | ptrdiff_t num_regs = search_regs.num_regs; | 3006 | ptrdiff_t num_regs = search_regs.num_regs; |
| 3007 | if (PTRDIFF_MAX < length) | ||
| 3008 | memory_full (SIZE_MAX); | ||
| 2996 | search_regs.start = | 3009 | search_regs.start = |
| 2997 | xpalloc (search_regs.start, &num_regs, length - num_regs, | 3010 | xpalloc (search_regs.start, &num_regs, length - num_regs, |
| 2998 | min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); | 3011 | min (PTRDIFF_MAX, UINT_MAX), sizeof (regoff_t)); |
| @@ -3022,7 +3035,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 3022 | } | 3035 | } |
| 3023 | else | 3036 | else |
| 3024 | { | 3037 | { |
| 3025 | EMACS_INT from; | 3038 | Lisp_Object from; |
| 3026 | Lisp_Object m; | 3039 | Lisp_Object m; |
| 3027 | 3040 | ||
| 3028 | m = marker; | 3041 | m = marker; |
| @@ -3035,7 +3048,7 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 3035 | } | 3048 | } |
| 3036 | 3049 | ||
| 3037 | CHECK_NUMBER_COERCE_MARKER (marker); | 3050 | CHECK_NUMBER_COERCE_MARKER (marker); |
| 3038 | from = XINT (marker); | 3051 | from = marker; |
| 3039 | 3052 | ||
| 3040 | if (!NILP (reseat) && MARKERP (m)) | 3053 | if (!NILP (reseat) && MARKERP (m)) |
| 3041 | { | 3054 | { |
| @@ -3052,8 +3065,18 @@ If optional arg RESEAT is non-nil, make markers on LIST point nowhere. */) | |||
| 3052 | XSETFASTINT (marker, 0); | 3065 | XSETFASTINT (marker, 0); |
| 3053 | 3066 | ||
| 3054 | CHECK_NUMBER_COERCE_MARKER (marker); | 3067 | CHECK_NUMBER_COERCE_MARKER (marker); |
| 3055 | search_regs.start[i] = from; | 3068 | if (TYPE_MINIMUM (regoff_t) <= XINT (from) |
| 3056 | search_regs.end[i] = XINT (marker); | 3069 | && XINT (from) <= TYPE_MAXIMUM (regoff_t) |
| 3070 | && TYPE_MINIMUM (regoff_t) <= XINT (marker) | ||
| 3071 | && XINT (marker) <= TYPE_MAXIMUM (regoff_t)) | ||
| 3072 | { | ||
| 3073 | search_regs.start[i] = XINT (from); | ||
| 3074 | search_regs.end[i] = XINT (marker); | ||
| 3075 | } | ||
| 3076 | else | ||
| 3077 | { | ||
| 3078 | search_regs.start[i] = -1; | ||
| 3079 | } | ||
| 3057 | 3080 | ||
| 3058 | if (!NILP (reseat) && MARKERP (m)) | 3081 | if (!NILP (reseat) && MARKERP (m)) |
| 3059 | { | 3082 | { |