summaryrefslogtreecommitdiffstats
path: root/Objects/descrobject.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-09-20 20:46:19 (GMT)
committerGuido van Rossum <guido@python.org>2001-09-20 20:46:19 (GMT)
commit6f7993765ac0989b5d13084240797913627a31d8 (patch)
tree51dd234049db1eb78c6dd25d23ec687bf91d817c /Objects/descrobject.c
parente0af35eb694179d8da5d3208ffdfb92e5356335f (diff)
downloadcpython-6f7993765ac0989b5d13084240797913627a31d8.zip
cpython-6f7993765ac0989b5d13084240797913627a31d8.tar.gz
cpython-6f7993765ac0989b5d13084240797913627a31d8.tar.bz2
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.
Diffstat (limited to 'Objects/descrobject.c')
-rw-r--r--Objects/descrobject.c33
1 files changed, 23 insertions, 10 deletions
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index e5b08c3..dfbb3b6 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -21,7 +21,7 @@ typedef struct {
typedef struct {
COMMON;
- struct memberlist *d_member;
+ PyMemberDef *d_member;
} PyMemberDescrObject;
typedef struct {
@@ -126,8 +126,7 @@ member_get(PyMemberDescrObject *descr, PyObject *obj, PyTypeObject *type)
if (descr_check((PyDescrObject *)descr, obj, type, &res))
return res;
- return PyMember_Get((char *)obj, descr->d_member,
- descr->d_member->name);
+ return PyMember_GetOne((char *)obj, descr->d_member);
}
static PyObject *
@@ -181,8 +180,7 @@ member_set(PyMemberDescrObject *descr, PyObject *obj, PyObject *value)
if (descr_setcheck((PyDescrObject *)descr, obj, value, &res))
return res;
- return PyMember_Set((char *)obj, descr->d_member,
- descr->d_member->name, value);
+ return PyMember_SetOne((char *)obj, descr->d_member, value);
}
static int
@@ -289,7 +287,7 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
}
static PyObject *
-member_get_doc(PyMethodDescrObject *descr, void *closure)
+method_get_doc(PyMethodDescrObject *descr, void *closure)
{
if (descr->d_method->ml_doc == NULL) {
Py_INCREF(Py_None);
@@ -298,12 +296,27 @@ member_get_doc(PyMethodDescrObject *descr, void *closure)
return PyString_FromString(descr->d_method->ml_doc);
}
-static struct memberlist descr_members[] = {
+static PyMemberDef descr_members[] = {
{"__objclass__", T_OBJECT, offsetof(PyDescrObject, d_type), READONLY},
{"__name__", T_OBJECT, offsetof(PyDescrObject, d_name), READONLY},
{0}
};
+static struct getsetlist method_getset[] = {
+ {"__doc__", (getter)method_get_doc},
+ {0}
+};
+
+static PyObject *
+member_get_doc(PyMemberDescrObject *descr, void *closure)
+{
+ if (descr->d_member->doc == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyString_FromString(descr->d_member->doc);
+}
+
static struct getsetlist member_getset[] = {
{"__doc__", (getter)member_get_doc},
{0}
@@ -355,7 +368,7 @@ static PyTypeObject PyMethodDescr_Type = {
0, /* tp_iternext */
0, /* tp_methods */
descr_members, /* tp_members */
- member_getset, /* tp_getset */
+ method_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)method_get, /* tp_descr_get */
@@ -393,7 +406,7 @@ static PyTypeObject PyMemberDescr_Type = {
0, /* tp_iternext */
0, /* tp_methods */
descr_members, /* tp_members */
- 0, /* tp_getset */
+ member_getset, /* tp_getset */
0, /* tp_base */
0, /* tp_dict */
(descrgetfunc)member_get, /* tp_descr_get */
@@ -507,7 +520,7 @@ PyDescr_NewMethod(PyTypeObject *type, PyMethodDef *method)
}
PyObject *
-PyDescr_NewMember(PyTypeObject *type, struct memberlist *member)
+PyDescr_NewMember(PyTypeObject *type, PyMemberDef *member)
{
PyMemberDescrObject *descr;