blob: fb2c7b2a430e6445e49fb9da66e885581895cba0 [file] [log] [blame]
Antoine Pitrou1d80a562018-04-07 18:14:03 +02001#include <Python.h>
2
3typedef struct {
4 PyObject_HEAD
5 /* Type-specific fields go here. */
6} CustomObject;
7
8static 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
18static 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
25PyMODINIT_FUNC
26PyInit_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}