Georg Brandl | 8ec7f65 | 2007-08-15 14:28:01 +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 = { |
INADA Naoki | 9436bbd | 2017-02-21 21:12:03 +0900 | [diff] [blame] | 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_compare */ |
| 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 | 8ec7f65 | 2007-08-15 14:28:01 +0000 | [diff] [blame] | 29 | "Noddy objects", /* tp_doc */ |
| 30 | }; |
| 31 | |
| 32 | static PyMethodDef noddy_methods[] = { |
| 33 | {NULL} /* Sentinel */ |
| 34 | }; |
| 35 | |
| 36 | #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ |
| 37 | #define PyMODINIT_FUNC void |
| 38 | #endif |
| 39 | PyMODINIT_FUNC |
| 40 | initnoddy(void) |
| 41 | { |
| 42 | PyObject* m; |
| 43 | |
| 44 | noddy_NoddyType.tp_new = PyType_GenericNew; |
| 45 | if (PyType_Ready(&noddy_NoddyType) < 0) |
| 46 | return; |
| 47 | |
| 48 | m = Py_InitModule3("noddy", noddy_methods, |
| 49 | "Example module that creates an extension type."); |
| 50 | |
| 51 | Py_INCREF(&noddy_NoddyType); |
| 52 | PyModule_AddObject(m, "Noddy", (PyObject *)&noddy_NoddyType); |
| 53 | } |