From: Guido van Rossum Date: Wed, 12 Feb 2003 19:09:45 +0000 (+0000) Subject: Backport SF #660455 fix. X-Git-Tag: v2.2.3c1~140 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=32810627a27fd8e6591b09bab045564030f10099;p=thirdparty%2FPython%2Fcpython.git Backport SF #660455 fix. --- diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py index 3801cacd87f8..378fae3845d9 100644 --- a/Lib/test/test_compile.py +++ b/Lib/test/test_compile.py @@ -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) diff --git a/Misc/NEWS b/Misc/NEWS index df94add92f1f..dec7862b57f9 100644 --- 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 diff --git a/Python/compile.c b/Python/compile.c index f3d9a20cf89f..7238e3dc45e5 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -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;