From: Philipp Stephani Date: Sat, 4 May 2019 21:31:40 +0000 (+0200) Subject: Refactoring: Factor out a function to set an mpz_t from a Lisp int. X-Git-Tag: emacs-27.0.90~2989 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=9684296a5d3405885e44d0b422deef19329567ef;p=emacs.git Refactoring: Factor out a function to set an mpz_t from a Lisp int. * src/bignum.h (mpz_set_integer): New function. * src/emacs-module.c (module_make_big_integer): Use it. --- diff --git a/src/bignum.h b/src/bignum.h index 4c670bd906f..743a18fc0f7 100644 --- a/src/bignum.h +++ b/src/bignum.h @@ -94,6 +94,18 @@ bignum_integer (mpz_t *tmp, Lisp_Object i) return &XBIGNUM (i)->value; } +/* Set RESULT to the value stored in the Lisp integer I. If I is a + big integer, copy it to RESULT. RESULT must already be + initialized. */ +INLINE void +mpz_set_integer (mpz_t result, Lisp_Object i) +{ + if (FIXNUMP (i)) + mpz_set_intmax (result, XFIXNUM (i)); + else + mpz_set (result, XBIGNUM (i)->value); +} + INLINE_HEADER_END #endif /* BIGNUM_H */ diff --git a/src/emacs-module.c b/src/emacs-module.c index 6b56146ca01..1a7a21a4a8c 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c @@ -785,10 +785,7 @@ module_extract_big_integer (emacs_env *env, emacs_value value, MODULE_FUNCTION_BEGIN (); Lisp_Object o = value_to_lisp (value); CHECK_INTEGER (o); - if (FIXNUMP (o)) - mpz_set_intmax (result->value, XFIXNUM (o)); - else - mpz_set (result->value, XBIGNUM (o)->value); + mpz_set_integer (result->value, o); } static emacs_value