develooper Front page | perl.perl5.porters | Postings from January 2001

[PATCH] Re: [PATCH: perl@8429] lib/tie-substrhash.t FAILED at test 11

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
January 17, 2001 09:31
Subject:
[PATCH] Re: [PATCH: perl@8429] lib/tie-substrhash.t FAILED at test 11
Message ID:
20010117173133.I2633@plum.flirble.org
On Wed, Jan 17, 2001 at 03:48:38PM +0100, Roca, Ignasi wrote:
> > On Wed, Jan 17, 2001 at 03:16:43PM +0100, Roca, Ignasi wrote:
> > > There is a bug in pp_int() function that has a bad influence in the wrap
> > > method of Tie::Substrhash

My bug. Sorry


> > > 
> > > $t1 = int($t0 / 59);
> > > print "int($t0/59)=$t1\n";
> > > 
> > > The result is 
> > > int(279964589018079/59)=4745162525730.15
> > >
> > > As you can see result is not an integer.
> > 
> > Wow, there's definitely a bug in there, though I see it a little
> > bit differently:
> > 
> > ./perl -le 'print int(279964589018079/59)'
> > 
> > Attempt to free unreferenced scalar.
> > 
> > mimosa being a Solaris/sparc box.

It seems that the "Attempt to free unreferenced scalar" depends on whether
you write int(279964589018079/59 or $a = 279964589018079; int($a/59)

Interesting, because I know there's at least 1 of these still in the core
http://bugs.perl.org/perlbug.cgi?req=bid&bid=19990805.004&range=5521&format=H
and now I sort of know how to fix these.
Except that why should

	  value = TOPn;
	  if (value >= 0.0) {
	      if (value < (NV)UV_MAX + 0.5) {
		  SETu(U_V(value));
	      } else {
#if defined(HAS_MODFL) || defined(LONG_DOUBLE_EQUALS_DOUBLE)
		  (void)Perl_modf(value, &value);
#else
		  double tmp = (double)value;
		  (void)Perl_modf(tmp, &tmp);
		  value = (NV)tmp;
#endif
		  SETn(value);
	      }
	  }


go wrong when the SETn() is removed?
Surely in that case the top item on the stack is the NV read by TOPn?
What is happening here?



Patch to spot this bug and relations:

--- t/op/int.t.orig	Tue Aug 29 13:54:13 2000
+++ t/op/int.t	Wed Jan 17 17:06:21 2001
@@ -5,7 +5,7 @@
     @INC = '../lib';
 }
 
-print "1..7\n";
+print "1..14\n";
 
 # compile time evaluation
 
@@ -34,3 +34,65 @@
 @x = ( 6, 8, 10);
 print "not " if $x["1foo"] != 8;
 print "ok 7\n";
+
+# check values > 32 bits work.
+
+$x = 4294967303.15;
+$y = int ($x);
+
+if ($y eq "4294967303") {
+  print "ok 8\n"
+} else {
+  print "not ok 8 # int($x) is $y, not 4294967303\n"
+}
+
+$y = int (-$x);
+
+if ($y eq "-4294967303") {
+  print "ok 9\n"
+} else {
+  print "not ok 9 # int($x) is $y, not -4294967303\n"
+}
+
+$x = 4294967294.2;
+$y = int ($x);
+
+if ($y eq "4294967294") {
+  print "ok 10\n"
+} else {
+  print "not ok 10 # int($x) is $y, not 4294967294\n"
+}
+
+$x = 4294967295.7;
+$y = int ($x);
+
+if ($y eq "4294967295") {
+  print "ok 11\n"
+} else {
+  print "not ok 11 # int($x) is $y, not 4294967295\n"
+}
+
+$x = 4294967296.11312;
+$y = int ($x);
+
+if ($y eq "4294967296") {
+  print "ok 12\n"
+} else {
+  print "not ok 12 # int($x) is $y, not 4294967296\n"
+}
+
+$y = int(279964589018079/59);
+if ($y == 4745162525730) {
+  print "ok 13\n"
+} else {
+  print "not ok 13 # int(279964589018079/59) is $y, not 4745162525730\n"
+}
+
+$y = 279964589018079;
+$y = int($y/59);
+if ($y == 4745162525730) {
+  print "ok 14\n"
+} else {
+  print "not ok 14 # int(279964589018079/59) is $y, not 4745162525730\n"
+}
+



Nicholas Clark

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About