Debian Codegraph @

src/c/compression_zstd/clinic/decompressor.c.h

raw
1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 #include "backports_zstd_edits.h"
6
7 PyDoc_STRVAR(_zstd_ZstdDecompressor_new__doc__,
8 "ZstdDecompressor(zstd_dict=None, options=None)\n"
9 "--\n"
10 "\n"
11 "Create a decompressor object for decompressing data incrementally.\n"
12 "\n"
13 " zstd_dict\n"
14 " A ZstdDict object, a pre-trained Zstandard dictionary.\n"
15 " options\n"
16 " A dict object that contains advanced decompression parameters.\n"
17 "\n"
18 "Thread-safe at method level. For one-shot decompression, use the\n"
19 "decompress() function instead.");
20
21 static PyObject *
22 _zstd_ZstdDecompressor_new_impl(PyTypeObject *type, PyObject *zstd_dict,
23 PyObject *options);
24
25 static PyObject *
26 _zstd_ZstdDecompressor_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
27 {
28 PyObject *return_value = NULL;
29 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
30
31 #define NUM_KEYWORDS 2
32 static struct {
33 PyGC_Head _this_is_not_used;
34 PyObject_VAR_HEAD
35 Py_hash_t ob_hash;
36 PyObject *ob_item[NUM_KEYWORDS];
37 } _kwtuple = {
38 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
39 .ob_hash = -1,
40 .ob_item = { &_Py_ID(zstd_dict), &_Py_ID(options), },
41 };
42 #undef NUM_KEYWORDS
43 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
44
45 #else // !Py_BUILD_CORE
46 # define KWTUPLE NULL
47 #endif // !Py_BUILD_CORE
48
49 static const char * const _keywords[] = {"zstd_dict", "options", NULL};
50 static _PyArg_Parser _parser = {
51 .keywords = _keywords,
52 .fname = "ZstdDecompressor",
53 .kwtuple = KWTUPLE,
54 };
55 #undef KWTUPLE
56 PyObject *argsbuf[2];
57 PyObject * const *fastargs;
58 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
59 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 0;
60 PyObject *zstd_dict = Py_None;
61 PyObject *options = Py_None;
62
63 fastargs = BACKPORTSZSTD__PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser,
64 /*minpos*/ 0, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
65 if (!fastargs) {
66 goto exit;
67 }
68 if (!noptargs) {
69 goto skip_optional_pos;
70 }
71 if (fastargs[0]) {
72 zstd_dict = fastargs[0];
73 if (!--noptargs) {
74 goto skip_optional_pos;
75 }
76 }
77 options = fastargs[1];
78 skip_optional_pos:
79 return_value = _zstd_ZstdDecompressor_new_impl(type, zstd_dict, options);
80
81 exit:
82 return return_value;
83 }
84
85 PyDoc_STRVAR(_zstd_ZstdDecompressor_unused_data__doc__,
86 "A bytes object of un-consumed input data.\n"
87 "\n"
88 "When ZstdDecompressor object stops after a frame is\n"
89 "decompressed, unused input data after the frame. Otherwise this\n"
90 "will be b\'\'.");
91 #if defined(_zstd_ZstdDecompressor_unused_data_DOCSTR)
92 # undef _zstd_ZstdDecompressor_unused_data_DOCSTR
93 #endif
94 #define _zstd_ZstdDecompressor_unused_data_DOCSTR _zstd_ZstdDecompressor_unused_data__doc__
95
96 #if !defined(_zstd_ZstdDecompressor_unused_data_DOCSTR)
97 # define _zstd_ZstdDecompressor_unused_data_DOCSTR NULL
98 #endif
99 #if defined(_ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF)
100 # undef _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF
101 # define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, (setter)_zstd_ZstdDecompressor_unused_data_set, _zstd_ZstdDecompressor_unused_data_DOCSTR},
102 #else
103 # define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, NULL, _zstd_ZstdDecompressor_unused_data_DOCSTR},
104 #endif
105
106 static PyObject *
107 _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self);
108
109 static PyObject *
110 _zstd_ZstdDecompressor_unused_data_get(PyObject *self, void *Py_UNUSED(context))
111 {
112 return _zstd_ZstdDecompressor_unused_data_get_impl((ZstdDecompressor *)self);
113 }
114
115 PyDoc_STRVAR(_zstd_ZstdDecompressor_decompress__doc__,
116 "decompress($self, /, data, max_length=-1)\n"
117 "--\n"
118 "\n"
119 "Decompress *data*, returning uncompressed bytes if possible, or b\'\' otherwise.\n"
120 "\n"
121 " data\n"
122 " A bytes-like object, Zstandard data to be decompressed.\n"
123 " max_length\n"
124 " Maximum size of returned data. When it is negative, the size of\n"
125 " output buffer is unlimited. When it is nonnegative, returns at\n"
126 " most max_length bytes of decompressed data.\n"
127 "\n"
128 "If *max_length* is nonnegative, returns at most *max_length* bytes\n"
129 "of decompressed data. If this limit is reached and further output\n"
130 "can be produced, *self.needs_input* will be set to ``False``. In\n"
131 "this case, the next call to *decompress()* may provide *data* as b\'\'\n"
132 "to obtain more of the output.\n"
133 "\n"
134 "If all of the input data was decompressed and returned (either\n"
135 "because this was less than *max_length* bytes, or because\n"
136 "*max_length* was negative), *self.needs_input* will be set to True.\n"
137 "\n"
138 "Attempting to decompress data after the end of a frame is reached\n"
139 "raises an EOFError. Any data found after the end of the frame is\n"
140 "ignored and saved in the self.unused_data attribute.");
141
142 #define _ZSTD_ZSTDDECOMPRESSOR_DECOMPRESS_METHODDEF \
143 {"decompress", _PyCFunction_CAST(_zstd_ZstdDecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _zstd_ZstdDecompressor_decompress__doc__},
144
145 static PyObject *
146 _zstd_ZstdDecompressor_decompress_impl(ZstdDecompressor *self,
147 Py_buffer *data,
148 Py_ssize_t max_length);
149
150 static PyObject *
151 _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
152 {
153 PyObject *return_value = NULL;
154 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
155
156 #define NUM_KEYWORDS 2
157 static struct {
158 PyGC_Head _this_is_not_used;
159 PyObject_VAR_HEAD
160 Py_hash_t ob_hash;
161 PyObject *ob_item[NUM_KEYWORDS];
162 } _kwtuple = {
163 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
164 .ob_hash = -1,
165 .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
166 };
167 #undef NUM_KEYWORDS
168 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
169
170 #else // !Py_BUILD_CORE
171 # define KWTUPLE NULL
172 #endif // !Py_BUILD_CORE
173
174 static const char * const _keywords[] = {"data", "max_length", NULL};
175 static _PyArg_Parser _parser = {
176 .keywords = _keywords,
177 .fname = "decompress",
178 .kwtuple = KWTUPLE,
179 };
180 #undef KWTUPLE
181 PyObject *argsbuf[2];
182 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
183 Py_buffer data = {NULL, NULL};
184 Py_ssize_t max_length = -1;
185
186 args = BACKPORTSZSTD__PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
187 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
188 if (!args) {
189 goto exit;
190 }
191 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
192 goto exit;
193 }
194 if (!noptargs) {
195 goto skip_optional_pos;
196 }
197 {
198 Py_ssize_t ival = -1;
199 PyObject *iobj = BACKPORTSZSTD__PyNumber_Index(args[1]);
200 if (iobj != NULL) {
201 ival = PyLong_AsSsize_t(iobj);
202 Py_DECREF(iobj);
203 }
204 if (ival == -1 && PyErr_Occurred()) {
205 goto exit;
206 }
207 max_length = ival;
208 }
209 skip_optional_pos:
210 return_value = _zstd_ZstdDecompressor_decompress_impl((ZstdDecompressor *)self, &data, max_length);
211
212 exit:
213 /* Cleanup for data */
214 if (data.obj) {
215 PyBuffer_Release(&data);
216 }
217
218 return return_value;
219 }
220 /*[clinic end generated code: output=70bc308e86463751 input=a9049054013a1b77]*/