unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* integer-expt dup init/clear
@ 2003-11-14 21:21 Kevin Ryde
  0 siblings, 0 replies; only message in thread
From: Kevin Ryde @ 2003-11-14 21:21 UTC (permalink / 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-11-14 21:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-14 21:21 integer-expt dup init/clear Kevin Ryde

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).