diff options
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 327 |
1 files changed, 165 insertions, 162 deletions
| @@ -250,8 +250,8 @@ If string STR1 is greater, the value is a positive number N; | |||
| 250 | N - 1 is the number of characters that match at the beginning. */) | 250 | N - 1 is the number of characters that match at the beginning. */) |
| 251 | (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case) | 251 | (Lisp_Object str1, Lisp_Object start1, Lisp_Object end1, Lisp_Object str2, Lisp_Object start2, Lisp_Object end2, Lisp_Object ignore_case) |
| 252 | { | 252 | { |
| 253 | register EMACS_INT end1_char, end2_char; | 253 | register ptrdiff_t end1_char, end2_char; |
| 254 | register EMACS_INT i1, i1_byte, i2, i2_byte; | 254 | register ptrdiff_t i1, i1_byte, i2, i2_byte; |
| 255 | 255 | ||
| 256 | CHECK_STRING (str1); | 256 | CHECK_STRING (str1); |
| 257 | CHECK_STRING (str2); | 257 | CHECK_STRING (str2); |
| @@ -266,19 +266,23 @@ If string STR1 is greater, the value is a positive number N; | |||
| 266 | if (! NILP (end2)) | 266 | if (! NILP (end2)) |
| 267 | CHECK_NATNUM (end2); | 267 | CHECK_NATNUM (end2); |
| 268 | 268 | ||
| 269 | i1 = XINT (start1); | ||
| 270 | i2 = XINT (start2); | ||
| 271 | |||
| 272 | i1_byte = string_char_to_byte (str1, i1); | ||
| 273 | i2_byte = string_char_to_byte (str2, i2); | ||
| 274 | |||
| 275 | end1_char = SCHARS (str1); | 269 | end1_char = SCHARS (str1); |
| 276 | if (! NILP (end1) && end1_char > XINT (end1)) | 270 | if (! NILP (end1) && end1_char > XINT (end1)) |
| 277 | end1_char = XINT (end1); | 271 | end1_char = XINT (end1); |
| 272 | if (end1_char < XINT (start1)) | ||
| 273 | args_out_of_range (str1, start1); | ||
| 278 | 274 | ||
| 279 | end2_char = SCHARS (str2); | 275 | end2_char = SCHARS (str2); |
| 280 | if (! NILP (end2) && end2_char > XINT (end2)) | 276 | if (! NILP (end2) && end2_char > XINT (end2)) |
| 281 | end2_char = XINT (end2); | 277 | end2_char = XINT (end2); |
| 278 | if (end2_char < XINT (start2)) | ||
| 279 | args_out_of_range (str2, start2); | ||
| 280 | |||
| 281 | i1 = XINT (start1); | ||
| 282 | i2 = XINT (start2); | ||
| 283 | |||
| 284 | i1_byte = string_char_to_byte (str1, i1); | ||
| 285 | i2_byte = string_char_to_byte (str2, i2); | ||
| 282 | 286 | ||
| 283 | while (i1 < end1_char && i2 < end2_char) | 287 | while (i1 < end1_char && i2 < end2_char) |
| 284 | { | 288 | { |
| @@ -341,8 +345,8 @@ Case is significant. | |||
| 341 | Symbols are also allowed; their print names are used instead. */) | 345 | Symbols are also allowed; their print names are used instead. */) |
| 342 | (register Lisp_Object s1, Lisp_Object s2) | 346 | (register Lisp_Object s1, Lisp_Object s2) |
| 343 | { | 347 | { |
| 344 | register EMACS_INT end; | 348 | register ptrdiff_t end; |
| 345 | register EMACS_INT i1, i1_byte, i2, i2_byte; | 349 | register ptrdiff_t i1, i1_byte, i2, i2_byte; |
| 346 | 350 | ||
| 347 | if (SYMBOLP (s1)) | 351 | if (SYMBOLP (s1)) |
| 348 | s1 = SYMBOL_NAME (s1); | 352 | s1 = SYMBOL_NAME (s1); |
| @@ -465,8 +469,8 @@ with the original. */) | |||
| 465 | struct textprop_rec | 469 | struct textprop_rec |
| 466 | { | 470 | { |
| 467 | ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */ | 471 | ptrdiff_t argnum; /* refer to ARGS (arguments of `concat') */ |
| 468 | EMACS_INT from; /* refer to ARGS[argnum] (argument string) */ | 472 | ptrdiff_t from; /* refer to ARGS[argnum] (argument string) */ |
| 469 | EMACS_INT to; /* refer to VAL (the target string) */ | 473 | ptrdiff_t to; /* refer to VAL (the target string) */ |
| 470 | }; | 474 | }; |
| 471 | 475 | ||
| 472 | static Lisp_Object | 476 | static Lisp_Object |
| @@ -476,8 +480,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 476 | Lisp_Object val; | 480 | Lisp_Object val; |
| 477 | register Lisp_Object tail; | 481 | register Lisp_Object tail; |
| 478 | register Lisp_Object this; | 482 | register Lisp_Object this; |
| 479 | EMACS_INT toindex; | 483 | ptrdiff_t toindex; |
| 480 | EMACS_INT toindex_byte = 0; | 484 | ptrdiff_t toindex_byte = 0; |
| 481 | register EMACS_INT result_len; | 485 | register EMACS_INT result_len; |
| 482 | register EMACS_INT result_len_byte; | 486 | register EMACS_INT result_len_byte; |
| 483 | ptrdiff_t argnum; | 487 | ptrdiff_t argnum; |
| @@ -530,10 +534,10 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 530 | { | 534 | { |
| 531 | /* We must count the number of bytes needed in the string | 535 | /* We must count the number of bytes needed in the string |
| 532 | as well as the number of characters. */ | 536 | as well as the number of characters. */ |
| 533 | EMACS_INT i; | 537 | ptrdiff_t i; |
| 534 | Lisp_Object ch; | 538 | Lisp_Object ch; |
| 535 | int c; | 539 | int c; |
| 536 | EMACS_INT this_len_byte; | 540 | ptrdiff_t this_len_byte; |
| 537 | 541 | ||
| 538 | if (VECTORP (this) || COMPILEDP (this)) | 542 | if (VECTORP (this) || COMPILEDP (this)) |
| 539 | for (i = 0; i < len; i++) | 543 | for (i = 0; i < len; i++) |
| @@ -542,6 +546,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 542 | CHECK_CHARACTER (ch); | 546 | CHECK_CHARACTER (ch); |
| 543 | c = XFASTINT (ch); | 547 | c = XFASTINT (ch); |
| 544 | this_len_byte = CHAR_BYTES (c); | 548 | this_len_byte = CHAR_BYTES (c); |
| 549 | if (STRING_BYTES_BOUND - result_len_byte < this_len_byte) | ||
| 550 | string_overflow (); | ||
| 545 | result_len_byte += this_len_byte; | 551 | result_len_byte += this_len_byte; |
| 546 | if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) | 552 | if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) |
| 547 | some_multibyte = 1; | 553 | some_multibyte = 1; |
| @@ -555,6 +561,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 555 | CHECK_CHARACTER (ch); | 561 | CHECK_CHARACTER (ch); |
| 556 | c = XFASTINT (ch); | 562 | c = XFASTINT (ch); |
| 557 | this_len_byte = CHAR_BYTES (c); | 563 | this_len_byte = CHAR_BYTES (c); |
| 564 | if (STRING_BYTES_BOUND - result_len_byte < this_len_byte) | ||
| 565 | string_overflow (); | ||
| 558 | result_len_byte += this_len_byte; | 566 | result_len_byte += this_len_byte; |
| 559 | if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) | 567 | if (! ASCII_CHAR_P (c) && ! CHAR_BYTE8_P (c)) |
| 560 | some_multibyte = 1; | 568 | some_multibyte = 1; |
| @@ -564,17 +572,20 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 564 | if (STRING_MULTIBYTE (this)) | 572 | if (STRING_MULTIBYTE (this)) |
| 565 | { | 573 | { |
| 566 | some_multibyte = 1; | 574 | some_multibyte = 1; |
| 567 | result_len_byte += SBYTES (this); | 575 | this_len_byte = SBYTES (this); |
| 568 | } | 576 | } |
| 569 | else | 577 | else |
| 570 | result_len_byte += count_size_as_multibyte (SDATA (this), | 578 | this_len_byte = count_size_as_multibyte (SDATA (this), |
| 571 | SCHARS (this)); | 579 | SCHARS (this)); |
| 580 | if (STRING_BYTES_BOUND - result_len_byte < this_len_byte) | ||
| 581 | string_overflow (); | ||
| 582 | result_len_byte += this_len_byte; | ||
| 572 | } | 583 | } |
| 573 | } | 584 | } |
| 574 | 585 | ||
| 575 | result_len += len; | 586 | result_len += len; |
| 576 | if (STRING_BYTES_BOUND < result_len) | 587 | if (MOST_POSITIVE_FIXNUM < result_len) |
| 577 | string_overflow (); | 588 | memory_full (SIZE_MAX); |
| 578 | } | 589 | } |
| 579 | 590 | ||
| 580 | if (! some_multibyte) | 591 | if (! some_multibyte) |
| @@ -607,9 +618,9 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 607 | for (argnum = 0; argnum < nargs; argnum++) | 618 | for (argnum = 0; argnum < nargs; argnum++) |
| 608 | { | 619 | { |
| 609 | Lisp_Object thislen; | 620 | Lisp_Object thislen; |
| 610 | EMACS_INT thisleni = 0; | 621 | ptrdiff_t thisleni = 0; |
| 611 | register EMACS_INT thisindex = 0; | 622 | register ptrdiff_t thisindex = 0; |
| 612 | register EMACS_INT thisindex_byte = 0; | 623 | register ptrdiff_t thisindex_byte = 0; |
| 613 | 624 | ||
| 614 | this = args[argnum]; | 625 | this = args[argnum]; |
| 615 | if (!CONSP (this)) | 626 | if (!CONSP (this)) |
| @@ -619,7 +630,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 619 | if (STRINGP (this) && STRINGP (val) | 630 | if (STRINGP (this) && STRINGP (val) |
| 620 | && STRING_MULTIBYTE (this) == some_multibyte) | 631 | && STRING_MULTIBYTE (this) == some_multibyte) |
| 621 | { | 632 | { |
| 622 | EMACS_INT thislen_byte = SBYTES (this); | 633 | ptrdiff_t thislen_byte = SBYTES (this); |
| 623 | 634 | ||
| 624 | memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this)); | 635 | memcpy (SDATA (val) + toindex_byte, SDATA (this), SBYTES (this)); |
| 625 | if (! NULL_INTERVAL_P (STRING_INTERVALS (this))) | 636 | if (! NULL_INTERVAL_P (STRING_INTERVALS (this))) |
| @@ -720,7 +731,7 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 720 | if (num_textprops > 0) | 731 | if (num_textprops > 0) |
| 721 | { | 732 | { |
| 722 | Lisp_Object props; | 733 | Lisp_Object props; |
| 723 | EMACS_INT last_to_end = -1; | 734 | ptrdiff_t last_to_end = -1; |
| 724 | 735 | ||
| 725 | for (argnum = 0; argnum < num_textprops; argnum++) | 736 | for (argnum = 0; argnum < num_textprops; argnum++) |
| 726 | { | 737 | { |
| @@ -744,8 +755,8 @@ concat (ptrdiff_t nargs, Lisp_Object *args, | |||
| 744 | } | 755 | } |
| 745 | 756 | ||
| 746 | static Lisp_Object string_char_byte_cache_string; | 757 | static Lisp_Object string_char_byte_cache_string; |
| 747 | static EMACS_INT string_char_byte_cache_charpos; | 758 | static ptrdiff_t string_char_byte_cache_charpos; |
| 748 | static EMACS_INT string_char_byte_cache_bytepos; | 759 | static ptrdiff_t string_char_byte_cache_bytepos; |
| 749 | 760 | ||
| 750 | void | 761 | void |
| 751 | clear_string_char_byte_cache (void) | 762 | clear_string_char_byte_cache (void) |
| @@ -755,12 +766,12 @@ clear_string_char_byte_cache (void) | |||
| 755 | 766 | ||
| 756 | /* Return the byte index corresponding to CHAR_INDEX in STRING. */ | 767 | /* Return the byte index corresponding to CHAR_INDEX in STRING. */ |
| 757 | 768 | ||
| 758 | EMACS_INT | 769 | ptrdiff_t |
| 759 | string_char_to_byte (Lisp_Object string, EMACS_INT char_index) | 770 | string_char_to_byte (Lisp_Object string, ptrdiff_t char_index) |
| 760 | { | 771 | { |
| 761 | EMACS_INT i_byte; | 772 | ptrdiff_t i_byte; |
| 762 | EMACS_INT best_below, best_below_byte; | 773 | ptrdiff_t best_below, best_below_byte; |
| 763 | EMACS_INT best_above, best_above_byte; | 774 | ptrdiff_t best_above, best_above_byte; |
| 764 | 775 | ||
| 765 | best_below = best_below_byte = 0; | 776 | best_below = best_below_byte = 0; |
| 766 | best_above = SCHARS (string); | 777 | best_above = SCHARS (string); |
| @@ -815,12 +826,12 @@ string_char_to_byte (Lisp_Object string, EMACS_INT char_index) | |||
| 815 | 826 | ||
| 816 | /* Return the character index corresponding to BYTE_INDEX in STRING. */ | 827 | /* Return the character index corresponding to BYTE_INDEX in STRING. */ |
| 817 | 828 | ||
| 818 | EMACS_INT | 829 | ptrdiff_t |
| 819 | string_byte_to_char (Lisp_Object string, EMACS_INT byte_index) | 830 | string_byte_to_char (Lisp_Object string, ptrdiff_t byte_index) |
| 820 | { | 831 | { |
| 821 | EMACS_INT i, i_byte; | 832 | ptrdiff_t i, i_byte; |
| 822 | EMACS_INT best_below, best_below_byte; | 833 | ptrdiff_t best_below, best_below_byte; |
| 823 | EMACS_INT best_above, best_above_byte; | 834 | ptrdiff_t best_above, best_above_byte; |
| 824 | 835 | ||
| 825 | best_below = best_below_byte = 0; | 836 | best_below = best_below_byte = 0; |
| 826 | best_above = SCHARS (string); | 837 | best_above = SCHARS (string); |
| @@ -883,7 +894,7 @@ static Lisp_Object | |||
| 883 | string_make_multibyte (Lisp_Object string) | 894 | string_make_multibyte (Lisp_Object string) |
| 884 | { | 895 | { |
| 885 | unsigned char *buf; | 896 | unsigned char *buf; |
| 886 | EMACS_INT nbytes; | 897 | ptrdiff_t nbytes; |
| 887 | Lisp_Object ret; | 898 | Lisp_Object ret; |
| 888 | USE_SAFE_ALLOCA; | 899 | USE_SAFE_ALLOCA; |
| 889 | 900 | ||
| @@ -916,7 +927,7 @@ Lisp_Object | |||
| 916 | string_to_multibyte (Lisp_Object string) | 927 | string_to_multibyte (Lisp_Object string) |
| 917 | { | 928 | { |
| 918 | unsigned char *buf; | 929 | unsigned char *buf; |
| 919 | EMACS_INT nbytes; | 930 | ptrdiff_t nbytes; |
| 920 | Lisp_Object ret; | 931 | Lisp_Object ret; |
| 921 | USE_SAFE_ALLOCA; | 932 | USE_SAFE_ALLOCA; |
| 922 | 933 | ||
| @@ -945,7 +956,7 @@ string_to_multibyte (Lisp_Object string) | |||
| 945 | Lisp_Object | 956 | Lisp_Object |
| 946 | string_make_unibyte (Lisp_Object string) | 957 | string_make_unibyte (Lisp_Object string) |
| 947 | { | 958 | { |
| 948 | EMACS_INT nchars; | 959 | ptrdiff_t nchars; |
| 949 | unsigned char *buf; | 960 | unsigned char *buf; |
| 950 | Lisp_Object ret; | 961 | Lisp_Object ret; |
| 951 | USE_SAFE_ALLOCA; | 962 | USE_SAFE_ALLOCA; |
| @@ -1010,7 +1021,7 @@ If STRING is multibyte and contains a character of charset | |||
| 1010 | 1021 | ||
| 1011 | if (STRING_MULTIBYTE (string)) | 1022 | if (STRING_MULTIBYTE (string)) |
| 1012 | { | 1023 | { |
| 1013 | EMACS_INT bytes = SBYTES (string); | 1024 | ptrdiff_t bytes = SBYTES (string); |
| 1014 | unsigned char *str = (unsigned char *) xmalloc (bytes); | 1025 | unsigned char *str = (unsigned char *) xmalloc (bytes); |
| 1015 | 1026 | ||
| 1016 | memcpy (str, SDATA (string), bytes); | 1027 | memcpy (str, SDATA (string), bytes); |
| @@ -1043,7 +1054,7 @@ If you're not sure, whether to use `string-as-multibyte' or | |||
| 1043 | if (! STRING_MULTIBYTE (string)) | 1054 | if (! STRING_MULTIBYTE (string)) |
| 1044 | { | 1055 | { |
| 1045 | Lisp_Object new_string; | 1056 | Lisp_Object new_string; |
| 1046 | EMACS_INT nchars, nbytes; | 1057 | ptrdiff_t nchars, nbytes; |
| 1047 | 1058 | ||
| 1048 | parse_str_as_multibyte (SDATA (string), | 1059 | parse_str_as_multibyte (SDATA (string), |
| 1049 | SBYTES (string), | 1060 | SBYTES (string), |
| @@ -1092,9 +1103,9 @@ an error is signaled. */) | |||
| 1092 | 1103 | ||
| 1093 | if (STRING_MULTIBYTE (string)) | 1104 | if (STRING_MULTIBYTE (string)) |
| 1094 | { | 1105 | { |
| 1095 | EMACS_INT chars = SCHARS (string); | 1106 | ptrdiff_t chars = SCHARS (string); |
| 1096 | unsigned char *str = (unsigned char *) xmalloc (chars); | 1107 | unsigned char *str = (unsigned char *) xmalloc (chars); |
| 1097 | EMACS_INT converted = str_to_unibyte (SDATA (string), str, chars, 0); | 1108 | ptrdiff_t converted = str_to_unibyte (SDATA (string), str, chars, 0); |
| 1098 | 1109 | ||
| 1099 | if (converted < chars) | 1110 | if (converted < chars) |
| 1100 | error ("Can't convert the %"pI"dth character to unibyte", converted); | 1111 | error ("Can't convert the %"pI"dth character to unibyte", converted); |
| @@ -1145,27 +1156,19 @@ value is a new vector that contains the elements between index FROM | |||
| 1145 | (Lisp_Object string, register Lisp_Object from, Lisp_Object to) | 1156 | (Lisp_Object string, register Lisp_Object from, Lisp_Object to) |
| 1146 | { | 1157 | { |
| 1147 | Lisp_Object res; | 1158 | Lisp_Object res; |
| 1148 | EMACS_INT size; | 1159 | ptrdiff_t size; |
| 1149 | EMACS_INT size_byte = 0; | ||
| 1150 | EMACS_INT from_char, to_char; | 1160 | EMACS_INT from_char, to_char; |
| 1151 | EMACS_INT from_byte = 0, to_byte = 0; | ||
| 1152 | 1161 | ||
| 1153 | CHECK_VECTOR_OR_STRING (string); | 1162 | CHECK_VECTOR_OR_STRING (string); |
| 1154 | CHECK_NUMBER (from); | 1163 | CHECK_NUMBER (from); |
| 1155 | 1164 | ||
| 1156 | if (STRINGP (string)) | 1165 | if (STRINGP (string)) |
| 1157 | { | 1166 | size = SCHARS (string); |
| 1158 | size = SCHARS (string); | ||
| 1159 | size_byte = SBYTES (string); | ||
| 1160 | } | ||
| 1161 | else | 1167 | else |
| 1162 | size = ASIZE (string); | 1168 | size = ASIZE (string); |
| 1163 | 1169 | ||
| 1164 | if (NILP (to)) | 1170 | if (NILP (to)) |
| 1165 | { | 1171 | to_char = size; |
| 1166 | to_char = size; | ||
| 1167 | to_byte = size_byte; | ||
| 1168 | } | ||
| 1169 | else | 1172 | else |
| 1170 | { | 1173 | { |
| 1171 | CHECK_NUMBER (to); | 1174 | CHECK_NUMBER (to); |
| @@ -1173,23 +1176,19 @@ value is a new vector that contains the elements between index FROM | |||
| 1173 | to_char = XINT (to); | 1176 | to_char = XINT (to); |
| 1174 | if (to_char < 0) | 1177 | if (to_char < 0) |
| 1175 | to_char += size; | 1178 | to_char += size; |
| 1176 | |||
| 1177 | if (STRINGP (string)) | ||
| 1178 | to_byte = string_char_to_byte (string, to_char); | ||
| 1179 | } | 1179 | } |
| 1180 | 1180 | ||
| 1181 | from_char = XINT (from); | 1181 | from_char = XINT (from); |
| 1182 | if (from_char < 0) | 1182 | if (from_char < 0) |
| 1183 | from_char += size; | 1183 | from_char += size; |
| 1184 | if (STRINGP (string)) | ||
| 1185 | from_byte = string_char_to_byte (string, from_char); | ||
| 1186 | |||
| 1187 | if (!(0 <= from_char && from_char <= to_char && to_char <= size)) | 1184 | if (!(0 <= from_char && from_char <= to_char && to_char <= size)) |
| 1188 | args_out_of_range_3 (string, make_number (from_char), | 1185 | args_out_of_range_3 (string, make_number (from_char), |
| 1189 | make_number (to_char)); | 1186 | make_number (to_char)); |
| 1190 | |||
| 1191 | if (STRINGP (string)) | 1187 | if (STRINGP (string)) |
| 1192 | { | 1188 | { |
| 1189 | ptrdiff_t to_byte = | ||
| 1190 | (NILP (to) ? SBYTES (string) : string_char_to_byte (string, to_char)); | ||
| 1191 | ptrdiff_t from_byte = string_char_to_byte (string, from_char); | ||
| 1193 | res = make_specified_string (SSDATA (string) + from_byte, | 1192 | res = make_specified_string (SSDATA (string) + from_byte, |
| 1194 | to_char - from_char, to_byte - from_byte, | 1193 | to_char - from_char, to_byte - from_byte, |
| 1195 | STRING_MULTIBYTE (string)); | 1194 | STRING_MULTIBYTE (string)); |
| @@ -1213,47 +1212,41 @@ If FROM or TO is negative, it counts from the end. | |||
| 1213 | With one argument, just copy STRING without its properties. */) | 1212 | With one argument, just copy STRING without its properties. */) |
| 1214 | (Lisp_Object string, register Lisp_Object from, Lisp_Object to) | 1213 | (Lisp_Object string, register Lisp_Object from, Lisp_Object to) |
| 1215 | { | 1214 | { |
| 1216 | EMACS_INT size, size_byte; | 1215 | ptrdiff_t size; |
| 1217 | EMACS_INT from_char, to_char; | 1216 | EMACS_INT from_char, to_char; |
| 1218 | EMACS_INT from_byte, to_byte; | 1217 | ptrdiff_t from_byte, to_byte; |
| 1219 | 1218 | ||
| 1220 | CHECK_STRING (string); | 1219 | CHECK_STRING (string); |
| 1221 | 1220 | ||
| 1222 | size = SCHARS (string); | 1221 | size = SCHARS (string); |
| 1223 | size_byte = SBYTES (string); | ||
| 1224 | 1222 | ||
| 1225 | if (NILP (from)) | 1223 | if (NILP (from)) |
| 1226 | from_char = from_byte = 0; | 1224 | from_char = 0; |
| 1227 | else | 1225 | else |
| 1228 | { | 1226 | { |
| 1229 | CHECK_NUMBER (from); | 1227 | CHECK_NUMBER (from); |
| 1230 | from_char = XINT (from); | 1228 | from_char = XINT (from); |
| 1231 | if (from_char < 0) | 1229 | if (from_char < 0) |
| 1232 | from_char += size; | 1230 | from_char += size; |
| 1233 | |||
| 1234 | from_byte = string_char_to_byte (string, from_char); | ||
| 1235 | } | 1231 | } |
| 1236 | 1232 | ||
| 1237 | if (NILP (to)) | 1233 | if (NILP (to)) |
| 1238 | { | 1234 | to_char = size; |
| 1239 | to_char = size; | ||
| 1240 | to_byte = size_byte; | ||
| 1241 | } | ||
| 1242 | else | 1235 | else |
| 1243 | { | 1236 | { |
| 1244 | CHECK_NUMBER (to); | 1237 | CHECK_NUMBER (to); |
| 1245 | |||
| 1246 | to_char = XINT (to); | 1238 | to_char = XINT (to); |
| 1247 | if (to_char < 0) | 1239 | if (to_char < 0) |
| 1248 | to_char += size; | 1240 | to_char += size; |
| 1249 | |||
| 1250 | to_byte = string_char_to_byte (string, to_char); | ||
| 1251 | } | 1241 | } |
| 1252 | 1242 | ||
| 1253 | if (!(0 <= from_char && from_char <= to_char && to_char <= size)) | 1243 | if (!(0 <= from_char && from_char <= to_char && to_char <= size)) |
| 1254 | args_out_of_range_3 (string, make_number (from_char), | 1244 | args_out_of_range_3 (string, make_number (from_char), |
| 1255 | make_number (to_char)); | 1245 | make_number (to_char)); |
| 1256 | 1246 | ||
| 1247 | from_byte = NILP (from) ? 0 : string_char_to_byte (string, from_char); | ||
| 1248 | to_byte = | ||
| 1249 | NILP (to) ? SBYTES (string) : string_char_to_byte (string, to_char); | ||
| 1257 | return make_specified_string (SSDATA (string) + from_byte, | 1250 | return make_specified_string (SSDATA (string) + from_byte, |
| 1258 | to_char - from_char, to_byte - from_byte, | 1251 | to_char - from_char, to_byte - from_byte, |
| 1259 | STRING_MULTIBYTE (string)); | 1252 | STRING_MULTIBYTE (string)); |
| @@ -1263,11 +1256,11 @@ With one argument, just copy STRING without its properties. */) | |||
| 1263 | both in characters and in bytes. */ | 1256 | both in characters and in bytes. */ |
| 1264 | 1257 | ||
| 1265 | Lisp_Object | 1258 | Lisp_Object |
| 1266 | substring_both (Lisp_Object string, EMACS_INT from, EMACS_INT from_byte, | 1259 | substring_both (Lisp_Object string, ptrdiff_t from, ptrdiff_t from_byte, |
| 1267 | EMACS_INT to, EMACS_INT to_byte) | 1260 | ptrdiff_t to, ptrdiff_t to_byte) |
| 1268 | { | 1261 | { |
| 1269 | Lisp_Object res; | 1262 | Lisp_Object res; |
| 1270 | EMACS_INT size; | 1263 | ptrdiff_t size; |
| 1271 | 1264 | ||
| 1272 | CHECK_VECTOR_OR_STRING (string); | 1265 | CHECK_VECTOR_OR_STRING (string); |
| 1273 | 1266 | ||
| @@ -1601,7 +1594,7 @@ to be sure of changing the value of `foo'. */) | |||
| 1601 | { | 1594 | { |
| 1602 | if (VECTORP (seq)) | 1595 | if (VECTORP (seq)) |
| 1603 | { | 1596 | { |
| 1604 | EMACS_INT i, n; | 1597 | ptrdiff_t i, n; |
| 1605 | 1598 | ||
| 1606 | for (i = n = 0; i < ASIZE (seq); ++i) | 1599 | for (i = n = 0; i < ASIZE (seq); ++i) |
| 1607 | if (NILP (Fequal (AREF (seq, i), elt))) | 1600 | if (NILP (Fequal (AREF (seq, i), elt))) |
| @@ -1620,7 +1613,7 @@ to be sure of changing the value of `foo'. */) | |||
| 1620 | } | 1613 | } |
| 1621 | else if (STRINGP (seq)) | 1614 | else if (STRINGP (seq)) |
| 1622 | { | 1615 | { |
| 1623 | EMACS_INT i, ibyte, nchars, nbytes, cbytes; | 1616 | ptrdiff_t i, ibyte, nchars, nbytes, cbytes; |
| 1624 | int c; | 1617 | int c; |
| 1625 | 1618 | ||
| 1626 | for (i = nchars = nbytes = ibyte = 0; | 1619 | for (i = nchars = nbytes = ibyte = 0; |
| @@ -1672,7 +1665,7 @@ to be sure of changing the value of `foo'. */) | |||
| 1672 | { | 1665 | { |
| 1673 | unsigned char *from = SDATA (seq) + ibyte; | 1666 | unsigned char *from = SDATA (seq) + ibyte; |
| 1674 | unsigned char *to = SDATA (tem) + nbytes; | 1667 | unsigned char *to = SDATA (tem) + nbytes; |
| 1675 | EMACS_INT n; | 1668 | ptrdiff_t n; |
| 1676 | 1669 | ||
| 1677 | ++nchars; | 1670 | ++nchars; |
| 1678 | nbytes += cbytes; | 1671 | nbytes += cbytes; |
| @@ -2079,7 +2072,7 @@ internal_equal (register Lisp_Object o1, register Lisp_Object o2, int depth, int | |||
| 2079 | case Lisp_Vectorlike: | 2072 | case Lisp_Vectorlike: |
| 2080 | { | 2073 | { |
| 2081 | register int i; | 2074 | register int i; |
| 2082 | EMACS_INT size = ASIZE (o1); | 2075 | ptrdiff_t size = ASIZE (o1); |
| 2083 | /* Pseudovectors have the type encoded in the size field, so this test | 2076 | /* Pseudovectors have the type encoded in the size field, so this test |
| 2084 | actually checks that the objects have the same type as well as the | 2077 | actually checks that the objects have the same type as well as the |
| 2085 | same size. */ | 2078 | same size. */ |
| @@ -2146,7 +2139,7 @@ DEFUN ("fillarray", Ffillarray, Sfillarray, 2, 2, 0, | |||
| 2146 | ARRAY is a vector, string, char-table, or bool-vector. */) | 2139 | ARRAY is a vector, string, char-table, or bool-vector. */) |
| 2147 | (Lisp_Object array, Lisp_Object item) | 2140 | (Lisp_Object array, Lisp_Object item) |
| 2148 | { | 2141 | { |
| 2149 | register EMACS_INT size, idx; | 2142 | register ptrdiff_t size, idx; |
| 2150 | 2143 | ||
| 2151 | if (VECTORP (array)) | 2144 | if (VECTORP (array)) |
| 2152 | { | 2145 | { |
| @@ -2174,7 +2167,7 @@ ARRAY is a vector, string, char-table, or bool-vector. */) | |||
| 2174 | { | 2167 | { |
| 2175 | unsigned char str[MAX_MULTIBYTE_LENGTH]; | 2168 | unsigned char str[MAX_MULTIBYTE_LENGTH]; |
| 2176 | int len = CHAR_STRING (charval, str); | 2169 | int len = CHAR_STRING (charval, str); |
| 2177 | EMACS_INT size_byte = SBYTES (array); | 2170 | ptrdiff_t size_byte = SBYTES (array); |
| 2178 | 2171 | ||
| 2179 | if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len) | 2172 | if (INT_MULTIPLY_OVERFLOW (SCHARS (array), len) |
| 2180 | || SCHARS (array) * len != size_byte) | 2173 | || SCHARS (array) * len != size_byte) |
| @@ -2189,18 +2182,16 @@ ARRAY is a vector, string, char-table, or bool-vector. */) | |||
| 2189 | else if (BOOL_VECTOR_P (array)) | 2182 | else if (BOOL_VECTOR_P (array)) |
| 2190 | { | 2183 | { |
| 2191 | register unsigned char *p = XBOOL_VECTOR (array)->data; | 2184 | register unsigned char *p = XBOOL_VECTOR (array)->data; |
| 2192 | EMACS_INT size_in_chars; | 2185 | size = |
| 2193 | size = XBOOL_VECTOR (array)->size; | 2186 | ((XBOOL_VECTOR (array)->size + BOOL_VECTOR_BITS_PER_CHAR - 1) |
| 2194 | size_in_chars | 2187 | / BOOL_VECTOR_BITS_PER_CHAR); |
| 2195 | = ((size + BOOL_VECTOR_BITS_PER_CHAR - 1) | ||
| 2196 | / BOOL_VECTOR_BITS_PER_CHAR); | ||
| 2197 | 2188 | ||
| 2198 | if (size_in_chars) | 2189 | if (size) |
| 2199 | { | 2190 | { |
| 2200 | memset (p, ! NILP (item) ? -1 : 0, size_in_chars); | 2191 | memset (p, ! NILP (item) ? -1 : 0, size); |
| 2201 | 2192 | ||
| 2202 | /* Clear any extraneous bits in the last byte. */ | 2193 | /* Clear any extraneous bits in the last byte. */ |
| 2203 | p[size_in_chars - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; | 2194 | p[size - 1] &= (1 << (size % BOOL_VECTOR_BITS_PER_CHAR)) - 1; |
| 2204 | } | 2195 | } |
| 2205 | } | 2196 | } |
| 2206 | else | 2197 | else |
| @@ -2214,7 +2205,7 @@ DEFUN ("clear-string", Fclear_string, Sclear_string, | |||
| 2214 | This makes STRING unibyte and may change its length. */) | 2205 | This makes STRING unibyte and may change its length. */) |
| 2215 | (Lisp_Object string) | 2206 | (Lisp_Object string) |
| 2216 | { | 2207 | { |
| 2217 | EMACS_INT len; | 2208 | ptrdiff_t len; |
| 2218 | CHECK_STRING (string); | 2209 | CHECK_STRING (string); |
| 2219 | len = SBYTES (string); | 2210 | len = SBYTES (string); |
| 2220 | memset (SDATA (string), 0, len); | 2211 | memset (SDATA (string), 0, len); |
| @@ -2324,12 +2315,12 @@ mapcar1 (EMACS_INT leni, Lisp_Object *vals, Lisp_Object fn, Lisp_Object seq) | |||
| 2324 | } | 2315 | } |
| 2325 | else if (STRINGP (seq)) | 2316 | else if (STRINGP (seq)) |
| 2326 | { | 2317 | { |
| 2327 | EMACS_INT i_byte; | 2318 | ptrdiff_t i_byte; |
| 2328 | 2319 | ||
| 2329 | for (i = 0, i_byte = 0; i < leni;) | 2320 | for (i = 0, i_byte = 0; i < leni;) |
| 2330 | { | 2321 | { |
| 2331 | int c; | 2322 | int c; |
| 2332 | EMACS_INT i_before = i; | 2323 | ptrdiff_t i_before = i; |
| 2333 | 2324 | ||
| 2334 | FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte); | 2325 | FETCH_STRING_CHAR_ADVANCE (c, seq, i, i_byte); |
| 2335 | XSETFASTINT (dummy, c); | 2326 | XSETFASTINT (dummy, c); |
| @@ -2362,7 +2353,8 @@ SEQUENCE may be a list, a vector, a bool-vector, or a string. */) | |||
| 2362 | { | 2353 | { |
| 2363 | Lisp_Object len; | 2354 | Lisp_Object len; |
| 2364 | register EMACS_INT leni; | 2355 | register EMACS_INT leni; |
| 2365 | ptrdiff_t i, nargs; | 2356 | EMACS_INT nargs; |
| 2357 | ptrdiff_t i; | ||
| 2366 | register Lisp_Object *args; | 2358 | register Lisp_Object *args; |
| 2367 | struct gcpro gcpro1; | 2359 | struct gcpro gcpro1; |
| 2368 | Lisp_Object ret; | 2360 | Lisp_Object ret; |
| @@ -2649,7 +2641,7 @@ The normal messages at start and end of loading FILENAME are suppressed. */) | |||
| 2649 | 2641 | ||
| 2650 | if (NILP (tem)) | 2642 | if (NILP (tem)) |
| 2651 | { | 2643 | { |
| 2652 | int count = SPECPDL_INDEX (); | 2644 | ptrdiff_t count = SPECPDL_INDEX (); |
| 2653 | int nesting = 0; | 2645 | int nesting = 0; |
| 2654 | 2646 | ||
| 2655 | /* This is to make sure that loadup.el gives a clear picture | 2647 | /* This is to make sure that loadup.el gives a clear picture |
| @@ -2952,9 +2944,9 @@ static const short base64_char_to_value[128] = | |||
| 2952 | base64 characters. */ | 2944 | base64 characters. */ |
| 2953 | 2945 | ||
| 2954 | 2946 | ||
| 2955 | static EMACS_INT base64_encode_1 (const char *, char *, EMACS_INT, int, int); | 2947 | static ptrdiff_t base64_encode_1 (const char *, char *, ptrdiff_t, int, int); |
| 2956 | static EMACS_INT base64_decode_1 (const char *, char *, EMACS_INT, int, | 2948 | static ptrdiff_t base64_decode_1 (const char *, char *, ptrdiff_t, int, |
| 2957 | EMACS_INT *); | 2949 | ptrdiff_t *); |
| 2958 | 2950 | ||
| 2959 | DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region, | 2951 | DEFUN ("base64-encode-region", Fbase64_encode_region, Sbase64_encode_region, |
| 2960 | 2, 3, "r", | 2952 | 2, 3, "r", |
| @@ -2965,9 +2957,9 @@ into shorter lines. */) | |||
| 2965 | (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break) | 2957 | (Lisp_Object beg, Lisp_Object end, Lisp_Object no_line_break) |
| 2966 | { | 2958 | { |
| 2967 | char *encoded; | 2959 | char *encoded; |
| 2968 | EMACS_INT allength, length; | 2960 | ptrdiff_t allength, length; |
| 2969 | EMACS_INT ibeg, iend, encoded_length; | 2961 | ptrdiff_t ibeg, iend, encoded_length; |
| 2970 | EMACS_INT old_pos = PT; | 2962 | ptrdiff_t old_pos = PT; |
| 2971 | USE_SAFE_ALLOCA; | 2963 | USE_SAFE_ALLOCA; |
| 2972 | 2964 | ||
| 2973 | validate_region (&beg, &end); | 2965 | validate_region (&beg, &end); |
| @@ -3023,7 +3015,7 @@ Optional second argument NO-LINE-BREAK means do not break long lines | |||
| 3023 | into shorter lines. */) | 3015 | into shorter lines. */) |
| 3024 | (Lisp_Object string, Lisp_Object no_line_break) | 3016 | (Lisp_Object string, Lisp_Object no_line_break) |
| 3025 | { | 3017 | { |
| 3026 | EMACS_INT allength, length, encoded_length; | 3018 | ptrdiff_t allength, length, encoded_length; |
| 3027 | char *encoded; | 3019 | char *encoded; |
| 3028 | Lisp_Object encoded_string; | 3020 | Lisp_Object encoded_string; |
| 3029 | USE_SAFE_ALLOCA; | 3021 | USE_SAFE_ALLOCA; |
| @@ -3059,12 +3051,12 @@ into shorter lines. */) | |||
| 3059 | return encoded_string; | 3051 | return encoded_string; |
| 3060 | } | 3052 | } |
| 3061 | 3053 | ||
| 3062 | static EMACS_INT | 3054 | static ptrdiff_t |
| 3063 | base64_encode_1 (const char *from, char *to, EMACS_INT length, | 3055 | base64_encode_1 (const char *from, char *to, ptrdiff_t length, |
| 3064 | int line_break, int multibyte) | 3056 | int line_break, int multibyte) |
| 3065 | { | 3057 | { |
| 3066 | int counter = 0; | 3058 | int counter = 0; |
| 3067 | EMACS_INT i = 0; | 3059 | ptrdiff_t i = 0; |
| 3068 | char *e = to; | 3060 | char *e = to; |
| 3069 | int c; | 3061 | int c; |
| 3070 | unsigned int value; | 3062 | unsigned int value; |
| @@ -3163,11 +3155,11 @@ Return the length of the decoded text. | |||
| 3163 | If the region can't be decoded, signal an error and don't modify the buffer. */) | 3155 | If the region can't be decoded, signal an error and don't modify the buffer. */) |
| 3164 | (Lisp_Object beg, Lisp_Object end) | 3156 | (Lisp_Object beg, Lisp_Object end) |
| 3165 | { | 3157 | { |
| 3166 | EMACS_INT ibeg, iend, length, allength; | 3158 | ptrdiff_t ibeg, iend, length, allength; |
| 3167 | char *decoded; | 3159 | char *decoded; |
| 3168 | EMACS_INT old_pos = PT; | 3160 | ptrdiff_t old_pos = PT; |
| 3169 | EMACS_INT decoded_length; | 3161 | ptrdiff_t decoded_length; |
| 3170 | EMACS_INT inserted_chars; | 3162 | ptrdiff_t inserted_chars; |
| 3171 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); | 3163 | int multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters)); |
| 3172 | USE_SAFE_ALLOCA; | 3164 | USE_SAFE_ALLOCA; |
| 3173 | 3165 | ||
| @@ -3225,7 +3217,7 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, | |||
| 3225 | (Lisp_Object string) | 3217 | (Lisp_Object string) |
| 3226 | { | 3218 | { |
| 3227 | char *decoded; | 3219 | char *decoded; |
| 3228 | EMACS_INT length, decoded_length; | 3220 | ptrdiff_t length, decoded_length; |
| 3229 | Lisp_Object decoded_string; | 3221 | Lisp_Object decoded_string; |
| 3230 | USE_SAFE_ALLOCA; | 3222 | USE_SAFE_ALLOCA; |
| 3231 | 3223 | ||
| @@ -3257,15 +3249,15 @@ DEFUN ("base64-decode-string", Fbase64_decode_string, Sbase64_decode_string, | |||
| 3257 | form. If NCHARS_RETRUN is not NULL, store the number of produced | 3249 | form. If NCHARS_RETRUN is not NULL, store the number of produced |
| 3258 | characters in *NCHARS_RETURN. */ | 3250 | characters in *NCHARS_RETURN. */ |
| 3259 | 3251 | ||
| 3260 | static EMACS_INT | 3252 | static ptrdiff_t |
| 3261 | base64_decode_1 (const char *from, char *to, EMACS_INT length, | 3253 | base64_decode_1 (const char *from, char *to, ptrdiff_t length, |
| 3262 | int multibyte, EMACS_INT *nchars_return) | 3254 | int multibyte, ptrdiff_t *nchars_return) |
| 3263 | { | 3255 | { |
| 3264 | EMACS_INT i = 0; /* Used inside READ_QUADRUPLET_BYTE */ | 3256 | ptrdiff_t i = 0; /* Used inside READ_QUADRUPLET_BYTE */ |
| 3265 | char *e = to; | 3257 | char *e = to; |
| 3266 | unsigned char c; | 3258 | unsigned char c; |
| 3267 | unsigned long value; | 3259 | unsigned long value; |
| 3268 | EMACS_INT nchars = 0; | 3260 | ptrdiff_t nchars = 0; |
| 3269 | 3261 | ||
| 3270 | while (1) | 3262 | while (1) |
| 3271 | { | 3263 | { |
| @@ -3432,23 +3424,31 @@ get_key_arg (Lisp_Object key, ptrdiff_t nargs, Lisp_Object *args, char *used) | |||
| 3432 | 3424 | ||
| 3433 | 3425 | ||
| 3434 | /* Return a Lisp vector which has the same contents as VEC but has | 3426 | /* Return a Lisp vector which has the same contents as VEC but has |
| 3435 | size NEW_SIZE, NEW_SIZE >= VEC->size. Entries in the resulting | 3427 | at least INCR_MIN more entries, where INCR_MIN is positive. |
| 3436 | vector that are not copied from VEC are set to INIT. */ | 3428 | If NITEMS_MAX is not -1, do not grow the vector to be any larger |
| 3429 | than NITEMS_MAX. Entries in the resulting | ||
| 3430 | vector that are not copied from VEC are set to nil. */ | ||
| 3437 | 3431 | ||
| 3438 | Lisp_Object | 3432 | Lisp_Object |
| 3439 | larger_vector (Lisp_Object vec, EMACS_INT new_size, Lisp_Object init) | 3433 | larger_vector (Lisp_Object vec, ptrdiff_t incr_min, ptrdiff_t size_max) |
| 3440 | { | 3434 | { |
| 3441 | struct Lisp_Vector *v; | 3435 | struct Lisp_Vector *v; |
| 3442 | EMACS_INT i, old_size; | 3436 | ptrdiff_t i, incr, incr_max, old_size, new_size; |
| 3443 | 3437 | ptrdiff_t C_language_max = min (PTRDIFF_MAX, SIZE_MAX) / sizeof *v->contents; | |
| 3438 | ptrdiff_t n_max = (0 <= size_max && size_max < C_language_max | ||
| 3439 | ? size_max : C_language_max); | ||
| 3444 | xassert (VECTORP (vec)); | 3440 | xassert (VECTORP (vec)); |
| 3441 | xassert (0 < incr_min && -1 <= size_max); | ||
| 3445 | old_size = ASIZE (vec); | 3442 | old_size = ASIZE (vec); |
| 3446 | xassert (new_size >= old_size); | 3443 | incr_max = n_max - old_size; |
| 3447 | 3444 | incr = max (incr_min, min (old_size >> 1, incr_max)); | |
| 3445 | if (incr_max < incr) | ||
| 3446 | memory_full (SIZE_MAX); | ||
| 3447 | new_size = old_size + incr; | ||
| 3448 | v = allocate_vector (new_size); | 3448 | v = allocate_vector (new_size); |
| 3449 | memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); | 3449 | memcpy (v->contents, XVECTOR (vec)->contents, old_size * sizeof *v->contents); |
| 3450 | for (i = old_size; i < new_size; ++i) | 3450 | for (i = old_size; i < new_size; ++i) |
| 3451 | v->contents[i] = init; | 3451 | v->contents[i] = Qnil; |
| 3452 | XSETVECTOR (vec, v); | 3452 | XSETVECTOR (vec, v); |
| 3453 | return vec; | 3453 | return vec; |
| 3454 | } | 3454 | } |
| @@ -3569,6 +3569,10 @@ hashfn_user_defined (struct Lisp_Hash_Table *h, Lisp_Object key) | |||
| 3569 | return XUINT (hash); | 3569 | return XUINT (hash); |
| 3570 | } | 3570 | } |
| 3571 | 3571 | ||
| 3572 | /* An upper bound on the size of a hash table index. It must fit in | ||
| 3573 | ptrdiff_t and be a valid Emacs fixnum. */ | ||
| 3574 | #define INDEX_SIZE_BOUND \ | ||
| 3575 | ((ptrdiff_t) min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX / sizeof (Lisp_Object))) | ||
| 3572 | 3576 | ||
| 3573 | /* Create and initialize a new hash table. | 3577 | /* Create and initialize a new hash table. |
| 3574 | 3578 | ||
| @@ -3599,7 +3603,8 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size, | |||
| 3599 | { | 3603 | { |
| 3600 | struct Lisp_Hash_Table *h; | 3604 | struct Lisp_Hash_Table *h; |
| 3601 | Lisp_Object table; | 3605 | Lisp_Object table; |
| 3602 | EMACS_INT index_size, i, sz; | 3606 | EMACS_INT index_size, sz; |
| 3607 | ptrdiff_t i; | ||
| 3603 | double index_float; | 3608 | double index_float; |
| 3604 | 3609 | ||
| 3605 | /* Preconditions. */ | 3610 | /* Preconditions. */ |
| @@ -3616,10 +3621,10 @@ make_hash_table (Lisp_Object test, Lisp_Object size, Lisp_Object rehash_size, | |||
| 3616 | 3621 | ||
| 3617 | sz = XFASTINT (size); | 3622 | sz = XFASTINT (size); |
| 3618 | index_float = sz / XFLOAT_DATA (rehash_threshold); | 3623 | index_float = sz / XFLOAT_DATA (rehash_threshold); |
| 3619 | index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 | 3624 | index_size = (index_float < INDEX_SIZE_BOUND + 1 |
| 3620 | ? next_almost_prime (index_float) | 3625 | ? next_almost_prime (index_float) |
| 3621 | : MOST_POSITIVE_FIXNUM + 1); | 3626 | : INDEX_SIZE_BOUND + 1); |
| 3622 | if (MOST_POSITIVE_FIXNUM < max (index_size, 2 * sz)) | 3627 | if (INDEX_SIZE_BOUND < max (index_size, 2 * sz)) |
| 3623 | error ("Hash table too large"); | 3628 | error ("Hash table too large"); |
| 3624 | 3629 | ||
| 3625 | /* Allocate a table and initialize it. */ | 3630 | /* Allocate a table and initialize it. */ |
| @@ -3720,9 +3725,9 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 3720 | { | 3725 | { |
| 3721 | if (NILP (h->next_free)) | 3726 | if (NILP (h->next_free)) |
| 3722 | { | 3727 | { |
| 3723 | EMACS_INT old_size = HASH_TABLE_SIZE (h); | 3728 | ptrdiff_t old_size = HASH_TABLE_SIZE (h); |
| 3724 | EMACS_INT i, new_size, index_size; | 3729 | EMACS_INT new_size, index_size, nsize; |
| 3725 | EMACS_INT nsize; | 3730 | ptrdiff_t i; |
| 3726 | double index_float; | 3731 | double index_float; |
| 3727 | 3732 | ||
| 3728 | if (INTEGERP (h->rehash_size)) | 3733 | if (INTEGERP (h->rehash_size)) |
| @@ -3730,26 +3735,27 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 3730 | else | 3735 | else |
| 3731 | { | 3736 | { |
| 3732 | double float_new_size = old_size * XFLOAT_DATA (h->rehash_size); | 3737 | double float_new_size = old_size * XFLOAT_DATA (h->rehash_size); |
| 3733 | if (float_new_size < MOST_POSITIVE_FIXNUM + 1) | 3738 | if (float_new_size < INDEX_SIZE_BOUND + 1) |
| 3734 | { | 3739 | { |
| 3735 | new_size = float_new_size; | 3740 | new_size = float_new_size; |
| 3736 | if (new_size <= old_size) | 3741 | if (new_size <= old_size) |
| 3737 | new_size = old_size + 1; | 3742 | new_size = old_size + 1; |
| 3738 | } | 3743 | } |
| 3739 | else | 3744 | else |
| 3740 | new_size = MOST_POSITIVE_FIXNUM + 1; | 3745 | new_size = INDEX_SIZE_BOUND + 1; |
| 3741 | } | 3746 | } |
| 3742 | index_float = new_size / XFLOAT_DATA (h->rehash_threshold); | 3747 | index_float = new_size / XFLOAT_DATA (h->rehash_threshold); |
| 3743 | index_size = (index_float < MOST_POSITIVE_FIXNUM + 1 | 3748 | index_size = (index_float < INDEX_SIZE_BOUND + 1 |
| 3744 | ? next_almost_prime (index_float) | 3749 | ? next_almost_prime (index_float) |
| 3745 | : MOST_POSITIVE_FIXNUM + 1); | 3750 | : INDEX_SIZE_BOUND + 1); |
| 3746 | nsize = max (index_size, 2 * new_size); | 3751 | nsize = max (index_size, 2 * new_size); |
| 3747 | if (nsize > MOST_POSITIVE_FIXNUM) | 3752 | if (INDEX_SIZE_BOUND < nsize) |
| 3748 | error ("Hash table too large to resize"); | 3753 | error ("Hash table too large to resize"); |
| 3749 | 3754 | ||
| 3750 | h->key_and_value = larger_vector (h->key_and_value, 2 * new_size, Qnil); | 3755 | h->key_and_value = larger_vector (h->key_and_value, |
| 3751 | h->next = larger_vector (h->next, new_size, Qnil); | 3756 | 2 * (new_size - old_size), -1); |
| 3752 | h->hash = larger_vector (h->hash, new_size, Qnil); | 3757 | h->next = larger_vector (h->next, new_size - old_size, -1); |
| 3758 | h->hash = larger_vector (h->hash, new_size - old_size, -1); | ||
| 3753 | h->index = Fmake_vector (make_number (index_size), Qnil); | 3759 | h->index = Fmake_vector (make_number (index_size), Qnil); |
| 3754 | 3760 | ||
| 3755 | /* Update the free list. Do it so that new entries are added at | 3761 | /* Update the free list. Do it so that new entries are added at |
| @@ -3777,7 +3783,7 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) | |||
| 3777 | if (!NILP (HASH_HASH (h, i))) | 3783 | if (!NILP (HASH_HASH (h, i))) |
| 3778 | { | 3784 | { |
| 3779 | EMACS_UINT hash_code = XUINT (HASH_HASH (h, i)); | 3785 | EMACS_UINT hash_code = XUINT (HASH_HASH (h, i)); |
| 3780 | EMACS_INT start_of_bucket = hash_code % ASIZE (h->index); | 3786 | ptrdiff_t start_of_bucket = hash_code % ASIZE (h->index); |
| 3781 | HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket); | 3787 | HASH_NEXT (h, i) = HASH_INDEX (h, start_of_bucket); |
| 3782 | HASH_INDEX (h, start_of_bucket) = make_number (i); | 3788 | HASH_INDEX (h, start_of_bucket) = make_number (i); |
| 3783 | } | 3789 | } |
| @@ -3806,7 +3812,7 @@ hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash) | |||
| 3806 | /* We need not gcpro idx since it's either an integer or nil. */ | 3812 | /* We need not gcpro idx since it's either an integer or nil. */ |
| 3807 | while (!NILP (idx)) | 3813 | while (!NILP (idx)) |
| 3808 | { | 3814 | { |
| 3809 | EMACS_INT i = XFASTINT (idx); | 3815 | ptrdiff_t i = XFASTINT (idx); |
| 3810 | if (EQ (key, HASH_KEY (h, i)) | 3816 | if (EQ (key, HASH_KEY (h, i)) |
| 3811 | || (h->cmpfn | 3817 | || (h->cmpfn |
| 3812 | && h->cmpfn (h, key, hash_code, | 3818 | && h->cmpfn (h, key, hash_code, |
| @@ -3858,7 +3864,7 @@ static void | |||
| 3858 | hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) | 3864 | hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) |
| 3859 | { | 3865 | { |
| 3860 | EMACS_UINT hash_code; | 3866 | EMACS_UINT hash_code; |
| 3861 | EMACS_INT start_of_bucket; | 3867 | ptrdiff_t start_of_bucket; |
| 3862 | Lisp_Object idx, prev; | 3868 | Lisp_Object idx, prev; |
| 3863 | 3869 | ||
| 3864 | hash_code = h->hashfn (h, key); | 3870 | hash_code = h->hashfn (h, key); |
| @@ -3869,7 +3875,7 @@ hash_remove_from_table (struct Lisp_Hash_Table *h, Lisp_Object key) | |||
| 3869 | /* We need not gcpro idx, prev since they're either integers or nil. */ | 3875 | /* We need not gcpro idx, prev since they're either integers or nil. */ |
| 3870 | while (!NILP (idx)) | 3876 | while (!NILP (idx)) |
| 3871 | { | 3877 | { |
| 3872 | EMACS_INT i = XFASTINT (idx); | 3878 | ptrdiff_t i = XFASTINT (idx); |
| 3873 | 3879 | ||
| 3874 | if (EQ (key, HASH_KEY (h, i)) | 3880 | if (EQ (key, HASH_KEY (h, i)) |
| 3875 | || (h->cmpfn | 3881 | || (h->cmpfn |
| @@ -3907,7 +3913,7 @@ hash_clear (struct Lisp_Hash_Table *h) | |||
| 3907 | { | 3913 | { |
| 3908 | if (h->count > 0) | 3914 | if (h->count > 0) |
| 3909 | { | 3915 | { |
| 3910 | EMACS_INT i, size = HASH_TABLE_SIZE (h); | 3916 | ptrdiff_t i, size = HASH_TABLE_SIZE (h); |
| 3911 | 3917 | ||
| 3912 | for (i = 0; i < size; ++i) | 3918 | for (i = 0; i < size; ++i) |
| 3913 | { | 3919 | { |
| @@ -3945,7 +3951,7 @@ init_weak_hash_tables (void) | |||
| 3945 | static int | 3951 | static int |
| 3946 | sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p) | 3952 | sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p) |
| 3947 | { | 3953 | { |
| 3948 | EMACS_INT bucket, n; | 3954 | ptrdiff_t bucket, n; |
| 3949 | int marked; | 3955 | int marked; |
| 3950 | 3956 | ||
| 3951 | n = ASIZE (h->index) & ~ARRAY_MARK_FLAG; | 3957 | n = ASIZE (h->index) & ~ARRAY_MARK_FLAG; |
| @@ -3960,7 +3966,7 @@ sweep_weak_table (struct Lisp_Hash_Table *h, int remove_entries_p) | |||
| 3960 | prev = Qnil; | 3966 | prev = Qnil; |
| 3961 | for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next) | 3967 | for (idx = HASH_INDEX (h, bucket); !NILP (idx); idx = next) |
| 3962 | { | 3968 | { |
| 3963 | EMACS_INT i = XFASTINT (idx); | 3969 | ptrdiff_t i = XFASTINT (idx); |
| 3964 | int key_known_to_survive_p = survives_gc_p (HASH_KEY (h, i)); | 3970 | int key_known_to_survive_p = survives_gc_p (HASH_KEY (h, i)); |
| 3965 | int value_known_to_survive_p = survives_gc_p (HASH_VALUE (h, i)); | 3971 | int value_known_to_survive_p = survives_gc_p (HASH_VALUE (h, i)); |
| 3966 | int remove_p; | 3972 | int remove_p; |
| @@ -4526,7 +4532,7 @@ FUNCTION is called with two arguments, KEY and VALUE. */) | |||
| 4526 | { | 4532 | { |
| 4527 | struct Lisp_Hash_Table *h = check_hash_table (table); | 4533 | struct Lisp_Hash_Table *h = check_hash_table (table); |
| 4528 | Lisp_Object args[3]; | 4534 | Lisp_Object args[3]; |
| 4529 | EMACS_INT i; | 4535 | ptrdiff_t i; |
| 4530 | 4536 | ||
| 4531 | for (i = 0; i < HASH_TABLE_SIZE (h); ++i) | 4537 | for (i = 0; i < HASH_TABLE_SIZE (h); ++i) |
| 4532 | if (!NILP (HASH_HASH (h, i))) | 4538 | if (!NILP (HASH_HASH (h, i))) |
| @@ -4575,10 +4581,9 @@ static Lisp_Object | |||
| 4575 | secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) | 4581 | secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_Object end, Lisp_Object coding_system, Lisp_Object noerror, Lisp_Object binary) |
| 4576 | { | 4582 | { |
| 4577 | int i; | 4583 | int i; |
| 4578 | EMACS_INT size; | 4584 | ptrdiff_t size; |
| 4579 | EMACS_INT size_byte = 0; | ||
| 4580 | EMACS_INT start_char = 0, end_char = 0; | 4585 | EMACS_INT start_char = 0, end_char = 0; |
| 4581 | EMACS_INT start_byte = 0, end_byte = 0; | 4586 | ptrdiff_t start_byte, end_byte; |
| 4582 | register EMACS_INT b, e; | 4587 | register EMACS_INT b, e; |
| 4583 | register struct buffer *bp; | 4588 | register struct buffer *bp; |
| 4584 | EMACS_INT temp; | 4589 | EMACS_INT temp; |
| @@ -4615,7 +4620,6 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ | |||
| 4615 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 1); | 4620 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 1); |
| 4616 | 4621 | ||
| 4617 | size = SCHARS (object); | 4622 | size = SCHARS (object); |
| 4618 | size_byte = SBYTES (object); | ||
| 4619 | 4623 | ||
| 4620 | if (!NILP (start)) | 4624 | if (!NILP (start)) |
| 4621 | { | 4625 | { |
| @@ -4625,15 +4629,10 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ | |||
| 4625 | 4629 | ||
| 4626 | if (start_char < 0) | 4630 | if (start_char < 0) |
| 4627 | start_char += size; | 4631 | start_char += size; |
| 4628 | |||
| 4629 | start_byte = string_char_to_byte (object, start_char); | ||
| 4630 | } | 4632 | } |
| 4631 | 4633 | ||
| 4632 | if (NILP (end)) | 4634 | if (NILP (end)) |
| 4633 | { | 4635 | end_char = size; |
| 4634 | end_char = size; | ||
| 4635 | end_byte = size_byte; | ||
| 4636 | } | ||
| 4637 | else | 4636 | else |
| 4638 | { | 4637 | { |
| 4639 | CHECK_NUMBER (end); | 4638 | CHECK_NUMBER (end); |
| @@ -4642,13 +4641,15 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ | |||
| 4642 | 4641 | ||
| 4643 | if (end_char < 0) | 4642 | if (end_char < 0) |
| 4644 | end_char += size; | 4643 | end_char += size; |
| 4645 | |||
| 4646 | end_byte = string_char_to_byte (object, end_char); | ||
| 4647 | } | 4644 | } |
| 4648 | 4645 | ||
| 4649 | if (!(0 <= start_char && start_char <= end_char && end_char <= size)) | 4646 | if (!(0 <= start_char && start_char <= end_char && end_char <= size)) |
| 4650 | args_out_of_range_3 (object, make_number (start_char), | 4647 | args_out_of_range_3 (object, make_number (start_char), |
| 4651 | make_number (end_char)); | 4648 | make_number (end_char)); |
| 4649 | |||
| 4650 | start_byte = NILP (start) ? 0 : string_char_to_byte (object, start_char); | ||
| 4651 | end_byte = | ||
| 4652 | NILP (end) ? SBYTES (object) : string_char_to_byte (object, end_char); | ||
| 4652 | } | 4653 | } |
| 4653 | else | 4654 | else |
| 4654 | { | 4655 | { |
| @@ -4755,6 +4756,8 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ | |||
| 4755 | 4756 | ||
| 4756 | if (STRING_MULTIBYTE (object)) | 4757 | if (STRING_MULTIBYTE (object)) |
| 4757 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 0); | 4758 | object = code_convert_string (object, coding_system, Qnil, 1, 0, 0); |
| 4759 | start_byte = 0; | ||
| 4760 | end_byte = SBYTES (object); | ||
| 4758 | } | 4761 | } |
| 4759 | 4762 | ||
| 4760 | if (EQ (algorithm, Qmd5)) | 4763 | if (EQ (algorithm, Qmd5)) |
| @@ -4795,7 +4798,7 @@ secure_hash (Lisp_Object algorithm, Lisp_Object object, Lisp_Object start, Lisp_ | |||
| 4795 | digest = make_uninit_string (digest_size * 2); | 4798 | digest = make_uninit_string (digest_size * 2); |
| 4796 | 4799 | ||
| 4797 | hash_func (SSDATA (object) + start_byte, | 4800 | hash_func (SSDATA (object) + start_byte, |
| 4798 | SBYTES (object) - (size_byte - end_byte), | 4801 | end_byte - start_byte, |
| 4799 | SSDATA (digest)); | 4802 | SSDATA (digest)); |
| 4800 | 4803 | ||
| 4801 | if (NILP (binary)) | 4804 | if (NILP (binary)) |