[Python-checkins] CVS: python/dist/src/Objects classobject.c,2.127,2.127.2.1

Guido van Rossum gvanrossum@users.sourceforge.net
Mon, 30 Apr 2001 07:37:21 -0700


Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv31492

Modified Files:
      Tag: descr-branch
	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.

This fix should also be made to the trunk.


Index: classobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/classobject.c,v
retrieving revision 2.127
retrieving revision 2.127.2.1
diff -C2 -r2.127 -r2.127.2.1
*** classobject.c	2001/04/23 14:08:49	2.127
--- classobject.c	2001/04/30 14:37:19	2.127.2.1
***************
*** 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 */