[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.126.4.3,2.126.4.4

Tim Peters tim_one@users.sourceforge.net
Sun, 17 Mar 2002 10:57:09 -0800


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

Modified Files:
      Tag: release22-maint
	typeobject.c 
Log Message:
SF patch 530070: pydoc regression, from Martin and Guido.
Change the way __doc__ is handled, to avoid blowing up on non-string
__doc__ values.


Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.126.4.3
retrieving revision 2.126.4.4
diff -C2 -d -r2.126.4.3 -r2.126.4.4
*** typeobject.c	16 Mar 2002 17:56:51 -0000	2.126.4.3
--- typeobject.c	17 Mar 2002 18:57:07 -0000	2.126.4.4
***************
*** 80,87 ****
--- 80,104 ----
  }
  
+ static PyObject *
+ type_get_doc(PyTypeObject *type, void *context)
+ {
+ 	PyObject *result;
+ 	if (!(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) {
+ 		if (type->tp_doc == NULL) {
+ 			Py_INCREF(Py_None);
+ 			return Py_None;
+ 		}
+ 		return PyString_FromString(type->tp_doc);
+ 	}
+ 	result = PyDict_GetItemString(type->tp_dict, "__doc__");
+ 	Py_INCREF(result);
+ 	return result;
+ }
+ 
  static PyGetSetDef type_getsets[] = {
  	{"__name__", (getter)type_name, NULL, NULL},
  	{"__module__", (getter)type_module, (setter)type_set_module, NULL},
  	{"__dict__",  (getter)type_dict,  NULL, NULL},
+ 	{"__doc__", (getter)type_get_doc, NULL, NULL},
  	{0}
  };
***************
*** 1080,1086 ****
  
  	/* Set tp_doc to a copy of dict['__doc__'], if the latter is there
! 	   and is a string.  Note that the tp_doc slot will only be used
! 	   by C code -- python code will use the version in tp_dict, so
! 	   it isn't that important that non string __doc__'s are ignored.
  	*/
  	{
--- 1097,1102 ----
  
  	/* Set tp_doc to a copy of dict['__doc__'], if the latter is there
! 	   and is a string.  The __doc__ accessor will first look for tp_doc;
! 	   if that fails, it will still look into __dict__.
  	*/
  	{