(continued from previous page) 

return NULL ; } if (self ->last==NULL ) { PyErr_SetString(PyExc_AttributeError, "last"); return NULL ; } return PyUnicode_FromFormat("%S %S ", self ->first, self ->last); } static PyMethodDef Custom_methods[] ={ { "name", (PyCFunction) Custom_name, METH_NOARGS, "Return the name, combining the first and last name " }, { NULL } /* Sentinel */ }; static PyTypeObject CustomType={ PyVarObject_HEAD_INIT(NULL ,0) .tp_name ="custom2.Custom ", .tp_doc="Custom objects", .tp_basicsize= sizeof (CustomObject), .tp_itemsize=0, .tp_flags =Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, .tp_new=Custom_new, .tp_init=(initproc) Custom_init, .tp_dealloc =(destructor) Custom_dealloc, .tp_members=Custom_members, .tp_methods=Custom_methods, }; static PyModuleDef custommodule={ PyModuleDef_HEAD_INIT, .m_name="custom2 ", .m_doc="Example module that creates an extension type. ", .m_size=-1 , }; PyMODINIT_FUNC PyInit_custom2 ( void ) { PyObject *m; if (PyType_Ready( &CustomType)<0) return NULL ; m =PyModule_Create(&custommodule); if (m==NULL ) return NULL ; Py_INCREF(&CustomType); if (PyModule_AddObject(m, "Custom", (PyObject*)&CustomType)<0) { Py_DECREF( &CustomType); Py_DECREF(m); return NULL ; } return m; } 

This version of the module has a number of changes. 

We’ve added an extra include: 

