blob: 13d16f5424ae4de319c58f0ae61aae0a1bd28ea4 [file] [log] [blame]
Inada Naokic88fece2019-04-13 10:46:21 +09001#define PY_SSIZE_T_CLEAN
Antoine Pitrou1d80a562018-04-07 18:14:03 +02002#include <Python.h>
3
4typedef struct {
5 PyObject_HEAD
6 /* Type-specific fields go here. */
7} CustomObject;
8
9static PyTypeObject CustomType = {
10 PyVarObject_HEAD_INIT(NULL, 0)
11 .tp_name = "custom.Custom",
12 .tp_doc = "Custom objects",
13 .tp_basicsize = sizeof(CustomObject),
14 .tp_itemsize = 0,
15 .tp_flags = Py_TPFLAGS_DEFAULT,
16 .tp_new = PyType_GenericNew,
17};
18
19static PyModuleDef custommodule = {
20 PyModuleDef_HEAD_INIT,
21 .m_name = "custom",
22 .m_doc = "Example module that creates an extension type.",
23 .m_size = -1,
24};
25
26PyMODINIT_FUNC
27PyInit_custom(void)
28{
29 PyObject *m;
30 if (PyType_Ready(&CustomType) < 0)
31 return NULL;
32
33 m = PyModule_Create(&custommodule);
34 if (m == NULL)
35 return NULL;
36
37 Py_INCREF(&CustomType);
38 PyModule_AddObject(m, "Custom", (PyObject *) &CustomType);
39 return m;
40}