Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 88dcf03

Browse files
committed
Add 'state' as a get/set attribute to spamlist. This serves as an
example.
1 parent e6b90ea commit 88dcf03

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

Modules/xxsubtype.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ spamlist_init(spamlistobject *self, PyObject *args, PyObject *kwds)
4949
return 0;
5050
}
5151

52+
static PyObject *
53+
spamlist_state_get(spamlistobject *self)
54+
{
55+
return PyInt_FromLong(self->state);
56+
}
57+
58+
static struct getsetlist spamlist_getsets[] = {
59+
{"state", (getter)spamlist_state_get, NULL, NULL},
60+
{0}
61+
};
62+
5263
static PyTypeObject spamlist_type = {
5364
PyObject_HEAD_INIT(&PyType_Type)
5465
0,
@@ -80,7 +91,7 @@ static PyTypeObject spamlist_type = {
8091
0, /* tp_iternext */
8192
spamlist_methods, /* tp_methods */
8293
0, /* tp_members */
83-
0, /* tp_getset */
94+
spamlist_getsets, /* tp_getset */
8495
&PyList_Type, /* tp_base */
8596
0, /* tp_dict */
8697
0, /* tp_descr_get */

0 commit comments

Comments
 (0)