-
Notifications
You must be signed in to change notification settings - Fork 0
/
datetimecpy.c
77 lines (73 loc) · 2.24 KB
/
datetimecpy.c
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
#define PY_SSIZE_T_CLEAN
#include <Python.h>
#include <time.h>
#include "include/date.h"
#include "include/time.h"
#include "include/timedelta.h"
PyDoc_STRVAR(datetimecpy_doc, "The datetimecpy module");
static PyModuleDef datetimecpy_def = {
PyModuleDef_HEAD_INIT,
"datetimecpy",
datetimecpy_doc,
-1, /* m_size */
NULL, /* m_methods */
NULL, /* m_slots */
NULL, /* m_traverse */
NULL, /* m_clear */
NULL, /* m_free */
};
PyMODINIT_FUNC PyInit_datetimecpy() {
if (PyType_Ready(&Date_type) < 0) {
return NULL;
}
if (PyType_Ready(&TimedeltaExporter_type) < 0) {
return NULL;
}
if (PyType_Ready(&Timedelta_type) < 0) {
return NULL;
}
PyObject* m = PyModule_Create(&datetimecpy_def);
if (!m)
{
return NULL;
}
PyModule_AddStringConstant(m, "__author__", "littlebutt");
PyModule_AddStringConstant(m, "__version__", "1.0.0");
Py_INCREF(&Date_type);
if (PyModule_AddObject(m, "date", (PyObject*)&Date_type) < 0)
{
Py_DECREF(&Date_type);
Py_DECREF(m);
return NULL;
}
PyObject* time_mod = PyModule_Create(&time_def);
if (time_mod != NULL) {
Py_INCREF(time_mod);
if (PyModule_AddObject(m, "time", time_mod) < 0) {
Py_DECREF(time_mod);
Py_DECREF(&Date_type);
Py_DECREF(m);
return NULL;
}
}
Py_INCREF(&TimedeltaExporter_type);
if (PyModule_AddObject(m, "_timedelta_exporter", (PyObject*)&TimedeltaExporter_type) < 0)
{
Py_DECREF(&TimedeltaExporter_type);
Py_DECREF(time_mod);
Py_DECREF(&Date_type);
Py_DECREF(m);
return NULL;
}
Py_INCREF(&Timedelta_type);
if (PyModule_AddObject(m, "timedelta", (PyObject*)&Timedelta_type) < 0)
{
Py_DECREF(&Timedelta_type);
Py_DECREF(&TimedeltaExporter_type);
Py_DECREF(time_mod);
Py_DECREF(&Date_type);
Py_DECREF(m);
return NULL;
}
return m;
}