[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: bignum branch
From: |
Andy Moreton |
Subject: |
Re: bignum branch |
Date: |
Tue, 07 Aug 2018 09:38:13 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt) |
On Mon 06 Aug 2018, Tom Tromey wrote:
>>>>>> "Andy" == Andy Moreton <address@hidden> writes:
>
> Andy> purecopy also needs updating tosupport bignums
>
> Did you have a use for this? It seems like there must not be any
> bignums being dumped currently, since if there were, surely something
> would fail.
>
> Anyway, if you do have a use, could you try the appended?
I don't have a use for this yet - more a case of thing that should be
done before this branch is merged to master.
> Andy> and also the macros in .gdbinit.
>
> This doesn't seem like a must-have to me; but if it is, I think it would
> be best to start by writing pretty-printers to submit to GMP.
GMP already has a gmp_*printf family of functions which should be
suitable for formatted output. Fixing up .gdbinit is nice to have, but
not essential before getting the bignum branch merged into master.
> diff --git a/src/alloc.c b/src/alloc.c
> index 367bb73fc1..dba90e7eb2 100644
> --- a/src/alloc.c
> +++ b/src/alloc.c
> @@ -5535,6 +5535,28 @@ 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 nbytes = value->value[0]._mp_alloc * sizeof (mp_limb_t);
This should use mpz_size.
> +
> + struct Lisp_Bignum *b = pure_alloc (sizeof (struct Lisp_Bignum),
> Lisp_Misc);
> + b->type = Lisp_Misc_Bignum;
> +
> + /* An mpz_t is an array of one element, so this is the correct way
> + to copy the contents. */
> + b->value[0] = value->value[0];
> +
> + b->value[0]._mp_d = pure_alloc (nbytes, -1);
> + memcpy (b->value[0]._mp_d, value->value[0]._mp_d, nbytes);
Use a loop with mpz_getlimbn or mpz_limbs_read to do this with the API.
mpz_roinit_n may be useful instead, using the low level APIs.
See (info "(gmp) Integer Special Functions").
> +
> + XSETMISC (new, b);
> + return new;
> +}
>
> /* Return a vector with room for LEN Lisp_Objects allocated from
> pure space. */
> @@ -5676,6 +5698,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");
- Re: bignum branch, (continued)
- Re: bignum branch, Achim Gratz, 2018/08/04
- Re: bignum branch, Tom Tromey, 2018/08/04
- Re: bignum branch, Achim Gratz, 2018/08/04
- Re: bignum branch, Eli Zaretskii, 2018/08/04
- Re: bignum branch, Andy Moreton, 2018/08/04
- Re: bignum branch, Tom Tromey, 2018/08/04
- Re: bignum branch, Robert Pluim, 2018/08/06
- Re: bignum branch, Tom Tromey, 2018/08/06
- Re: bignum branch,
Andy Moreton <=
- Re: bignum branch, Tom Tromey, 2018/08/07
- Re: bignum branch, Tom Tromey, 2018/08/04
Re: bignum branch, Tom Tromey, 2018/08/03
- Re: bignum branch, Andy Moreton, 2018/08/03
- Re: bignum branch, Eli Zaretskii, 2018/08/04
- Re: bignum branch, Andy Moreton, 2018/08/05
- Re: bignum branch, Eli Zaretskii, 2018/08/05
- Re: bignum branch, Andy Moreton, 2018/08/06
- Re: bignum branch, Tom Tromey, 2018/08/06
- Re: bignum branch, Paul Eggert, 2018/08/06