diff Python/compile.c @ 34630:660419bdb4ae legacy-trunk

Preserve sign of -0.0 when result is run through marshal.
author Raymond Hettinger <python@rcn.com>
date Wed, 23 Feb 2005 13:37:55 +0000
parents fcacf9d4b8f0
children a9f161e36bf9
line wrap: on
line diff
--- a/Python/compile.c	Tue Feb 22 15:33:26 2005 +0000
+++ b/Python/compile.c	Wed Feb 23 13:37:55 2005 +0000
@@ -545,7 +545,7 @@
 static int
 fold_unaryops_on_constants(unsigned char *codestr, PyObject *consts)
 {
-	PyObject *newconst, *v;
+	PyObject *newconst=NULL, *v;
 	int len_consts, opcode;
 
 	/* Pre-conditions */
@@ -557,7 +557,9 @@
 	opcode = codestr[3];
 	switch (opcode) {
 	case UNARY_NEGATIVE:
-		newconst = PyNumber_Negative(v);
+		/* Preserve the sign of -0.0 */
+		if (PyObject_IsTrue(v) == 1)
+			newconst = PyNumber_Negative(v);
 		break;
 	case UNARY_CONVERT:
 		newconst = PyObject_Repr(v);