diff Python/symtable.c @ 20012:3faabf54b8b8 legacy-trunk

Add optional docstrings to member descriptors. For backwards compatibility, this required all places where an array of "struct memberlist" structures was declared that is referenced from a type's tp_members slot to change the type of the structure to PyMemberDef; "struct memberlist" is now only used by old code that still calls PyMember_Get/Set. The code in PyObject_GenericGetAttr/SetAttr now calls the new APIs PyMember_GetOne/SetOne, which take a PyMemberDef argument. As examples, I added actual docstrings to the attributes of a few types: file, complex, instance method, super, and xxsubtype.spamlist. Also converted the symtable to new style getattr.
author Guido van Rossum <guido@python.org>
date Thu, 20 Sep 2001 20:46:19 +0000
parents 7bc473b2c654
children 5e25c669741c
line wrap: on
line diff
--- a/Python/symtable.c	Thu Sep 20 20:43:28 2001 +0000
+++ b/Python/symtable.c	Thu Sep 20 20:46:19 2001 +0000
@@ -106,7 +106,7 @@
 
 #define OFF(x) offsetof(PySymtableEntryObject, x)
 
-static struct memberlist ste_memberlist[] = {
+static PyMemberDef ste_memberlist[] = {
 	{"id",       T_OBJECT, OFF(ste_id), READONLY},
 	{"name",     T_OBJECT, OFF(ste_name), READONLY},
 	{"symbols",  T_OBJECT, OFF(ste_symbols), READONLY},
@@ -119,12 +119,6 @@
 	{NULL}
 };
 
-static PyObject *
-ste_getattr(PySymtableEntryObject *ste, char *name)
-{
-	return PyMember_Get((char *)ste, ste_memberlist, name);
-}
-
 PyTypeObject PySymtableEntry_Type = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,
@@ -133,7 +127,7 @@
 	0,
 	(destructor)ste_dealloc,                /* tp_dealloc */
 	0,                                      /* tp_print */
-	(getattrfunc)ste_getattr,               /* tp_getattr */
+	0,			               /* tp_getattr */
 	0,					/* tp_setattr */
 	0,			                /* tp_compare */
 	(reprfunc)ste_repr,			/* tp_repr */
@@ -143,9 +137,26 @@
 	0,					/* tp_hash */
 	0,					/* tp_call */
 	0,					/* tp_str */
-	0,					/* tp_getattro */
+	PyObject_GenericGetAttr,		/* tp_getattro */
 	0,					/* tp_setattro */
 	0,					/* tp_as_buffer */
 	Py_TPFLAGS_DEFAULT,	                /* tp_flags */
  	0,					/* tp_doc */
+	0,					/* tp_traverse */
+	0,					/* tp_clear */
+	0,					/* tp_richcompare */
+	0,					/* tp_weaklistoffset */
+	0,					/* tp_iter */
+	0,					/* tp_iternext */
+	0,					/* tp_methods */
+	ste_memberlist,				/* tp_members */
+	0,					/* tp_getset */
+	0,					/* tp_base */
+	0,					/* tp_dict */
+	0,					/* tp_descr_get */
+	0,					/* tp_descr_set */
+	0,					/* tp_dictoffset */
+	0,					/* tp_init */
+	0,					/* tp_alloc */
+	0,					/* tp_new */
 };