[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.127,2.128
Guido van Rossum
gvanrossum@users.sourceforge.net
Mon, 30 Apr 2001 07:39:20 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31866
Modified Files:
classobject.c
Log Message:
Well darnit! The innocuous fix I made to PyObject_Print() caused
printing of instances not to look for __str__(). Fix this.
Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.127
retrieving revision 2.128
diff -C2 -r2.127 -r2.128
*** classobject.c 2001/04/23 14:08:49 2.127
--- classobject.c 2001/04/30 14:39:18 2.128
***************
*** 782,785 ****
--- 782,804 ----
}
+ static PyObject *
+ instance_str(PyInstanceObject *inst)
+ {
+ PyObject *func;
+ PyObject *res;
+ static PyObject *strstr;
+
+ if (strstr == NULL)
+ strstr = PyString_InternFromString("__str__");
+ func = instance_getattr(inst, strstr);
+ if (func == NULL) {
+ PyErr_Clear();
+ return instance_repr(inst);
+ }
+ res = PyEval_CallObject(func, (PyObject *)NULL);
+ Py_DECREF(func);
+ return res;
+ }
+
static long
instance_hash(PyInstanceObject *inst)
***************
*** 1828,1832 ****
(hashfunc)instance_hash, /* tp_hash */
0, /* tp_call */
! 0, /* tp_str */
(getattrofunc)instance_getattr, /* tp_getattro */
(setattrofunc)instance_setattr, /* tp_setattro */
--- 1847,1851 ----
(hashfunc)instance_hash, /* tp_hash */
0, /* tp_call */
! (reprfunc)instance_str, /* tp_str */
(getattrofunc)instance_getattr, /* tp_getattro */
(setattrofunc)instance_setattr, /* tp_setattro */