summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2003-03-02 13:51:47 (GMT)
committerGuido van Rossum <guido@python.org>2003-03-02 13:51:47 (GMT)
commit4eadfa2b2eeca190546261149cbf1607488dea0a (patch)
tree767587708c3dd9965e9d4eadd43bd74637e42bdc
parent41bcbe3050564caf69ad5ef2438e1f65ddb02df6 (diff)
downloadcpython-4eadfa2b2eeca190546261149cbf1607488dea0a.zip
cpython-4eadfa2b2eeca190546261149cbf1607488dea0a.tar.gz
cpython-4eadfa2b2eeca190546261149cbf1607488dea0a.tar.bz2
Fix from Greg Chapman from SF bug #695651: a complex subclass
constructor, when passed a single complex argument, returns the argument unchanged. This should be done only for the complex base class; a complex subclass should of course cast the value to the subclass in this case. The fix also revealed a segfault in complex_getnewargs(): the argument for the Py_BuildValue() format code "D" is the *address* of a Py_complex struct, not the value. (This corroborated by the API documentation.) I expect this needs to be backported to 2.2.3.
-rw-r--r--Objects/complexobject.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c
index 201da4d..a346ac2 100644
--- a/Objects/complexobject.c
+++ b/Objects/complexobject.c
@@ -642,7 +642,7 @@ complex_conjugate(PyObject *self)
static PyObject *
complex_getnewargs(PyComplexObject *v)
{
- return Py_BuildValue("(D)", v->cval);
+ return Py_BuildValue("(D)", &v->cval);
}
static PyMethodDef complex_methods[] = {
@@ -832,7 +832,8 @@ complex_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return NULL;
/* Special-case for single argumet that is already complex */
- if (PyComplex_CheckExact(r) && i == NULL) {
+ if (PyComplex_CheckExact(r) && i == NULL &&
+ type == &PyComplex_Type) {
/* Note that we can't know whether it's safe to return
a complex *subclass* instance as-is, hence the restriction
to exact complexes here. */