diff options
author | Tom Tromey <tom@tromey.com> | 2018-08-08 17:01:14 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-08-08 17:01:14 -0600 |
commit | fb26c9fd69d93aaa789e71365c030083c7f3c775 (patch) | |
tree | 90f3e28a4ff77119f33d5eafd6f38fbbfe9d7d95 /src | |
parent | d1ec3a0a8e4d7d56ebc1e4fa743130b9974ac6a8 (diff) | |
download | emacs-fb26c9fd69d93aaa789e71365c030083c7f3c775.tar.gz |
Make purecopy work for bignums
* src/alloc.c (make_pure_bignum): New function.
(purecopy): Use it.
Diffstat (limited to 'src')
-rw-r--r-- | src/alloc.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/alloc.c b/src/alloc.c index 512fdadfb2e..edfb87e5cdd 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -5535,6 +5535,34 @@ make_pure_float (double num) return new; } +/* Value is a bignum object with value VALUE allocated from pure + space. */ + +static Lisp_Object +make_pure_bignum (struct Lisp_Bignum *value) +{ + Lisp_Object new; + size_t i, nlimbs = mpz_size (value->value); + size_t nbytes = nlimbs * sizeof (mp_limb_t); + mp_limb_t *pure_limbs; + mp_size_t new_size; + + struct Lisp_Bignum *b = pure_alloc (sizeof (struct Lisp_Bignum), Lisp_Misc); + b->type = Lisp_Misc_Bignum; + + pure_limbs = pure_alloc (nbytes, -1); + for (i = 0; i < nlimbs; ++i) + pure_limbs[i] = mpz_getlimbn (value->value, i); + + new_size = nlimbs; + if (mpz_sgn (value->value) < 0) + new_size = -new_size; + + mpz_roinit_n (b->value, pure_limbs, new_size); + + XSETMISC (new, b); + return new; +} /* Return a vector with room for LEN Lisp_Objects allocated from pure space. */ @@ -5676,6 +5704,8 @@ purecopy (Lisp_Object obj) /* Don't hash-cons it. */ return obj; } + else if (BIGNUMP (obj)) + obj = make_pure_bignum (XBIGNUM (obj)); else { AUTO_STRING (fmt, "Don't know how to purify: %S"); |