From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: Forwarded patch for modular exponentiation support (GMP powm) Date: Thu, 12 Feb 2004 09:44:21 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87vfmdfaga.fsf@zip.com.au> References: <87k73cng30.fsf@raven.i.defaultvalue.org> <874qtzsv3c.fsf@zip.com.au> <87llnah2hf.fsf@offby1.atm01.sea.blarg.net> <87hdxyctsa.fsf@zip.com.au> <87ad3qm76l.fsf@offby1.atm01.sea.blarg.net> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1076543242 1958 80.91.224.253 (11 Feb 2004 23:47:22 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Wed, 11 Feb 2004 23:47:22 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Feb 12 00:47:11 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1Ar44U-0006S7-01 for ; Thu, 12 Feb 2004 00:47:11 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Ar42r-0005jS-EI for guile-devel@m.gmane.org; Wed, 11 Feb 2004 18:45:29 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1Ar42Z-0005iY-AE for guile-devel@gnu.org; Wed, 11 Feb 2004 18:45:11 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1Ar422-0005aZ-78 for guile-devel@gnu.org; Wed, 11 Feb 2004 18:45:09 -0500 Original-Received: from [61.8.0.85] (helo=mailout2.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.24) id 1Ar421-0005a5-Ds for guile-devel@gnu.org; Wed, 11 Feb 2004 18:44:37 -0500 Original-Received: from mailproxy1.pacific.net.au (mailproxy1.pacific.net.au [61.8.0.86]) by mailout2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1BNiX5O019301; Thu, 12 Feb 2004 10:44:33 +1100 Original-Received: from localhost (ppp232.dyn251.pacific.net.au [203.143.251.232]) by mailproxy1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i1BNiVi0018551; Thu, 12 Feb 2004 10:44:32 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1Ar41o-0000X5-00; Thu, 12 Feb 2004 09:44:24 +1000 Original-To: Eric Hanchrow Mail-Copies-To: never In-Reply-To: <87ad3qm76l.fsf@offby1.atm01.sea.blarg.net> (Eric Hanchrow's message of "Tue, 10 Feb 2004 23:00:50 -0800") User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Developers list for Guile, the GNU extensibility library List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3362 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3362 Eric Hanchrow writes: > > +static void > +coerce_to_big(SCM in, mpz_t out) > +{ > + if (SCM_BIGP(in)) > + mpz_set(out, SCM_I_BIG_MPZ(in)); > + else if (SCM_INUMP(in)) > + { > + mpz_set_si(out, SCM_INUM(in)); You could use mpz_init_set and mpz_init_set_si here rather than separate mpz_init's. > + mpz_t inverted; > + mpz_init(inverted); > + if (!mpz_invert (inverted, SCM_I_BIG_MPZ(result), m_tmp)) > + { > + mpz_clear(inverted); > + scm_num_overflow(FUNC_NAME); > + } > + mpz_set(SCM_I_BIG_MPZ(result), inverted); > + mpz_clear(inverted); I'm pretty sure you don't need the extra mpz_t temporary here. Just tell mpz_invert to put the result straight into SCM_I_BIG_MPZ(result). > + mpz_clear(m_tmp); > + mpz_clear(k_tmp); > + mpz_clear(n_tmp); I think you need this under the inversion failure too, to avoid a memory leak. _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel