summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-08-15 18:09:11 (GMT)
committerGuido van Rossum <guido@python.org>2001-08-15 18:09:11 (GMT)
commite6b90eaea1d04953238b3b1603e9bccc2ba4500b (patch)
tree71977ca389d13181247d38594d413d2ae03c407a
parent23cc2b4991001b79f0b87deef554ee7b66e8bbc4 (diff)
downloadcpython-e6b90eaea1d04953238b3b1603e9bccc2ba4500b.zip
cpython-e6b90eaea1d04953238b3b1603e9bccc2ba4500b.tar.gz
cpython-e6b90eaea1d04953238b3b1603e9bccc2ba4500b.tar.bz2
Add 'state' as a read-only attribute to spamdict. This serves as an
example.
-rw-r--r--Modules/xxsubtype.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/Modules/xxsubtype.c b/Modules/xxsubtype.c
index 5b8e254..1b9648c 100644
--- a/Modules/xxsubtype.c
+++ b/Modules/xxsubtype.c
@@ -1,4 +1,5 @@
#include "Python.h"
+#include "structmember.h"
/* Examples showing how to subtype the builtin list and dict types from C. */
@@ -136,6 +137,11 @@ spamdict_init(spamdictobject *self, PyObject *args, PyObject *kwds)
return 0;
}
+static struct memberlist spamdict_members[] = {
+ {"state", T_INT, offsetof(spamdictobject, state), READONLY},
+ {0}
+};
+
static PyTypeObject spamdict_type = {
PyObject_HEAD_INIT(&PyType_Type)
0,
@@ -166,7 +172,7 @@ static PyTypeObject spamdict_type = {
0, /* tp_iter */
0, /* tp_iternext */
spamdict_methods, /* tp_methods */
- 0, /* tp_members */
+ spamdict_members, /* tp_members */
0, /* tp_getset */
&PyDict_Type, /* tp_base */
0, /* tp_dict */