aboutsummaryrefslogtreecommitdiffstats
path: root/src/data.c
diff options
context:
space:
mode:
authorPaul Eggert2018-08-18 20:40:10 -0700
committerPaul Eggert2018-08-18 20:41:09 -0700
commitb1840206ff22359fc099236602928e0fb3828d66 (patch)
treedc7a23519474955ed4efcbd975c79c0629a96a2b /src/data.c
parent6eade1efde873d0b048d8f2841646924cb2ceb16 (diff)
downloademacs-b1840206ff22359fc099236602928e0fb3828d66.tar.gz
emacs-b1840206ff22359fc099236602928e0fb3828d66.zip
Minor fixups for intmax_t→mpz_t conversion
* src/alloc.c (mpz_set_intmax_slow): Tighten assertion. Work even in the unlikely case where libgmp uses nails. * src/data.c (FIXNUMS_FIT_IN_LONG): New constant. (arith_driver): Use it to tighten compile-time checks. * src/lisp.h (mpz_set_intmax): Do not assume that converting an out-of-range value to ‘long’ is harmless, as it might raise a signal. Use simpler expression; compiler can optimize.
Diffstat (limited to 'src/data.c')
-rw-r--r--src/data.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/data.c b/src/data.c
index 0754d4c176d..7a8179ed38d 100644
--- a/src/data.c
+++ b/src/data.c
@@ -2775,6 +2775,9 @@ enum arithop
2775 Alogxor 2775 Alogxor
2776 }; 2776 };
2777 2777
2778enum { FIXNUMS_FIT_IN_LONG = (LONG_MIN <= MOST_NEGATIVE_FIXNUM
2779 && MOST_POSITIVE_FIXNUM <= LONG_MAX) };
2780
2778static void 2781static void
2779free_mpz_value (void *value_ptr) 2782free_mpz_value (void *value_ptr)
2780{ 2783{
@@ -2829,7 +2832,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
2829 case Aadd: 2832 case Aadd:
2830 if (BIGNUMP (val)) 2833 if (BIGNUMP (val))
2831 mpz_add (accum, accum, XBIGNUM (val)->value); 2834 mpz_add (accum, accum, XBIGNUM (val)->value);
2832 else if (sizeof (EMACS_INT) > sizeof (long)) 2835 else if (! FIXNUMS_FIT_IN_LONG)
2833 { 2836 {
2834 mpz_t tem; 2837 mpz_t tem;
2835 mpz_init (tem); 2838 mpz_init (tem);
@@ -2854,7 +2857,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
2854 } 2857 }
2855 else if (BIGNUMP (val)) 2858 else if (BIGNUMP (val))
2856 mpz_sub (accum, accum, XBIGNUM (val)->value); 2859 mpz_sub (accum, accum, XBIGNUM (val)->value);
2857 else if (sizeof (EMACS_INT) > sizeof (long)) 2860 else if (! FIXNUMS_FIT_IN_LONG)
2858 { 2861 {
2859 mpz_t tem; 2862 mpz_t tem;
2860 mpz_init (tem); 2863 mpz_init (tem);
@@ -2870,7 +2873,7 @@ arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args)
2870 case Amult: 2873 case Amult:
2871 if (BIGNUMP (val)) 2874 if (BIGNUMP (val))
2872 mpz_mul (accum, accum, XBIGNUM (val)->value); 2875 mpz_mul (accum, accum, XBIGNUM (val)->value);
2873 else if (sizeof (EMACS_INT) > sizeof (long)) 2876 else if (! FIXNUMS_FIT_IN_LONG)
2874 { 2877 {
2875 mpz_t tem; 2878 mpz_t tem;
2876 mpz_init (tem); 2879 mpz_init (tem);