mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
SF #660455 : patch by NNorwitz.
"Unsigned" (i.e., positive-looking, but really negative) hex/oct constants with a leading minus sign are once again properly negated. The micro-optimization for negated numeric constants did the wrong thing for such hex/oct constants. The patch avoids the optimization for all hex/oct constants. This needs to be backported to Python 2.2!
This commit is contained in:
parent
e71b9f830b
commit
66b1259dbc
3 changed files with 14 additions and 8 deletions
|
@ -133,9 +133,12 @@ expect_same("000000000000007", 7)
|
||||||
expect_same("000000000000008.", 8.)
|
expect_same("000000000000008.", 8.)
|
||||||
expect_same("000000000000009.", 9.)
|
expect_same("000000000000009.", 9.)
|
||||||
|
|
||||||
## # Verify treatment of unary minus on negative numbers SF bug #660455
|
# Verify treatment of unary minus on negative numbers SF bug #660455
|
||||||
## import warnings
|
import warnings
|
||||||
## warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning)
|
warnings.filterwarnings("ignore", "hex/oct constants", FutureWarning)
|
||||||
## # XXX Of course the following test will have to be changed in Python 2.4
|
# XXX Of course the following test will have to be changed in Python 2.4
|
||||||
## expect_same("0xffffffff", -1)
|
# This test is in a <string> so the filterwarnings() can affect it
|
||||||
## expect_same("-0xffffffff", 1)
|
exec """
|
||||||
|
expect_same("0xffffffff", -1)
|
||||||
|
expect_same("-0xffffffff", 1)
|
||||||
|
"""
|
||||||
|
|
|
@ -37,7 +37,9 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
maxint = 2147483647
|
maxint = 2147483647
|
||||||
if maxint == 2147483647:
|
if maxint == 2147483647:
|
||||||
if -2147483647-1 != -020000000000: raise TestFailed, 'max negative int'
|
# The following test will start to fail in Python 2.4;
|
||||||
|
# change the 020000000000 to -020000000000
|
||||||
|
if -2147483647-1 != 020000000000: raise TestFailed, 'max negative int'
|
||||||
# XXX -2147483648
|
# XXX -2147483648
|
||||||
if 037777777777 != -1: raise TestFailed, 'oct -1'
|
if 037777777777 != -1: raise TestFailed, 'oct -1'
|
||||||
if 0xffffffff != -1: raise TestFailed, 'hex -1'
|
if 0xffffffff != -1: raise TestFailed, 'hex -1'
|
||||||
|
|
|
@ -2069,7 +2069,8 @@ com_factor(struct compiling *c, node *n)
|
||||||
&& NCH(ppower) == 1
|
&& NCH(ppower) == 1
|
||||||
&& TYPE((patom = CHILD(ppower, 0))) == atom
|
&& TYPE((patom = CHILD(ppower, 0))) == atom
|
||||||
&& TYPE((pnum = CHILD(patom, 0))) == NUMBER
|
&& 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) {
|
if (childtype == TILDE) {
|
||||||
com_invert_constant(c, pnum);
|
com_invert_constant(c, pnum);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue