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 */ |
Stefan Krah | b1558a0 | 2017-09-22 18:14:13 +0200 | [diff] [blame] | 30 | 0, /* tp_traverse */ |
| 31 | 0, /* tp_clear */ |
| 32 | 0, /* tp_richcompare */ |
| 33 | 0, /* tp_weaklistoffset */ |
| 34 | 0, /* tp_iter */ |
| 35 | 0, /* tp_iternext */ |
| 36 | 0, /* tp_methods */ |
| 37 | 0, /* tp_members */ |
| 38 | 0, /* tp_getset */ |
| 39 | 0, /* tp_base */ |
| 40 | 0, /* tp_dict */ |
| 41 | 0, /* tp_descr_get */ |
| 42 | 0, /* tp_descr_set */ |
| 43 | 0, /* tp_dictoffset */ |
| 44 | 0, /* tp_init */ |
| 45 | 0, /* tp_alloc */ |
| 46 | PyType_GenericNew, /* tp_new */ |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 49 | static PyModuleDef noddymodule = { |
| 50 | PyModuleDef_HEAD_INIT, |
| 51 | "noddy", |
| 52 | "Example module that creates an extension type.", |
| 53 | -1, |
| 54 | NULL, NULL, NULL, NULL, NULL |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 57 | PyMODINIT_FUNC |
Serhiy Storchaka | 009b811 | 2015-03-18 21:53:15 +0200 | [diff] [blame] | 58 | PyInit_noddy(void) |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 59 | { |
| 60 | PyObject* m; |
| 61 | |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 62 | if (PyType_Ready(&noddy_NoddyType) < 0) |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 63 | return NULL; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 64 | |
Georg Brandl | 913b2a3 | 2008-12-05 15:12:15 +0000 | [diff] [blame] | 65 | m = PyModule_Create(&noddymodule); |
| 66 | if (m == NULL) |
| 67 | return NULL; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 68 | |
| 69 | Py_INCREF(&noddy_NoddyType); |
| 70 | PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); |
Benjamin Peterson | 71e30a0 | 2008-12-24 16:27:25 +0000 | [diff] [blame] | 71 | return m; |
Georg Brandl | 116aa62 | 2007-08-15 14:28:22 +0000 | [diff] [blame] | 72 | } |