1 #include <Python.h>
2
3 typedef struct {
4 PyObject_HEAD
5 /* Type-specific fields go here. */
6 } CustomObject;
7
8 static PyTypeObject CustomType = {
9 PyVarObject_HEAD_INIT(NULL, 0)
10 .tp_name = "custom.Custom",
11 .tp_doc = "Custom objects",
12 .tp_basicsize = sizeof(CustomObject),
13 .tp_itemsize = 0,
14 .tp_flags = Py_TPFLAGS_DEFAULT,
15 .tp_new = PyType_GenericNew,
16 };
17
18 static PyModuleDef custommodule = {
19 PyModuleDef_HEAD_INIT,
20 .m_name = "custom",
21 .m_doc = "Example module that creates an extension type.",
22 .m_size = -1,
23 };
24
25 PyMODINIT_FUNC
PyInit_custom(void)26 PyInit_custom(void)
27 {
28 PyObject *m;
29 if (PyType_Ready(&CustomType) < 0)
30 return NULL;
31
32 m = PyModule_Create(&custommodule);
33 if (m == NULL)
34 return NULL;
35
36 Py_INCREF(&CustomType);
37 PyModule_AddObject(m, "Custom", (PyObject *) &CustomType);
38 return m;
39 }
40