develooper Front page | perl.perl5.porters | Postings from October 2003

[PATCH bleadperl] [perl #24313] (was Re: [PATCH lib/overload.t] TODO tests for bug #24313.)

Thread Previous | Thread Next
From:
Rick Delaney
Date:
October 27, 2003 09:18
Subject:
[PATCH bleadperl] [perl #24313] (was Re: [PATCH lib/overload.t] TODO tests for bug #24313.)
Message ID:
20031027121749.E2233@biff.bort.ca
On Mon, Oct 27, 2003 at 01:05:37PM +0100, Abigail wrote:
> 
[snip tests]

The original bug is "Can't overload numeric constant 0.", specifically
with overload::constant('integer').  This is because a plain "0" is
being treated as a binary constant.  The following patch treats a plain
zero as an integer constant under overload::constant('integer').  For
backwards compatibility it will still treat it as a binary constant
under overload::constant('binary') but if both are specified 'integer'
takes precedence.

-- 
Rick Delaney
rick@bort.ca


--- toke.c.orig	Mon Oct 27 11:04:56 2003
+++ toke.c	Mon Oct 27 12:00:13 2003
@@ -7252,6 +7252,7 @@
 	    UV u = 0;
 	    I32 shift;
 	    bool overflowed = FALSE;
+	    bool just_zero  = TRUE;	/* just plain 0 or binary number? */
 	    static NV nvshift[5] = { 1.0, 2.0, 4.0, 8.0, 16.0 };
 	    static char* bases[5] = { "", "binary", "", "octal",
 				      "hexadecimal" };
@@ -7268,9 +7269,11 @@
 	    if (s[1] == 'x') {
 		shift = 4;
 		s += 2;
+		just_zero = FALSE;
 	    } else if (s[1] == 'b') {
 		shift = 1;
 		s += 2;
+		just_zero = FALSE;
 	    }
 	    /* check for a decimal in disguise */
 	    else if (s[1] == '.' || s[1] == 'e' || s[1] == 'E')
@@ -7342,6 +7345,7 @@
 		    */
 
 		  digit:
+		    just_zero = FALSE;
 		    if (!overflowed) {
 			x = u << shift;	/* make room for the digit */
 
@@ -7400,7 +7404,10 @@
 #endif
 		sv_setuv(sv, u);
 	    }
-	    if (PL_hints & HINT_NEW_BINARY)
+	    if (just_zero && (PL_hints & HINT_NEW_INTEGER))
+		sv = new_constant(start, s - start, "integer", 
+				  sv, Nullsv, NULL);
+	    else if (PL_hints & HINT_NEW_BINARY)
 		sv = new_constant(start, s - start, "binary", sv, Nullsv, NULL);
 	}
 	break;

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