Show More
@@ -1,226 +1,226 | |||||
1 | /** |
|
1 | /** | |
2 | * Copyright (c) 2016-present, Gregory Szorc |
|
2 | * Copyright (c) 2016-present, Gregory Szorc | |
3 | * All rights reserved. |
|
3 | * All rights reserved. | |
4 | * |
|
4 | * | |
5 | * This software may be modified and distributed under the terms |
|
5 | * This software may be modified and distributed under the terms | |
6 | * of the BSD license. See the LICENSE file for details. |
|
6 | * of the BSD license. See the LICENSE file for details. | |
7 | */ |
|
7 | */ | |
8 |
|
8 | |||
9 | #include "python-zstandard.h" |
|
9 | #include "python-zstandard.h" | |
10 |
|
10 | |||
11 | void ztopy_compression_parameters(CompressionParametersObject* params, ZSTD_compressionParameters* zparams) { |
|
11 | void ztopy_compression_parameters(CompressionParametersObject* params, ZSTD_compressionParameters* zparams) { | |
12 | zparams->windowLog = params->windowLog; |
|
12 | zparams->windowLog = params->windowLog; | |
13 | zparams->chainLog = params->chainLog; |
|
13 | zparams->chainLog = params->chainLog; | |
14 | zparams->hashLog = params->hashLog; |
|
14 | zparams->hashLog = params->hashLog; | |
15 | zparams->searchLog = params->searchLog; |
|
15 | zparams->searchLog = params->searchLog; | |
16 | zparams->searchLength = params->searchLength; |
|
16 | zparams->searchLength = params->searchLength; | |
17 | zparams->targetLength = params->targetLength; |
|
17 | zparams->targetLength = params->targetLength; | |
18 | zparams->strategy = params->strategy; |
|
18 | zparams->strategy = params->strategy; | |
19 | } |
|
19 | } | |
20 |
|
20 | |||
21 | CompressionParametersObject* get_compression_parameters(PyObject* self, PyObject* args) { |
|
21 | CompressionParametersObject* get_compression_parameters(PyObject* self, PyObject* args) { | |
22 | int compressionLevel; |
|
22 | int compressionLevel; | |
23 | unsigned PY_LONG_LONG sourceSize = 0; |
|
23 | unsigned PY_LONG_LONG sourceSize = 0; | |
24 | Py_ssize_t dictSize = 0; |
|
24 | Py_ssize_t dictSize = 0; | |
25 | ZSTD_compressionParameters params; |
|
25 | ZSTD_compressionParameters params; | |
26 | CompressionParametersObject* result; |
|
26 | CompressionParametersObject* result; | |
27 |
|
27 | |||
28 | if (!PyArg_ParseTuple(args, "i|Kn", &compressionLevel, &sourceSize, &dictSize)) { |
|
28 | if (!PyArg_ParseTuple(args, "i|Kn", &compressionLevel, &sourceSize, &dictSize)) { | |
29 | return NULL; |
|
29 | return NULL; | |
30 | } |
|
30 | } | |
31 |
|
31 | |||
32 | params = ZSTD_getCParams(compressionLevel, sourceSize, dictSize); |
|
32 | params = ZSTD_getCParams(compressionLevel, sourceSize, dictSize); | |
33 |
|
33 | |||
34 | result = PyObject_New(CompressionParametersObject, &CompressionParametersType); |
|
34 | result = PyObject_New(CompressionParametersObject, &CompressionParametersType); | |
35 | if (!result) { |
|
35 | if (!result) { | |
36 | return NULL; |
|
36 | return NULL; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | result->windowLog = params.windowLog; |
|
39 | result->windowLog = params.windowLog; | |
40 | result->chainLog = params.chainLog; |
|
40 | result->chainLog = params.chainLog; | |
41 | result->hashLog = params.hashLog; |
|
41 | result->hashLog = params.hashLog; | |
42 | result->searchLog = params.searchLog; |
|
42 | result->searchLog = params.searchLog; | |
43 | result->searchLength = params.searchLength; |
|
43 | result->searchLength = params.searchLength; | |
44 | result->targetLength = params.targetLength; |
|
44 | result->targetLength = params.targetLength; | |
45 | result->strategy = params.strategy; |
|
45 | result->strategy = params.strategy; | |
46 |
|
46 | |||
47 | return result; |
|
47 | return result; | |
48 | } |
|
48 | } | |
49 |
|
49 | |||
50 | PyObject* estimate_compression_context_size(PyObject* self, PyObject* args) { |
|
50 | PyObject* estimate_compression_context_size(PyObject* self, PyObject* args) { | |
51 | CompressionParametersObject* params; |
|
51 | CompressionParametersObject* params; | |
52 | ZSTD_compressionParameters zparams; |
|
52 | ZSTD_compressionParameters zparams; | |
53 | PyObject* result; |
|
53 | PyObject* result; | |
54 |
|
54 | |||
55 | if (!PyArg_ParseTuple(args, "O!", &CompressionParametersType, ¶ms)) { |
|
55 | if (!PyArg_ParseTuple(args, "O!", &CompressionParametersType, ¶ms)) { | |
56 | return NULL; |
|
56 | return NULL; | |
57 | } |
|
57 | } | |
58 |
|
58 | |||
59 | ztopy_compression_parameters(params, &zparams); |
|
59 | ztopy_compression_parameters(params, &zparams); | |
60 | result = PyLong_FromSize_t(ZSTD_estimateCCtxSize(zparams)); |
|
60 | result = PyLong_FromSize_t(ZSTD_estimateCCtxSize(zparams)); | |
61 | return result; |
|
61 | return result; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | PyDoc_STRVAR(CompressionParameters__doc__, |
|
64 | PyDoc_STRVAR(CompressionParameters__doc__, | |
65 | "CompressionParameters: low-level control over zstd compression"); |
|
65 | "CompressionParameters: low-level control over zstd compression"); | |
66 |
|
66 | |||
67 | static PyObject* CompressionParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) { |
|
67 | static PyObject* CompressionParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) { | |
68 | CompressionParametersObject* self; |
|
68 | CompressionParametersObject* self; | |
69 | unsigned windowLog; |
|
69 | unsigned windowLog; | |
70 | unsigned chainLog; |
|
70 | unsigned chainLog; | |
71 | unsigned hashLog; |
|
71 | unsigned hashLog; | |
72 | unsigned searchLog; |
|
72 | unsigned searchLog; | |
73 | unsigned searchLength; |
|
73 | unsigned searchLength; | |
74 | unsigned targetLength; |
|
74 | unsigned targetLength; | |
75 | unsigned strategy; |
|
75 | unsigned strategy; | |
76 |
|
76 | |||
77 | if (!PyArg_ParseTuple(args, "IIIIIII", &windowLog, &chainLog, &hashLog, &searchLog, |
|
77 | if (!PyArg_ParseTuple(args, "IIIIIII", &windowLog, &chainLog, &hashLog, &searchLog, | |
78 | &searchLength, &targetLength, &strategy)) { |
|
78 | &searchLength, &targetLength, &strategy)) { | |
79 | return NULL; |
|
79 | return NULL; | |
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | if (windowLog < ZSTD_WINDOWLOG_MIN || windowLog > ZSTD_WINDOWLOG_MAX) { |
|
82 | if (windowLog < ZSTD_WINDOWLOG_MIN || windowLog > ZSTD_WINDOWLOG_MAX) { | |
83 | PyErr_SetString(PyExc_ValueError, "invalid window log value"); |
|
83 | PyErr_SetString(PyExc_ValueError, "invalid window log value"); | |
84 | return NULL; |
|
84 | return NULL; | |
85 | } |
|
85 | } | |
86 |
|
86 | |||
87 | if (chainLog < ZSTD_CHAINLOG_MIN || chainLog > ZSTD_CHAINLOG_MAX) { |
|
87 | if (chainLog < ZSTD_CHAINLOG_MIN || chainLog > ZSTD_CHAINLOG_MAX) { | |
88 | PyErr_SetString(PyExc_ValueError, "invalid chain log value"); |
|
88 | PyErr_SetString(PyExc_ValueError, "invalid chain log value"); | |
89 | return NULL; |
|
89 | return NULL; | |
90 | } |
|
90 | } | |
91 |
|
91 | |||
92 | if (hashLog < ZSTD_HASHLOG_MIN || hashLog > ZSTD_HASHLOG_MAX) { |
|
92 | if (hashLog < ZSTD_HASHLOG_MIN || hashLog > ZSTD_HASHLOG_MAX) { | |
93 | PyErr_SetString(PyExc_ValueError, "invalid hash log value"); |
|
93 | PyErr_SetString(PyExc_ValueError, "invalid hash log value"); | |
94 | return NULL; |
|
94 | return NULL; | |
95 | } |
|
95 | } | |
96 |
|
96 | |||
97 | if (searchLog < ZSTD_SEARCHLOG_MIN || searchLog > ZSTD_SEARCHLOG_MAX) { |
|
97 | if (searchLog < ZSTD_SEARCHLOG_MIN || searchLog > ZSTD_SEARCHLOG_MAX) { | |
98 | PyErr_SetString(PyExc_ValueError, "invalid search log value"); |
|
98 | PyErr_SetString(PyExc_ValueError, "invalid search log value"); | |
99 | return NULL; |
|
99 | return NULL; | |
100 | } |
|
100 | } | |
101 |
|
101 | |||
102 | if (searchLength < ZSTD_SEARCHLENGTH_MIN || searchLength > ZSTD_SEARCHLENGTH_MAX) { |
|
102 | if (searchLength < ZSTD_SEARCHLENGTH_MIN || searchLength > ZSTD_SEARCHLENGTH_MAX) { | |
103 | PyErr_SetString(PyExc_ValueError, "invalid search length value"); |
|
103 | PyErr_SetString(PyExc_ValueError, "invalid search length value"); | |
104 | return NULL; |
|
104 | return NULL; | |
105 | } |
|
105 | } | |
106 |
|
106 | |||
107 | if (targetLength < ZSTD_TARGETLENGTH_MIN || targetLength > ZSTD_TARGETLENGTH_MAX) { |
|
107 | if (targetLength < ZSTD_TARGETLENGTH_MIN || targetLength > ZSTD_TARGETLENGTH_MAX) { | |
108 | PyErr_SetString(PyExc_ValueError, "invalid target length value"); |
|
108 | PyErr_SetString(PyExc_ValueError, "invalid target length value"); | |
109 | return NULL; |
|
109 | return NULL; | |
110 | } |
|
110 | } | |
111 |
|
111 | |||
112 | if (strategy < ZSTD_fast || strategy > ZSTD_btopt) { |
|
112 | if (strategy < ZSTD_fast || strategy > ZSTD_btopt) { | |
113 | PyErr_SetString(PyExc_ValueError, "invalid strategy value"); |
|
113 | PyErr_SetString(PyExc_ValueError, "invalid strategy value"); | |
114 | return NULL; |
|
114 | return NULL; | |
115 | } |
|
115 | } | |
116 |
|
116 | |||
117 | self = (CompressionParametersObject*)subtype->tp_alloc(subtype, 1); |
|
117 | self = (CompressionParametersObject*)subtype->tp_alloc(subtype, 1); | |
118 | if (!self) { |
|
118 | if (!self) { | |
119 | return NULL; |
|
119 | return NULL; | |
120 | } |
|
120 | } | |
121 |
|
121 | |||
122 | self->windowLog = windowLog; |
|
122 | self->windowLog = windowLog; | |
123 | self->chainLog = chainLog; |
|
123 | self->chainLog = chainLog; | |
124 | self->hashLog = hashLog; |
|
124 | self->hashLog = hashLog; | |
125 | self->searchLog = searchLog; |
|
125 | self->searchLog = searchLog; | |
126 | self->searchLength = searchLength; |
|
126 | self->searchLength = searchLength; | |
127 | self->targetLength = targetLength; |
|
127 | self->targetLength = targetLength; | |
128 | self->strategy = strategy; |
|
128 | self->strategy = strategy; | |
129 |
|
129 | |||
130 | return (PyObject*)self; |
|
130 | return (PyObject*)self; | |
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | static void CompressionParameters_dealloc(PyObject* self) { |
|
133 | static void CompressionParameters_dealloc(PyObject* self) { | |
134 | PyObject_Del(self); |
|
134 | PyObject_Del(self); | |
135 | } |
|
135 | } | |
136 |
|
136 | |||
137 | static Py_ssize_t CompressionParameters_length(PyObject* self) { |
|
137 | static Py_ssize_t CompressionParameters_length(PyObject* self) { | |
138 | return 7; |
|
138 | return 7; | |
139 |
} |
|
139 | } | |
140 |
|
140 | |||
141 | static PyObject* CompressionParameters_item(PyObject* o, Py_ssize_t i) { |
|
141 | static PyObject* CompressionParameters_item(PyObject* o, Py_ssize_t i) { | |
142 | CompressionParametersObject* self = (CompressionParametersObject*)o; |
|
142 | CompressionParametersObject* self = (CompressionParametersObject*)o; | |
143 |
|
143 | |||
144 | switch (i) { |
|
144 | switch (i) { | |
145 | case 0: |
|
145 | case 0: | |
146 | return PyLong_FromLong(self->windowLog); |
|
146 | return PyLong_FromLong(self->windowLog); | |
147 | case 1: |
|
147 | case 1: | |
148 | return PyLong_FromLong(self->chainLog); |
|
148 | return PyLong_FromLong(self->chainLog); | |
149 | case 2: |
|
149 | case 2: | |
150 | return PyLong_FromLong(self->hashLog); |
|
150 | return PyLong_FromLong(self->hashLog); | |
151 | case 3: |
|
151 | case 3: | |
152 | return PyLong_FromLong(self->searchLog); |
|
152 | return PyLong_FromLong(self->searchLog); | |
153 | case 4: |
|
153 | case 4: | |
154 | return PyLong_FromLong(self->searchLength); |
|
154 | return PyLong_FromLong(self->searchLength); | |
155 | case 5: |
|
155 | case 5: | |
156 | return PyLong_FromLong(self->targetLength); |
|
156 | return PyLong_FromLong(self->targetLength); | |
157 | case 6: |
|
157 | case 6: | |
158 | return PyLong_FromLong(self->strategy); |
|
158 | return PyLong_FromLong(self->strategy); | |
159 | default: |
|
159 | default: | |
160 | PyErr_SetString(PyExc_IndexError, "index out of range"); |
|
160 | PyErr_SetString(PyExc_IndexError, "index out of range"); | |
161 | return NULL; |
|
161 | return NULL; | |
162 | } |
|
162 | } | |
163 | } |
|
163 | } | |
164 |
|
164 | |||
165 | static PySequenceMethods CompressionParameters_sq = { |
|
165 | static PySequenceMethods CompressionParameters_sq = { | |
166 | CompressionParameters_length, /* sq_length */ |
|
166 | CompressionParameters_length, /* sq_length */ | |
167 | 0, /* sq_concat */ |
|
167 | 0, /* sq_concat */ | |
168 | 0, /* sq_repeat */ |
|
168 | 0, /* sq_repeat */ | |
169 | CompressionParameters_item, /* sq_item */ |
|
169 | CompressionParameters_item, /* sq_item */ | |
170 | 0, /* sq_ass_item */ |
|
170 | 0, /* sq_ass_item */ | |
171 | 0, /* sq_contains */ |
|
171 | 0, /* sq_contains */ | |
172 | 0, /* sq_inplace_concat */ |
|
172 | 0, /* sq_inplace_concat */ | |
173 | 0 /* sq_inplace_repeat */ |
|
173 | 0 /* sq_inplace_repeat */ | |
174 | }; |
|
174 | }; | |
175 |
|
175 | |||
176 | PyTypeObject CompressionParametersType = { |
|
176 | PyTypeObject CompressionParametersType = { | |
177 | PyVarObject_HEAD_INIT(NULL, 0) |
|
177 | PyVarObject_HEAD_INIT(NULL, 0) | |
178 | "CompressionParameters", /* tp_name */ |
|
178 | "CompressionParameters", /* tp_name */ | |
179 | sizeof(CompressionParametersObject), /* tp_basicsize */ |
|
179 | sizeof(CompressionParametersObject), /* tp_basicsize */ | |
180 | 0, /* tp_itemsize */ |
|
180 | 0, /* tp_itemsize */ | |
181 | (destructor)CompressionParameters_dealloc, /* tp_dealloc */ |
|
181 | (destructor)CompressionParameters_dealloc, /* tp_dealloc */ | |
182 | 0, /* tp_print */ |
|
182 | 0, /* tp_print */ | |
183 | 0, /* tp_getattr */ |
|
183 | 0, /* tp_getattr */ | |
184 | 0, /* tp_setattr */ |
|
184 | 0, /* tp_setattr */ | |
185 | 0, /* tp_compare */ |
|
185 | 0, /* tp_compare */ | |
186 | 0, /* tp_repr */ |
|
186 | 0, /* tp_repr */ | |
187 | 0, /* tp_as_number */ |
|
187 | 0, /* tp_as_number */ | |
188 | &CompressionParameters_sq, /* tp_as_sequence */ |
|
188 | &CompressionParameters_sq, /* tp_as_sequence */ | |
189 | 0, /* tp_as_mapping */ |
|
189 | 0, /* tp_as_mapping */ | |
190 | 0, /* tp_hash */ |
|
190 | 0, /* tp_hash */ | |
191 | 0, /* tp_call */ |
|
191 | 0, /* tp_call */ | |
192 | 0, /* tp_str */ |
|
192 | 0, /* tp_str */ | |
193 | 0, /* tp_getattro */ |
|
193 | 0, /* tp_getattro */ | |
194 | 0, /* tp_setattro */ |
|
194 | 0, /* tp_setattro */ | |
195 | 0, /* tp_as_buffer */ |
|
195 | 0, /* tp_as_buffer */ | |
196 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
196 | Py_TPFLAGS_DEFAULT, /* tp_flags */ | |
197 | CompressionParameters__doc__, /* tp_doc */ |
|
197 | CompressionParameters__doc__, /* tp_doc */ | |
198 | 0, /* tp_traverse */ |
|
198 | 0, /* tp_traverse */ | |
199 | 0, /* tp_clear */ |
|
199 | 0, /* tp_clear */ | |
200 | 0, /* tp_richcompare */ |
|
200 | 0, /* tp_richcompare */ | |
201 | 0, /* tp_weaklistoffset */ |
|
201 | 0, /* tp_weaklistoffset */ | |
202 | 0, /* tp_iter */ |
|
202 | 0, /* tp_iter */ | |
203 | 0, /* tp_iternext */ |
|
203 | 0, /* tp_iternext */ | |
204 | 0, /* tp_methods */ |
|
204 | 0, /* tp_methods */ | |
205 | 0, /* tp_members */ |
|
205 | 0, /* tp_members */ | |
206 | 0, /* tp_getset */ |
|
206 | 0, /* tp_getset */ | |
207 | 0, /* tp_base */ |
|
207 | 0, /* tp_base */ | |
208 | 0, /* tp_dict */ |
|
208 | 0, /* tp_dict */ | |
209 | 0, /* tp_descr_get */ |
|
209 | 0, /* tp_descr_get */ | |
210 | 0, /* tp_descr_set */ |
|
210 | 0, /* tp_descr_set */ | |
211 | 0, /* tp_dictoffset */ |
|
211 | 0, /* tp_dictoffset */ | |
212 | 0, /* tp_init */ |
|
212 | 0, /* tp_init */ | |
213 | 0, /* tp_alloc */ |
|
213 | 0, /* tp_alloc */ | |
214 | CompressionParameters_new, /* tp_new */ |
|
214 | CompressionParameters_new, /* tp_new */ | |
215 | }; |
|
215 | }; | |
216 |
|
216 | |||
217 | void compressionparams_module_init(PyObject* mod) { |
|
217 | void compressionparams_module_init(PyObject* mod) { | |
218 | Py_TYPE(&CompressionParametersType) = &PyType_Type; |
|
218 | Py_TYPE(&CompressionParametersType) = &PyType_Type; | |
219 | if (PyType_Ready(&CompressionParametersType) < 0) { |
|
219 | if (PyType_Ready(&CompressionParametersType) < 0) { | |
220 | return; |
|
220 | return; | |
221 | } |
|
221 | } | |
222 |
|
222 | |||
223 | Py_IncRef((PyObject*)&CompressionParametersType); |
|
223 | Py_IncRef((PyObject*)&CompressionParametersType); | |
224 | PyModule_AddObject(mod, "CompressionParameters", |
|
224 | PyModule_AddObject(mod, "CompressionParameters", | |
225 | (PyObject*)&CompressionParametersType); |
|
225 | (PyObject*)&CompressionParametersType); | |
226 | } |
|
226 | } |
@@ -1,125 +1,125 | |||||
1 | /** |
|
1 | /** | |
2 | * Copyright (c) 2016-present, Gregory Szorc |
|
2 | * Copyright (c) 2016-present, Gregory Szorc | |
3 | * All rights reserved. |
|
3 | * All rights reserved. | |
4 | * |
|
4 | * | |
5 | * This software may be modified and distributed under the terms |
|
5 | * This software may be modified and distributed under the terms | |
6 | * of the BSD license. See the LICENSE file for details. |
|
6 | * of the BSD license. See the LICENSE file for details. | |
7 | */ |
|
7 | */ | |
8 |
|
8 | |||
9 | #include "python-zstandard.h" |
|
9 | #include "python-zstandard.h" | |
10 |
|
10 | |||
11 | PyDoc_STRVAR(DictParameters__doc__, |
|
11 | PyDoc_STRVAR(DictParameters__doc__, | |
12 | "DictParameters: low-level control over dictionary generation"); |
|
12 | "DictParameters: low-level control over dictionary generation"); | |
13 |
|
13 | |||
14 | static PyObject* DictParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) { |
|
14 | static PyObject* DictParameters_new(PyTypeObject* subtype, PyObject* args, PyObject* kwargs) { | |
15 | DictParametersObject* self; |
|
15 | DictParametersObject* self; | |
16 | unsigned selectivityLevel; |
|
16 | unsigned selectivityLevel; | |
17 | int compressionLevel; |
|
17 | int compressionLevel; | |
18 | unsigned notificationLevel; |
|
18 | unsigned notificationLevel; | |
19 | unsigned dictID; |
|
19 | unsigned dictID; | |
20 |
|
20 | |||
21 | if (!PyArg_ParseTuple(args, "IiII", &selectivityLevel, &compressionLevel, |
|
21 | if (!PyArg_ParseTuple(args, "IiII", &selectivityLevel, &compressionLevel, | |
22 | ¬ificationLevel, &dictID)) { |
|
22 | ¬ificationLevel, &dictID)) { | |
23 | return NULL; |
|
23 | return NULL; | |
24 | } |
|
24 | } | |
25 |
|
25 | |||
26 | self = (DictParametersObject*)subtype->tp_alloc(subtype, 1); |
|
26 | self = (DictParametersObject*)subtype->tp_alloc(subtype, 1); | |
27 | if (!self) { |
|
27 | if (!self) { | |
28 | return NULL; |
|
28 | return NULL; | |
29 | } |
|
29 | } | |
30 |
|
30 | |||
31 | self->selectivityLevel = selectivityLevel; |
|
31 | self->selectivityLevel = selectivityLevel; | |
32 | self->compressionLevel = compressionLevel; |
|
32 | self->compressionLevel = compressionLevel; | |
33 | self->notificationLevel = notificationLevel; |
|
33 | self->notificationLevel = notificationLevel; | |
34 | self->dictID = dictID; |
|
34 | self->dictID = dictID; | |
35 |
|
35 | |||
36 | return (PyObject*)self; |
|
36 | return (PyObject*)self; | |
37 | } |
|
37 | } | |
38 |
|
38 | |||
39 | static void DictParameters_dealloc(PyObject* self) { |
|
39 | static void DictParameters_dealloc(PyObject* self) { | |
40 | PyObject_Del(self); |
|
40 | PyObject_Del(self); | |
41 | } |
|
41 | } | |
42 |
|
42 | |||
43 | static Py_ssize_t DictParameters_length(PyObject* self) { |
|
43 | static Py_ssize_t DictParameters_length(PyObject* self) { | |
44 | return 4; |
|
44 | return 4; | |
45 |
} |
|
45 | } | |
46 |
|
46 | |||
47 | static PyObject* DictParameters_item(PyObject* o, Py_ssize_t i) { |
|
47 | static PyObject* DictParameters_item(PyObject* o, Py_ssize_t i) { | |
48 | DictParametersObject* self = (DictParametersObject*)o; |
|
48 | DictParametersObject* self = (DictParametersObject*)o; | |
49 |
|
49 | |||
50 | switch (i) { |
|
50 | switch (i) { | |
51 | case 0: |
|
51 | case 0: | |
52 | return PyLong_FromLong(self->selectivityLevel); |
|
52 | return PyLong_FromLong(self->selectivityLevel); | |
53 | case 1: |
|
53 | case 1: | |
54 | return PyLong_FromLong(self->compressionLevel); |
|
54 | return PyLong_FromLong(self->compressionLevel); | |
55 | case 2: |
|
55 | case 2: | |
56 | return PyLong_FromLong(self->notificationLevel); |
|
56 | return PyLong_FromLong(self->notificationLevel); | |
57 | case 3: |
|
57 | case 3: | |
58 | return PyLong_FromLong(self->dictID); |
|
58 | return PyLong_FromLong(self->dictID); | |
59 | default: |
|
59 | default: | |
60 | PyErr_SetString(PyExc_IndexError, "index out of range"); |
|
60 | PyErr_SetString(PyExc_IndexError, "index out of range"); | |
61 | return NULL; |
|
61 | return NULL; | |
62 | } |
|
62 | } | |
63 | } |
|
63 | } | |
64 |
|
64 | |||
65 | static PySequenceMethods DictParameters_sq = { |
|
65 | static PySequenceMethods DictParameters_sq = { | |
66 | DictParameters_length, /* sq_length */ |
|
66 | DictParameters_length, /* sq_length */ | |
67 | 0, /* sq_concat */ |
|
67 | 0, /* sq_concat */ | |
68 | 0, /* sq_repeat */ |
|
68 | 0, /* sq_repeat */ | |
69 | DictParameters_item, /* sq_item */ |
|
69 | DictParameters_item, /* sq_item */ | |
70 | 0, /* sq_ass_item */ |
|
70 | 0, /* sq_ass_item */ | |
71 | 0, /* sq_contains */ |
|
71 | 0, /* sq_contains */ | |
72 | 0, /* sq_inplace_concat */ |
|
72 | 0, /* sq_inplace_concat */ | |
73 | 0 /* sq_inplace_repeat */ |
|
73 | 0 /* sq_inplace_repeat */ | |
74 | }; |
|
74 | }; | |
75 |
|
75 | |||
76 | PyTypeObject DictParametersType = { |
|
76 | PyTypeObject DictParametersType = { | |
77 | PyVarObject_HEAD_INIT(NULL, 0) |
|
77 | PyVarObject_HEAD_INIT(NULL, 0) | |
78 | "DictParameters", /* tp_name */ |
|
78 | "DictParameters", /* tp_name */ | |
79 | sizeof(DictParametersObject), /* tp_basicsize */ |
|
79 | sizeof(DictParametersObject), /* tp_basicsize */ | |
80 | 0, /* tp_itemsize */ |
|
80 | 0, /* tp_itemsize */ | |
81 | (destructor)DictParameters_dealloc, /* tp_dealloc */ |
|
81 | (destructor)DictParameters_dealloc, /* tp_dealloc */ | |
82 | 0, /* tp_print */ |
|
82 | 0, /* tp_print */ | |
83 | 0, /* tp_getattr */ |
|
83 | 0, /* tp_getattr */ | |
84 | 0, /* tp_setattr */ |
|
84 | 0, /* tp_setattr */ | |
85 | 0, /* tp_compare */ |
|
85 | 0, /* tp_compare */ | |
86 | 0, /* tp_repr */ |
|
86 | 0, /* tp_repr */ | |
87 | 0, /* tp_as_number */ |
|
87 | 0, /* tp_as_number */ | |
88 | &DictParameters_sq, /* tp_as_sequence */ |
|
88 | &DictParameters_sq, /* tp_as_sequence */ | |
89 | 0, /* tp_as_mapping */ |
|
89 | 0, /* tp_as_mapping */ | |
90 | 0, /* tp_hash */ |
|
90 | 0, /* tp_hash */ | |
91 | 0, /* tp_call */ |
|
91 | 0, /* tp_call */ | |
92 | 0, /* tp_str */ |
|
92 | 0, /* tp_str */ | |
93 | 0, /* tp_getattro */ |
|
93 | 0, /* tp_getattro */ | |
94 | 0, /* tp_setattro */ |
|
94 | 0, /* tp_setattro */ | |
95 | 0, /* tp_as_buffer */ |
|
95 | 0, /* tp_as_buffer */ | |
96 | Py_TPFLAGS_DEFAULT, /* tp_flags */ |
|
96 | Py_TPFLAGS_DEFAULT, /* tp_flags */ | |
97 | DictParameters__doc__, /* tp_doc */ |
|
97 | DictParameters__doc__, /* tp_doc */ | |
98 | 0, /* tp_traverse */ |
|
98 | 0, /* tp_traverse */ | |
99 | 0, /* tp_clear */ |
|
99 | 0, /* tp_clear */ | |
100 | 0, /* tp_richcompare */ |
|
100 | 0, /* tp_richcompare */ | |
101 | 0, /* tp_weaklistoffset */ |
|
101 | 0, /* tp_weaklistoffset */ | |
102 | 0, /* tp_iter */ |
|
102 | 0, /* tp_iter */ | |
103 | 0, /* tp_iternext */ |
|
103 | 0, /* tp_iternext */ | |
104 | 0, /* tp_methods */ |
|
104 | 0, /* tp_methods */ | |
105 | 0, /* tp_members */ |
|
105 | 0, /* tp_members */ | |
106 | 0, /* tp_getset */ |
|
106 | 0, /* tp_getset */ | |
107 | 0, /* tp_base */ |
|
107 | 0, /* tp_base */ | |
108 | 0, /* tp_dict */ |
|
108 | 0, /* tp_dict */ | |
109 | 0, /* tp_descr_get */ |
|
109 | 0, /* tp_descr_get */ | |
110 | 0, /* tp_descr_set */ |
|
110 | 0, /* tp_descr_set */ | |
111 | 0, /* tp_dictoffset */ |
|
111 | 0, /* tp_dictoffset */ | |
112 | 0, /* tp_init */ |
|
112 | 0, /* tp_init */ | |
113 | 0, /* tp_alloc */ |
|
113 | 0, /* tp_alloc */ | |
114 | DictParameters_new, /* tp_new */ |
|
114 | DictParameters_new, /* tp_new */ | |
115 | }; |
|
115 | }; | |
116 |
|
116 | |||
117 | void dictparams_module_init(PyObject* mod) { |
|
117 | void dictparams_module_init(PyObject* mod) { | |
118 | Py_TYPE(&DictParametersType) = &PyType_Type; |
|
118 | Py_TYPE(&DictParametersType) = &PyType_Type; | |
119 | if (PyType_Ready(&DictParametersType) < 0) { |
|
119 | if (PyType_Ready(&DictParametersType) < 0) { | |
120 | return; |
|
120 | return; | |
121 | } |
|
121 | } | |
122 |
|
122 | |||
123 | Py_IncRef((PyObject*)&DictParametersType); |
|
123 | Py_IncRef((PyObject*)&DictParametersType); | |
124 | PyModule_AddObject(mod, "DictParameters", (PyObject*)&DictParametersType); |
|
124 | PyModule_AddObject(mod, "DictParameters", (PyObject*)&DictParametersType); | |
125 | } |
|
125 | } |
General Comments 0
You need to be logged in to leave comments.
Login now