1 #include <Python.h>
2
3 typedef struct {
4 PyObject_HEAD
5 /* Type-specific fields go here. */
6 } noddy_NoddyObject;
7
8 static PyTypeObject noddy_NoddyType = {
9 PyVarObject_HEAD_INIT(NULL, 0)
10 "noddy.Noddy", /* tp_name */
11 sizeof(noddy_NoddyObject), /* tp_basicsize */
12 0, /* tp_itemsize */
13 0, /* tp_dealloc */
14 0, /* tp_print */
15 0, /* tp_getattr */
16 0, /* tp_setattr */
17 0, /* tp_reserved */
18 0, /* tp_repr */
19 0, /* tp_as_number */
20 0, /* tp_as_sequence */
21 0, /* tp_as_mapping */
22 0, /* tp_hash */
23 0, /* tp_call */
24 0, /* tp_str */
25 0, /* tp_getattro */
26 0, /* tp_setattro */
27 0, /* tp_as_buffer */
28 Py_TPFLAGS_DEFAULT, /* tp_flags */
29 "Noddy objects", /* tp_doc */
30 };
31
32 static PyModuleDef noddymodule = {
33 PyModuleDef_HEAD_INIT,
34 "noddy",
35 "Example module that creates an extension type.",
36 -1,
37 NULL, NULL, NULL, NULL, NULL
38 };
39
40 PyMODINIT_FUNC
PyInit_noddy(void)41 PyInit_noddy(void)
42 {
43 PyObject* m;
44
45 noddy_NoddyType.tp_new = PyType_GenericNew;
46 if (PyType_Ready(&noddy_NoddyType) < 0)
47 return NULL;
48
49 m = PyModule_Create(&noddymodule);
50 if (m == NULL)
51 return NULL;
52
53 Py_INCREF(&noddy_NoddyType);
54 PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType);
55 return m;
56 }
57