diff options
author | Christian Heimes <christian@cheimes.de> | 2008-02-01 08:12:03 (GMT) |
---|---|---|
committer | Christian Heimes <christian@cheimes.de> | 2008-02-01 08:12:03 (GMT) |
commit | 400adb030a78c3fcb1eb458b25c990449fbf3c93 (patch) | |
tree | 8dc99c561ec91ec9d2f887eb7b04e7227d30b8ac /Python | |
parent | a7712090f78d19d0711553d58e403c9fa44474a8 (diff) | |
download | cpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.zip cpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.tar.gz cpython-400adb030a78c3fcb1eb458b25c990449fbf3c93.tar.bz2 |
Merged revisions 60475-60479,60481-60488 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r60482 | raymond.hettinger | 2008-01-31 23:07:16 +0100 (Thu, 31 Jan 2008) | 1 line
Minor wordsmithing on docstring
........
r60483 | mark.dickinson | 2008-01-31 23:17:37 +0100 (Thu, 31 Jan 2008) | 5 lines
Issue #1678380. Fix a bug that identifies 0j and -0j when they appear
in the same code unit. The fix is essentially the same as the fix for a
previous bug identifying 0. and -0.
........
r60484 | christian.heimes | 2008-02-01 00:08:23 +0100 (Fri, 01 Feb 2008) | 1 line
Fixed bug #1983: Return from fork() is pid_t, not int
........
r60486 | jeffrey.yasskin | 2008-02-01 07:22:46 +0100 (Fri, 01 Feb 2008) | 4 lines
Move __builtins__.trunc() to math.trunc() per
http://mail.python.org/pipermail/python-dev/2008-January/076626.html and issue
1965.
........
r60487 | jeffrey.yasskin | 2008-02-01 08:05:46 +0100 (Fri, 01 Feb 2008) | 3 lines
Roll back r60248. It's useful to encourage users not to change Rational
instances.
........
r60488 | neal.norwitz | 2008-02-01 08:22:59 +0100 (Fri, 01 Feb 2008) | 1 line
Fix refleak
........
Diffstat (limited to 'Python')
-rw-r--r-- | Python/bltinmodule.c | 35 | ||||
-rw-r--r-- | Python/compile.c | 59 | ||||
-rw-r--r-- | Python/marshal.c | 1 |
3 files changed, 48 insertions, 47 deletions
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index b86e3fb..a86bb9e 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -1570,40 +1570,6 @@ PyDoc_STRVAR(vars_doc, Without arguments, equivalent to locals().\n\ With an argument, equivalent to object.__dict__."); -static PyObject * -builtin_trunc(PyObject *self, PyObject *number) -{ - static PyObject *trunc_str = NULL; - PyObject *trunc; - - if (Py_TYPE(number)->tp_dict == NULL) { - if (PyType_Ready(Py_TYPE(number)) < 0) - return NULL; - } - - if (trunc_str == NULL) { - trunc_str = PyUnicode_InternFromString("__trunc__"); - if (trunc_str == NULL) - return NULL; - } - - trunc = _PyType_Lookup(Py_TYPE(number), trunc_str); - if (trunc == NULL) { - PyErr_Format(PyExc_TypeError, - "type %.100s doesn't define __trunc__ method", - Py_TYPE(number)->tp_name); - return NULL; - } - return PyObject_CallFunction(trunc, "O", number); -} - -PyDoc_STRVAR(trunc_doc, -"trunc(Real) -> Integral\n\ -\n\ -returns the integral closest to x between 0 and x."); - - - static PyObject* builtin_sum(PyObject *self, PyObject *args) { @@ -1870,7 +1836,6 @@ static PyMethodDef builtin_methods[] = { {"sorted", (PyCFunction)builtin_sorted, METH_VARARGS | METH_KEYWORDS, sorted_doc}, {"sum", builtin_sum, METH_VARARGS, sum_doc}, {"vars", builtin_vars, METH_VARARGS, vars_doc}, - {"trunc", builtin_trunc, METH_O, trunc_doc}, {"zip", builtin_zip, METH_VARARGS, zip_doc}, {NULL, NULL}, }; diff --git a/Python/compile.c b/Python/compile.c index 6ce465c..b256198 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -885,24 +885,59 @@ compiler_add_o(struct compiler *c, PyObject *dict, PyObject *o) { PyObject *t, *v; Py_ssize_t arg; + unsigned char *p, *q; + Py_complex z; + double d; + int real_part_zero, imag_part_zero; /* necessary to make sure types aren't coerced (e.g., int and long) */ /* _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); + d = PyFloat_AS_DOUBLE(o); + 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 if (PyComplex_Check(o)) { + /* complex case is even messier: we need to make complex(x, + 0.) different from complex(x, -0.) and complex(0., y) + different from complex(-0., y), for any x and y. In + particular, all four complex zeros should be + distinguished.*/ + z = PyComplex_AsCComplex(o); + p = (unsigned char*) &(z.real); + q = (unsigned char*) &(z.imag); + /* all that matters here is that on IEEE platforms + real_part_zero will be true if z.real == 0., and false if + z.real == -0. In fact, real_part_zero will also be true + for some other rarely occurring nonzero floats, but this + doesn't matter. Similar comments apply to + imag_part_zero. */ + real_part_zero = *p==0 && p[sizeof(double)-1]==0; + imag_part_zero = *q==0 && q[sizeof(double)-1]==0; + if (real_part_zero && imag_part_zero) { + t = PyTuple_Pack(4, o, o->ob_type, Py_True, Py_True); + } + else if (real_part_zero && !imag_part_zero) { + t = PyTuple_Pack(4, o, o->ob_type, Py_True, Py_False); + } + else if (!real_part_zero && imag_part_zero) { + t = PyTuple_Pack(4, o, o->ob_type, Py_False, Py_True); + } + else { + t = PyTuple_Pack(2, o, o->ob_type); + } + } + else { + t = PyTuple_Pack(2, o, o->ob_type); } if (t == NULL) - return -1; + return -1; v = PyDict_GetItem(dict, t); if (!v) { diff --git a/Python/marshal.c b/Python/marshal.c index 175ac0e..22f84a8 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -833,6 +833,7 @@ r_object(RFILE *p) v = NULL; break; } + Py_DECREF(v2); } retval = v; break; |