From d0fac17abdf6883bbf82b1752988db38d05282e6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 7 Jul 2018 22:51:58 -0600 Subject: [PATCH] Let C modules access bignum values * src/emacs-module.c (module_extract_integer, module_make_integer): Handle bignums. --- src/emacs-module.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/emacs-module.c b/src/emacs-module.c index e781c38f462..7709eeca94a 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -518,17 +518,31 @@ module_extract_integer (emacs_env *env, emacs_value n) { MODULE_FUNCTION_BEGIN (0); Lisp_Object l = value_to_lisp (n); - CHECK_FIXNUM (l); + CHECK_INTEGER (l); + if (BIGNUMP (l)) + { + if (!mpz_fits_slong_p (XBIGNUM (l)->value)) + xsignal1 (Qoverflow_error, l); + return mpz_get_si (XBIGNUM (l)->value); + } return XINT (l); } static emacs_value module_make_integer (emacs_env *env, intmax_t n) { + Lisp_Object obj; MODULE_FUNCTION_BEGIN (module_nil); if (FIXNUM_OVERFLOW_P (n)) - xsignal0 (Qoverflow_error); - return lisp_to_value (env, make_fixnum (n)); + { + mpz_t val; + mpz_init_set_si (val, n); + obj = make_number (val); + mpz_clear (val); + } + else + obj = make_fixnum (n); + return lisp_to_value (env, obj); } static double -- 2.39.2