diff options
| author | Tom Tromey | 2018-07-19 15:58:10 -0600 |
|---|---|---|
| committer | Tom Tromey | 2018-07-19 16:08:41 -0600 |
| commit | 76715f8921dca740880cd22c644a6328cd810846 (patch) | |
| tree | d85940e4c452575c453ab3ea6a7d0ec25b20f2ab /src/alloc.c | |
| parent | 678881e428073b39a906c1ffd01e1b76e271cb5d (diff) | |
| download | emacs-76715f8921dca740880cd22c644a6328cd810846.tar.gz emacs-76715f8921dca740880cd22c644a6328cd810846.zip | |
Fix bignum creation when EMACS_INT is wider than long
* src/alloc.c (mpz_set_intmax_slow, mpz_set_uintmax_slow): New
functions.
* src/data.c (arith_driver, Frem, Fmod, ash_lsh_impl, Fadd1)
(Fsub1): Use mpz_set_intmax, mpz_set_uintmax.
* src/emacs-module.c (module_make_integer): Use mpz_set_intmax.
* src/floatfns.c (Fabs): Use mpz_set_intmax.
* src/lisp.h (mpz_set_intmax, mpz_set_uintmax): New inline
functions.
(mpz_set_uintmax_slow, mpz_set_intmax_slow): Declare.
Diffstat (limited to 'src/alloc.c')
| -rw-r--r-- | src/alloc.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index b775948fd96..1dc1bbb031a 100644 --- a/src/alloc.c +++ b/src/alloc.c | |||
| @@ -3824,6 +3824,36 @@ make_number (mpz_t value) | |||
| 3824 | return obj; | 3824 | return obj; |
| 3825 | } | 3825 | } |
| 3826 | 3826 | ||
| 3827 | void | ||
| 3828 | mpz_set_intmax_slow (mpz_t result, intmax_t v) | ||
| 3829 | { | ||
| 3830 | /* If long is larger then a faster path is taken. */ | ||
| 3831 | eassert (sizeof (intmax_t) > sizeof (long)); | ||
| 3832 | |||
| 3833 | bool negate = false; | ||
| 3834 | if (v < 0) | ||
| 3835 | { | ||
| 3836 | v = -v; | ||
| 3837 | negate = true; | ||
| 3838 | } | ||
| 3839 | mpz_set_uintmax_slow (result, (uintmax_t) v); | ||
| 3840 | if (negate) | ||
| 3841 | mpz_neg (result, result); | ||
| 3842 | } | ||
| 3843 | |||
| 3844 | void | ||
| 3845 | mpz_set_uintmax_slow (mpz_t result, uintmax_t v) | ||
| 3846 | { | ||
| 3847 | /* If long is larger then a faster path is taken. */ | ||
| 3848 | eassert (sizeof (uintmax_t) > sizeof (unsigned long)); | ||
| 3849 | /* This restriction could be lifted if needed. */ | ||
| 3850 | eassert (sizeof (uintmax_t) <= 2 * sizeof (unsigned long)); | ||
| 3851 | |||
| 3852 | mpz_set_ui (result, v >> (CHAR_BIT * sizeof (unsigned long))); | ||
| 3853 | mpz_mul_2exp (result, result, CHAR_BIT * sizeof (unsigned long)); | ||
| 3854 | mpz_add_ui (result, result, v & -1ul); | ||
| 3855 | } | ||
| 3856 | |||
| 3827 | 3857 | ||
| 3828 | /* Return a newly created vector or string with specified arguments as | 3858 | /* Return a newly created vector or string with specified arguments as |
| 3829 | elements. If all the arguments are characters that can fit | 3859 | elements. If all the arguments are characters that can fit |