From: Kevin Ryde <user42@zip.com.au>
Subject: integer-expt dup init/clear
Date: Sat, 15 Nov 2003 07:21:35 +1000 [thread overview]
Message-ID: <87wua27ijk.fsf@zip.com.au> (raw)
[-- Attachment #1: Type: text/plain, Size: 550 bytes --]
A bit of an init/clear gremlin in integer-expt,
* numbers.c (scm_integer_expt): Don't mpz_init after scm_i_clonebig or
scm_i_mkbig, since they do so already. Don't mpz_clear a bignum SCM,
since gc does this.
The bad cases are a bignum exponent and a flonum exponent bigger than
a fixnum, so
(integer-expt 0.5 (ash 1 128))
(gc) (gc)
and
(integer-expt 0.5 (exact->inexact (ash 1 128)))
(gc) (gc)
Run under your favourite malloc debugger to see the duplicate
mpz_clear free when the gc gets around to releasing z_i2.
[-- Attachment #2: numbers.c.integer-expt.diff --]
[-- Type: text/plain, Size: 1048 bytes --]
--- numbers.c.~1.206.~ 1970-01-01 10:00:01.000000000 +1000
+++ numbers.c 2003-11-13 11:47:30.000000000 +1000
@@ -1355,7 +1355,6 @@
else if (SCM_BIGP (k))
{
z_i2 = scm_i_clonebig (k, 1);
- mpz_init_set (SCM_I_BIG_MPZ (z_i2), SCM_I_BIG_MPZ (k));
scm_remember_upto_here_1 (k);
i2_is_big = 1;
}
@@ -1367,7 +1366,7 @@
if ((r > SCM_MOST_POSITIVE_FIXNUM) || (r < SCM_MOST_NEGATIVE_FIXNUM))
{
z_i2 = scm_i_mkbig ();
- mpz_init_set_d (SCM_I_BIG_MPZ (z_i2), r);
+ mpz_set_d (SCM_I_BIG_MPZ (z_i2), r);
i2_is_big = 1;
}
else
@@ -1389,12 +1388,10 @@
{
if (mpz_sgn(SCM_I_BIG_MPZ (z_i2)) == 0)
{
- mpz_clear (SCM_I_BIG_MPZ (z_i2));
return acc;
}
if (mpz_cmp_ui(SCM_I_BIG_MPZ (z_i2), 1) == 0)
{
- mpz_clear (SCM_I_BIG_MPZ (z_i2));
return scm_product (acc, n);
}
if (mpz_tstbit(SCM_I_BIG_MPZ (z_i2), 0))
[-- Attachment #3: Type: text/plain, Size: 142 bytes --]
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
reply other threads:[~2003-11-14 21:21 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87wua27ijk.fsf@zip.com.au \
--to=user42@zip.com.au \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).