diff options
author | Mark Dickinson <mdickinson@enthought.com> | 2011-03-23 17:59:37 (GMT) |
---|---|---|
committer | Mark Dickinson <mdickinson@enthought.com> | 2011-03-23 17:59:37 (GMT) |
commit | 7c9e80328458de501a544b5c24342d969bcbe76d (patch) | |
tree | e2dc7e2c637c6b7584b8d1b9bfa84906905096ac | |
parent | ba7b560c1d3aca8dac21e824c7d4a11e7f584e76 (diff) | |
download | cpython-7c9e80328458de501a544b5c24342d969bcbe76d.zip cpython-7c9e80328458de501a544b5c24342d969bcbe76d.tar.gz cpython-7c9e80328458de501a544b5c24342d969bcbe76d.tar.bz2 |
Issue #11244: Remove outdated peepholer check that was preventing the peepholer from folding -0 and -0.0. Thanks Eugene Toder for the patch.
-rw-r--r-- | Lib/test/test_peepholer.py | 11 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS | 3 | ||||
-rw-r--r-- | Python/peephole.c | 6 |
4 files changed, 17 insertions, 4 deletions
diff --git a/Lib/test/test_peepholer.py b/Lib/test/test_peepholer.py index f73565e..78de909 100644 --- a/Lib/test/test_peepholer.py +++ b/Lib/test/test_peepholer.py @@ -3,6 +3,7 @@ import re import sys from io import StringIO import unittest +from math import copysign def disassemble(func): f = StringIO() @@ -207,6 +208,9 @@ class TestTranforms(unittest.TestCase): def test_folding_of_unaryops_on_constants(self): for line, elem in ( ('-0.5', '(-0.5)'), # unary negative + ('-0.0', '(-0.0)'), # -0.0 + ('-(1.0-1.0)','(-0.0)'), # -0.0 after folding + ('-0', '(0)'), # -0 ('~-2', '(1)'), # unary invert ('+1', '(1)'), # unary positive ): @@ -214,6 +218,13 @@ class TestTranforms(unittest.TestCase): self.assertIn(elem, asm, asm) self.assertNotIn('UNARY_', asm) + # Check that -0.0 works after marshaling + def negzero(): + return -(1.0-1.0) + + self.assertNotIn('UNARY_', disassemble(negzero)) + self.assertTrue(copysign(1.0, negzero()) < 0) + # Verify that unfoldables are skipped for line, elem in ( ('-"abc"', "('abc')"), # unary negative @@ -867,6 +867,7 @@ Christian Tismer Frank J. Tobin R Lindsay Todd Bennett Todd +Eugene Toder Matias Torchinsky Sandro Tosi Richard Townsend @@ -10,6 +10,9 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #11244: Remove an unnecessary peepholer check that was preventing + negative zeros from being constant-folded properly. + - Issue #11395: io.FileIO().write() clamps the data length to 32,767 bytes on Windows if the file is a TTY to workaround a Windows bug. The Windows console returns an error (12: not enough space error) on writing into stdout if diff --git a/Python/peephole.c b/Python/peephole.c index 4bc65dc..69f6161 100644 --- a/Python/peephole.c +++ b/Python/peephole.c @@ -238,7 +238,7 @@ fold_binops_on_constants(unsigned char *codestr, PyObject *consts, PyObject **ob static int fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v) { - PyObject *newconst=NULL/*, *v*/; + PyObject *newconst; Py_ssize_t len_consts; int opcode; @@ -250,9 +250,7 @@ fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts, PyObject *v opcode = codestr[3]; switch (opcode) { case UNARY_NEGATIVE: - /* Preserve the sign of -0.0 */ - if (PyObject_IsTrue(v) == 1) - newconst = PyNumber_Negative(v); + newconst = PyNumber_Negative(v); break; case UNARY_INVERT: newconst = PyNumber_Invert(v); |