-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.cpp
88 lines (81 loc) · 3.13 KB
/
module.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include "module.h"
#include "oocmap.h"
#include "lazytuple.h"
#include "lazylist.h"
#include "lazydict.h"
static PyMethodDef OocmapMethods[] = {
{nullptr, nullptr, 0, nullptr} /* Sentinel */
};
static struct PyModuleDef oocmap_module = {
PyModuleDef_HEAD_INIT,
"oocmap", /* name of module */
"A Python dictionary that reads and writes its contents to disk.",
-1,
OocmapMethods
};
PyMODINIT_FUNC PyInit_oocmap() {
if(PyType_Ready(&OOCMapType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyTupleType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyListType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyListIterType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictItemsType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictItemsIterType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictKeysType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictKeysIterType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictValuesType) < 0)
return nullptr;
if(PyType_Ready(&OOCLazyDictValuesIterType) < 0)
return nullptr;
PyObject* const m = PyModule_Create(&oocmap_module);
if(m == nullptr)
return nullptr;
Py_INCREF(&OOCMapType);
Py_INCREF(&OOCLazyTupleType);
Py_INCREF(&OOCLazyListType);
Py_INCREF(&OOCLazyListIterType);
Py_INCREF(&OOCLazyDictType);
Py_INCREF(&OOCLazyDictItemsType);
Py_INCREF(&OOCLazyDictItemsIterType);
Py_INCREF(&OOCLazyDictKeysType);
Py_INCREF(&OOCLazyDictKeysIterType);
Py_INCREF(&OOCLazyDictValuesType);
Py_INCREF(&OOCLazyDictValuesIterType);
if(
PyModule_AddObject(m, "OOCMap", (PyObject*)&OOCMapType) < 0 ||
PyModule_AddObject(m, "LazyTuple", (PyObject*)&OOCLazyTupleType) < 0 ||
PyModule_AddObject(m, "LazyList", (PyObject*)&OOCLazyListType) < 0 ||
PyModule_AddObject(m, "LazyListIter", (PyObject*)&OOCLazyListIterType) < 0 ||
PyModule_AddObject(m, "LazyDict", (PyObject*)&OOCLazyDictType) < 0 ||
PyModule_AddObject(m, "LazyDictItems", (PyObject*)&OOCLazyDictItemsType) < 0 ||
PyModule_AddObject(m, "LazyDictItemsIter", (PyObject*)&OOCLazyDictItemsIterType) < 0 ||
PyModule_AddObject(m, "LazyDictKeys", (PyObject*)&OOCLazyDictKeysType) < 0 ||
PyModule_AddObject(m, "LazyDictKeysIter", (PyObject*)&OOCLazyDictKeysIterType) < 0 ||
PyModule_AddObject(m, "LazyDictValues", (PyObject*)&OOCLazyDictKeysType) < 0 ||
PyModule_AddObject(m, "LazyDictValuesIter", (PyObject*)&OOCLazyDictKeysIterType) < 0
) {
Py_DECREF(&OOCMapType);
Py_DECREF(&OOCLazyTupleType);
Py_DECREF(&OOCLazyListType);
Py_DECREF(&OOCLazyListIterType);
Py_DECREF(&OOCLazyDictType);
Py_DECREF(&OOCLazyDictItemsType);
Py_DECREF(&OOCLazyDictItemsIterType);
Py_DECREF(&OOCLazyDictKeysType);
Py_DECREF(&OOCLazyDictKeysIterType);
Py_DECREF(&OOCLazyDictValuesType);
Py_DECREF(&OOCLazyDictValuesIterType);
Py_DECREF(m);
return nullptr;
}
return m;
}