This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bignum printing bug


Gary Houston <ghouston@ghouston.easynet.co.uk> writes:

> Someone reported a bug a while ago in the bignum support: a factorial
> procedure wasn't giving the right answer.  e.g.,:


> the problem seems to be in the bignum -> string conversion.
> this is a work-around: i don't know why it helps.
> 
> --- numbers.c.orig      Wed Oct  7 22:31:18 1998
> +++ numbers.c   Wed Oct  7 22:28:56 1998
> @@ -1387,7 +1387,8 @@
>       SCM b;
>       register unsigned int radix;
>  {
> -  SCM t = scm_copybig(b, 0);   /* sign of temp doesn't matter */
> +  /* volatile to avoid the (fact 7350) bug.  */
> +  volatile SCM t = scm_copybig(b, 0);  /* sign of temp doesn't matter */
>    register SCM_BIGDIG *ds = SCM_BDIGITS(t);
>    scm_sizet i = SCM_NUMDIGS(t);
>    scm_sizet j = radix==16 ? (SCM_BITSPERDIG*i)/4+2


The problem is that t may be garbage collected, since a clever C
compiler need never allocate storage on the stack for it.  But its
elements, pointed to by ds, may continue to be used after gc.

In SCM, we defined a function scm_protect_temp(SCM *tmp), which does
nothing but interfere with optimization in cases like this.

eg

  SCM t = scm_copybig(b, 0);

  ...
 
  scm_protect_temp(&t);