aboutsummaryrefslogtreecommitdiffstats
path: root/src/lisp.h
diff options
context:
space:
mode:
authorTom Tromey2018-07-19 15:58:10 -0600
committerTom Tromey2018-07-19 16:08:41 -0600
commit76715f8921dca740880cd22c644a6328cd810846 (patch)
treed85940e4c452575c453ab3ea6a7d0ec25b20f2ab /src/lisp.h
parent678881e428073b39a906c1ffd01e1b76e271cb5d (diff)
downloademacs-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/lisp.h')
-rw-r--r--src/lisp.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lisp.h b/src/lisp.h
index e046429c1b1..4208634fa95 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3655,6 +3655,32 @@ extern Lisp_Object listn (enum constype, ptrdiff_t, Lisp_Object, ...);
3655 3655
3656extern Lisp_Object make_bignum_str (const char *num, int base); 3656extern Lisp_Object make_bignum_str (const char *num, int base);
3657extern Lisp_Object make_number (mpz_t value); 3657extern Lisp_Object make_number (mpz_t value);
3658extern void mpz_set_intmax_slow (mpz_t result, intmax_t v);
3659extern void mpz_set_uintmax_slow (mpz_t result, uintmax_t v);
3660
3661INLINE void
3662mpz_set_intmax (mpz_t result, intmax_t v)
3663{
3664 /* mpz_set_si works in terms of long, but Emacs may use a wider
3665 integer type, and so sometimes will have to construct the mpz_t
3666 by hand. */
3667 if (sizeof (intmax_t) > sizeof (long) && (long) v != v)
3668 mpz_set_intmax_slow (result, v);
3669 else
3670 mpz_set_si (result, v);
3671}
3672
3673INLINE void
3674mpz_set_uintmax (mpz_t result, uintmax_t v)
3675{
3676 /* mpz_set_ui works in terms of unsigned long, but Emacs may use a
3677 wider integer type, and so sometimes will have to construct the
3678 mpz_t by hand. */
3679 if (sizeof (uintmax_t) > sizeof (unsigned long) && (unsigned long) v != v)
3680 mpz_set_uintmax_slow (result, v);
3681 else
3682 mpz_set_ui (result, v);
3683}
3658 3684
3659/* Build a frequently used 2/3/4-integer lists. */ 3685/* Build a frequently used 2/3/4-integer lists. */
3660 3686