From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Andy Moreton Newsgroups: gmane.emacs.devel Subject: Re: bignum branch Date: Tue, 07 Aug 2018 09:38:13 +0100 Message-ID: <86r2jamv0q.fsf@gmail.com> References: <87o9fbbw1t.fsf@tromey.com> <86in5jdj49.fsf@gmail.com> <83wotxaiwi.fsf@gnu.org> <86k1pxmvmx.fsf@gmail.com> <87efg4a9xc.fsf@tromey.com> <87a7qr8cz7.fsf@tromey.com> <86tvoy3je9.fsf@gmail.com> <86bmb0vbxf.fsf@gmail.com> <87k1pnfcg1.fsf@tromey.com> <86sh4b1833.fsf@gmail.com> <861sbgz3dm.fsf@gmail.com> <83a7q4ufxp.fsf@gnu.org> <86in4resc8.fsf@gmail.com> <831sbfvl11.fsf@gnu.org> <8636vv7ohh.fsf@gmail.com> <83y3dntwsw.fsf@gnu.org> <83wot7tkdh.fsf@gnu.org> <87y3dnyzkl.fsf@tromey.com> <861sbegz37.fsf@gmail.com> <87k1p3ko6a.fsf@tromey.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1533630990 23963 195.159.176.226 (7 Aug 2018 08:36:30 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 7 Aug 2018 08:36:30 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (windows-nt) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 07 10:36:25 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fmxTd-00068e-5L for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2018 10:36:25 +0200 Original-Received: from localhost ([::1]:37917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmxVj-0000Ri-Tn for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2018 04:38:35 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41281) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmxVd-0000RS-N9 for emacs-devel@gnu.org; Tue, 07 Aug 2018 04:38:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmxVY-0007gj-Nh for emacs-devel@gnu.org; Tue, 07 Aug 2018 04:38:29 -0400 Original-Received: from [195.159.176.226] (port=38168 helo=blaine.gmane.org) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmxVY-0007eZ-Fh for emacs-devel@gnu.org; Tue, 07 Aug 2018 04:38:24 -0400 Original-Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1fmxTO-0005r8-VL for emacs-devel@gnu.org; Tue, 07 Aug 2018 10:36:10 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 73 Original-X-Complaints-To: usenet@blaine.gmane.org Cancel-Lock: sha1:Y6BxBd2/gFCYykTXZ/Ufj4327kw= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 195.159.176.226 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:228262 Archived-At: On Mon 06 Aug 2018, Tom Tromey wrote: >>>>>> "Andy" == Andy Moreton 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");