diff options
| author | Paul Eggert | 2018-08-18 20:40:10 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-18 20:41:09 -0700 |
| commit | b1840206ff22359fc099236602928e0fb3828d66 (patch) | |
| tree | dc7a23519474955ed4efcbd975c79c0629a96a2b /src/alloc.c | |
| parent | 6eade1efde873d0b048d8f2841646924cb2ceb16 (diff) | |
| download | emacs-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/alloc.c')
| -rw-r--r-- | src/alloc.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/alloc.c b/src/alloc.c index 60850f73d51..ddc0696ba91 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3785,18 +3785,21 @@ make_number (mpz_t value) | |||
| 3785 | void | 3785 | void |
| 3786 | mpz_set_intmax_slow (mpz_t result, intmax_t v) | 3786 | mpz_set_intmax_slow (mpz_t result, intmax_t v) |
| 3787 | { | 3787 | { |
| 3788 | /* If long is larger then a faster path is taken. */ | 3788 | /* If V fits in long, a faster path is taken. */ |
| 3789 | eassert (sizeof (intmax_t) > sizeof (long)); | 3789 | eassert (! (LONG_MIN <= v && v <= LONG_MAX)); |
| 3790 | 3790 | ||
| 3791 | bool complement = v < 0; | 3791 | bool complement = v < 0; |
| 3792 | if (complement) | 3792 | if (complement) |
| 3793 | v = -1 - v; | 3793 | v = -1 - v; |
| 3794 | 3794 | ||
| 3795 | /* COUNT = 1 means just a single word of the given size. ORDER = -1 | 3795 | enum { nails = sizeof v * CHAR_BIT - INTMAX_WIDTH }; |
| 3796 | is arbitrary since there's only a single word. ENDIAN = 0 means | 3796 | # ifndef HAVE_GMP |
| 3797 | use the native endian-ness. NAILS = 0 means use the whole | 3797 | /* mini-gmp requires NAILS to be zero, which is true for all |
| 3798 | word. */ | 3798 | likely Emacs platforms. Sanity-check this. */ |
| 3799 | mpz_import (result, 1, -1, sizeof v, 0, 0, &v); | 3799 | verify (nails == 0); |
| 3800 | # endif | ||
| 3801 | |||
| 3802 | mpz_import (result, 1, -1, sizeof v, 0, nails, &v); | ||
| 3800 | if (complement) | 3803 | if (complement) |
| 3801 | mpz_com (result, result); | 3804 | mpz_com (result, result); |
| 3802 | } | 3805 | } |