Extending and Embedding Python, Release 3.9.5 Chapter 2. Creating extensions without third party tools 34 &first,&last, &self->number)) return -1 ; if (first) { tmp =self->first; Py_INCREF(first); self->first =first; Py_DECREF(tmp); } if (last) { tmp =self->last; Py_INCREF(last); self->last=last; Py_DECREF(tmp); } return 0; } static PyMemberDef Custom_members[]={ { "number", T_INT, offsetof(CustomObject, number), 0, "custom number "}, { NULL } /* Sentinel */ }; static PyObject * Custom_getfirst(CustomObject *self, void *closure) { Py_INCREF(self->first); return self->first; } static int Custom_setfirst(CustomObject *self, PyObject*value, void *closure) { PyObject *tmp; if (value==NULL ) { PyErr_SetString(PyExc_TypeError, "Cannot delete the first attribute"); return -1 ; } if (!PyUnicode_Check(value)) { PyErr_SetString(PyExc_TypeError, "The first attribute value must be a string "); return -1 ; } tmp =self->first; Py_INCREF(value); self->first =value; Py_DECREF(tmp); return 0; } static PyObject * Custom_getlast(CustomObject *self, void *closure) { Py_INCREF(self->last); return self->last; } static int Custom_setlast(CustomObject *self, PyObject*value, void *closure) (continued from previous page) (continues on next page)