blob: 136524b6a7134e1ad05134cd9e61c4d2c0b30b70 [file] [log] [blame]
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +02001/*[clinic input]
2preserve
3[clinic start generated code]*/
4
5PyDoc_STRVAR(_pickle_Pickler_clear_memo__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -08006"clear_memo($self, /)\n"
7"--\n"
8"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +02009"Clears the pickler\'s \"memo\".\n"
10"\n"
11"The memo is the data structure that remembers which objects the\n"
12"pickler has already seen, so that shared or recursive objects are\n"
13"pickled by reference and not by value. This method is useful when\n"
14"re-using picklers.");
15
16#define _PICKLE_PICKLER_CLEAR_MEMO_METHODDEF \
17 {"clear_memo", (PyCFunction)_pickle_Pickler_clear_memo, METH_NOARGS, _pickle_Pickler_clear_memo__doc__},
18
19static PyObject *
20_pickle_Pickler_clear_memo_impl(PicklerObject *self);
21
22static PyObject *
23_pickle_Pickler_clear_memo(PicklerObject *self, PyObject *Py_UNUSED(ignored))
24{
25 return _pickle_Pickler_clear_memo_impl(self);
26}
27
28PyDoc_STRVAR(_pickle_Pickler_dump__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -080029"dump($self, obj, /)\n"
30"--\n"
31"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020032"Write a pickled representation of the given object to the open file.");
33
34#define _PICKLE_PICKLER_DUMP_METHODDEF \
35 {"dump", (PyCFunction)_pickle_Pickler_dump, METH_O, _pickle_Pickler_dump__doc__},
36
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020037PyDoc_STRVAR(_pickle_Pickler___sizeof____doc__,
38"__sizeof__($self, /)\n"
39"--\n"
40"\n"
41"Returns size in memory, in bytes.");
42
43#define _PICKLE_PICKLER___SIZEOF___METHODDEF \
44 {"__sizeof__", (PyCFunction)_pickle_Pickler___sizeof__, METH_NOARGS, _pickle_Pickler___sizeof____doc__},
45
46static Py_ssize_t
47_pickle_Pickler___sizeof___impl(PicklerObject *self);
48
49static PyObject *
50_pickle_Pickler___sizeof__(PicklerObject *self, PyObject *Py_UNUSED(ignored))
51{
52 PyObject *return_value = NULL;
53 Py_ssize_t _return_value;
54
55 _return_value = _pickle_Pickler___sizeof___impl(self);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030056 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020057 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +030058 }
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +020059 return_value = PyLong_FromSsize_t(_return_value);
60
61exit:
62 return return_value;
63}
64
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020065PyDoc_STRVAR(_pickle_Pickler___init____doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +020066"Pickler(file, protocol=None, fix_imports=True, buffer_callback=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -080067"--\n"
68"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020069"This takes a binary file for writing a pickle data stream.\n"
70"\n"
71"The optional *protocol* argument tells the pickler to use the given\n"
Mark Dickinsone9652e82020-01-24 10:03:22 +000072"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
73"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
74"with previous versions.\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020075"\n"
76"Specifying a negative protocol version selects the highest protocol\n"
77"version supported. The higher the protocol used, the more recent the\n"
78"version of Python needed to read the pickle produced.\n"
79"\n"
80"The *file* argument must have a write() method that accepts a single\n"
81"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +000082"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020083"this interface.\n"
84"\n"
85"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
86"to map the new Python 3 names to the old module names used in Python\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +020087"2, so that the pickle data stream is readable with Python 2.\n"
88"\n"
89"If *buffer_callback* is None (the default), buffer views are\n"
90"serialized into *file* as part of the pickle stream.\n"
91"\n"
92"If *buffer_callback* is not None, then it can be called any number\n"
93"of times with a buffer view. If the callback returns a false value\n"
94"(such as None), the given buffer is out-of-band; otherwise the\n"
95"buffer is serialized in-band, i.e. inside the pickle stream.\n"
96"\n"
97"It is an error if *buffer_callback* is not None and *protocol*\n"
98"is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020099
100static int
Larry Hastings89964c42015-04-14 18:07:59 -0400101_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200102 PyObject *protocol, int fix_imports,
103 PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200104
105static int
106_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
107{
108 int return_value = -1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200109 static const char * const _keywords[] = {"file", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200110 static _PyArg_Parser _parser = {NULL, _keywords, "Pickler", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200111 PyObject *argsbuf[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200112 PyObject * const *fastargs;
113 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
114 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200115 PyObject *file;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300116 PyObject *protocol = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200117 int fix_imports = 1;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300118 PyObject *buffer_callback = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200119
Antoine Pitrou91f43802019-05-26 17:10:09 +0200120 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200121 if (!fastargs) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200122 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300123 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200124 file = fastargs[0];
125 if (!noptargs) {
126 goto skip_optional_pos;
127 }
128 if (fastargs[1]) {
129 protocol = fastargs[1];
130 if (!--noptargs) {
131 goto skip_optional_pos;
132 }
133 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200134 if (fastargs[2]) {
135 fix_imports = PyObject_IsTrue(fastargs[2]);
136 if (fix_imports < 0) {
137 goto exit;
138 }
139 if (!--noptargs) {
140 goto skip_optional_pos;
141 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200142 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200143 buffer_callback = fastargs[3];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200144skip_optional_pos:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200145 return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200146
147exit:
148 return return_value;
149}
150
151PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800152"clear($self, /)\n"
153"--\n"
154"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200155"Remove all items from memo.");
156
157#define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \
158 {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
159
160static PyObject *
161_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
162
163static PyObject *
164_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
165{
166 return _pickle_PicklerMemoProxy_clear_impl(self);
167}
168
169PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800170"copy($self, /)\n"
171"--\n"
172"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200173"Copy the memo to a new object.");
174
175#define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \
176 {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
177
178static PyObject *
179_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
180
181static PyObject *
182_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
183{
184 return _pickle_PicklerMemoProxy_copy_impl(self);
185}
186
187PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800188"__reduce__($self, /)\n"
189"--\n"
190"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200191"Implement pickle support.");
192
193#define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \
194 {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
195
196static PyObject *
197_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
198
199static PyObject *
200_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
201{
202 return _pickle_PicklerMemoProxy___reduce___impl(self);
203}
204
205PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800206"load($self, /)\n"
207"--\n"
208"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200209"Load a pickle.\n"
210"\n"
211"Read a pickled object representation from the open file object given\n"
212"in the constructor, and return the reconstituted object hierarchy\n"
213"specified therein.");
214
215#define _PICKLE_UNPICKLER_LOAD_METHODDEF \
216 {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
217
218static PyObject *
219_pickle_Unpickler_load_impl(UnpicklerObject *self);
220
221static PyObject *
222_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
223{
224 return _pickle_Unpickler_load_impl(self);
225}
226
227PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800228"find_class($self, module_name, global_name, /)\n"
229"--\n"
230"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200231"Return an object from a specified module.\n"
232"\n"
233"If necessary, the module will be imported. Subclasses may override\n"
234"this method (e.g. to restrict unpickling of arbitrary classes and\n"
235"functions).\n"
236"\n"
237"This method is called whenever a class or a function object is\n"
238"needed. Both arguments passed are str objects.");
239
240#define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200241 {"find_class", (PyCFunction)(void(*)(void))_pickle_Unpickler_find_class, METH_FASTCALL, _pickle_Unpickler_find_class__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200242
243static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400244_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
245 PyObject *module_name,
246 PyObject *global_name);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200247
248static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200249_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200250{
251 PyObject *return_value = NULL;
252 PyObject *module_name;
253 PyObject *global_name;
254
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200255 if (!_PyArg_CheckPositional("find_class", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100256 goto exit;
257 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200258 module_name = args[0];
259 global_name = args[1];
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200260 return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
261
262exit:
263 return return_value;
264}
265
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200266PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__,
267"__sizeof__($self, /)\n"
268"--\n"
269"\n"
270"Returns size in memory, in bytes.");
271
272#define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \
273 {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__},
274
275static Py_ssize_t
276_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
277
278static PyObject *
279_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
280{
281 PyObject *return_value = NULL;
282 Py_ssize_t _return_value;
283
284 _return_value = _pickle_Unpickler___sizeof___impl(self);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300285 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200286 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300287 }
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200288 return_value = PyLong_FromSsize_t(_return_value);
289
290exit:
291 return return_value;
292}
293
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200294PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200295"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\',\n"
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300296" buffers=())\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800297"--\n"
298"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200299"This takes a binary file for reading a pickle data stream.\n"
300"\n"
301"The protocol version of the pickle is detected automatically, so no\n"
302"protocol argument is needed. Bytes past the pickled object\'s\n"
303"representation are ignored.\n"
304"\n"
305"The argument *file* must have two methods, a read() method that takes\n"
306"an integer argument, and a readline() method that requires no\n"
307"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000308"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200309"other custom object that meets this interface.\n"
310"\n"
311"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000312"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200313"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
314"map the old Python 2 names to the new names used in Python 3. The\n"
315"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
316"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
317"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
318"string instances as bytes objects.");
319
320static int
Larry Hastings89964c42015-04-14 18:07:59 -0400321_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
322 int fix_imports, const char *encoding,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200323 const char *errors, PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200324
325static int
326_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
327{
328 int return_value = -1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200329 static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200330 static _PyArg_Parser _parser = {NULL, _keywords, "Unpickler", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200331 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200332 PyObject * const *fastargs;
333 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
334 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200335 PyObject *file;
336 int fix_imports = 1;
337 const char *encoding = "ASCII";
338 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200339 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200340
Serhiy Storchaka31913912019-03-14 10:32:22 +0200341 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
342 if (!fastargs) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200343 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300344 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200345 file = fastargs[0];
346 if (!noptargs) {
347 goto skip_optional_kwonly;
348 }
349 if (fastargs[1]) {
350 fix_imports = PyObject_IsTrue(fastargs[1]);
351 if (fix_imports < 0) {
352 goto exit;
353 }
354 if (!--noptargs) {
355 goto skip_optional_kwonly;
356 }
357 }
358 if (fastargs[2]) {
359 if (!PyUnicode_Check(fastargs[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200360 _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200361 goto exit;
362 }
363 Py_ssize_t encoding_length;
364 encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
365 if (encoding == NULL) {
366 goto exit;
367 }
368 if (strlen(encoding) != (size_t)encoding_length) {
369 PyErr_SetString(PyExc_ValueError, "embedded null character");
370 goto exit;
371 }
372 if (!--noptargs) {
373 goto skip_optional_kwonly;
374 }
375 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200376 if (fastargs[3]) {
377 if (!PyUnicode_Check(fastargs[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200378 _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200379 goto exit;
380 }
381 Py_ssize_t errors_length;
382 errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
383 if (errors == NULL) {
384 goto exit;
385 }
386 if (strlen(errors) != (size_t)errors_length) {
387 PyErr_SetString(PyExc_ValueError, "embedded null character");
388 goto exit;
389 }
390 if (!--noptargs) {
391 goto skip_optional_kwonly;
392 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200393 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200394 buffers = fastargs[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200395skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200396 return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200397
398exit:
399 return return_value;
400}
401
402PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800403"clear($self, /)\n"
404"--\n"
405"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200406"Remove all items from memo.");
407
408#define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \
409 {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
410
411static PyObject *
412_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
413
414static PyObject *
415_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
416{
417 return _pickle_UnpicklerMemoProxy_clear_impl(self);
418}
419
420PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800421"copy($self, /)\n"
422"--\n"
423"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200424"Copy the memo to a new object.");
425
426#define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \
427 {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
428
429static PyObject *
430_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
431
432static PyObject *
433_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
434{
435 return _pickle_UnpicklerMemoProxy_copy_impl(self);
436}
437
438PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800439"__reduce__($self, /)\n"
440"--\n"
441"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200442"Implement pickling support.");
443
444#define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \
445 {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
446
447static PyObject *
448_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
449
450static PyObject *
451_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
452{
453 return _pickle_UnpicklerMemoProxy___reduce___impl(self);
454}
455
456PyDoc_STRVAR(_pickle_dump__doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200457"dump($module, /, obj, file, protocol=None, *, fix_imports=True,\n"
458" buffer_callback=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800459"--\n"
460"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200461"Write a pickled representation of obj to the open file object file.\n"
462"\n"
463"This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n"
464"be more efficient.\n"
465"\n"
466"The optional *protocol* argument tells the pickler to use the given\n"
Mark Dickinsone9652e82020-01-24 10:03:22 +0000467"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
468"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
Łukasz Langac51d8c92018-04-03 23:06:53 -0700469"with previous versions.\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200470"\n"
471"Specifying a negative protocol version selects the highest protocol\n"
472"version supported. The higher the protocol used, the more recent the\n"
473"version of Python needed to read the pickle produced.\n"
474"\n"
475"The *file* argument must have a write() method that accepts a single\n"
476"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000477"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200478"this interface.\n"
479"\n"
480"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
481"to map the new Python 3 names to the old module names used in Python\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200482"2, so that the pickle data stream is readable with Python 2.\n"
483"\n"
484"If *buffer_callback* is None (the default), buffer views are serialized\n"
485"into *file* as part of the pickle stream. It is an error if\n"
486"*buffer_callback* is not None and *protocol* is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200487
488#define _PICKLE_DUMP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200489 {"dump", (PyCFunction)(void(*)(void))_pickle_dump, METH_FASTCALL|METH_KEYWORDS, _pickle_dump__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200490
491static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300492_pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200493 PyObject *protocol, int fix_imports,
494 PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200495
496static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200497_pickle_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200498{
499 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200500 static const char * const _keywords[] = {"obj", "file", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200501 static _PyArg_Parser _parser = {NULL, _keywords, "dump", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200502 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200503 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200504 PyObject *obj;
505 PyObject *file;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300506 PyObject *protocol = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200507 int fix_imports = 1;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300508 PyObject *buffer_callback = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200509
Serhiy Storchaka31913912019-03-14 10:32:22 +0200510 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
511 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200512 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300513 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200514 obj = args[0];
515 file = args[1];
516 if (!noptargs) {
517 goto skip_optional_pos;
518 }
519 if (args[2]) {
520 protocol = args[2];
521 if (!--noptargs) {
522 goto skip_optional_pos;
523 }
524 }
525skip_optional_pos:
526 if (!noptargs) {
527 goto skip_optional_kwonly;
528 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200529 if (args[3]) {
530 fix_imports = PyObject_IsTrue(args[3]);
531 if (fix_imports < 0) {
532 goto exit;
533 }
534 if (!--noptargs) {
535 goto skip_optional_kwonly;
536 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200537 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200538 buffer_callback = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200539skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200540 return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200541
542exit:
543 return return_value;
544}
545
546PyDoc_STRVAR(_pickle_dumps__doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200547"dumps($module, /, obj, protocol=None, *, fix_imports=True,\n"
548" buffer_callback=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800549"--\n"
550"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200551"Return the pickled representation of the object as a bytes object.\n"
552"\n"
553"The optional *protocol* argument tells the pickler to use the given\n"
Mark Dickinsone9652e82020-01-24 10:03:22 +0000554"protocol; supported protocols are 0, 1, 2, 3, 4 and 5. The default\n"
555"protocol is 4. It was introduced in Python 3.4, and is incompatible\n"
Łukasz Langac51d8c92018-04-03 23:06:53 -0700556"with previous versions.\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200557"\n"
558"Specifying a negative protocol version selects the highest protocol\n"
559"version supported. The higher the protocol used, the more recent the\n"
560"version of Python needed to read the pickle produced.\n"
561"\n"
562"If *fix_imports* is True and *protocol* is less than 3, pickle will\n"
563"try to map the new Python 3 names to the old module names used in\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200564"Python 2, so that the pickle data stream is readable with Python 2.\n"
565"\n"
566"If *buffer_callback* is None (the default), buffer views are serialized\n"
567"into *file* as part of the pickle stream. It is an error if\n"
568"*buffer_callback* is not None and *protocol* is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200569
570#define _PICKLE_DUMPS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200571 {"dumps", (PyCFunction)(void(*)(void))_pickle_dumps, METH_FASTCALL|METH_KEYWORDS, _pickle_dumps__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200572
573static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300574_pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200575 int fix_imports, PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200576
577static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200578_pickle_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200579{
580 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200581 static const char * const _keywords[] = {"obj", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200582 static _PyArg_Parser _parser = {NULL, _keywords, "dumps", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200583 PyObject *argsbuf[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200584 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200585 PyObject *obj;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300586 PyObject *protocol = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200587 int fix_imports = 1;
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300588 PyObject *buffer_callback = Py_None;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200589
Serhiy Storchaka31913912019-03-14 10:32:22 +0200590 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
591 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200592 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300593 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200594 obj = args[0];
595 if (!noptargs) {
596 goto skip_optional_pos;
597 }
598 if (args[1]) {
599 protocol = args[1];
600 if (!--noptargs) {
601 goto skip_optional_pos;
602 }
603 }
604skip_optional_pos:
605 if (!noptargs) {
606 goto skip_optional_kwonly;
607 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200608 if (args[2]) {
609 fix_imports = PyObject_IsTrue(args[2]);
610 if (fix_imports < 0) {
611 goto exit;
612 }
613 if (!--noptargs) {
614 goto skip_optional_kwonly;
615 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200616 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200617 buffer_callback = args[3];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200618skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200619 return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200620
621exit:
622 return return_value;
623}
624
625PyDoc_STRVAR(_pickle_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800626"load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n"
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300627" errors=\'strict\', buffers=())\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800628"--\n"
629"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200630"Read and return an object from the pickle data stored in a file.\n"
631"\n"
632"This is equivalent to ``Unpickler(file).load()``, but may be more\n"
633"efficient.\n"
634"\n"
635"The protocol version of the pickle is detected automatically, so no\n"
636"protocol argument is needed. Bytes past the pickled object\'s\n"
637"representation are ignored.\n"
638"\n"
639"The argument *file* must have two methods, a read() method that takes\n"
640"an integer argument, and a readline() method that requires no\n"
641"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000642"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200643"other custom object that meets this interface.\n"
644"\n"
645"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000646"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200647"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
648"map the old Python 2 names to the new names used in Python 3. The\n"
649"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
650"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
651"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
652"string instances as bytes objects.");
653
654#define _PICKLE_LOAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200655 {"load", (PyCFunction)(void(*)(void))_pickle_load, METH_FASTCALL|METH_KEYWORDS, _pickle_load__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200656
657static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300658_pickle_load_impl(PyObject *module, PyObject *file, int fix_imports,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200659 const char *encoding, const char *errors,
660 PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200661
662static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200663_pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200664{
665 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200666 static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200667 static _PyArg_Parser _parser = {NULL, _keywords, "load", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200668 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200669 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200670 PyObject *file;
671 int fix_imports = 1;
672 const char *encoding = "ASCII";
673 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200674 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200675
Serhiy Storchaka31913912019-03-14 10:32:22 +0200676 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
677 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200678 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300679 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200680 file = args[0];
681 if (!noptargs) {
682 goto skip_optional_kwonly;
683 }
684 if (args[1]) {
685 fix_imports = PyObject_IsTrue(args[1]);
686 if (fix_imports < 0) {
687 goto exit;
688 }
689 if (!--noptargs) {
690 goto skip_optional_kwonly;
691 }
692 }
693 if (args[2]) {
694 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200695 _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200696 goto exit;
697 }
698 Py_ssize_t encoding_length;
699 encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
700 if (encoding == NULL) {
701 goto exit;
702 }
703 if (strlen(encoding) != (size_t)encoding_length) {
704 PyErr_SetString(PyExc_ValueError, "embedded null character");
705 goto exit;
706 }
707 if (!--noptargs) {
708 goto skip_optional_kwonly;
709 }
710 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200711 if (args[3]) {
712 if (!PyUnicode_Check(args[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200713 _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200714 goto exit;
715 }
716 Py_ssize_t errors_length;
717 errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
718 if (errors == NULL) {
719 goto exit;
720 }
721 if (strlen(errors) != (size_t)errors_length) {
722 PyErr_SetString(PyExc_ValueError, "embedded null character");
723 goto exit;
724 }
725 if (!--noptargs) {
726 goto skip_optional_kwonly;
727 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200728 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200729 buffers = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200730skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200731 return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200732
733exit:
734 return return_value;
735}
736
737PyDoc_STRVAR(_pickle_loads__doc__,
Serhiy Storchaka531d1e52020-05-02 09:38:01 +0300738"loads($module, data, /, *, fix_imports=True, encoding=\'ASCII\',\n"
Serhiy Storchaka279f4462019-09-14 12:24:05 +0300739" errors=\'strict\', buffers=())\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800740"--\n"
741"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200742"Read and return an object from the given pickle data.\n"
743"\n"
744"The protocol version of the pickle is detected automatically, so no\n"
745"protocol argument is needed. Bytes past the pickled object\'s\n"
746"representation are ignored.\n"
747"\n"
748"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000749"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200750"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
751"map the old Python 2 names to the new names used in Python 3. The\n"
752"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
753"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
754"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
755"string instances as bytes objects.");
756
757#define _PICKLE_LOADS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200758 {"loads", (PyCFunction)(void(*)(void))_pickle_loads, METH_FASTCALL|METH_KEYWORDS, _pickle_loads__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200759
760static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300761_pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200762 const char *encoding, const char *errors,
763 PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200764
765static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200766_pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200767{
768 PyObject *return_value = NULL;
Serhiy Storchaka531d1e52020-05-02 09:38:01 +0300769 static const char * const _keywords[] = {"", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200770 static _PyArg_Parser _parser = {NULL, _keywords, "loads", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200771 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200772 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200773 PyObject *data;
774 int fix_imports = 1;
775 const char *encoding = "ASCII";
776 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200777 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200778
Serhiy Storchaka31913912019-03-14 10:32:22 +0200779 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
780 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200781 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300782 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200783 data = args[0];
784 if (!noptargs) {
785 goto skip_optional_kwonly;
786 }
787 if (args[1]) {
788 fix_imports = PyObject_IsTrue(args[1]);
789 if (fix_imports < 0) {
790 goto exit;
791 }
792 if (!--noptargs) {
793 goto skip_optional_kwonly;
794 }
795 }
796 if (args[2]) {
797 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200798 _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200799 goto exit;
800 }
801 Py_ssize_t encoding_length;
802 encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
803 if (encoding == NULL) {
804 goto exit;
805 }
806 if (strlen(encoding) != (size_t)encoding_length) {
807 PyErr_SetString(PyExc_ValueError, "embedded null character");
808 goto exit;
809 }
810 if (!--noptargs) {
811 goto skip_optional_kwonly;
812 }
813 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200814 if (args[3]) {
815 if (!PyUnicode_Check(args[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200816 _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200817 goto exit;
818 }
819 Py_ssize_t errors_length;
820 errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
821 if (errors == NULL) {
822 goto exit;
823 }
824 if (strlen(errors) != (size_t)errors_length) {
825 PyErr_SetString(PyExc_ValueError, "embedded null character");
826 goto exit;
827 }
828 if (!--noptargs) {
829 goto skip_optional_kwonly;
830 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200831 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200832 buffers = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200833skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200834 return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200835
836exit:
837 return return_value;
838}
Serhiy Storchaka531d1e52020-05-02 09:38:01 +0300839/*[clinic end generated code: output=324aad69644beda2 input=a9049054013a1b77]*/