]> granicus.if.org Git - python/commitdiff
Issue #11244: Remove outdated peepholer check that was preventing the peepholer from...
authorMark Dickinson <mdickinson@enthought.com>
Wed, 23 Mar 2011 17:59:37 +0000 (17:59 +0000)
committerMark Dickinson <mdickinson@enthought.com>
Wed, 23 Mar 2011 17:59:37 +0000 (17:59 +0000)
Lib/test/test_peepholer.py
Misc/ACKS
Misc/NEWS
Python/peephole.c

index f73565eb46fb132295381621881d7fac0469ffba..78de90923eccd17338345d3372cf12ff50bcfb51 100644 (file)
@@ -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
index 91bcec8ebbff1182f09a1a3ac0ae20002c69ef0e..58011519d9dcc9e5f9581d52ee42d4908474e1f6 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -867,6 +867,7 @@ Christian Tismer
 Frank J. Tobin
 R Lindsay Todd
 Bennett Todd
+Eugene Toder
 Matias Torchinsky
 Sandro Tosi
 Richard Townsend
index 363d5e99b34ac049acfaff0b4186ec06ee24107e..64a35ddf58b28db05922cc0ad99d2c1585a4999d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -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
index 4bc65dcc312b2dbd77137c42d86083b639ab0f0e..69f61617f875da398e52407cae866bd8f5afa8e5 100644 (file)
@@ -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);