]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport SF #660455 fix.
authorGuido van Rossum <guido@python.org>
Wed, 12 Feb 2003 19:09:45 +0000 (19:09 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 12 Feb 2003 19:09:45 +0000 (19:09 +0000)
Lib/test/test_compile.py
Misc/NEWS
Python/compile.c

index 3801cacd87f804b6409c0043bd2c846e69c0d0c9..378fae3845d94d7a776ff1a74f000cb118a7276d 100644 (file)
@@ -123,3 +123,7 @@ expect_error("000000000000008")  # plain octal literal w/ decimal digit
 expect_same("000000000000007", 7)
 expect_same("000000000000008.", 8.)
 expect_same("000000000000009.", 9.)
+
+# Verify treatment of unary minus on negative numbers SF bug #660455
+expect_same("0xffffffff", -1)
+expect_same("-0xffffffff", 1)
index df94add92f1f92283576cd544109160dea7c8735..dec7862b57f97be965ce51b01729754add62041e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -2,6 +2,18 @@ What's New in Python 2.2.3 ?
 Release date: XX-XXX-2003
 ============================
 
+- Through a bytecode optimizer bug (and I bet you didn't even know
+  Python *had* a bytecode optimizer :-), "unsigned" hex/oct constants
+  with a leading minus sign would come out with the wrong sign.
+  ("Unsigned" hex/oct constants are those with a face value in the
+  range sys.maxint+1 through sys.maxint*2+1, inclusive; these have
+  always been interpreted as negative numbers through sign folding.)
+  E.g. 0xffffffff is -1, and -(0xffffffff) is 1, but -0xffffffff would
+  come out as -4294967295.  This was the case in Python 2.2 through
+  2.2.2 and 2.3a1, and in Python 2.4 it will once again have that
+  value, but according to PEP 237 it really needs to be 1 in Python
+  2.2.3 and 2.3.  (SF #660455)
+
 - SF bug #678518:  fix some bugs in the parser module.  
 
 - Bastion.py and rexec.py are disabled.  These modules are not safe in
index f3d9a20cf89fb817fdb961e9401575188cfbc31d..7238e3dc45e553eb651e8148665b4a5a92348f77 100644 (file)
@@ -1952,7 +1952,8 @@ com_factor(struct compiling *c, node *n)
            && NCH(ppower) == 1
            && TYPE((patom = CHILD(ppower, 0))) == atom
            && TYPE((pnum = CHILD(patom, 0))) == NUMBER
-           && !(childtype == MINUS && is_float_zero(STR(pnum)))) {
+           && !(childtype == MINUS &&
+                (STR(pnum)[0] == '0' || is_float_zero(STR(pnum))))) {
                if (childtype == TILDE) {
                        com_invert_constant(c, pnum);
                        return;