summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorAlex Martelli <aleaxit@gmail.com>2007-08-22 21:14:17 (GMT)
committerAlex Martelli <aleaxit@gmail.com>2007-08-22 21:14:17 (GMT)
commitd8672aa8a4c925c69cac51561c68a9820cf97124 (patch)
tree8b9b8a463b69f80c2b9e38805d0686cb7e120692 /Python/compile.c
parent89e975fc74d794c2087244d6f684477b334233c3 (diff)
downloadcpython-d8672aa8a4c925c69cac51561c68a9820cf97124.zip
cpython-d8672aa8a4c925c69cac51561c68a9820cf97124.tar.gz
cpython-d8672aa8a4c925c69cac51561c68a9820cf97124.tar.bz2
Fix compile.c so that it records 0.0 and -0.0 as separate constants in a code
object's co_consts tuple; add a test to show that the previous behavior (where these two constants were "collapsed" into one) causes serious malfunctioning.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c15
1 files changed, 14 insertions, 1 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 01dbb1a..eed1379 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -907,7 +907,20 @@ compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o)
Py_ssize_t arg;
/* necessary to make sure types aren't coerced (e.g., int and long) */
- t = PyTuple_Pack(2, o, o->ob_type);
+ /* _and_ to distinguish 0.0 from -0.0 e.g. on IEEE platforms */
+ if (PyFloat_Check(o)) {
+ double d = PyFloat_AS_DOUBLE(o);
+ unsigned char* p = (unsigned char*) &d;
+ /* all we need is to make the tuple different in either the 0.0
+ * or -0.0 case from all others, just to avoid the "coercion".
+ */
+ if (*p==0 && p[sizeof(double)-1]==0)
+ t = PyTuple_Pack(3, o, o->ob_type, Py_None);
+ else
+ t = PyTuple_Pack(2, o, o->ob_type);
+ } else {
+ t = PyTuple_Pack(2, o, o->ob_type);
+ }
if (t == NULL)
return -1;