Extending and Embedding Python, Release 3.9.5 27 2.2. Defining Extension Types: Tutorial (continues on next page) (continued from previous page) Custom_new(PyTypeObject *type, PyObject*args, PyObject*kwds) { CustomObject*self; self =(CustomObject*) type ->tp_alloc(type, 0); if (self!=NULL ) { self->first =PyUnicode_FromString(""); if (self ->first ==NULL ) { Py_DECREF(self); return NULL ; } self->last=PyUnicode_FromString(""); if (self ->last==NULL ) { Py_DECREF(self); return NULL ; } self->number =0; } return (PyObject*) self; } static int Custom_init(CustomObject *self, PyObject*args, PyObject*kwds) { static char *kwlist[] ={ "first","last","number",NULL }; PyObject *first =NULL ,*last=NULL ,*tmp; if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OOi ", kwlist, &first,&last, &self->number)) return -1 ; if (first) { tmp =self->first; Py_INCREF(first); self->first =first; Py_XDECREF(tmp); } if (last) { tmp =self->last; Py_INCREF(last); self->last=last; Py_XDECREF(tmp); } return 0; } static PyMemberDef Custom_members[]={ { "first", T_OBJECT_EX, offsetof(CustomObject, first), 0, "first name"}, { "last", T_OBJECT_EX, offsetof(CustomObject, last), 0, "last name "}, { "number", T_INT, offsetof(CustomObject, number), 0, "custom number "}, { NULL } /* Sentinel */ }; static PyObject * Custom_name(CustomObject *self, PyObject*Py_UNUSED(ignored)) { if (self ->first ==NULL ) { PyErr_SetString(PyExc_AttributeError, "first");