Skip to content

Commit 3281062

Browse files
committed
Backport SF #660455 fix.
1 parent 9aa5027 commit 3281062

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

‎Lib/test/test_compile.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,3 +123,7 @@ def expect_same(test_source, expected):
123123
expect_same("000000000000007", 7)
124124
expect_same("000000000000008.", 8.)
125125
expect_same("000000000000009.", 9.)
126+
127+
# Verify treatment of unary minus on negative numbers SF bug #660455
128+
expect_same("0xffffffff", -1)
129+
expect_same("-0xffffffff", 1)

‎Misc/NEWS‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ What's New in Python 2.2.3 ?
22
Release date: XX-XXX-2003
33
============================
44

5+
- Through a bytecode optimizer bug (and I bet you didn't even know
6+
Python *had* a bytecode optimizer :-), "unsigned" hex/oct constants
7+
with a leading minus sign would come out with the wrong sign.
8+
("Unsigned" hex/oct constants are those with a face value in the
9+
range sys.maxint+1 through sys.maxint*2+1, inclusive; these have
10+
always been interpreted as negative numbers through sign folding.)
11+
E.g. 0xffffffff is -1, and -(0xffffffff) is 1, but -0xffffffff would
12+
come out as -4294967295. This was the case in Python 2.2 through
13+
2.2.2 and 2.3a1, and in Python 2.4 it will once again have that
14+
value, but according to PEP 237 it really needs to be 1 in Python
15+
2.2.3 and 2.3. (SF #660455)
16+
517
- SF bug #678518: fix some bugs in the parser module.
618

719
- Bastion.py and rexec.py are disabled. These modules are not safe in

‎Python/compile.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1952,7 +1952,8 @@ com_factor(struct compiling *c, node *n)
19521952
&& NCH(ppower) == 1
19531953
&& TYPE((patom = CHILD(ppower, 0))) == atom
19541954
&& TYPE((pnum = CHILD(patom, 0))) == NUMBER
1955-
&& !(childtype == MINUS && is_float_zero(STR(pnum)))) {
1955+
&& !(childtype == MINUS &&
1956+
(STR(pnum)[0] == '0' || is_float_zero(STR(pnum))))) {
19561957
if (childtype == TILDE) {
19571958
com_invert_constant(c, pnum);
19581959
return;

0 commit comments

Comments
 (0)