|
@@ -0,0 +1,104 @@
|
|
1
|
+#include<Python.h>
|
|
2
|
+#include"structmember.h"
|
|
3
|
+
|
|
4
|
+typedef struct
|
|
5
|
+{
|
|
6
|
+ PyObject VAR_HEAD;
|
|
7
|
+ Py_ssize_t len;
|
|
8
|
+} CTurmit;
|
|
9
|
+
|
|
10
|
+static PyModuleDef cturmitmodule = {
|
|
11
|
+ PyModuleDef_HEAD_INIT,
|
|
12
|
+ "cturmit",
|
|
13
|
+ "Module that implements turmits in C",
|
|
14
|
+ -1,
|
|
15
|
+ NULL, NULL, NULL, NULL, NULL
|
|
16
|
+};
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+static PyMemberDef CTurmit_members[] = {
|
|
20
|
+ {"len", T_PYSSIZET, offsetof(CTurmit, len), 0,
|
|
21
|
+ "Expression len"},
|
|
22
|
+ /*
|
|
23
|
+ {"heap_sz", T_PYSSIZET, offsetof(CTurmit, heap_sz), 0,
|
|
24
|
+ "Item heap counter"},
|
|
25
|
+ */
|
|
26
|
+ {NULL} /* Sentinel */
|
|
27
|
+};
|
|
28
|
+
|
|
29
|
+Py_ssize_t CTurmit_len(CTurmit*);
|
|
30
|
+
|
|
31
|
+static PyMappingMethods CTurmit_asmapping[] = {{
|
|
32
|
+ (void*)CTurmit_len,
|
|
33
|
+}};
|
|
34
|
+
|
|
35
|
+static PyMethodDef CTurmit_methods[] = {
|
|
36
|
+ {NULL} /* Sentinel */
|
|
37
|
+};
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+static PyObject *
|
|
41
|
+CTurmit_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|
42
|
+{
|
|
43
|
+ CTurmit *self;
|
|
44
|
+ self = (CTurmit *)type->tp_alloc(type, 0);
|
|
45
|
+ if(self != NULL) {
|
|
46
|
+ //do stuff
|
|
47
|
+ }
|
|
48
|
+ return (PyObject *)self;
|
|
49
|
+}
|
|
50
|
+
|
|
51
|
+void
|
|
52
|
+CTurmit_dealloc(CTurmit *self);
|
|
53
|
+
|
|
54
|
+static int
|
|
55
|
+CTurmit_init(CTurmit *self, PyObject *args, PyObject *kwds)
|
|
56
|
+{
|
|
57
|
+ //Init attributes
|
|
58
|
+ self->len = 0;
|
|
59
|
+ return 0;
|
|
60
|
+}
|
|
61
|
+
|
|
62
|
+static PyTypeObject CTurmitType = {
|
|
63
|
+ PyVarObject_HEAD_INIT(NULL, 0)
|
|
64
|
+ "cturmit.CTurmit", /* tp_name */
|
|
65
|
+ sizeof(CTurmit), /* tp_basicsize */
|
|
66
|
+ 0, /* tp_itemsize */
|
|
67
|
+ (destructor)CTurmit_dealloc, /* tp_dealloc */
|
|
68
|
+ 0, /* tp_print */
|
|
69
|
+ 0, /* tp_getattr */
|
|
70
|
+ 0, /* tp_setattr */
|
|
71
|
+ 0, /* tp_reserved */
|
|
72
|
+ 0, /* tp_repr */
|
|
73
|
+ 0, /* tp_as_number */
|
|
74
|
+ 0, /* tp_as_sequence */
|
|
75
|
+ CTurmit_asmapping, /* tp_as_mapping */
|
|
76
|
+ 0, /* tp_hash */
|
|
77
|
+ 0, /* tp_call */
|
|
78
|
+ 0, /* tp_str */
|
|
79
|
+ 0, /* tp_getattro */
|
|
80
|
+ 0, /* tp_setattro */
|
|
81
|
+ 0, /* tp_as_buffer */
|
|
82
|
+ Py_TPFLAGS_DEFAULT |
|
|
83
|
+ Py_TPFLAGS_BASETYPE, /* tp_flags */
|
|
84
|
+ "CTurmit objects", /* tp_doc */
|
|
85
|
+ 0, /* tp_traverse */
|
|
86
|
+ 0, /* tp_clear */
|
|
87
|
+ 0, /* tp_richcompare */
|
|
88
|
+ 0, /* tp_weaklistoffset */
|
|
89
|
+ 0, /* tp_iter */
|
|
90
|
+ 0, /* tp_iternext */
|
|
91
|
+ CTurmit_methods, /* tp_methods */
|
|
92
|
+ CTurmit_members, /* tp_members */
|
|
93
|
+ 0, /* tp_getset */
|
|
94
|
+ 0, /* tp_base */
|
|
95
|
+ 0, /* tp_dict */
|
|
96
|
+ 0, /* tp_descr_get */
|
|
97
|
+ 0, /* tp_descr_set */
|
|
98
|
+ 0, /* tp_dictoffset */
|
|
99
|
+ (initproc)CTurmit_init, /* tp_init */
|
|
100
|
+ 0, /* tp_alloc */
|
|
101
|
+ CTurmit_new, /* tp_new */
|
|
102
|
+};
|
|
103
|
+
|
|
104
|
+
|