blob: b92daa72105a61cf0d72d6dddd17a2ab3d377eba [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"
72"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
73"protocol is 3; a backward-incompatible protocol designed for Python 3.\n"
74"\n"
75"Specifying a negative protocol version selects the highest protocol\n"
76"version supported. The higher the protocol used, the more recent the\n"
77"version of Python needed to read the pickle produced.\n"
78"\n"
79"The *file* argument must have a write() method that accepts a single\n"
80"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +000081"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020082"this interface.\n"
83"\n"
84"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
85"to map the new Python 3 names to the old module names used in Python\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +020086"2, so that the pickle data stream is readable with Python 2.\n"
87"\n"
88"If *buffer_callback* is None (the default), buffer views are\n"
89"serialized into *file* as part of the pickle stream.\n"
90"\n"
91"If *buffer_callback* is not None, then it can be called any number\n"
92"of times with a buffer view. If the callback returns a false value\n"
93"(such as None), the given buffer is out-of-band; otherwise the\n"
94"buffer is serialized in-band, i.e. inside the pickle stream.\n"
95"\n"
96"It is an error if *buffer_callback* is not None and *protocol*\n"
97"is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +020098
99static int
Larry Hastings89964c42015-04-14 18:07:59 -0400100_pickle_Pickler___init___impl(PicklerObject *self, PyObject *file,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200101 PyObject *protocol, int fix_imports,
102 PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200103
104static int
105_pickle_Pickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
106{
107 int return_value = -1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200108 static const char * const _keywords[] = {"file", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200109 static _PyArg_Parser _parser = {NULL, _keywords, "Pickler", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200110 PyObject *argsbuf[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200111 PyObject * const *fastargs;
112 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
113 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200114 PyObject *file;
115 PyObject *protocol = NULL;
116 int fix_imports = 1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200117 PyObject *buffer_callback = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200118
Antoine Pitrou91f43802019-05-26 17:10:09 +0200119 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 4, 0, argsbuf);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200120 if (!fastargs) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200121 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300122 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200123 file = fastargs[0];
124 if (!noptargs) {
125 goto skip_optional_pos;
126 }
127 if (fastargs[1]) {
128 protocol = fastargs[1];
129 if (!--noptargs) {
130 goto skip_optional_pos;
131 }
132 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200133 if (fastargs[2]) {
134 fix_imports = PyObject_IsTrue(fastargs[2]);
135 if (fix_imports < 0) {
136 goto exit;
137 }
138 if (!--noptargs) {
139 goto skip_optional_pos;
140 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200141 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200142 buffer_callback = fastargs[3];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200143skip_optional_pos:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200144 return_value = _pickle_Pickler___init___impl((PicklerObject *)self, file, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200145
146exit:
147 return return_value;
148}
149
150PyDoc_STRVAR(_pickle_PicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800151"clear($self, /)\n"
152"--\n"
153"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200154"Remove all items from memo.");
155
156#define _PICKLE_PICKLERMEMOPROXY_CLEAR_METHODDEF \
157 {"clear", (PyCFunction)_pickle_PicklerMemoProxy_clear, METH_NOARGS, _pickle_PicklerMemoProxy_clear__doc__},
158
159static PyObject *
160_pickle_PicklerMemoProxy_clear_impl(PicklerMemoProxyObject *self);
161
162static PyObject *
163_pickle_PicklerMemoProxy_clear(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
164{
165 return _pickle_PicklerMemoProxy_clear_impl(self);
166}
167
168PyDoc_STRVAR(_pickle_PicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800169"copy($self, /)\n"
170"--\n"
171"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200172"Copy the memo to a new object.");
173
174#define _PICKLE_PICKLERMEMOPROXY_COPY_METHODDEF \
175 {"copy", (PyCFunction)_pickle_PicklerMemoProxy_copy, METH_NOARGS, _pickle_PicklerMemoProxy_copy__doc__},
176
177static PyObject *
178_pickle_PicklerMemoProxy_copy_impl(PicklerMemoProxyObject *self);
179
180static PyObject *
181_pickle_PicklerMemoProxy_copy(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
182{
183 return _pickle_PicklerMemoProxy_copy_impl(self);
184}
185
186PyDoc_STRVAR(_pickle_PicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800187"__reduce__($self, /)\n"
188"--\n"
189"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200190"Implement pickle support.");
191
192#define _PICKLE_PICKLERMEMOPROXY___REDUCE___METHODDEF \
193 {"__reduce__", (PyCFunction)_pickle_PicklerMemoProxy___reduce__, METH_NOARGS, _pickle_PicklerMemoProxy___reduce____doc__},
194
195static PyObject *
196_pickle_PicklerMemoProxy___reduce___impl(PicklerMemoProxyObject *self);
197
198static PyObject *
199_pickle_PicklerMemoProxy___reduce__(PicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
200{
201 return _pickle_PicklerMemoProxy___reduce___impl(self);
202}
203
204PyDoc_STRVAR(_pickle_Unpickler_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800205"load($self, /)\n"
206"--\n"
207"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200208"Load a pickle.\n"
209"\n"
210"Read a pickled object representation from the open file object given\n"
211"in the constructor, and return the reconstituted object hierarchy\n"
212"specified therein.");
213
214#define _PICKLE_UNPICKLER_LOAD_METHODDEF \
215 {"load", (PyCFunction)_pickle_Unpickler_load, METH_NOARGS, _pickle_Unpickler_load__doc__},
216
217static PyObject *
218_pickle_Unpickler_load_impl(UnpicklerObject *self);
219
220static PyObject *
221_pickle_Unpickler_load(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
222{
223 return _pickle_Unpickler_load_impl(self);
224}
225
226PyDoc_STRVAR(_pickle_Unpickler_find_class__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800227"find_class($self, module_name, global_name, /)\n"
228"--\n"
229"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200230"Return an object from a specified module.\n"
231"\n"
232"If necessary, the module will be imported. Subclasses may override\n"
233"this method (e.g. to restrict unpickling of arbitrary classes and\n"
234"functions).\n"
235"\n"
236"This method is called whenever a class or a function object is\n"
237"needed. Both arguments passed are str objects.");
238
239#define _PICKLE_UNPICKLER_FIND_CLASS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200240 {"find_class", (PyCFunction)(void(*)(void))_pickle_Unpickler_find_class, METH_FASTCALL, _pickle_Unpickler_find_class__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200241
242static PyObject *
Larry Hastings89964c42015-04-14 18:07:59 -0400243_pickle_Unpickler_find_class_impl(UnpicklerObject *self,
244 PyObject *module_name,
245 PyObject *global_name);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200246
247static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200248_pickle_Unpickler_find_class(UnpicklerObject *self, PyObject *const *args, Py_ssize_t nargs)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200249{
250 PyObject *return_value = NULL;
251 PyObject *module_name;
252 PyObject *global_name;
253
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200254 if (!_PyArg_CheckPositional("find_class", nargs, 2, 2)) {
Victor Stinner0c4a8282017-01-17 02:21:47 +0100255 goto exit;
256 }
Serhiy Storchaka2a39d252019-01-11 18:01:42 +0200257 module_name = args[0];
258 global_name = args[1];
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200259 return_value = _pickle_Unpickler_find_class_impl(self, module_name, global_name);
260
261exit:
262 return return_value;
263}
264
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200265PyDoc_STRVAR(_pickle_Unpickler___sizeof____doc__,
266"__sizeof__($self, /)\n"
267"--\n"
268"\n"
269"Returns size in memory, in bytes.");
270
271#define _PICKLE_UNPICKLER___SIZEOF___METHODDEF \
272 {"__sizeof__", (PyCFunction)_pickle_Unpickler___sizeof__, METH_NOARGS, _pickle_Unpickler___sizeof____doc__},
273
274static Py_ssize_t
275_pickle_Unpickler___sizeof___impl(UnpicklerObject *self);
276
277static PyObject *
278_pickle_Unpickler___sizeof__(UnpicklerObject *self, PyObject *Py_UNUSED(ignored))
279{
280 PyObject *return_value = NULL;
281 Py_ssize_t _return_value;
282
283 _return_value = _pickle_Unpickler___sizeof___impl(self);
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300284 if ((_return_value == -1) && PyErr_Occurred()) {
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200285 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300286 }
Serhiy Storchaka5bbd2312014-12-16 19:39:08 +0200287 return_value = PyLong_FromSsize_t(_return_value);
288
289exit:
290 return return_value;
291}
292
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200293PyDoc_STRVAR(_pickle_Unpickler___init____doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200294"Unpickler(file, *, fix_imports=True, encoding=\'ASCII\', errors=\'strict\',\n"
295" buffers=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800296"--\n"
297"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200298"This takes a binary file for reading a pickle data stream.\n"
299"\n"
300"The protocol version of the pickle is detected automatically, so no\n"
301"protocol argument is needed. Bytes past the pickled object\'s\n"
302"representation are ignored.\n"
303"\n"
304"The argument *file* must have two methods, a read() method that takes\n"
305"an integer argument, and a readline() method that requires no\n"
306"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000307"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200308"other custom object that meets this interface.\n"
309"\n"
310"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000311"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200312"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
313"map the old Python 2 names to the new names used in Python 3. The\n"
314"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
315"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
316"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
317"string instances as bytes objects.");
318
319static int
Larry Hastings89964c42015-04-14 18:07:59 -0400320_pickle_Unpickler___init___impl(UnpicklerObject *self, PyObject *file,
321 int fix_imports, const char *encoding,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200322 const char *errors, PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200323
324static int
325_pickle_Unpickler___init__(PyObject *self, PyObject *args, PyObject *kwargs)
326{
327 int return_value = -1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200328 static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200329 static _PyArg_Parser _parser = {NULL, _keywords, "Unpickler", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200330 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200331 PyObject * const *fastargs;
332 Py_ssize_t nargs = PyTuple_GET_SIZE(args);
333 Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200334 PyObject *file;
335 int fix_imports = 1;
336 const char *encoding = "ASCII";
337 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200338 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200339
Serhiy Storchaka31913912019-03-14 10:32:22 +0200340 fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
341 if (!fastargs) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200342 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300343 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200344 file = fastargs[0];
345 if (!noptargs) {
346 goto skip_optional_kwonly;
347 }
348 if (fastargs[1]) {
349 fix_imports = PyObject_IsTrue(fastargs[1]);
350 if (fix_imports < 0) {
351 goto exit;
352 }
353 if (!--noptargs) {
354 goto skip_optional_kwonly;
355 }
356 }
357 if (fastargs[2]) {
358 if (!PyUnicode_Check(fastargs[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200359 _PyArg_BadArgument("Unpickler", "argument 'encoding'", "str", fastargs[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200360 goto exit;
361 }
362 Py_ssize_t encoding_length;
363 encoding = PyUnicode_AsUTF8AndSize(fastargs[2], &encoding_length);
364 if (encoding == NULL) {
365 goto exit;
366 }
367 if (strlen(encoding) != (size_t)encoding_length) {
368 PyErr_SetString(PyExc_ValueError, "embedded null character");
369 goto exit;
370 }
371 if (!--noptargs) {
372 goto skip_optional_kwonly;
373 }
374 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200375 if (fastargs[3]) {
376 if (!PyUnicode_Check(fastargs[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200377 _PyArg_BadArgument("Unpickler", "argument 'errors'", "str", fastargs[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200378 goto exit;
379 }
380 Py_ssize_t errors_length;
381 errors = PyUnicode_AsUTF8AndSize(fastargs[3], &errors_length);
382 if (errors == NULL) {
383 goto exit;
384 }
385 if (strlen(errors) != (size_t)errors_length) {
386 PyErr_SetString(PyExc_ValueError, "embedded null character");
387 goto exit;
388 }
389 if (!--noptargs) {
390 goto skip_optional_kwonly;
391 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200392 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200393 buffers = fastargs[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200394skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200395 return_value = _pickle_Unpickler___init___impl((UnpicklerObject *)self, file, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200396
397exit:
398 return return_value;
399}
400
401PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_clear__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800402"clear($self, /)\n"
403"--\n"
404"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200405"Remove all items from memo.");
406
407#define _PICKLE_UNPICKLERMEMOPROXY_CLEAR_METHODDEF \
408 {"clear", (PyCFunction)_pickle_UnpicklerMemoProxy_clear, METH_NOARGS, _pickle_UnpicklerMemoProxy_clear__doc__},
409
410static PyObject *
411_pickle_UnpicklerMemoProxy_clear_impl(UnpicklerMemoProxyObject *self);
412
413static PyObject *
414_pickle_UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
415{
416 return _pickle_UnpicklerMemoProxy_clear_impl(self);
417}
418
419PyDoc_STRVAR(_pickle_UnpicklerMemoProxy_copy__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800420"copy($self, /)\n"
421"--\n"
422"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200423"Copy the memo to a new object.");
424
425#define _PICKLE_UNPICKLERMEMOPROXY_COPY_METHODDEF \
426 {"copy", (PyCFunction)_pickle_UnpicklerMemoProxy_copy, METH_NOARGS, _pickle_UnpicklerMemoProxy_copy__doc__},
427
428static PyObject *
429_pickle_UnpicklerMemoProxy_copy_impl(UnpicklerMemoProxyObject *self);
430
431static PyObject *
432_pickle_UnpicklerMemoProxy_copy(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
433{
434 return _pickle_UnpicklerMemoProxy_copy_impl(self);
435}
436
437PyDoc_STRVAR(_pickle_UnpicklerMemoProxy___reduce____doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800438"__reduce__($self, /)\n"
439"--\n"
440"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200441"Implement pickling support.");
442
443#define _PICKLE_UNPICKLERMEMOPROXY___REDUCE___METHODDEF \
444 {"__reduce__", (PyCFunction)_pickle_UnpicklerMemoProxy___reduce__, METH_NOARGS, _pickle_UnpicklerMemoProxy___reduce____doc__},
445
446static PyObject *
447_pickle_UnpicklerMemoProxy___reduce___impl(UnpicklerMemoProxyObject *self);
448
449static PyObject *
450_pickle_UnpicklerMemoProxy___reduce__(UnpicklerMemoProxyObject *self, PyObject *Py_UNUSED(ignored))
451{
452 return _pickle_UnpicklerMemoProxy___reduce___impl(self);
453}
454
455PyDoc_STRVAR(_pickle_dump__doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200456"dump($module, /, obj, file, protocol=None, *, fix_imports=True,\n"
457" buffer_callback=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800458"--\n"
459"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200460"Write a pickled representation of obj to the open file object file.\n"
461"\n"
462"This is equivalent to ``Pickler(file, protocol).dump(obj)``, but may\n"
463"be more efficient.\n"
464"\n"
465"The optional *protocol* argument tells the pickler to use the given\n"
Łukasz Langac51d8c92018-04-03 23:06:53 -0700466"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
467"protocol is 4. It was introduced in Python 3.4, it is incompatible\n"
468"with previous versions.\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200469"\n"
470"Specifying a negative protocol version selects the highest protocol\n"
471"version supported. The higher the protocol used, the more recent the\n"
472"version of Python needed to read the pickle produced.\n"
473"\n"
474"The *file* argument must have a write() method that accepts a single\n"
475"bytes argument. It can thus be a file object opened for binary\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000476"writing, an io.BytesIO instance, or any other custom object that meets\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200477"this interface.\n"
478"\n"
479"If *fix_imports* is True and protocol is less than 3, pickle will try\n"
480"to map the new Python 3 names to the old module names used in Python\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200481"2, so that the pickle data stream is readable with Python 2.\n"
482"\n"
483"If *buffer_callback* is None (the default), buffer views are serialized\n"
484"into *file* as part of the pickle stream. It is an error if\n"
485"*buffer_callback* is not None and *protocol* is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200486
487#define _PICKLE_DUMP_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200488 {"dump", (PyCFunction)(void(*)(void))_pickle_dump, METH_FASTCALL|METH_KEYWORDS, _pickle_dump__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200489
490static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300491_pickle_dump_impl(PyObject *module, PyObject *obj, PyObject *file,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200492 PyObject *protocol, int fix_imports,
493 PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200494
495static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200496_pickle_dump(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200497{
498 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200499 static const char * const _keywords[] = {"obj", "file", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200500 static _PyArg_Parser _parser = {NULL, _keywords, "dump", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200501 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200502 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200503 PyObject *obj;
504 PyObject *file;
505 PyObject *protocol = NULL;
506 int fix_imports = 1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200507 PyObject *buffer_callback = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200508
Serhiy Storchaka31913912019-03-14 10:32:22 +0200509 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
510 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200511 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300512 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200513 obj = args[0];
514 file = args[1];
515 if (!noptargs) {
516 goto skip_optional_pos;
517 }
518 if (args[2]) {
519 protocol = args[2];
520 if (!--noptargs) {
521 goto skip_optional_pos;
522 }
523 }
524skip_optional_pos:
525 if (!noptargs) {
526 goto skip_optional_kwonly;
527 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200528 if (args[3]) {
529 fix_imports = PyObject_IsTrue(args[3]);
530 if (fix_imports < 0) {
531 goto exit;
532 }
533 if (!--noptargs) {
534 goto skip_optional_kwonly;
535 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200536 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200537 buffer_callback = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200538skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200539 return_value = _pickle_dump_impl(module, obj, file, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200540
541exit:
542 return return_value;
543}
544
545PyDoc_STRVAR(_pickle_dumps__doc__,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200546"dumps($module, /, obj, protocol=None, *, fix_imports=True,\n"
547" buffer_callback=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800548"--\n"
549"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200550"Return the pickled representation of the object as a bytes object.\n"
551"\n"
552"The optional *protocol* argument tells the pickler to use the given\n"
553"protocol; supported protocols are 0, 1, 2, 3 and 4. The default\n"
Łukasz Langac51d8c92018-04-03 23:06:53 -0700554"protocol is 4. It was introduced in Python 3.4, it is incompatible\n"
555"with previous versions.\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200556"\n"
557"Specifying a negative protocol version selects the highest protocol\n"
558"version supported. The higher the protocol used, the more recent the\n"
559"version of Python needed to read the pickle produced.\n"
560"\n"
561"If *fix_imports* is True and *protocol* is less than 3, pickle will\n"
562"try to map the new Python 3 names to the old module names used in\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200563"Python 2, so that the pickle data stream is readable with Python 2.\n"
564"\n"
565"If *buffer_callback* is None (the default), buffer views are serialized\n"
566"into *file* as part of the pickle stream. It is an error if\n"
567"*buffer_callback* is not None and *protocol* is None or smaller than 5.");
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200568
569#define _PICKLE_DUMPS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200570 {"dumps", (PyCFunction)(void(*)(void))_pickle_dumps, METH_FASTCALL|METH_KEYWORDS, _pickle_dumps__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200571
572static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300573_pickle_dumps_impl(PyObject *module, PyObject *obj, PyObject *protocol,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200574 int fix_imports, PyObject *buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200575
576static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200577_pickle_dumps(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200578{
579 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200580 static const char * const _keywords[] = {"obj", "protocol", "fix_imports", "buffer_callback", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200581 static _PyArg_Parser _parser = {NULL, _keywords, "dumps", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200582 PyObject *argsbuf[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200583 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200584 PyObject *obj;
585 PyObject *protocol = NULL;
586 int fix_imports = 1;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200587 PyObject *buffer_callback = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200588
Serhiy Storchaka31913912019-03-14 10:32:22 +0200589 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
590 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200591 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300592 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200593 obj = args[0];
594 if (!noptargs) {
595 goto skip_optional_pos;
596 }
597 if (args[1]) {
598 protocol = args[1];
599 if (!--noptargs) {
600 goto skip_optional_pos;
601 }
602 }
603skip_optional_pos:
604 if (!noptargs) {
605 goto skip_optional_kwonly;
606 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200607 if (args[2]) {
608 fix_imports = PyObject_IsTrue(args[2]);
609 if (fix_imports < 0) {
610 goto exit;
611 }
612 if (!--noptargs) {
613 goto skip_optional_kwonly;
614 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200615 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200616 buffer_callback = args[3];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200617skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200618 return_value = _pickle_dumps_impl(module, obj, protocol, fix_imports, buffer_callback);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200619
620exit:
621 return return_value;
622}
623
624PyDoc_STRVAR(_pickle_load__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800625"load($module, /, file, *, fix_imports=True, encoding=\'ASCII\',\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200626" errors=\'strict\', buffers=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800627"--\n"
628"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200629"Read and return an object from the pickle data stored in a file.\n"
630"\n"
631"This is equivalent to ``Unpickler(file).load()``, but may be more\n"
632"efficient.\n"
633"\n"
634"The protocol version of the pickle is detected automatically, so no\n"
635"protocol argument is needed. Bytes past the pickled object\'s\n"
636"representation are ignored.\n"
637"\n"
638"The argument *file* must have two methods, a read() method that takes\n"
639"an integer argument, and a readline() method that requires no\n"
640"arguments. Both methods should return bytes. Thus *file* can be a\n"
Martin Panter7462b6492015-11-02 03:37:02 +0000641"binary file object opened for reading, an io.BytesIO object, or any\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200642"other custom object that meets this interface.\n"
643"\n"
644"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000645"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200646"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
647"map the old Python 2 names to the new names used in Python 3. The\n"
648"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
649"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
650"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
651"string instances as bytes objects.");
652
653#define _PICKLE_LOAD_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200654 {"load", (PyCFunction)(void(*)(void))_pickle_load, METH_FASTCALL|METH_KEYWORDS, _pickle_load__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200655
656static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300657_pickle_load_impl(PyObject *module, PyObject *file, int fix_imports,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200658 const char *encoding, const char *errors,
659 PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200660
661static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200662_pickle_load(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200663{
664 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200665 static const char * const _keywords[] = {"file", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200666 static _PyArg_Parser _parser = {NULL, _keywords, "load", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200667 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200668 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200669 PyObject *file;
670 int fix_imports = 1;
671 const char *encoding = "ASCII";
672 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200673 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200674
Serhiy Storchaka31913912019-03-14 10:32:22 +0200675 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
676 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200677 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300678 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200679 file = args[0];
680 if (!noptargs) {
681 goto skip_optional_kwonly;
682 }
683 if (args[1]) {
684 fix_imports = PyObject_IsTrue(args[1]);
685 if (fix_imports < 0) {
686 goto exit;
687 }
688 if (!--noptargs) {
689 goto skip_optional_kwonly;
690 }
691 }
692 if (args[2]) {
693 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200694 _PyArg_BadArgument("load", "argument 'encoding'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200695 goto exit;
696 }
697 Py_ssize_t encoding_length;
698 encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
699 if (encoding == NULL) {
700 goto exit;
701 }
702 if (strlen(encoding) != (size_t)encoding_length) {
703 PyErr_SetString(PyExc_ValueError, "embedded null character");
704 goto exit;
705 }
706 if (!--noptargs) {
707 goto skip_optional_kwonly;
708 }
709 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200710 if (args[3]) {
711 if (!PyUnicode_Check(args[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200712 _PyArg_BadArgument("load", "argument 'errors'", "str", args[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200713 goto exit;
714 }
715 Py_ssize_t errors_length;
716 errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
717 if (errors == NULL) {
718 goto exit;
719 }
720 if (strlen(errors) != (size_t)errors_length) {
721 PyErr_SetString(PyExc_ValueError, "embedded null character");
722 goto exit;
723 }
724 if (!--noptargs) {
725 goto skip_optional_kwonly;
726 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200727 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200728 buffers = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200729skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200730 return_value = _pickle_load_impl(module, file, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200731
732exit:
733 return return_value;
734}
735
736PyDoc_STRVAR(_pickle_loads__doc__,
Larry Hastings2623c8c2014-02-08 22:15:29 -0800737"loads($module, /, data, *, fix_imports=True, encoding=\'ASCII\',\n"
Antoine Pitrou91f43802019-05-26 17:10:09 +0200738" errors=\'strict\', buffers=None)\n"
Larry Hastings2623c8c2014-02-08 22:15:29 -0800739"--\n"
740"\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200741"Read and return an object from the given pickle data.\n"
742"\n"
743"The protocol version of the pickle is detected automatically, so no\n"
744"protocol argument is needed. Bytes past the pickled object\'s\n"
745"representation are ignored.\n"
746"\n"
747"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
Martin Panter46f50722016-05-26 05:35:26 +0000748"which are used to control compatibility support for pickle stream\n"
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200749"generated by Python 2. If *fix_imports* is True, pickle will try to\n"
750"map the old Python 2 names to the new names used in Python 3. The\n"
751"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
752"instances pickled by Python 2; these default to \'ASCII\' and \'strict\',\n"
753"respectively. The *encoding* can be \'bytes\' to read these 8-bit\n"
754"string instances as bytes objects.");
755
756#define _PICKLE_LOADS_METHODDEF \
Serhiy Storchaka4a934d42018-11-27 11:27:36 +0200757 {"loads", (PyCFunction)(void(*)(void))_pickle_loads, METH_FASTCALL|METH_KEYWORDS, _pickle_loads__doc__},
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200758
759static PyObject *
Serhiy Storchaka1a2b24f2016-07-07 17:35:15 +0300760_pickle_loads_impl(PyObject *module, PyObject *data, int fix_imports,
Antoine Pitrou91f43802019-05-26 17:10:09 +0200761 const char *encoding, const char *errors,
762 PyObject *buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200763
764static PyObject *
Serhiy Storchakaa5552f02017-12-15 13:11:11 +0200765_pickle_loads(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200766{
767 PyObject *return_value = NULL;
Antoine Pitrou91f43802019-05-26 17:10:09 +0200768 static const char * const _keywords[] = {"data", "fix_imports", "encoding", "errors", "buffers", NULL};
Serhiy Storchaka31913912019-03-14 10:32:22 +0200769 static _PyArg_Parser _parser = {NULL, _keywords, "loads", 0};
Antoine Pitrou91f43802019-05-26 17:10:09 +0200770 PyObject *argsbuf[5];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200771 Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200772 PyObject *data;
773 int fix_imports = 1;
774 const char *encoding = "ASCII";
775 const char *errors = "strict";
Antoine Pitrou91f43802019-05-26 17:10:09 +0200776 PyObject *buffers = NULL;
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200777
Serhiy Storchaka31913912019-03-14 10:32:22 +0200778 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
779 if (!args) {
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200780 goto exit;
Serhiy Storchaka5dee6552016-06-09 16:16:06 +0300781 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200782 data = args[0];
783 if (!noptargs) {
784 goto skip_optional_kwonly;
785 }
786 if (args[1]) {
787 fix_imports = PyObject_IsTrue(args[1]);
788 if (fix_imports < 0) {
789 goto exit;
790 }
791 if (!--noptargs) {
792 goto skip_optional_kwonly;
793 }
794 }
795 if (args[2]) {
796 if (!PyUnicode_Check(args[2])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200797 _PyArg_BadArgument("loads", "argument 'encoding'", "str", args[2]);
Serhiy Storchaka31913912019-03-14 10:32:22 +0200798 goto exit;
799 }
800 Py_ssize_t encoding_length;
801 encoding = PyUnicode_AsUTF8AndSize(args[2], &encoding_length);
802 if (encoding == NULL) {
803 goto exit;
804 }
805 if (strlen(encoding) != (size_t)encoding_length) {
806 PyErr_SetString(PyExc_ValueError, "embedded null character");
807 goto exit;
808 }
809 if (!--noptargs) {
810 goto skip_optional_kwonly;
811 }
812 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200813 if (args[3]) {
814 if (!PyUnicode_Check(args[3])) {
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200815 _PyArg_BadArgument("loads", "argument 'errors'", "str", args[3]);
Antoine Pitrou91f43802019-05-26 17:10:09 +0200816 goto exit;
817 }
818 Py_ssize_t errors_length;
819 errors = PyUnicode_AsUTF8AndSize(args[3], &errors_length);
820 if (errors == NULL) {
821 goto exit;
822 }
823 if (strlen(errors) != (size_t)errors_length) {
824 PyErr_SetString(PyExc_ValueError, "embedded null character");
825 goto exit;
826 }
827 if (!--noptargs) {
828 goto skip_optional_kwonly;
829 }
Serhiy Storchaka31913912019-03-14 10:32:22 +0200830 }
Antoine Pitrou91f43802019-05-26 17:10:09 +0200831 buffers = args[4];
Serhiy Storchaka31913912019-03-14 10:32:22 +0200832skip_optional_kwonly:
Antoine Pitrou91f43802019-05-26 17:10:09 +0200833 return_value = _pickle_loads_impl(module, data, fix_imports, encoding, errors, buffers);
Serhiy Storchaka3c1f0f12014-01-27 10:34:22 +0200834
835exit:
836 return return_value;
837}
Rémi Lapeyre4901fe22019-08-29 16:49:08 +0200838/*[clinic end generated code: output=17f6a76ebd94325d input=a9049054013a1b77]*/