-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathmodule.cpp
More file actions
162 lines (145 loc) · 5.44 KB
/
module.cpp
File metadata and controls
162 lines (145 loc) · 5.44 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include <Python.h>
#include "range_coder_interface.h"
static PyMethodDef RangeEncoder_methods[] = {
{"encode",
(PyCFunction)RangeEncoder_encode,
METH_VARARGS | METH_KEYWORDS,
RangeEncoder_encode_doc},
{"close",
(PyCFunction)RangeEncoder_close,
METH_VARARGS | METH_KEYWORDS,
RangeEncoder_close_doc},
{0}
};
static PyGetSetDef RangeEncoder_getset[] = {
{0}
};
PyTypeObject RangeEncoder_type = {
PyVarObject_HEAD_INIT(0, 0)
"range_coder.RangeEncoder", /*tp_name*/
sizeof(RangeEncoderObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)RangeEncoder_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
RangeEncoder_doc, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
RangeEncoder_methods, /*tp_methods*/
0, /*tp_members*/
RangeEncoder_getset, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
(initproc)RangeEncoder_init, /*tp_init*/
0, /*tp_alloc*/
RangeEncoder_new, /*tp_new*/
};
static PyMethodDef RangeDecoder_methods[] = {
{"decode",
(PyCFunction)RangeDecoder_decode,
METH_VARARGS | METH_KEYWORDS,
RangeDecoder_decode_doc},
{"close",
(PyCFunction)RangeDecoder_close,
METH_VARARGS | METH_KEYWORDS,
RangeDecoder_close_doc},
{0}
};
static PyGetSetDef RangeDecoder_getset[] = {
{0}
};
PyTypeObject RangeDecoder_type = {
PyVarObject_HEAD_INIT(0, 0)
"range_coder.RangeDecoder", /*tp_name*/
sizeof(RangeDecoderObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)RangeDecoder_dealloc, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequdece*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT, /*tp_flags*/
RangeDecoder_doc, /*tp_doc*/
0, /*tp_traverse*/
0, /*tp_clear*/
0, /*tp_richcompare*/
0, /*tp_weaklistoffset*/
0, /*tp_iter*/
0, /*tp_iternext*/
RangeDecoder_methods, /*tp_methods*/
0, /*tp_members*/
RangeDecoder_getset, /*tp_getset*/
0, /*tp_base*/
0, /*tp_dict*/
0, /*tp_descr_get*/
0, /*tp_descr_set*/
0, /*tp_dictoffset*/
(initproc)RangeDecoder_init, /*tp_init*/
0, /*tp_alloc*/
RangeDecoder_new, /*tp_new*/
};
#if PY_MAJOR_VERSION >= 3
static PyModuleDef range_coder_module = {
PyModuleDef_HEAD_INIT,
"_range_coder",
"A fast implementation of a range encoder and decoder.",
-1, 0, 0, 0, 0, 0
};
#endif
#if PY_MAJOR_VERSION >= 3
PyMODINIT_FUNC PyInit__range_coder() {
// create module object
PyObject* module = PyModule_Create(&range_coder_module);
#define RETVAL 0;
#else
PyMODINIT_FUNC init_range_coder() {
PyObject* module = Py_InitModule3(
"_range_coder", 0, "A fast implementation of a range encoder and decoder.");
#define RETVAL void();
#endif
if(!module)
return RETVAL;
// initialize types
if(PyType_Ready(&RangeEncoder_type) < 0)
return RETVAL;
if(PyType_Ready(&RangeDecoder_type) < 0)
return RETVAL;
// add types to module
Py_INCREF(&RangeEncoder_type);
PyModule_AddObject(module, "RangeEncoder", reinterpret_cast<PyObject*>(&RangeEncoder_type));
Py_INCREF(&RangeDecoder_type);
PyModule_AddObject(module, "RangeDecoder", reinterpret_cast<PyObject*>(&RangeDecoder_type));
#if PY_MAJOR_VERSION >= 3
return module;
#endif
}