[Python-checkins] python/dist/src/Objects complexobject.c,2.65,2.66
gvanrossum@users.sourceforge.net
gvanrossum@users.sourceforge.net
Sun, 02 Mar 2003 05:51:49 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory sc8-pr-cvs1:/tmp/cvs-serv21390
Modified Files:
complexobject.c
Log Message:
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.
Index: complexobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/complexobject.c,v
retrieving revision 2.65
retrieving revision 2.66
diff -C2 -d -r2.65 -r2.66
*** complexobject.c 29 Jan 2003 17:58:44 -0000 2.65
--- complexobject.c 2 Mar 2003 13:51:47 -0000 2.66
***************
*** 643,647 ****
complex_getnewargs(PyComplexObject *v)
{
! return Py_BuildValue("(D)", v->cval);
}
--- 643,647 ----
complex_getnewargs(PyComplexObject *v)
{
! return Py_BuildValue("(D)", &v->cval);
}
***************
*** 833,837 ****
/* Special-case for single argumet that is already complex */
! if (PyComplex_CheckExact(r) && i == NULL) {
/* Note that we can't know whether it's safe to return
a complex *subclass* instance as-is, hence the restriction
--- 833,838 ----
/* Special-case for single argumet that is already complex */
! 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