diff options
| author | Philipp Stephani | 2019-05-04 23:31:40 +0200 |
|---|---|---|
| committer | Philipp Stephani | 2019-05-04 23:31:40 +0200 |
| commit | 9684296a5d3405885e44d0b422deef19329567ef (patch) | |
| tree | 321f96e59734e4eba0d7f5f1497bc4ffe71dbfea /src | |
| parent | 1242a63671f3fc3d427d9d8061338f826e585031 (diff) | |
| download | emacs-9684296a5d3405885e44d0b422deef19329567ef.tar.gz emacs-9684296a5d3405885e44d0b422deef19329567ef.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bignum.h | 12 | ||||
| -rw-r--r-- | src/emacs-module.c | 5 |
2 files changed, 13 insertions, 4 deletions
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) | |||
| 94 | return &XBIGNUM (i)->value; | 94 | return &XBIGNUM (i)->value; |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | /* Set RESULT to the value stored in the Lisp integer I. If I is a | ||
| 98 | big integer, copy it to RESULT. RESULT must already be | ||
| 99 | initialized. */ | ||
| 100 | INLINE void | ||
| 101 | mpz_set_integer (mpz_t result, Lisp_Object i) | ||
| 102 | { | ||
| 103 | if (FIXNUMP (i)) | ||
| 104 | mpz_set_intmax (result, XFIXNUM (i)); | ||
| 105 | else | ||
| 106 | mpz_set (result, XBIGNUM (i)->value); | ||
| 107 | } | ||
| 108 | |||
| 97 | INLINE_HEADER_END | 109 | INLINE_HEADER_END |
| 98 | 110 | ||
| 99 | #endif /* BIGNUM_H */ | 111 | #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, | |||
| 785 | MODULE_FUNCTION_BEGIN (); | 785 | MODULE_FUNCTION_BEGIN (); |
| 786 | Lisp_Object o = value_to_lisp (value); | 786 | Lisp_Object o = value_to_lisp (value); |
| 787 | CHECK_INTEGER (o); | 787 | CHECK_INTEGER (o); |
| 788 | if (FIXNUMP (o)) | 788 | mpz_set_integer (result->value, o); |
| 789 | mpz_set_intmax (result->value, XFIXNUM (o)); | ||
| 790 | else | ||
| 791 | mpz_set (result->value, XBIGNUM (o)->value); | ||
| 792 | } | 789 | } |
| 793 | 790 | ||
| 794 | static emacs_value | 791 | static emacs_value |