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 decompress()\n"
19 "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 will be b\'\'.");
90 #if defined(_zstd_ZstdDecompressor_unused_data_DOCSTR)
91 # undef _zstd_ZstdDecompressor_unused_data_DOCSTR
92 #endif
93 #define _zstd_ZstdDecompressor_unused_data_DOCSTR _zstd_ZstdDecompressor_unused_data__doc__
94
95 #if !defined(_zstd_ZstdDecompressor_unused_data_DOCSTR)
96 # define _zstd_ZstdDecompressor_unused_data_DOCSTR NULL
97 #endif
98 #if defined(_ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF)
99 # undef _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF
100 # 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},
101 #else
102 # define _ZSTD_ZSTDDECOMPRESSOR_UNUSED_DATA_GETSETDEF {"unused_data", (getter)_zstd_ZstdDecompressor_unused_data_get, NULL, _zstd_ZstdDecompressor_unused_data_DOCSTR},
103 #endif
104
105 static PyObject *
106 _zstd_ZstdDecompressor_unused_data_get_impl(ZstdDecompressor *self);
107
108 static PyObject *
109 _zstd_ZstdDecompressor_unused_data_get(PyObject *self, void *Py_UNUSED(context))
110 {
111 return _zstd_ZstdDecompressor_unused_data_get_impl((ZstdDecompressor *)self);
112 }
113
114 PyDoc_STRVAR(_zstd_ZstdDecompressor_decompress__doc__,
115 "decompress($self, /, data, max_length=-1)\n"
116 "--\n"
117 "\n"
118 "Decompress *data*, returning uncompressed bytes if possible, or b\'\' otherwise.\n"
119 "\n"
120 " data\n"
121 " A bytes-like object, Zstandard data to be decompressed.\n"
122 " max_length\n"
123 " Maximum size of returned data. When it is negative, the size of\n"
124 " output buffer is unlimited. When it is nonnegative, returns at\n"
125 " most max_length bytes of decompressed data.\n"
126 "\n"
127 "If *max_length* is nonnegative, returns at most *max_length* bytes of\n"
128 "decompressed data. If this limit is reached and further output can be\n"
129 "produced, *self.needs_input* will be set to ``False``. In this case, the next\n"
130 "call to *decompress()* may provide *data* as b\'\' to obtain more of the output.\n"
131 "\n"
132 "If all of the input data was decompressed and returned (either because this\n"
133 "was less than *max_length* bytes, or because *max_length* was negative),\n"
134 "*self.needs_input* will be set to True.\n"
135 "\n"
136 "Attempting to decompress data after the end of a frame is reached raises an\n"
137 "EOFError. Any data found after the end of the frame is ignored and saved in\n"
138 "the self.unused_data attribute.");
139
140 #define _ZSTD_ZSTDDECOMPRESSOR_DECOMPRESS_METHODDEF \
141 {"decompress", _PyCFunction_CAST(_zstd_ZstdDecompressor_decompress), METH_FASTCALL|METH_KEYWORDS, _zstd_ZstdDecompressor_decompress__doc__},
142
143 static PyObject *
144 _zstd_ZstdDecompressor_decompress_impl(ZstdDecompressor *self,
145 Py_buffer *data,
146 Py_ssize_t max_length);
147
148 static PyObject *
149 _zstd_ZstdDecompressor_decompress(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
150 {
151 PyObject *return_value = NULL;
152 #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
153
154 #define NUM_KEYWORDS 2
155 static struct {
156 PyGC_Head _this_is_not_used;
157 PyObject_VAR_HEAD
158 Py_hash_t ob_hash;
159 PyObject *ob_item[NUM_KEYWORDS];
160 } _kwtuple = {
161 .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
162 .ob_hash = -1,
163 .ob_item = { &_Py_ID(data), &_Py_ID(max_length), },
164 };
165 #undef NUM_KEYWORDS
166 #define KWTUPLE (&_kwtuple.ob_base.ob_base)
167
168 #else // !Py_BUILD_CORE
169 # define KWTUPLE NULL
170 #endif // !Py_BUILD_CORE
171
172 static const char * const _keywords[] = {"data", "max_length", NULL};
173 static _PyArg_Parser _parser = {
174 .keywords = _keywords,
175 .fname = "decompress",
176 .kwtuple = KWTUPLE,
177 };
178 #undef KWTUPLE
179 PyObject *argsbuf[2];
180 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
181 Py_buffer data = {NULL, NULL};
182 Py_ssize_t max_length = -1;
183
184 args = BACKPORTSZSTD__PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser,
185 /*minpos*/ 1, /*maxpos*/ 2, /*minkw*/ 0, /*varpos*/ 0, argsbuf);
186 if (!args) {
187 goto exit;
188 }
189 if (PyObject_GetBuffer(args[0], &data, PyBUF_SIMPLE) != 0) {
190 goto exit;
191 }
192 if (!noptargs) {
193 goto skip_optional_pos;
194 }
195 {
196 Py_ssize_t ival = -1;
197 PyObject *iobj = BACKPORTSZSTD__PyNumber_Index(args[1]);
198 if (iobj != NULL) {
199 ival = PyLong_AsSsize_t(iobj);
200 Py_DECREF(iobj);
201 }
202 if (ival == -1 && PyErr_Occurred()) {
203 goto exit;
204 }
205 max_length = ival;
206 }
207 skip_optional_pos:
208 return_value = _zstd_ZstdDecompressor_decompress_impl((ZstdDecompressor *)self, &data, max_length);
209
210 exit:
211 /* Cleanup for data */
212 if (data.obj) {
213 PyBuffer_Release(&data);
214 }
215
216 return return_value;
217 }
218 /*[clinic end generated code: output=30c12ef047027ede input=a9049054013a1b77]*/