Debian Codegraph @

Modules/_zstd/clinic/_zstdmodule.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
6 # include "pycore_gc.h" // PyGC_Head
7 # include "pycore_runtime.h" // _Py_ID()
8 #endif
9 #include "pycore_abstract.h" // _PyNumber_Index()
10 #include "pycore_modsupport.h" // _PyArg_CheckPositional()
11
12 PyDoc_STRVAR(_zstd_train_dict__doc__,
13 "train_dict($module, samples_bytes, samples_sizes, dict_size, /)\n"
14 "--\n"
15 "\n"
16 "Train a Zstandard dictionary on sample data.\n"
17 "\n"
18 " samples_bytes\n"
19 " Concatenation of samples.\n"
20 " samples_sizes\n"
21 " Tuple of samples\' sizes.\n"
22 " dict_size\n"
23 " The size of the dictionary.");
24
25 #define _ZSTD_TRAIN_DICT_METHODDEF \
26 {"train_dict", _PyCFunction_CAST(_zstd_train_dict), METH_FASTCALL, _zstd_train_dict__doc__},
27
28 static PyObject *
29 _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes,
30 PyObject *samples_sizes, Py_ssize_t dict_size);
31
32 static PyObject *
33 _zstd_train_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
34 {
35 PyObject *return_value = NULL;
36 PyBytesObject *samples_bytes;
37 PyObject *samples_sizes;
38 Py_ssize_t dict_size;
39
40 if (!_PyArg_CheckPositional("train_dict", nargs, 3, 3)) {
41 goto exit;
42 }
43 if (!PyBytes_Check(args[0])) {
44 _PyArg_BadArgument("train_dict", "argument 1", "bytes", args[0]);
45 goto exit;
46 }
47 samples_bytes = (PyBytesObject *)args[0];
48 if (!PyTuple_Check(args[1])) {
49 _PyArg_BadArgument("train_dict", "argument 2", "tuple", args[1]);
50 goto exit;
51 }
52 samples_sizes = args[1];
53 {
54 Py_ssize_t ival = -1;
55 PyObject *iobj = _PyNumber_Index(args[2]);
56 if (iobj != NULL) {
57 ival = PyLong_AsSsize_t(iobj);
58 Py_DECREF(iobj);
59 }
60 if (ival == -1 && PyErr_Occurred()) {
61 goto exit;
62 }
63 dict_size = ival;
64 }
65 return_value = _zstd_train_dict_impl(module, samples_bytes, samples_sizes, dict_size);
66
67 exit:
68 return return_value;
69 }
70
71 PyDoc_STRVAR(_zstd_finalize_dict__doc__,
72 "finalize_dict($module, custom_dict_bytes, samples_bytes, samples_sizes,\n"
73 " dict_size, compression_level, /)\n"
74 "--\n"
75 "\n"
76 "Finalize a Zstandard dictionary.\n"
77 "\n"
78 " custom_dict_bytes\n"
79 " Custom dictionary content.\n"
80 " samples_bytes\n"
81 " Concatenation of samples.\n"
82 " samples_sizes\n"
83 " Tuple of samples\' sizes.\n"
84 " dict_size\n"
85 " The size of the dictionary.\n"
86 " compression_level\n"
87 " Optimize for a specific Zstandard compression level, 0 means default.");
88
89 #define _ZSTD_FINALIZE_DICT_METHODDEF \
90 {"finalize_dict", _PyCFunction_CAST(_zstd_finalize_dict), METH_FASTCALL, _zstd_finalize_dict__doc__},
91
92 static PyObject *
93 _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes,
94 PyBytesObject *samples_bytes,
95 PyObject *samples_sizes, Py_ssize_t dict_size,
96 int compression_level);
97
98 static PyObject *
99 _zstd_finalize_dict(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
100 {
101 PyObject *return_value = NULL;
102 PyBytesObject *custom_dict_bytes;
103 PyBytesObject *samples_bytes;
104 PyObject *samples_sizes;
105 Py_ssize_t dict_size;
106 int compression_level;
107
108 if (!_PyArg_CheckPositional("finalize_dict", nargs, 5, 5)) {
109 goto exit;
110 }
111 if (!PyBytes_Check(args[0])) {
112 _PyArg_BadArgument("finalize_dict", "argument 1", "bytes", args[0]);
113 goto exit;
114 }
115 custom_dict_bytes = (PyBytesObject *)args[0];
116 if (!PyBytes_Check(args[1])) {
117 _PyArg_BadArgument("finalize_dict", "argument 2", "bytes", args[1]);
118 goto exit;
119 }
120 samples_bytes = (PyBytesObject *)args[1];
121 if (!PyTuple_Check(args[2])) {
122 _PyArg_BadArgument("finalize_dict", "argument 3", "tuple", args[2]);
123 goto exit;
124 }
125 samples_sizes = args[2];
126 {
127 Py_ssize_t ival = -1;
128 PyObject *iobj = _PyNumber_Index(args[3]);
129 if (iobj != NULL) {
130 ival = PyLong_AsSsize_t(iobj);
131 Py_DECREF(iobj);
132 }
133 if (ival == -1 && PyErr_Occurred()) {
134 goto exit;
135 }
136 dict_size = ival;
137 }
138 compression_level = PyLong_AsInt(args[4]);
139 if (compression_level == -1 && PyErr_Occurred()) {
140 goto exit;
141 }
142 return_value = _zstd_finalize_dict_impl(module, custom_dict_bytes, samples_bytes, samples_sizes, dict_size, compression_level);
143
144 exit:
145 return return_value;
146 }
147
148 PyDoc_STRVAR(_zstd_get_param_bounds__doc__,
149 "get_param_bounds($module, /, parameter, is_compress)\n"
150 "--\n"
151 "\n"
152 "Get CompressionParameter/DecompressionParameter bounds.\n"
153 "\n"
154 " parameter\n"
155 " The parameter to get bounds.\n"
156 " is_compress\n"
157 " True for CompressionParameter, False for DecompressionParameter.");
158
159 #define _ZSTD_GET_PARAM_BOUNDS_METHODDEF \
160 {"get_param_bounds", _PyCFunction_CAST(_zstd_get_param_bounds), METH_FASTCALL|METH_KEYWORDS, _zstd_get_param_bounds__doc__},
161
162 static PyObject *
163 _zstd_get_param_bounds_impl(PyObject *module, int parameter, int is_compress);
164
165 static PyObject *
166 _zstd_get_param_bounds(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
167 {
168 PyObject *return_value = NULL;
169 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
170
171 #define NUM_KEYWORDS 2
172 static struct {
173 PyGC_Head _this_is_not_used;
174 PyObject_VAR_HEAD
175 Py_hash_t ob_hash;
176 PyObject *ob_item[NUM_KEYWORDS];
177 } _kwtuple = {
178 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
179 .ob_hash = -1,
180 .ob_item = { &_Py_ID(parameter), &_Py_ID(is_compress), },
181 };
182 #undef NUM_KEYWORDS
183 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
184
185 #else // !Py_BUILD_CORE
186 # define KWTUPLE NULL
187 #endif // !Py_BUILD_CORE
188
189 static const char * const _keywords[] = {"parameter", "is_compress", NULL};
190 static _PyArg_Parser _parser = {
191 .keywords = _keywords,
192 .fname = "get_param_bounds",
193 .kwtuple = KWTUPLE,
194 };
195 #undef KWTUPLE
196 PyObject *argsbuf[2];
197 int parameter;
198 int is_compress;
199
200 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
201 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
202 if (!args) {
203 goto exit;
204 }
205 parameter = PyLong_AsInt(args[0]);
206 if (parameter == -1 && PyErr_Occurred()) {
207 goto exit;
208 }
209 is_compress = PyObject_IsTrue(args[1]);
210 if (is_compress < 0) {
211 goto exit;
212 }
213 return_value = _zstd_get_param_bounds_impl(module, parameter, is_compress);
214
215 exit:
216 return return_value;
217 }
218
219 PyDoc_STRVAR(_zstd_get_frame_size__doc__,
220 "get_frame_size($module, /, frame_buffer)\n"
221 "--\n"
222 "\n"
223 "Get the size of a Zstandard frame, including the header and optional checksum.\n"
224 "\n"
225 " frame_buffer\n"
226 " A bytes-like object, it should start from the beginning of a frame,\n"
227 " and contains at least one complete frame.");
228
229 #define _ZSTD_GET_FRAME_SIZE_METHODDEF \
230 {"get_frame_size", _PyCFunction_CAST(_zstd_get_frame_size), METH_FASTCALL|METH_KEYWORDS, _zstd_get_frame_size__doc__},
231
232 static PyObject *
233 _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer);
234
235 static PyObject *
236 _zstd_get_frame_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
237 {
238 PyObject *return_value = NULL;
239 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
240
241 #define NUM_KEYWORDS 1
242 static struct {
243 PyGC_Head _this_is_not_used;
244 PyObject_VAR_HEAD
245 Py_hash_t ob_hash;
246 PyObject *ob_item[NUM_KEYWORDS];
247 } _kwtuple = {
248 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
249 .ob_hash = -1,
250 .ob_item = { &_Py_ID(frame_buffer), },
251 };
252 #undef NUM_KEYWORDS
253 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
254
255 #else // !Py_BUILD_CORE
256 # define KWTUPLE NULL
257 #endif // !Py_BUILD_CORE
258
259 static const char * const _keywords[] = {"frame_buffer", NULL};
260 static _PyArg_Parser _parser = {
261 .keywords = _keywords,
262 .fname = "get_frame_size",
263 .kwtuple = KWTUPLE,
264 };
265 #undef KWTUPLE
266 PyObject *argsbuf[1];
267 Py_buffer frame_buffer = {NULL, NULL};
268
269 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
270 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
271 if (!args) {
272 goto exit;
273 }
274 if (PyObject_GetBuffer(args[0], &frame_buffer, PyBUF_SIMPLE) != 0) {
275 goto exit;
276 }
277 return_value = _zstd_get_frame_size_impl(module, &frame_buffer);
278
279 exit:
280 /* Cleanup for frame_buffer */
281 if (frame_buffer.obj) {
282 PyBuffer_Release(&frame_buffer);
283 }
284
285 return return_value;
286 }
287
288 PyDoc_STRVAR(_zstd_get_frame_info__doc__,
289 "get_frame_info($module, /, frame_buffer)\n"
290 "--\n"
291 "\n"
292 "Get Zstandard frame infomation from a frame header.\n"
293 "\n"
294 " frame_buffer\n"
295 " A bytes-like object, containing the header of a Zstandard frame.");
296
297 #define _ZSTD_GET_FRAME_INFO_METHODDEF \
298 {"get_frame_info", _PyCFunction_CAST(_zstd_get_frame_info), METH_FASTCALL|METH_KEYWORDS, _zstd_get_frame_info__doc__},
299
300 static PyObject *
301 _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer);
302
303 static PyObject *
304 _zstd_get_frame_info(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
305 {
306 PyObject *return_value = NULL;
307 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
308
309 #define NUM_KEYWORDS 1
310 static struct {
311 PyGC_Head _this_is_not_used;
312 PyObject_VAR_HEAD
313 Py_hash_t ob_hash;
314 PyObject *ob_item[NUM_KEYWORDS];
315 } _kwtuple = {
316 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
317 .ob_hash = -1,
318 .ob_item = { &_Py_ID(frame_buffer), },
319 };
320 #undef NUM_KEYWORDS
321 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
322
323 #else // !Py_BUILD_CORE
324 # define KWTUPLE NULL
325 #endif // !Py_BUILD_CORE
326
327 static const char * const _keywords[] = {"frame_buffer", NULL};
328 static _PyArg_Parser _parser = {
329 .keywords = _keywords,
330 .fname = "get_frame_info",
331 .kwtuple = KWTUPLE,
332 };
333 #undef KWTUPLE
334 PyObject *argsbuf[1];
335 Py_buffer frame_buffer = {NULL, NULL};
336
337 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
338 /*minpos*/ 1, /*maxpos*/ 1, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
339 if (!args) {
340 goto exit;
341 }
342 if (PyObject_GetBuffer(args[0], &frame_buffer, PyBUF_SIMPLE) != 0) {
343 goto exit;
344 }
345 return_value = _zstd_get_frame_info_impl(module, &frame_buffer);
346
347 exit:
348 /* Cleanup for frame_buffer */
349 if (frame_buffer.obj) {
350 PyBuffer_Release(&frame_buffer);
351 }
352
353 return return_value;
354 }
355
356 PyDoc_STRVAR(_zstd_set_parameter_types__doc__,
357 "set_parameter_types($module, /, c_parameter_type, d_parameter_type)\n"
358 "--\n"
359 "\n"
360 "Set CompressionParameter and DecompressionParameter types for validity check.\n"
361 "\n"
362 " c_parameter_type\n"
363 " CompressionParameter IntEnum type object\n"
364 " d_parameter_type\n"
365 " DecompressionParameter IntEnum type object");
366
367 #define _ZSTD_SET_PARAMETER_TYPES_METHODDEF \
368 {"set_parameter_types", _PyCFunction_CAST(_zstd_set_parameter_types), METH_FASTCALL|METH_KEYWORDS, _zstd_set_parameter_types__doc__},
369
370 static PyObject *
371 _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type,
372 PyObject *d_parameter_type);
373
374 static PyObject *
375 _zstd_set_parameter_types(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
376 {
377 PyObject *return_value = NULL;
378 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
379
380 #define NUM_KEYWORDS 2
381 static struct {
382 PyGC_Head _this_is_not_used;
383 PyObject_VAR_HEAD
384 Py_hash_t ob_hash;
385 PyObject *ob_item[NUM_KEYWORDS];
386 } _kwtuple = {
387 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
388 .ob_hash = -1,
389 .ob_item = { &_Py_ID(c_parameter_type), &_Py_ID(d_parameter_type), },
390 };
391 #undef NUM_KEYWORDS
392 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
393
394 #else // !Py_BUILD_CORE
395 # define KWTUPLE NULL
396 #endif // !Py_BUILD_CORE
397
398 static const char * const _keywords[] = {"c_parameter_type", "d_parameter_type", NULL};
399 static _PyArg_Parser _parser = {
400 .keywords = _keywords,
401 .fname = "set_parameter_types",
402 .kwtuple = KWTUPLE,
403 };
404 #undef KWTUPLE
405 PyObject *argsbuf[2];
406 PyObject *c_parameter_type;
407 PyObject *d_parameter_type;
408
409 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
410 /*minpos*/ 2, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
411 if (!args) {
412 goto exit;
413 }
414 if (!PyObject_TypeCheck(args[0], &PyType_Type)) {
415 _PyArg_BadArgument("set_parameter_types", "argument 'c_parameter_type'", (&PyType_Type)->tp_name, args[0]);
416 goto exit;
417 }
418 c_parameter_type = args[0];
419 if (!PyObject_TypeCheck(args[1], &PyType_Type)) {
420 _PyArg_BadArgument("set_parameter_types", "argument 'd_parameter_type'", (&PyType_Type)->tp_name, args[1]);
421 goto exit;
422 }
423 d_parameter_type = args[1];
424 return_value = _zstd_set_parameter_types_impl(module, c_parameter_type, d_parameter_type);
425
426 exit:
427 return return_value;
428 }
429 /*[clinic end generated code: output=437b084f149e68e5 input=a9049054013a1b77]*/