[Python-checkins] CVS: python/dist/src/Objects typeobject.c,2.126,2.127
Martin v. L?wis
loewis@users.sourceforge.net
Mon, 18 Feb 2002 09:46:50 -0800
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv20825
Modified Files:
typeobject.c
Log Message:
Allow __doc__ to be of arbitrary type. Patch by James Henstridge,
fixes #504343. 2.2.1 candidate.
Index: typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.126
retrieving revision 2.127
diff -C2 -d -r2.126 -r2.127
*** typeobject.c 17 Dec 2001 17:14:22 -0000 2.126
--- typeobject.c 18 Feb 2002 17:46:48 -0000 2.127
***************
*** 9,13 ****
{"__itemsize__", T_INT, offsetof(PyTypeObject, tp_itemsize), READONLY},
{"__flags__", T_LONG, offsetof(PyTypeObject, tp_flags), READONLY},
- {"__doc__", T_STRING, offsetof(PyTypeObject, tp_doc), READONLY},
{"__weakrefoffset__", T_LONG,
offsetof(PyTypeObject, tp_weaklistoffset), READONLY},
--- 9,12 ----
***************
*** 1045,1051 ****
/* Set tp_doc to a copy of dict['__doc__'], if the latter is there
! and is a string (tp_doc is a char* -- can't copy a general object
! into it).
! XXX What if it's a Unicode string? Don't know -- this ignores it.
*/
{
--- 1044,1050 ----
/* 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.
*/
{
***************
*** 2023,2026 ****
--- 2022,2038 ----
if (PyType_Check(b))
inherit_slots(type, (PyTypeObject *)b);
+ }
+
+ /* if the type dictionary doesn't contain a __doc__, set it from
+ the tp_doc slot.
+ */
+ if (PyDict_GetItemString(type->tp_dict, "__doc__") == NULL) {
+ if (type->tp_doc != NULL) {
+ PyObject *doc = PyString_FromString(type->tp_doc);
+ PyDict_SetItemString(type->tp_dict, "__doc__", doc);
+ Py_DECREF(doc);
+ } else {
+ PyDict_SetItemString(type->tp_dict, "__doc__", Py_None);
+ }
}