diff options
| author | Paul Eggert | 2018-08-27 21:27:50 -0700 |
|---|---|---|
| committer | Paul Eggert | 2018-08-27 21:45:22 -0700 |
| commit | 9abaf5f3581ecb76f30e8a6e7ee0e9633c133d1c (patch) | |
| tree | c39260a6e26845b0a1307be98b38581468925c58 /src/emacs-module.c | |
| parent | bf1b147b55e1328efca6e40181e79dd9a369895d (diff) | |
| download | emacs-9abaf5f3581ecb76f30e8a6e7ee0e9633c133d1c.tar.gz emacs-9abaf5f3581ecb76f30e8a6e7ee0e9633c133d1c.zip | |
Modularize bignums better
* src/bignum.c, src/bignum.h: New files. Only modules that
need to know how bignums are implemented should include
bignum.h. Currently these are alloc.c, bignum.c (of course),
data.c, emacs.c, emacs-module.c, floatfns.c, fns.c, print.c.
* src/Makefile.in (base_obj): Add bignum.o.
* src/alloc.c (make_bignum_str): Move to bignum.c.
(make_number): Remove; replaced by bignum.c’s make_integer.
All callers changed.
* src/conf_post.h (ARG_NONNULL): New macro.
* src/json.c (json_to_lisp): Use it.
* src/data.c (Fnatnump):
Move NATNUMP’s implementation here from lisp.h.
* src/data.c (Fnumber_to_string):
* src/editfns.c (styled_format):
Move conversion of string to bignum to bignum_to_string, and
call it here.
* src/emacs-module.c (module_make_integer):
* src/floatfns.c (Fabs):
Simplify by using make_int.
* src/emacs.c: Include bignum.h, to expand its inline fns.
* src/floatfns.c (Ffloat): Simplify by using XFLOATINT.
(rounding_driver): Simplify by using double_to_bignum.
(rounddiv_q): Clarify use of temporaries.
* src/lisp.h: Move decls that need to know bignum internals to
bignum.h. Do not include gmp.h or mini-gmp.h; that is now
bignum.h’s job.
(GMP_NUM_BITS, struct Lisp_Bignum, XBIGNUM, mpz_set_intmax):
Move to bignum.h.
(make_int): New function.
(NATNUMP): Remove; all callers changed to use Fnatnump.
(XFLOATINT): If arg is a bignum, use bignum_to_double, so that
bignum internals are not exposed here.
* src/print.c (print_vectorlike): Use SAFE_ALLOCA to avoid the
need for a record_unwind_protect_ptr.
Diffstat (limited to 'src/emacs-module.c')
| -rw-r--r-- | src/emacs-module.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/src/emacs-module.c b/src/emacs-module.c index f2844c40d0f..a1bed491b62 100644 --- a/src/emacs-module.c +++ b/src/emacs-module.c | |||
| @@ -27,6 +27,7 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */ | |||
| 27 | #include <stdio.h> | 27 | #include <stdio.h> |
| 28 | 28 | ||
| 29 | #include "lisp.h" | 29 | #include "lisp.h" |
| 30 | #include "bignum.h" | ||
| 30 | #include "dynlib.h" | 31 | #include "dynlib.h" |
| 31 | #include "coding.h" | 32 | #include "coding.h" |
| 32 | #include "keyboard.h" | 33 | #include "keyboard.h" |
| @@ -521,6 +522,8 @@ module_extract_integer (emacs_env *env, emacs_value n) | |||
| 521 | CHECK_INTEGER (l); | 522 | CHECK_INTEGER (l); |
| 522 | if (BIGNUMP (l)) | 523 | if (BIGNUMP (l)) |
| 523 | { | 524 | { |
| 525 | /* FIXME: This can incorrectly signal overflow on platforms | ||
| 526 | where long is narrower than intmax_t. */ | ||
| 524 | if (!mpz_fits_slong_p (XBIGNUM (l)->value)) | 527 | if (!mpz_fits_slong_p (XBIGNUM (l)->value)) |
| 525 | xsignal1 (Qoverflow_error, l); | 528 | xsignal1 (Qoverflow_error, l); |
| 526 | return mpz_get_si (XBIGNUM (l)->value); | 529 | return mpz_get_si (XBIGNUM (l)->value); |
| @@ -531,19 +534,8 @@ module_extract_integer (emacs_env *env, emacs_value n) | |||
| 531 | static emacs_value | 534 | static emacs_value |
| 532 | module_make_integer (emacs_env *env, intmax_t n) | 535 | module_make_integer (emacs_env *env, intmax_t n) |
| 533 | { | 536 | { |
| 534 | Lisp_Object obj; | ||
| 535 | MODULE_FUNCTION_BEGIN (module_nil); | 537 | MODULE_FUNCTION_BEGIN (module_nil); |
| 536 | if (FIXNUM_OVERFLOW_P (n)) | 538 | return lisp_to_value (env, make_int (n)); |
| 537 | { | ||
| 538 | mpz_t val; | ||
| 539 | mpz_init (val); | ||
| 540 | mpz_set_intmax (val, n); | ||
| 541 | obj = make_number (val); | ||
| 542 | mpz_clear (val); | ||
| 543 | } | ||
| 544 | else | ||
| 545 | obj = make_fixnum (n); | ||
| 546 | return lisp_to_value (env, obj); | ||
| 547 | } | 539 | } |
| 548 | 540 | ||
| 549 | static double | 541 | static double |