Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 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 = { |
Georg Brandl | 5133529 | 2009-05-05 07:55:26 +0000 | [diff] [blame] | 9 | PyVarObject_HEAD_INIT(NULL, 0) |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 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 */ |
Mark Dickinson | 9f98926 | 2009-02-02 21:29:40 +0000 | [diff] [blame] | 17 | 0, /* tp_reserved */ |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 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 */ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 29 | "Noddy objects", /* tp_doc */ |
| 30 | }; |
| 31 | |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 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 |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 40 | PyMODINIT_FUNC |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 41 | PyInit_noddy(void) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 42 | { |
| 43 | PyObject* m; |
| 44 | |
| 45 | noddy_NoddyType.tp_new = PyType_GenericNew; |
| 46 | if (PyType_Ready(&noddy_NoddyType) < 0) |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 47 | return NULL; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 48 | |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 49 | m = PyModule_Create(&noddymodule); |
| 50 | if (m == NULL) |
| 51 | return NULL; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 52 | |
| 53 | Py_INCREF(&noddy_NoddyType); |
| 54 | PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); |
Benjamin Peterson | 71e30a0 | 2008-12-24 16:27:25 +0000 | [diff] [blame] | 55 | return m; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 56 | } |