diff options
| author | Paul Eggert | 2018-09-04 19:14:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-09-04 19:15:57 -0700 |
| commit | ecb985c10d5241a65ab9552ebfcecaa150b35427 (patch) | |
| tree | c4f12a76561d84518c597cb8e25cfd3813023456 /src | |
| parent | e3661f8c35b3057c58e8c0b474f597697ce413ba (diff) | |
| download | emacs-ecb985c10d5241a65ab9552ebfcecaa150b35427.tar.gz emacs-ecb985c10d5241a65ab9552ebfcecaa150b35427.zip | |
Simplify bignum->intmax conversion
* src/lisp.h (integer_to_intmax, integer_to_uintmax): New functions.
* src/data.c (cons_to_unsigned, cons_to_signed)
(arith_driver):
* src/dbusbind.c (xd_extract_signed, xd_extract_unsigned):
* src/dispnew.c (sit_for):
* src/editfns.c (styled_format):
* src/emacs-module.c (module_extract_integer):
* src/fileio.c (file_offset):
* src/font.c (font_unparse_xlfd, Fopen_font):
* src/xdisp.c (calc_line_height_property):
* src/process.c (handle_child_signal):
Diffstat (limited to 'src')
| -rw-r--r-- | src/data.c | 34 | ||||
| -rw-r--r-- | src/dbusbind.c | 30 | ||||
| -rw-r--r-- | src/dispnew.c | 26 | ||||
| -rw-r--r-- | src/editfns.c | 19 | ||||
| -rw-r--r-- | src/emacs-module.c | 12 | ||||
| -rw-r--r-- | src/fileio.c | 12 | ||||
| -rw-r--r-- | src/font.c | 19 | ||||
| -rw-r--r-- | src/lisp.h | 33 | ||||
| -rw-r--r-- | src/process.c | 5 | ||||
| -rw-r--r-- | src/xdisp.c | 8 |
10 files changed, 89 insertions, 109 deletions
diff --git a/src/data.c b/src/data.c index 7be2052362b..66f69e7e83a 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -2653,17 +2653,7 @@ cons_to_unsigned (Lisp_Object c, uintmax_t max) | |||
| 2653 | else | 2653 | else |
| 2654 | { | 2654 | { |
| 2655 | Lisp_Object hi = CONSP (c) ? XCAR (c) : c; | 2655 | Lisp_Object hi = CONSP (c) ? XCAR (c) : c; |
| 2656 | 2656 | valid = integer_to_uintmax (hi, &val); | |
| 2657 | if (FIXNUMP (hi)) | ||
| 2658 | { | ||
| 2659 | val = XFIXNUM (hi); | ||
| 2660 | valid = 0 <= val; | ||
| 2661 | } | ||
| 2662 | else | ||
| 2663 | { | ||
| 2664 | val = bignum_to_uintmax (hi); | ||
| 2665 | valid = val != 0; | ||
| 2666 | } | ||
| 2667 | 2657 | ||
| 2668 | if (valid && CONSP (c)) | 2658 | if (valid && CONSP (c)) |
| 2669 | { | 2659 | { |
| @@ -2724,17 +2714,7 @@ cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max) | |||
| 2724 | else | 2714 | else |
| 2725 | { | 2715 | { |
| 2726 | Lisp_Object hi = CONSP (c) ? XCAR (c) : c; | 2716 | Lisp_Object hi = CONSP (c) ? XCAR (c) : c; |
| 2727 | 2717 | valid = integer_to_intmax (hi, &val); | |
| 2728 | if (FIXNUMP (hi)) | ||
| 2729 | { | ||
| 2730 | val = XFIXNUM (hi); | ||
| 2731 | valid = true; | ||
| 2732 | } | ||
| 2733 | else if (BIGNUMP (hi)) | ||
| 2734 | { | ||
| 2735 | val = bignum_to_intmax (hi); | ||
| 2736 | valid = val != 0; | ||
| 2737 | } | ||
| 2738 | 2718 | ||
| 2739 | if (valid && CONSP (c)) | 2719 | if (valid && CONSP (c)) |
| 2740 | { | 2720 | { |
| @@ -2972,16 +2952,8 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args, | |||
| 2972 | 2952 | ||
| 2973 | /* Set NEXT to the next value if it fits, else exit the loop. */ | 2953 | /* Set NEXT to the next value if it fits, else exit the loop. */ |
| 2974 | intmax_t next; | 2954 | intmax_t next; |
| 2975 | if (FIXNUMP (val)) | 2955 | if (! (INTEGERP (val) && integer_to_intmax (val, &next))) |
| 2976 | next = XFIXNUM (val); | ||
| 2977 | else if (FLOATP (val)) | ||
| 2978 | break; | 2956 | break; |
| 2979 | else | ||
| 2980 | { | ||
| 2981 | next = bignum_to_intmax (val); | ||
| 2982 | if (next == 0) | ||
| 2983 | break; | ||
| 2984 | } | ||
| 2985 | 2957 | ||
| 2986 | /* Set ACCUM to the next operation's result if it fits, | 2958 | /* Set ACCUM to the next operation's result if it fits, |
| 2987 | else exit the loop. */ | 2959 | else exit the loop. */ |
diff --git a/src/dbusbind.c b/src/dbusbind.c index 47346a7d4d4..9bc344e9612 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -520,12 +520,13 @@ static intmax_t | |||
| 520 | xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | 520 | xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) |
| 521 | { | 521 | { |
| 522 | CHECK_NUMBER (x); | 522 | CHECK_NUMBER (x); |
| 523 | if (FIXNUMP (x)) | 523 | if (INTEGERP (x)) |
| 524 | { | 524 | { |
| 525 | if (lo <= XFIXNUM (x) && XFIXNUM (x) <= hi) | 525 | intmax_t i; |
| 526 | return XFIXNUM (x); | 526 | if (integer_to_intmax (x, &i) && lo <= i && i <= hi) |
| 527 | return i; | ||
| 527 | } | 528 | } |
| 528 | else if (FLOATP (x)) | 529 | else |
| 529 | { | 530 | { |
| 530 | double d = XFLOAT_DATA (x); | 531 | double d = XFLOAT_DATA (x); |
| 531 | if (lo <= d && d < 1.0 + hi) | 532 | if (lo <= d && d < 1.0 + hi) |
| @@ -535,12 +536,6 @@ xd_extract_signed (Lisp_Object x, intmax_t lo, intmax_t hi) | |||
| 535 | return n; | 536 | return n; |
| 536 | } | 537 | } |
| 537 | } | 538 | } |
| 538 | else if (! (MOST_NEGATIVE_FIXNUM <= lo && hi <= MOST_POSITIVE_FIXNUM)) | ||
| 539 | { | ||
| 540 | intmax_t i = bignum_to_intmax (x); | ||
| 541 | if (i != 0 && lo <= i && i <= hi) | ||
| 542 | return i; | ||
| 543 | } | ||
| 544 | 539 | ||
| 545 | if (xd_in_read_queued_messages) | 540 | if (xd_in_read_queued_messages) |
| 546 | Fthrow (Qdbus_error, Qnil); | 541 | Fthrow (Qdbus_error, Qnil); |
| @@ -553,12 +548,13 @@ static uintmax_t | |||
| 553 | xd_extract_unsigned (Lisp_Object x, uintmax_t hi) | 548 | xd_extract_unsigned (Lisp_Object x, uintmax_t hi) |
| 554 | { | 549 | { |
| 555 | CHECK_NUMBER (x); | 550 | CHECK_NUMBER (x); |
| 556 | if (FIXNUMP (x)) | 551 | if (INTEGERP (x)) |
| 557 | { | 552 | { |
| 558 | if (0 <= XFIXNUM (x) && XFIXNUM (x) <= hi) | 553 | uintmax_t i; |
| 559 | return XFIXNUM (x); | 554 | if (integer_to_uintmax (x, &i) && i <= hi) |
| 555 | return i; | ||
| 560 | } | 556 | } |
| 561 | else if (FLOATP (x)) | 557 | else |
| 562 | { | 558 | { |
| 563 | double d = XFLOAT_DATA (x); | 559 | double d = XFLOAT_DATA (x); |
| 564 | if (0 <= d && d < 1.0 + hi) | 560 | if (0 <= d && d < 1.0 + hi) |
| @@ -568,12 +564,6 @@ xd_extract_unsigned (Lisp_Object x, uintmax_t hi) | |||
| 568 | return n; | 564 | return n; |
| 569 | } | 565 | } |
| 570 | } | 566 | } |
| 571 | else if (! (hi <= MOST_POSITIVE_FIXNUM)) | ||
| 572 | { | ||
| 573 | uintmax_t i = bignum_to_uintmax (x); | ||
| 574 | if (i != 0 && i <= hi) | ||
| 575 | return i; | ||
| 576 | } | ||
| 577 | 567 | ||
| 578 | if (xd_in_read_queued_messages) | 568 | if (xd_in_read_queued_messages) |
| 579 | Fthrow (Qdbus_error, Qnil); | 569 | Fthrow (Qdbus_error, Qnil); |
diff --git a/src/dispnew.c b/src/dispnew.c index bd246799b23..798413d091c 100644 --- a/src/dispnew.c +++ b/src/dispnew.c | |||
| @@ -5765,20 +5765,20 @@ sit_for (Lisp_Object timeout, bool reading, int display_option) | |||
| 5765 | if (display_option > 1) | 5765 | if (display_option > 1) |
| 5766 | redisplay_preserve_echo_area (2); | 5766 | redisplay_preserve_echo_area (2); |
| 5767 | 5767 | ||
| 5768 | if (FIXNUMP (timeout)) | 5768 | if (INTEGERP (timeout)) |
| 5769 | { | 5769 | { |
| 5770 | sec = XFIXNUM (timeout); | 5770 | if (integer_to_intmax (timeout, &sec)) |
| 5771 | if (sec <= 0) | 5771 | { |
| 5772 | return Qt; | 5772 | if (sec <= 0) |
| 5773 | nsec = 0; | 5773 | return Qt; |
| 5774 | } | 5774 | sec = min (sec, WAIT_READING_MAX); |
| 5775 | else if (BIGNUMP (timeout)) | 5775 | } |
| 5776 | { | 5776 | else |
| 5777 | if (NILP (Fnatnump (timeout))) | 5777 | { |
| 5778 | return Qt; | 5778 | if (NILP (Fnatnump (timeout))) |
| 5779 | sec = bignum_to_intmax (timeout); | 5779 | return Qt; |
| 5780 | if (sec == 0) | 5780 | sec = WAIT_READING_MAX; |
| 5781 | sec = WAIT_READING_MAX; | 5781 | } |
| 5782 | nsec = 0; | 5782 | nsec = 0; |
| 5783 | } | 5783 | } |
| 5784 | else if (FLOATP (timeout)) | 5784 | else if (FLOATP (timeout)) |
diff --git a/src/editfns.c b/src/editfns.c index 3b1c21a1781..4ea70253793 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -4691,21 +4691,16 @@ styled_format (ptrdiff_t nargs, Lisp_Object *args, bool message) | |||
| 4691 | } | 4691 | } |
| 4692 | else | 4692 | else |
| 4693 | { | 4693 | { |
| 4694 | if (FIXNUMP (arg)) | 4694 | if (INTEGERP (arg)) |
| 4695 | ldarg = XFIXNUM (arg); | ||
| 4696 | else | ||
| 4697 | { | 4695 | { |
| 4698 | intmax_t iarg = bignum_to_intmax (arg); | 4696 | intmax_t iarg; |
| 4699 | if (iarg != 0) | 4697 | uintmax_t uarg; |
| 4698 | if (integer_to_intmax (arg, &iarg)) | ||
| 4700 | ldarg = iarg; | 4699 | ldarg = iarg; |
| 4700 | else if (integer_to_uintmax (arg, &uarg)) | ||
| 4701 | ldarg = uarg; | ||
| 4701 | else | 4702 | else |
| 4702 | { | 4703 | format_bignum_as_double = true; |
| 4703 | uintmax_t uarg = bignum_to_uintmax (arg); | ||
| 4704 | if (uarg != 0) | ||
| 4705 | ldarg = uarg; | ||
| 4706 | else | ||
| 4707 | format_bignum_as_double = true; | ||
| 4708 | } | ||
| 4709 | } | 4704 | } |
| 4710 | if (!format_bignum_as_double) | 4705 | if (!format_bignum_as_double) |
| 4711 | { | 4706 | { |
diff --git a/src/emacs-module.c b/src/emacs-module.c index 2ba5540d9a1..6155535f869 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -519,14 +519,10 @@ module_extract_integer (emacs_env *env, emacs_value n) | |||
| 519 | MODULE_FUNCTION_BEGIN (0); | 519 | MODULE_FUNCTION_BEGIN (0); |
| 520 | Lisp_Object l = value_to_lisp (n); | 520 | Lisp_Object l = value_to_lisp (n); |
| 521 | CHECK_INTEGER (l); | 521 | CHECK_INTEGER (l); |
| 522 | if (BIGNUMP (l)) | 522 | intmax_t i; |
| 523 | { | 523 | if (! integer_to_intmax (l, &i)) |
| 524 | intmax_t i = bignum_to_intmax (l); | 524 | xsignal1 (Qoverflow_error, l); |
| 525 | if (i == 0) | 525 | return i; |
| 526 | xsignal1 (Qoverflow_error, l); | ||
| 527 | return i; | ||
| 528 | } | ||
| 529 | return XFIXNUM (l); | ||
| 530 | } | 526 | } |
| 531 | 527 | ||
| 532 | static emacs_value | 528 | static emacs_value |
diff --git a/src/fileio.c b/src/fileio.c index a91bdaa53d1..66b23333172 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -3424,17 +3424,13 @@ read_non_regular_quit (Lisp_Object ignore) | |||
| 3424 | static off_t | 3424 | static off_t |
| 3425 | file_offset (Lisp_Object val) | 3425 | file_offset (Lisp_Object val) |
| 3426 | { | 3426 | { |
| 3427 | if (RANGED_FIXNUMP (0, val, TYPE_MAXIMUM (off_t))) | 3427 | if (INTEGERP (val)) |
| 3428 | return XFIXNUM (val); | ||
| 3429 | |||
| 3430 | if (BIGNUMP (val)) | ||
| 3431 | { | 3428 | { |
| 3432 | intmax_t v = bignum_to_intmax (val); | 3429 | intmax_t v; |
| 3433 | if (0 < v && v <= TYPE_MAXIMUM (off_t)) | 3430 | if (integer_to_intmax (val, &v) && 0 <= v && v <= TYPE_MAXIMUM (off_t)) |
| 3434 | return v; | 3431 | return v; |
| 3435 | } | 3432 | } |
| 3436 | 3433 | else if (FLOATP (val)) | |
| 3437 | if (FLOATP (val)) | ||
| 3438 | { | 3434 | { |
| 3439 | double v = XFLOAT_DATA (val); | 3435 | double v = XFLOAT_DATA (val); |
| 3440 | if (0 <= v && v < 1.0 + TYPE_MAXIMUM (off_t)) | 3436 | if (0 <= v && v < 1.0 + TYPE_MAXIMUM (off_t)) |
diff --git a/src/font.c b/src/font.c index e2414582f67..50ec39a9a49 100644 --- a/src/font.c +++ b/src/font.c | |||
| @@ -1289,8 +1289,9 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes) | |||
| 1289 | 1 + DBL_MAX_10_EXP + 1)]; | 1289 | 1 + DBL_MAX_10_EXP + 1)]; |
| 1290 | if (INTEGERP (val)) | 1290 | if (INTEGERP (val)) |
| 1291 | { | 1291 | { |
| 1292 | intmax_t v = FIXNUMP (val) ? XFIXNUM (val) : bignum_to_intmax (val); | 1292 | intmax_t v; |
| 1293 | if (! (0 < v && v <= TYPE_MAXIMUM (uprintmax_t))) | 1293 | if (! (integer_to_intmax (val, &v) |
| 1294 | && 0 < v && v <= TYPE_MAXIMUM (uprintmax_t))) | ||
| 1294 | v = pixel_size; | 1295 | v = pixel_size; |
| 1295 | if (v > 0) | 1296 | if (v > 0) |
| 1296 | { | 1297 | { |
| @@ -4747,16 +4748,10 @@ DEFUN ("open-font", Fopen_font, Sopen_font, 1, 3, 0, | |||
| 4747 | else | 4748 | else |
| 4748 | { | 4749 | { |
| 4749 | CHECK_NUMBER (size); | 4750 | CHECK_NUMBER (size); |
| 4750 | if (BIGNUMP (size)) | 4751 | if (FLOATP (size)) |
| 4751 | { | 4752 | isize = POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f)); |
| 4752 | isize = bignum_to_intmax (size); | 4753 | else if (! integer_to_intmax (size, &isize)) |
| 4753 | if (isize == 0) | 4754 | args_out_of_range (font_entity, size); |
| 4754 | args_out_of_range (font_entity, size); | ||
| 4755 | } | ||
| 4756 | else | ||
| 4757 | isize = (FLOATP (size) | ||
| 4758 | ? POINT_TO_PIXEL (XFLOAT_DATA (size), FRAME_RES_Y (f)) | ||
| 4759 | : XFIXNUM (size)); | ||
| 4760 | if (! (INT_MIN <= isize && isize <= INT_MAX)) | 4755 | if (! (INT_MIN <= isize && isize <= INT_MAX)) |
| 4761 | args_out_of_range (font_entity, size); | 4756 | args_out_of_range (font_entity, size); |
| 4762 | if (isize == 0) | 4757 | if (isize == 0) |
diff --git a/src/lisp.h b/src/lisp.h index d244bc02d4b..78c25f97dc8 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -3297,6 +3297,39 @@ extern Lisp_Object bignum_to_string (Lisp_Object, int); | |||
| 3297 | extern Lisp_Object make_bignum_str (char const *, int); | 3297 | extern Lisp_Object make_bignum_str (char const *, int); |
| 3298 | extern Lisp_Object double_to_bignum (double); | 3298 | extern Lisp_Object double_to_bignum (double); |
| 3299 | 3299 | ||
| 3300 | /* Converthe integer NUM to *N. Return true if successful, false | ||
| 3301 | (possibly setting *N) otherwise. */ | ||
| 3302 | INLINE bool | ||
| 3303 | integer_to_intmax (Lisp_Object num, intmax_t *n) | ||
| 3304 | { | ||
| 3305 | if (FIXNUMP (num)) | ||
| 3306 | { | ||
| 3307 | *n = XFIXNUM (num); | ||
| 3308 | return true; | ||
| 3309 | } | ||
| 3310 | else | ||
| 3311 | { | ||
| 3312 | intmax_t i = bignum_to_intmax (num); | ||
| 3313 | *n = i; | ||
| 3314 | return i != 0; | ||
| 3315 | } | ||
| 3316 | } | ||
| 3317 | INLINE bool | ||
| 3318 | integer_to_uintmax (Lisp_Object num, uintmax_t *n) | ||
| 3319 | { | ||
| 3320 | if (FIXNUMP (num)) | ||
| 3321 | { | ||
| 3322 | *n = XFIXNUM (num); | ||
| 3323 | return 0 <= XFIXNUM (num); | ||
| 3324 | } | ||
| 3325 | else | ||
| 3326 | { | ||
| 3327 | uintmax_t i = bignum_to_uintmax (num); | ||
| 3328 | *n = i; | ||
| 3329 | return i != 0; | ||
| 3330 | } | ||
| 3331 | } | ||
| 3332 | |||
| 3300 | /* Defined in data.c. */ | 3333 | /* Defined in data.c. */ |
| 3301 | extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object); | 3334 | extern _Noreturn void wrong_choice (Lisp_Object, Lisp_Object); |
| 3302 | extern void notify_variable_watchers (Lisp_Object, Lisp_Object, | 3335 | extern void notify_variable_watchers (Lisp_Object, Lisp_Object, |
diff --git a/src/process.c b/src/process.c index 9d03eb9774d..454278a5a27 100644 --- a/src/process.c +++ b/src/process.c | |||
| @@ -7055,8 +7055,9 @@ handle_child_signal (int sig) | |||
| 7055 | xpid = XCAR (head); | 7055 | xpid = XCAR (head); |
| 7056 | if (all_pids_are_fixnums ? FIXNUMP (xpid) : INTEGERP (xpid)) | 7056 | if (all_pids_are_fixnums ? FIXNUMP (xpid) : INTEGERP (xpid)) |
| 7057 | { | 7057 | { |
| 7058 | pid_t deleted_pid = (FIXNUMP (xpid) ? XFIXNUM (xpid) | 7058 | intmax_t deleted_pid; |
| 7059 | : bignum_to_intmax (xpid)); | 7059 | bool ok = integer_to_intmax (xpid, &deleted_pid); |
| 7060 | eassert (ok); | ||
| 7060 | if (child_status_changed (deleted_pid, 0, 0)) | 7061 | if (child_status_changed (deleted_pid, 0, 0)) |
| 7061 | { | 7062 | { |
| 7062 | if (STRINGP (XCDR (head))) | 7063 | if (STRINGP (XCDR (head))) |
diff --git a/src/xdisp.c b/src/xdisp.c index 04033665d76..47286e25c80 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -27910,10 +27910,12 @@ calc_line_height_property (struct it *it, Lisp_Object val, struct font *font, | |||
| 27910 | /* FIXME: Check for overflow in multiplication or conversion. */ | 27910 | /* FIXME: Check for overflow in multiplication or conversion. */ |
| 27911 | if (FLOATP (val)) | 27911 | if (FLOATP (val)) |
| 27912 | height = (int)(XFLOAT_DATA (val) * height); | 27912 | height = (int)(XFLOAT_DATA (val) * height); |
| 27913 | else if (FIXNUMP (val)) | ||
| 27914 | height *= XFIXNUM (val); | ||
| 27915 | else | 27913 | else |
| 27916 | height *= bignum_to_intmax (val); | 27914 | { |
| 27915 | intmax_t v; | ||
| 27916 | if (integer_to_intmax (val, &v)) | ||
| 27917 | height *= v; | ||
| 27918 | } | ||
| 27917 | 27919 | ||
| 27918 | return make_fixnum (height); | 27920 | return make_fixnum (height); |
| 27919 | } | 27921 | } |