Bug Summary

File:Modules/_pickle.c
Location:line 2966, column 13
Description:Access to field 'ob_refcnt' results in a dereference of a null pointer (loaded from variable 'obj_class')

Annotated Source Code

1#include "Python.h"
2#include "structmember.h"
3
4PyDoc_STRVAR(pickle_module_doc,static char pickle_module_doc[] = "Optimized C implementation for the Python pickle module."
5"Optimized C implementation for the Python pickle module.")static char pickle_module_doc[] = "Optimized C implementation for the Python pickle module.";
6
7/* Bump this when new opcodes are added to the pickle protocol. */
8enum {
9 HIGHEST_PROTOCOL = 3,
10 DEFAULT_PROTOCOL = 3
11};
12
13/* Pickle opcodes. These must be kept updated with pickle.py.
14 Extensive docs are in pickletools.py. */
15enum opcode {
16 MARK = '(',
17 STOP = '.',
18 POP = '0',
19 POP_MARK = '1',
20 DUP = '2',
21 FLOAT = 'F',
22 INT = 'I',
23 BININT = 'J',
24 BININT1 = 'K',
25 LONG = 'L',
26 BININT2 = 'M',
27 NONE = 'N',
28 PERSID = 'P',
29 BINPERSID = 'Q',
30 REDUCE = 'R',
31 STRING = 'S',
32 BINSTRING = 'T',
33 SHORT_BINSTRING = 'U',
34 UNICODE = 'V',
35 BINUNICODE = 'X',
36 APPEND = 'a',
37 BUILD = 'b',
38 GLOBAL = 'c',
39 DICT = 'd',
40 EMPTY_DICT = '}',
41 APPENDS = 'e',
42 GET = 'g',
43 BINGET = 'h',
44 INST = 'i',
45 LONG_BINGET = 'j',
46 LIST = 'l',
47 EMPTY_LIST = ']',
48 OBJ = 'o',
49 PUT = 'p',
50 BINPUT = 'q',
51 LONG_BINPUT = 'r',
52 SETITEM = 's',
53 TUPLE = 't',
54 EMPTY_TUPLE = ')',
55 SETITEMS = 'u',
56 BINFLOAT = 'G',
57
58 /* Protocol 2. */
59 PROTO = '\x80',
60 NEWOBJ = '\x81',
61 EXT1 = '\x82',
62 EXT2 = '\x83',
63 EXT4 = '\x84',
64 TUPLE1 = '\x85',
65 TUPLE2 = '\x86',
66 TUPLE3 = '\x87',
67 NEWTRUE = '\x88',
68 NEWFALSE = '\x89',
69 LONG1 = '\x8a',
70 LONG4 = '\x8b',
71
72 /* Protocol 3 (Python 3.x) */
73 BINBYTES = 'B',
74 SHORT_BINBYTES = 'C'
75};
76
77/* These aren't opcodes -- they're ways to pickle bools before protocol 2
78 * so that unpicklers written before bools were introduced unpickle them
79 * as ints, but unpicklers after can recognize that bools were intended.
80 * Note that protocol 2 added direct ways to pickle bools.
81 */
82#undef TRUE"I01\n"
83#define TRUE"I01\n" "I01\n"
84#undef FALSE"I00\n"
85#define FALSE"I00\n" "I00\n"
86
87enum {
88 /* Keep in synch with pickle.Pickler._BATCHSIZE. This is how many elements
89 batch_list/dict() pumps out before doing APPENDS/SETITEMS. Nothing will
90 break if this gets out of synch with pickle.py, but it's unclear that would
91 help anything either. */
92 BATCHSIZE = 1000,
93
94 /* Nesting limit until Pickler, when running in "fast mode", starts
95 checking for self-referential data-structures. */
96 FAST_NESTING_LIMIT = 50,
97
98 /* Initial size of the write buffer of Pickler. */
99 WRITE_BUF_SIZE = 4096,
100
101 /* Maximum size of the write buffer of Pickler when pickling to a
102 stream. This is ignored for in-memory pickling. */
103 MAX_WRITE_BUF_SIZE = 64 * 1024,
104
105 /* Prefetch size when unpickling (disabled on unpeekable streams) */
106 PREFETCH = 8192 * 16
107};
108
109/* Exception classes for pickle. These should override the ones defined in
110 pickle.py, when the C-optimized Pickler and Unpickler are used. */
111static PyObject *PickleError = NULL((void*)0);
112static PyObject *PicklingError = NULL((void*)0);
113static PyObject *UnpicklingError = NULL((void*)0);
114
115/* copyreg.dispatch_table, {type_object: pickling_function} */
116static PyObject *dispatch_table = NULL((void*)0);
117/* For EXT[124] opcodes. */
118/* copyreg._extension_registry, {(module_name, function_name): code} */
119static PyObject *extension_registry = NULL((void*)0);
120/* copyreg._inverted_registry, {code: (module_name, function_name)} */
121static PyObject *inverted_registry = NULL((void*)0);
122/* copyreg._extension_cache, {code: object} */
123static PyObject *extension_cache = NULL((void*)0);
124
125/* _compat_pickle.NAME_MAPPING, {(oldmodule, oldname): (newmodule, newname)} */
126static PyObject *name_mapping_2to3 = NULL((void*)0);
127/* _compat_pickle.IMPORT_MAPPING, {oldmodule: newmodule} */
128static PyObject *import_mapping_2to3 = NULL((void*)0);
129/* Same, but with REVERSE_NAME_MAPPING / REVERSE_IMPORT_MAPPING */
130static PyObject *name_mapping_3to2 = NULL((void*)0);
131static PyObject *import_mapping_3to2 = NULL((void*)0);
132
133/* XXX: Are these really nescessary? */
134/* As the name says, an empty tuple. */
135static PyObject *empty_tuple = NULL((void*)0);
136/* For looking up name pairs in copyreg._extension_registry. */
137static PyObject *two_tuple = NULL((void*)0);
138
139static int
140stack_underflow(void)
141{
142 PyErr_SetString(UnpicklingError, "unpickling stack underflow");
143 return -1;
144}
145
146/* Internal data type used as the unpickling stack. */
147typedef struct {
148 PyObject_VAR_HEADPyVarObject ob_base;
149 PyObject **data;
150 Py_ssize_t allocated; /* number of slots in data allocated */
151} Pdata;
152
153static void
154Pdata_dealloc(Pdata *self)
155{
156 int i = Py_SIZE(self)(((PyVarObject*)(self))->ob_size);
157 while (--i >= 0) {
158 Py_DECREF(self->data[i])do { if (_Py_RefTotal-- , --((PyObject*)(self->data[i]))->
ob_refcnt != 0) { if (((PyObject*)self->data[i])->ob_refcnt
< 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 158, (PyObject *)(self->data[i])); } else _Py_Dealloc((PyObject
*)(self->data[i])); } while (0)
;
159 }
160 PyMem_FREE_PyMem_DebugFree(self->data);
161 PyObject_Del_PyObject_DebugFree(self);
162}
163
164static PyTypeObject Pdata_Type = {
165 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
166 "_pickle.Pdata", /*tp_name*/
167 sizeof(Pdata), /*tp_basicsize*/
168 0, /*tp_itemsize*/
169 (destructor)Pdata_dealloc, /*tp_dealloc*/
170};
171
172static PyObject *
173Pdata_New(void)
174{
175 Pdata *self;
176
177 if (!(self = PyObject_New(Pdata, &Pdata_Type)( (Pdata *) _PyObject_New(&Pdata_Type) )))
178 return NULL((void*)0);
179 Py_SIZE(self)(((PyVarObject*)(self))->ob_size) = 0;
180 self->allocated = 8;
181 self->data = PyMem_MALLOC_PyMem_DebugMalloc(self->allocated * sizeof(PyObject *));
182 if (self->data)
183 return (PyObject *)self;
184 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 184, (
PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self)); }
while (0)
;
185 return PyErr_NoMemory();
186}
187
188
189/* Retain only the initial clearto items. If clearto >= the current
190 * number of items, this is a (non-erroneous) NOP.
191 */
192static int
193Pdata_clear(Pdata *self, int clearto)
194{
195 int i = Py_SIZE(self)(((PyVarObject*)(self))->ob_size);
196
197 if (clearto < 0)
198 return stack_underflow();
199 if (clearto >= i)
200 return 0;
201
202 while (--i >= clearto) {
203 Py_CLEAR(self->data[i])do { if (self->data[i]) { PyObject *_py_tmp = (PyObject *)
(self->data[i]); (self->data[i]) = ((void*)0); do { if (
_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0)
{ if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 203, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
204 }
205 Py_SIZE(self)(((PyVarObject*)(self))->ob_size) = clearto;
206 return 0;
207}
208
209static int
210Pdata_grow(Pdata *self)
211{
212 PyObject **data = self->data;
213 Py_ssize_t allocated = self->allocated;
214 Py_ssize_t new_allocated;
215
216 new_allocated = (allocated >> 3) + 6;
217 /* check for integer overflow */
218 if (new_allocated > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) - allocated)
219 goto nomemory;
220 new_allocated += allocated;
221 if (new_allocated > (PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) / sizeof(PyObject *)))
222 goto nomemory;
223 data = PyMem_REALLOC_PyMem_DebugRealloc(data, new_allocated * sizeof(PyObject *));
224 if (data == NULL((void*)0))
225 goto nomemory;
226
227 self->data = data;
228 self->allocated = new_allocated;
229 return 0;
230
231 nomemory:
232 PyErr_NoMemory();
233 return -1;
234}
235
236/* D is a Pdata*. Pop the topmost element and store it into V, which
237 * must be an lvalue holding PyObject*. On stack underflow, UnpicklingError
238 * is raised and V is set to NULL.
239 */
240static PyObject *
241Pdata_pop(Pdata *self)
242{
243 if (Py_SIZE(self)(((PyVarObject*)(self))->ob_size) == 0) {
244 PyErr_SetString(UnpicklingError, "bad pickle data");
245 return NULL((void*)0);
246 }
247 return self->data[--Py_SIZE(self)(((PyVarObject*)(self))->ob_size)];
248}
249#define PDATA_POP(D, V)do { (V) = Pdata_pop((D)); } while (0) do { (V) = Pdata_pop((D)); } while (0)
250
251static int
252Pdata_push(Pdata *self, PyObject *obj)
253{
254 if (Py_SIZE(self)(((PyVarObject*)(self))->ob_size) == self->allocated && Pdata_grow(self) < 0) {
255 return -1;
256 }
257 self->data[Py_SIZE(self)(((PyVarObject*)(self))->ob_size)++] = obj;
258 return 0;
259}
260
261/* Push an object on stack, transferring its ownership to the stack. */
262#define PDATA_PUSH(D, O, ER)do { if (Pdata_push((D), (O)) < 0) return (ER); } while(0) do { \
263 if (Pdata_push((D), (O)) < 0) return (ER); } while(0)
264
265/* Push an object on stack, adding a new reference to the object. */
266#define PDATA_APPEND(D, O, ER)do { ( _Py_RefTotal++ , ((PyObject*)((O)))->ob_refcnt++); if
(Pdata_push((D), (O)) < 0) return (ER); } while(0)
do { \
267 Py_INCREF((O))( _Py_RefTotal++ , ((PyObject*)((O)))->ob_refcnt++); \
268 if (Pdata_push((D), (O)) < 0) return (ER); } while(0)
269
270static PyObject *
271Pdata_poptuple(Pdata *self, Py_ssize_t start)
272{
273 PyObject *tuple;
274 Py_ssize_t len, i, j;
275
276 len = Py_SIZE(self)(((PyVarObject*)(self))->ob_size) - start;
277 tuple = PyTuple_New(len);
278 if (tuple == NULL((void*)0))
279 return NULL((void*)0);
280 for (i = start, j = 0; j < len; i++, j++)
281 PyTuple_SET_ITEM(tuple, j, self->data[i])(((PyTupleObject *)(tuple))->ob_item[j] = self->data[i]
)
;
282
283 Py_SIZE(self)(((PyVarObject*)(self))->ob_size) = start;
284 return tuple;
285}
286
287static PyObject *
288Pdata_poplist(Pdata *self, Py_ssize_t start)
289{
290 PyObject *list;
291 Py_ssize_t len, i, j;
292
293 len = Py_SIZE(self)(((PyVarObject*)(self))->ob_size) - start;
294 list = PyList_New(len);
295 if (list == NULL((void*)0))
296 return NULL((void*)0);
297 for (i = start, j = 0; j < len; i++, j++)
298 PyList_SET_ITEM(list, j, self->data[i])(((PyListObject *)(list))->ob_item[j] = (self->data[i])
)
;
299
300 Py_SIZE(self)(((PyVarObject*)(self))->ob_size) = start;
301 return list;
302}
303
304typedef struct {
305 PyObject *me_key;
306 long me_value;
307} PyMemoEntry;
308
309typedef struct {
310 Py_ssize_t mt_mask;
311 Py_ssize_t mt_used;
312 Py_ssize_t mt_allocated;
313 PyMemoEntry *mt_table;
314} PyMemoTable;
315
316typedef struct PicklerObject {
317 PyObject_HEADPyObject ob_base;
318 PyMemoTable *memo; /* Memo table, keep track of the seen
319 objects to support self-referential objects
320 pickling. */
321 PyObject *pers_func; /* persistent_id() method, can be NULL */
322 PyObject *arg;
323
324 PyObject *write; /* write() method of the output stream. */
325 PyObject *output_buffer; /* Write into a local bytearray buffer before
326 flushing to the stream. */
327 Py_ssize_t output_len; /* Length of output_buffer. */
328 Py_ssize_t max_output_len; /* Allocation size of output_buffer. */
329 int proto; /* Pickle protocol number, >= 0 */
330 int bin; /* Boolean, true if proto > 0 */
331 int buf_size; /* Size of the current buffered pickle data */
332 int fast; /* Enable fast mode if set to a true value.
333 The fast mode disable the usage of memo,
334 therefore speeding the pickling process by
335 not generating superfluous PUT opcodes. It
336 should not be used if with self-referential
337 objects. */
338 int fast_nesting;
339 int fix_imports; /* Indicate whether Pickler should fix
340 the name of globals for Python 2.x. */
341 PyObject *fast_memo;
342} PicklerObject;
343
344typedef struct UnpicklerObject {
345 PyObject_HEADPyObject ob_base;
346 Pdata *stack; /* Pickle data stack, store unpickled objects. */
347
348 /* The unpickler memo is just an array of PyObject *s. Using a dict
349 is unnecessary, since the keys are contiguous ints. */
350 PyObject **memo;
351 Py_ssize_t memo_size;
352
353 PyObject *arg;
354 PyObject *pers_func; /* persistent_load() method, can be NULL. */
355
356 Py_buffer buffer;
357 char *input_buffer;
358 char *input_line;
359 Py_ssize_t input_len;
360 Py_ssize_t next_read_idx;
361 Py_ssize_t prefetched_idx; /* index of first prefetched byte */
362 PyObject *read; /* read() method of the input stream. */
363 PyObject *readline; /* readline() method of the input stream. */
364 PyObject *peek; /* peek() method of the input stream, or NULL */
365
366 char *encoding; /* Name of the encoding to be used for
367 decoding strings pickled using Python
368 2.x. The default value is "ASCII" */
369 char *errors; /* Name of errors handling scheme to used when
370 decoding strings. The default value is
371 "strict". */
372 int *marks; /* Mark stack, used for unpickling container
373 objects. */
374 Py_ssize_t num_marks; /* Number of marks in the mark stack. */
375 Py_ssize_t marks_size; /* Current allocated size of the mark stack. */
376 int proto; /* Protocol of the pickle loaded. */
377 int fix_imports; /* Indicate whether Unpickler should fix
378 the name of globals pickled by Python 2.x. */
379} UnpicklerObject;
380
381/* Forward declarations */
382static int save(PicklerObject *, PyObject *, int);
383static int save_reduce(PicklerObject *, PyObject *, PyObject *);
384static PyTypeObject Pickler_Type;
385static PyTypeObject Unpickler_Type;
386
387
388/*************************************************************************
389 A custom hashtable mapping void* to longs. This is used by the pickler for
390 memoization. Using a custom hashtable rather than PyDict allows us to skip
391 a bunch of unnecessary object creation. This makes a huge performance
392 difference. */
393
394#define MT_MINSIZE 8
395#define PERTURB_SHIFT 5
396
397
398static PyMemoTable *
399PyMemoTable_New(void)
400{
401 PyMemoTable *memo = PyMem_MALLOC_PyMem_DebugMalloc(sizeof(PyMemoTable));
402 if (memo == NULL((void*)0)) {
403 PyErr_NoMemory();
404 return NULL((void*)0);
405 }
406
407 memo->mt_used = 0;
408 memo->mt_allocated = MT_MINSIZE;
409 memo->mt_mask = MT_MINSIZE - 1;
410 memo->mt_table = PyMem_MALLOC_PyMem_DebugMalloc(MT_MINSIZE * sizeof(PyMemoEntry));
411 if (memo->mt_table == NULL((void*)0)) {
412 PyMem_FREE_PyMem_DebugFree(memo);
413 PyErr_NoMemory();
414 return NULL((void*)0);
415 }
416 memset(memo->mt_table, 0, MT_MINSIZE * sizeof(PyMemoEntry))((__builtin_object_size (memo->mt_table, 0) != (size_t) -1
) ? __builtin___memset_chk (memo->mt_table, 0, MT_MINSIZE *
sizeof(PyMemoEntry), __builtin_object_size (memo->mt_table
, 0)) : __inline_memset_chk (memo->mt_table, 0, MT_MINSIZE
* sizeof(PyMemoEntry)))
;
417
418 return memo;
419}
420
421static PyMemoTable *
422PyMemoTable_Copy(PyMemoTable *self)
423{
424 Py_ssize_t i;
425 PyMemoTable *new = PyMemoTable_New();
426 if (new == NULL((void*)0))
427 return NULL((void*)0);
428
429 new->mt_used = self->mt_used;
430 new->mt_allocated = self->mt_allocated;
431 new->mt_mask = self->mt_mask;
432 /* The table we get from _New() is probably smaller than we wanted.
433 Free it and allocate one that's the right size. */
434 PyMem_FREE_PyMem_DebugFree(new->mt_table);
435 new->mt_table = PyMem_MALLOC_PyMem_DebugMalloc(self->mt_allocated * sizeof(PyMemoEntry));
436 if (new->mt_table == NULL((void*)0)) {
437 PyMem_FREE_PyMem_DebugFree(new);
438 return NULL((void*)0);
439 }
440 for (i = 0; i < self->mt_allocated; i++) {
441 Py_XINCREF(self->mt_table[i].me_key)do { if ((self->mt_table[i].me_key) == ((void*)0)) ; else (
_Py_RefTotal++ , ((PyObject*)(self->mt_table[i].me_key))->
ob_refcnt++); } while (0)
;
442 }
443 memcpy(new->mt_table, self->mt_table,((__builtin_object_size (new->mt_table, 0) != (size_t) -1)
? __builtin___memcpy_chk (new->mt_table, self->mt_table
, sizeof(PyMemoEntry) * self->mt_allocated, __builtin_object_size
(new->mt_table, 0)) : __inline_memcpy_chk (new->mt_table
, self->mt_table, sizeof(PyMemoEntry) * self->mt_allocated
))
444 sizeof(PyMemoEntry) * self->mt_allocated)((__builtin_object_size (new->mt_table, 0) != (size_t) -1)
? __builtin___memcpy_chk (new->mt_table, self->mt_table
, sizeof(PyMemoEntry) * self->mt_allocated, __builtin_object_size
(new->mt_table, 0)) : __inline_memcpy_chk (new->mt_table
, self->mt_table, sizeof(PyMemoEntry) * self->mt_allocated
))
;
445
446 return new;
447}
448
449static Py_ssize_t
450PyMemoTable_Size(PyMemoTable *self)
451{
452 return self->mt_used;
453}
454
455static int
456PyMemoTable_Clear(PyMemoTable *self)
457{
458 Py_ssize_t i = self->mt_allocated;
459
460 while (--i >= 0) {
461 Py_XDECREF(self->mt_table[i].me_key)do { if ((self->mt_table[i].me_key) == ((void*)0)) ; else do
{ if (_Py_RefTotal-- , --((PyObject*)(self->mt_table[i].me_key
))->ob_refcnt != 0) { if (((PyObject*)self->mt_table[i]
.me_key)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 461, (PyObject *)(self->mt_table[i].me_key)); } else _Py_Dealloc
((PyObject *)(self->mt_table[i].me_key)); } while (0); } while
(0)
;
462 }
463 self->mt_used = 0;
464 memset(self->mt_table, 0, self->mt_allocated * sizeof(PyMemoEntry))((__builtin_object_size (self->mt_table, 0) != (size_t) -1
) ? __builtin___memset_chk (self->mt_table, 0, self->mt_allocated
* sizeof(PyMemoEntry), __builtin_object_size (self->mt_table
, 0)) : __inline_memset_chk (self->mt_table, 0, self->mt_allocated
* sizeof(PyMemoEntry)))
;
465 return 0;
466}
467
468static void
469PyMemoTable_Del(PyMemoTable *self)
470{
471 if (self == NULL((void*)0))
472 return;
473 PyMemoTable_Clear(self);
474
475 PyMem_FREE_PyMem_DebugFree(self->mt_table);
476 PyMem_FREE_PyMem_DebugFree(self);
477}
478
479/* Since entries cannot be deleted from this hashtable, _PyMemoTable_Lookup()
480 can be considerably simpler than dictobject.c's lookdict(). */
481static PyMemoEntry *
482_PyMemoTable_Lookup(PyMemoTable *self, PyObject *key)
483{
484 size_t i;
485 size_t perturb;
486 size_t mask = (size_t)self->mt_mask;
487 PyMemoEntry *table = self->mt_table;
488 PyMemoEntry *entry;
489 Py_hash_t hash = (Py_hash_t)key >> 3;
490
491 i = hash & mask;
492 entry = &table[i];
493 if (entry->me_key == NULL((void*)0) || entry->me_key == key)
494 return entry;
495
496 for (perturb = hash; ; perturb >>= PERTURB_SHIFT) {
497 i = (i << 2) + i + perturb + 1;
498 entry = &table[i & mask];
499 if (entry->me_key == NULL((void*)0) || entry->me_key == key)
500 return entry;
501 }
502 assert(0)(__builtin_expect(!(0), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 502, "0") : (void)0)
; /* Never reached */
503 return NULL((void*)0);
504}
505
506/* Returns -1 on failure, 0 on success. */
507static int
508_PyMemoTable_ResizeTable(PyMemoTable *self, Py_ssize_t min_size)
509{
510 PyMemoEntry *oldtable = NULL((void*)0);
511 PyMemoEntry *oldentry, *newentry;
512 Py_ssize_t new_size = MT_MINSIZE;
513 Py_ssize_t to_process;
514
515 assert(min_size > 0)(__builtin_expect(!(min_size > 0), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 515, "min_size > 0"
) : (void)0)
;
516
517 /* Find the smallest valid table size >= min_size. */
518 while (new_size < min_size && new_size > 0)
519 new_size <<= 1;
520 if (new_size <= 0) {
521 PyErr_NoMemory();
522 return -1;
523 }
524 /* new_size needs to be a power of two. */
525 assert((new_size & (new_size - 1)) == 0)(__builtin_expect(!((new_size & (new_size - 1)) == 0), 0)
? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 525, "(new_size & (new_size - 1)) == 0") : (void)0)
;
526
527 /* Allocate new table. */
528 oldtable = self->mt_table;
529 self->mt_table = PyMem_MALLOC_PyMem_DebugMalloc(new_size * sizeof(PyMemoEntry));
530 if (self->mt_table == NULL((void*)0)) {
531 PyMem_FREE_PyMem_DebugFree(oldtable);
532 PyErr_NoMemory();
533 return -1;
534 }
535 self->mt_allocated = new_size;
536 self->mt_mask = new_size - 1;
537 memset(self->mt_table, 0, sizeof(PyMemoEntry) * new_size)((__builtin_object_size (self->mt_table, 0) != (size_t) -1
) ? __builtin___memset_chk (self->mt_table, 0, sizeof(PyMemoEntry
) * new_size, __builtin_object_size (self->mt_table, 0)) :
__inline_memset_chk (self->mt_table, 0, sizeof(PyMemoEntry
) * new_size))
;
538
539 /* Copy entries from the old table. */
540 to_process = self->mt_used;
541 for (oldentry = oldtable; to_process > 0; oldentry++) {
542 if (oldentry->me_key != NULL((void*)0)) {
543 to_process--;
544 /* newentry is a pointer to a chunk of the new
545 mt_table, so we're setting the key:value pair
546 in-place. */
547 newentry = _PyMemoTable_Lookup(self, oldentry->me_key);
548 newentry->me_key = oldentry->me_key;
549 newentry->me_value = oldentry->me_value;
550 }
551 }
552
553 /* Deallocate the old table. */
554 PyMem_FREE_PyMem_DebugFree(oldtable);
555 return 0;
556}
557
558/* Returns NULL on failure, a pointer to the value otherwise. */
559static long *
560PyMemoTable_Get(PyMemoTable *self, PyObject *key)
561{
562 PyMemoEntry *entry = _PyMemoTable_Lookup(self, key);
563 if (entry->me_key == NULL((void*)0))
564 return NULL((void*)0);
565 return &entry->me_value;
566}
567
568/* Returns -1 on failure, 0 on success. */
569static int
570PyMemoTable_Set(PyMemoTable *self, PyObject *key, long value)
571{
572 PyMemoEntry *entry;
573
574 assert(key != NULL)(__builtin_expect(!(key != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 574, "key != NULL"
) : (void)0)
;
575
576 entry = _PyMemoTable_Lookup(self, key);
577 if (entry->me_key != NULL((void*)0)) {
578 entry->me_value = value;
579 return 0;
580 }
581 Py_INCREF(key)( _Py_RefTotal++ , ((PyObject*)(key))->ob_refcnt++);
582 entry->me_key = key;
583 entry->me_value = value;
584 self->mt_used++;
585
586 /* If we added a key, we can safely resize. Otherwise just return!
587 * If used >= 2/3 size, adjust size. Normally, this quaduples the size.
588 *
589 * Quadrupling the size improves average table sparseness
590 * (reducing collisions) at the cost of some memory. It also halves
591 * the number of expensive resize operations in a growing memo table.
592 *
593 * Very large memo tables (over 50K items) use doubling instead.
594 * This may help applications with severe memory constraints.
595 */
596 if (!(self->mt_used * 3 >= (self->mt_mask + 1) * 2))
597 return 0;
598 return _PyMemoTable_ResizeTable(self,
599 (self->mt_used > 50000 ? 2 : 4) * self->mt_used);
600}
601
602#undef MT_MINSIZE
603#undef PERTURB_SHIFT
604
605/*************************************************************************/
606
607/* Helpers for creating the argument tuple passed to functions. This has the
608 performance advantage of calling PyTuple_New() only once.
609
610 XXX(avassalotti): Inline directly in _Pickler_FastCall() and
611 _Unpickler_FastCall(). */
612#define ARG_TUP(self, obj)do { if ((self)->arg || ((self)->arg=PyTuple_New(1))) {
do { if (((((PyTupleObject *)((self)->arg))->ob_item[0
])) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject
*)((((PyTupleObject *)((self)->arg))->ob_item[0])))->
ob_refcnt != 0) { if (((PyObject*)(((PyTupleObject *)((self)->
arg))->ob_item[0]))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 612, (
PyObject *)((((PyTupleObject *)((self)->arg))->ob_item[
0]))); } else _Py_Dealloc((PyObject *)((((PyTupleObject *)((self
)->arg))->ob_item[0]))); } while (0); } while (0); (((PyTupleObject
*)((self)->arg))->ob_item[0] = (obj)); } else { do { if
(_Py_RefTotal-- , --((PyObject*)((obj)))->ob_refcnt != 0)
{ if (((PyObject*)(obj))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 612, (
PyObject *)((obj))); } else _Py_Dealloc((PyObject *)((obj)));
} while (0); } } while (0)
do { \
613 if ((self)->arg || ((self)->arg=PyTuple_New(1))) { \
614 Py_XDECREF(PyTuple_GET_ITEM((self)->arg, 0))do { if (((((PyTupleObject *)((self)->arg))->ob_item[0]
)) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject
*)((((PyTupleObject *)((self)->arg))->ob_item[0])))->
ob_refcnt != 0) { if (((PyObject*)(((PyTupleObject *)((self)->
arg))->ob_item[0]))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 614, (
PyObject *)((((PyTupleObject *)((self)->arg))->ob_item[
0]))); } else _Py_Dealloc((PyObject *)((((PyTupleObject *)((self
)->arg))->ob_item[0]))); } while (0); } while (0)
; \
615 PyTuple_SET_ITEM((self)->arg, 0, (obj))(((PyTupleObject *)((self)->arg))->ob_item[0] = (obj)); \
616 } \
617 else { \
618 Py_DECREF((obj))do { if (_Py_RefTotal-- , --((PyObject*)((obj)))->ob_refcnt
!= 0) { if (((PyObject*)(obj))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 618, (
PyObject *)((obj))); } else _Py_Dealloc((PyObject *)((obj)));
} while (0)
; \
619 } \
620 } while (0)
621
622#define FREE_ARG_TUP(self)do { if ((self)->arg->ob_refcnt > 1) do { if ((self)
->arg) { PyObject *_py_tmp = (PyObject *)((self)->arg);
((self)->arg) = ((void*)0); do { if (_Py_RefTotal-- , --(
(PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 622, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0); } while (0)
do { \
623 if ((self)->arg->ob_refcnt > 1) \
624 Py_CLEAR((self)->arg)do { if ((self)->arg) { PyObject *_py_tmp = (PyObject *)((
self)->arg); ((self)->arg) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 624, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
; \
625 } while (0)
626
627/* A temporary cleaner API for fast single argument function call.
628
629 XXX: Does caching the argument tuple provides any real performance benefits?
630
631 A quick benchmark, on a 2.0GHz Athlon64 3200+ running Linux 2.6.24 with
632 glibc 2.7, tells me that it takes roughly 20,000,000 PyTuple_New(1) calls
633 when the tuple is retrieved from the freelist (i.e, call PyTuple_New() then
634 immediately DECREF it) and 1,200,000 calls when allocating brand new tuples
635 (i.e, call PyTuple_New() and store the returned value in an array), to save
636 one second (wall clock time). Either ways, the loading time a pickle stream
637 large enough to generate this number of calls would be massively
638 overwhelmed by other factors, like I/O throughput, the GC traversal and
639 object allocation overhead. So, I really doubt these functions provide any
640 real benefits.
641
642 On the other hand, oprofile reports that pickle spends a lot of time in
643 these functions. But, that is probably more related to the function call
644 overhead, than the argument tuple allocation.
645
646 XXX: And, what is the reference behavior of these? Steal, borrow? At first
647 glance, it seems to steal the reference of 'arg' and borrow the reference
648 of 'func'. */
649static PyObject *
650_Pickler_FastCall(PicklerObject *self, PyObject *func, PyObject *arg)
651{
652 PyObject *result = NULL((void*)0);
653
654 ARG_TUP(self, arg)do { if ((self)->arg || ((self)->arg=PyTuple_New(1))) {
do { if (((((PyTupleObject *)((self)->arg))->ob_item[0
])) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject
*)((((PyTupleObject *)((self)->arg))->ob_item[0])))->
ob_refcnt != 0) { if (((PyObject*)(((PyTupleObject *)((self)->
arg))->ob_item[0]))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 654, (
PyObject *)((((PyTupleObject *)((self)->arg))->ob_item[
0]))); } else _Py_Dealloc((PyObject *)((((PyTupleObject *)((self
)->arg))->ob_item[0]))); } while (0); } while (0); (((PyTupleObject
*)((self)->arg))->ob_item[0] = (arg)); } else { do { if
(_Py_RefTotal-- , --((PyObject*)((arg)))->ob_refcnt != 0)
{ if (((PyObject*)(arg))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 654, (
PyObject *)((arg))); } else _Py_Dealloc((PyObject *)((arg)));
} while (0); } } while (0)
;
655 if (self->arg) {
656 result = PyObject_Call(func, self->arg, NULL((void*)0));
657 FREE_ARG_TUP(self)do { if ((self)->arg->ob_refcnt > 1) do { if ((self)
->arg) { PyObject *_py_tmp = (PyObject *)((self)->arg);
((self)->arg) = ((void*)0); do { if (_Py_RefTotal-- , --(
(PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 657, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0); } while (0)
;
658 }
659 return result;
660}
661
662static int
663_Pickler_ClearBuffer(PicklerObject *self)
664{
665 Py_CLEAR(self->output_buffer)do { if (self->output_buffer) { PyObject *_py_tmp = (PyObject
*)(self->output_buffer); (self->output_buffer) = ((void
*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->
ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 665, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
666 self->output_buffer =
667 PyBytes_FromStringAndSize(NULL((void*)0), self->max_output_len);
668 if (self->output_buffer == NULL((void*)0))
669 return -1;
670 self->output_len = 0;
671 return 0;
672}
673
674static PyObject *
675_Pickler_GetString(PicklerObject *self)
676{
677 PyObject *output_buffer = self->output_buffer;
678
679 assert(self->output_buffer != NULL)(__builtin_expect(!(self->output_buffer != ((void*)0)), 0)
? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 679, "self->output_buffer != NULL") : (void)0)
;
680 self->output_buffer = NULL((void*)0);
681 /* Resize down to exact size */
682 if (_PyBytes_Resize(&output_buffer, self->output_len) < 0)
683 return NULL((void*)0);
684 return output_buffer;
685}
686
687static int
688_Pickler_FlushToFile(PicklerObject *self)
689{
690 PyObject *output, *result;
691
692 assert(self->write != NULL)(__builtin_expect(!(self->write != ((void*)0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 692, "self->write != NULL") : (void)0)
;
693
694 output = _Pickler_GetString(self);
695 if (output == NULL((void*)0))
696 return -1;
697
698 result = _Pickler_FastCall(self, self->write, output);
699 Py_XDECREF(result)do { if ((result) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(result))->ob_refcnt != 0) { if (((PyObject
*)result)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 699, (PyObject *)(result)); } else _Py_Dealloc((PyObject *)
(result)); } while (0); } while (0)
;
700 return (result == NULL((void*)0)) ? -1 : 0;
701}
702
703static int
704_Pickler_Write(PicklerObject *self, const char *s, Py_ssize_t n)
705{
706 Py_ssize_t i, required;
707 char *buffer;
708
709 assert(s != NULL)(__builtin_expect(!(s != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 709, "s != NULL"
) : (void)0)
;
710
711 required = self->output_len + n;
712 if (required > self->max_output_len) {
713 if (self->write != NULL((void*)0) && required > MAX_WRITE_BUF_SIZE) {
714 /* XXX This reallocates a new buffer every time, which is a bit
715 wasteful. */
716 if (_Pickler_FlushToFile(self) < 0)
717 return -1;
718 if (_Pickler_ClearBuffer(self) < 0)
719 return -1;
720 }
721 if (self->write != NULL((void*)0) && n > MAX_WRITE_BUF_SIZE) {
722 /* we already flushed above, so the buffer is empty */
723 PyObject *result;
724 /* XXX we could spare an intermediate copy and pass
725 a memoryview instead */
726 PyObject *output = PyBytes_FromStringAndSize(s, n);
727 if (s == NULL((void*)0))
728 return -1;
729 result = _Pickler_FastCall(self, self->write, output);
730 Py_XDECREF(result)do { if ((result) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(result))->ob_refcnt != 0) { if (((PyObject
*)result)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 730, (PyObject *)(result)); } else _Py_Dealloc((PyObject *)
(result)); } while (0); } while (0)
;
731 return (result == NULL((void*)0)) ? -1 : 0;
732 }
733 else {
734 if (self->output_len >= PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) / 2 - n) {
735 PyErr_NoMemory();
736 return -1;
737 }
738 self->max_output_len = (self->output_len + n) * 2;
739 if (_PyBytes_Resize(&self->output_buffer, self->max_output_len) < 0)
740 return -1;
741 }
742 }
743 buffer = PyBytes_AS_STRING(self->output_buffer)((__builtin_expect(!(((((((PyObject*)(self->output_buffer)
)->ob_type))->tp_flags & ((1L<<27))) != 0)), 0
) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 743, "PyBytes_Check(self->output_buffer)") : (void)0), (
((PyBytesObject *)(self->output_buffer))->ob_sval))
;
744 if (n < 8) {
745 /* This is faster than memcpy when the string is short. */
746 for (i = 0; i < n; i++) {
747 buffer[self->output_len + i] = s[i];
748 }
749 }
750 else {
751 memcpy(buffer + self->output_len, s, n)((__builtin_object_size (buffer + self->output_len, 0) != (
size_t) -1) ? __builtin___memcpy_chk (buffer + self->output_len
, s, n, __builtin_object_size (buffer + self->output_len, 0
)) : __inline_memcpy_chk (buffer + self->output_len, s, n)
)
;
752 }
753 self->output_len += n;
754 return n;
755}
756
757static PicklerObject *
758_Pickler_New(void)
759{
760 PicklerObject *self;
761
762 self = PyObject_GC_New(PicklerObject, &Pickler_Type)( (PicklerObject *) _PyObject_GC_New(&Pickler_Type) );
763 if (self == NULL((void*)0))
764 return NULL((void*)0);
765
766 self->pers_func = NULL((void*)0);
767 self->arg = NULL((void*)0);
768 self->write = NULL((void*)0);
769 self->proto = 0;
770 self->bin = 0;
771 self->fast = 0;
772 self->fast_nesting = 0;
773 self->fix_imports = 0;
774 self->fast_memo = NULL((void*)0);
775
776 self->memo = PyMemoTable_New();
777 if (self->memo == NULL((void*)0)) {
778 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 778, (
PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self)); }
while (0)
;
779 return NULL((void*)0);
780 }
781 self->max_output_len = WRITE_BUF_SIZE;
782 self->output_len = 0;
783 self->output_buffer = PyBytes_FromStringAndSize(NULL((void*)0),
784 self->max_output_len);
785 if (self->output_buffer == NULL((void*)0)) {
786 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 786, (
PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self)); }
while (0)
;
787 return NULL((void*)0);
788 }
789 return self;
790}
791
792static int
793_Pickler_SetProtocol(PicklerObject *self, PyObject *proto_obj,
794 PyObject *fix_imports_obj)
795{
796 long proto = 0;
797 int fix_imports;
798
799 if (proto_obj == NULL((void*)0) || proto_obj == Py_None(&_Py_NoneStruct))
800 proto = DEFAULT_PROTOCOL;
801 else {
802 proto = PyLong_AsLong(proto_obj);
803 if (proto == -1 && PyErr_Occurred())
804 return -1;
805 }
806 if (proto < 0)
807 proto = HIGHEST_PROTOCOL;
808 if (proto > HIGHEST_PROTOCOL) {
809 PyErr_Format(PyExc_ValueError, "pickle protocol must be <= %d",
810 HIGHEST_PROTOCOL);
811 return -1;
812 }
813 fix_imports = PyObject_IsTrue(fix_imports_obj);
814 if (fix_imports == -1)
815 return -1;
816
817 self->proto = proto;
818 self->bin = proto > 0;
819 self->fix_imports = fix_imports && proto < 3;
820
821 return 0;
822}
823
824/* Returns -1 (with an exception set) on failure, 0 on success. This may
825 be called once on a freshly created Pickler. */
826static int
827_Pickler_SetOutputStream(PicklerObject *self, PyObject *file)
828{
829 assert(file != NULL)(__builtin_expect(!(file != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 829, "file != NULL"
) : (void)0)
;
830 self->write = PyObject_GetAttrString(file, "write");
831 if (self->write == NULL((void*)0)) {
832 if (PyErr_ExceptionMatches(PyExc_AttributeError))
833 PyErr_SetString(PyExc_TypeError,
834 "file must have a 'write' attribute");
835 return -1;
836 }
837
838 return 0;
839}
840
841/* See documentation for _Pickler_FastCall(). */
842static PyObject *
843_Unpickler_FastCall(UnpicklerObject *self, PyObject *func, PyObject *arg)
844{
845 PyObject *result = NULL((void*)0);
846
847 ARG_TUP(self, arg)do { if ((self)->arg || ((self)->arg=PyTuple_New(1))) {
do { if (((((PyTupleObject *)((self)->arg))->ob_item[0
])) == ((void*)0)) ; else do { if (_Py_RefTotal-- , --((PyObject
*)((((PyTupleObject *)((self)->arg))->ob_item[0])))->
ob_refcnt != 0) { if (((PyObject*)(((PyTupleObject *)((self)->
arg))->ob_item[0]))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 847, (
PyObject *)((((PyTupleObject *)((self)->arg))->ob_item[
0]))); } else _Py_Dealloc((PyObject *)((((PyTupleObject *)((self
)->arg))->ob_item[0]))); } while (0); } while (0); (((PyTupleObject
*)((self)->arg))->ob_item[0] = (arg)); } else { do { if
(_Py_RefTotal-- , --((PyObject*)((arg)))->ob_refcnt != 0)
{ if (((PyObject*)(arg))->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 847, (
PyObject *)((arg))); } else _Py_Dealloc((PyObject *)((arg)));
} while (0); } } while (0)
;
848 if (self->arg) {
849 result = PyObject_Call(func, self->arg, NULL((void*)0));
850 FREE_ARG_TUP(self)do { if ((self)->arg->ob_refcnt > 1) do { if ((self)
->arg) { PyObject *_py_tmp = (PyObject *)((self)->arg);
((self)->arg) = ((void*)0); do { if (_Py_RefTotal-- , --(
(PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 850, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0); } while (0)
;
851 }
852 return result;
853}
854
855/* Returns the size of the input on success, -1 on failure. This takes its
856 own reference to `input`. */
857static Py_ssize_t
858_Unpickler_SetStringInput(UnpicklerObject *self, PyObject *input)
859{
860 if (self->buffer.buf != NULL((void*)0))
861 PyBuffer_Release(&self->buffer);
862 if (PyObject_GetBuffer(input, &self->buffer, PyBUF_CONTIG_RO(0x0008)) < 0)
863 return -1;
864 self->input_buffer = self->buffer.buf;
865 self->input_len = self->buffer.len;
866 self->next_read_idx = 0;
867 self->prefetched_idx = self->input_len;
868 return self->input_len;
869}
870
871static int
872_Unpickler_SkipConsumed(UnpicklerObject *self)
873{
874 Py_ssize_t consumed = self->next_read_idx - self->prefetched_idx;
875
876 if (consumed > 0) {
877 PyObject *r;
878 assert(self->peek)(__builtin_expect(!(self->peek), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 878, "self->peek"
) : (void)0)
; /* otherwise we did something wrong */
879 /* This makes an useless copy... */
880 r = PyObject_CallFunction(self->read, "n", consumed);
881 if (r == NULL((void*)0))
882 return -1;
883 Py_DECREF(r)do { if (_Py_RefTotal-- , --((PyObject*)(r))->ob_refcnt !=
0) { if (((PyObject*)r)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 883, (
PyObject *)(r)); } else _Py_Dealloc((PyObject *)(r)); } while
(0)
;
884 self->prefetched_idx = self->next_read_idx;
885 }
886 return 0;
887}
888
889static const Py_ssize_t READ_WHOLE_LINE = -1;
890
891/* If reading from a file, we need to only pull the bytes we need, since there
892 may be multiple pickle objects arranged contiguously in the same input
893 buffer.
894
895 If `n` is READ_WHOLE_LINE, read a whole line. Otherwise, read up to `n`
896 bytes from the input stream/buffer.
897
898 Update the unpickler's input buffer with the newly-read data. Returns -1 on
899 failure; on success, returns the number of bytes read from the file.
900
901 On success, self->input_len will be 0; this is intentional so that when
902 unpickling from a file, the "we've run out of data" code paths will trigger,
903 causing the Unpickler to go back to the file for more data. Use the returned
904 size to tell you how much data you can process. */
905static Py_ssize_t
906_Unpickler_ReadFromFile(UnpicklerObject *self, Py_ssize_t n)
907{
908 PyObject *data;
909 Py_ssize_t read_size, prefetched_size = 0;
910
911 assert(self->read != NULL)(__builtin_expect(!(self->read != ((void*)0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 911, "self->read != NULL") : (void)0)
;
912
913 if (_Unpickler_SkipConsumed(self) < 0)
914 return -1;
915
916 if (n == READ_WHOLE_LINE)
917 data = PyObject_Call(self->readline, empty_tuple, NULL((void*)0));
918 else {
919 PyObject *len = PyLong_FromSsize_t(n);
920 if (len == NULL((void*)0))
921 return -1;
922 data = _Unpickler_FastCall(self, self->read, len);
923 }
924 if (data == NULL((void*)0))
925 return -1;
926
927 /* Prefetch some data without advancing the file pointer, if possible */
928 if (self->peek) {
929 PyObject *len, *prefetched;
930 len = PyLong_FromSsize_t(PREFETCH);
931 if (len == NULL((void*)0)) {
932 Py_DECREF(data)do { if (_Py_RefTotal-- , --((PyObject*)(data))->ob_refcnt
!= 0) { if (((PyObject*)data)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 932, (
PyObject *)(data)); } else _Py_Dealloc((PyObject *)(data)); }
while (0)
;
933 return -1;
934 }
935 prefetched = _Unpickler_FastCall(self, self->peek, len);
936 if (prefetched == NULL((void*)0)) {
937 if (PyErr_ExceptionMatches(PyExc_NotImplementedError)) {
938 /* peek() is probably not supported by the given file object */
939 PyErr_Clear();
940 Py_CLEAR(self->peek)do { if (self->peek) { PyObject *_py_tmp = (PyObject *)(self
->peek); (self->peek) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 940, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
941 }
942 else {
943 Py_DECREF(data)do { if (_Py_RefTotal-- , --((PyObject*)(data))->ob_refcnt
!= 0) { if (((PyObject*)data)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 943, (
PyObject *)(data)); } else _Py_Dealloc((PyObject *)(data)); }
while (0)
;
944 return -1;
945 }
946 }
947 else {
948 assert(PyBytes_Check(prefetched))(__builtin_expect(!(((((((PyObject*)(prefetched))->ob_type
))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 948, "PyBytes_Check(prefetched)") : (void)0)
;
949 prefetched_size = PyBytes_GET_SIZE(prefetched)((__builtin_expect(!(((((((PyObject*)(prefetched))->ob_type
))->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 949, "PyBytes_Check(prefetched)") : (void)0),(((PyVarObject
*)(prefetched))->ob_size))
;
950 PyBytes_ConcatAndDel(&data, prefetched);
951 if (data == NULL((void*)0))
952 return -1;
953 }
954 }
955
956 read_size = _Unpickler_SetStringInput(self, data) - prefetched_size;
957 Py_DECREF(data)do { if (_Py_RefTotal-- , --((PyObject*)(data))->ob_refcnt
!= 0) { if (((PyObject*)data)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 957, (
PyObject *)(data)); } else _Py_Dealloc((PyObject *)(data)); }
while (0)
;
958 self->prefetched_idx = read_size;
959 return read_size;
960}
961
962/* Read `n` bytes from the unpickler's data source, storing the result in `*s`.
963
964 This should be used for all data reads, rather than accessing the unpickler's
965 input buffer directly. This method deals correctly with reading from input
966 streams, which the input buffer doesn't deal with.
967
968 Note that when reading from a file-like object, self->next_read_idx won't
969 be updated (it should remain at 0 for the entire unpickling process). You
970 should use this function's return value to know how many bytes you can
971 consume.
972
973 Returns -1 (with an exception set) on failure. On success, return the
974 number of chars read. */
975static Py_ssize_t
976_Unpickler_Read(UnpicklerObject *self, char **s, Py_ssize_t n)
977{
978 Py_ssize_t num_read;
979
980 if (n == 0) {
981 *s = NULL((void*)0);
982 return 0;
983 }
984
985 if (self->next_read_idx + n <= self->input_len) {
986 *s = self->input_buffer + self->next_read_idx;
987 self->next_read_idx += n;
988 return n;
989 }
990 if (!self->read) {
991 PyErr_Format(PyExc_EOFError, "Ran out of input");
992 return -1;
993 }
994 num_read = _Unpickler_ReadFromFile(self, n);
995 if (num_read < 0)
996 return -1;
997 if (num_read < n) {
998 PyErr_Format(PyExc_EOFError, "Ran out of input");
999 return -1;
1000 }
1001 *s = self->input_buffer;
1002 self->next_read_idx = n;
1003 return n;
1004}
1005
1006static Py_ssize_t
1007_Unpickler_CopyLine(UnpicklerObject *self, char *line, Py_ssize_t len,
1008 char **result)
1009{
1010 char *input_line = PyMem_Realloc(self->input_line, len + 1);
1011 if (input_line == NULL((void*)0))
1012 return -1;
1013
1014 memcpy(input_line, line, len)((__builtin_object_size (input_line, 0) != (size_t) -1) ? __builtin___memcpy_chk
(input_line, line, len, __builtin_object_size (input_line, 0
)) : __inline_memcpy_chk (input_line, line, len))
;
1015 input_line[len] = '\0';
1016 self->input_line = input_line;
1017 *result = self->input_line;
1018 return len;
1019}
1020
1021/* Read a line from the input stream/buffer. If we run off the end of the input
1022 before hitting \n, return the data we found.
1023
1024 Returns the number of chars read, or -1 on failure. */
1025static Py_ssize_t
1026_Unpickler_Readline(UnpicklerObject *self, char **result)
1027{
1028 Py_ssize_t i, num_read;
1029
1030 for (i = self->next_read_idx; i < self->input_len; i++) {
1031 if (self->input_buffer[i] == '\n') {
1032 char *line_start = self->input_buffer + self->next_read_idx;
1033 num_read = i - self->next_read_idx + 1;
1034 self->next_read_idx = i + 1;
1035 return _Unpickler_CopyLine(self, line_start, num_read, result);
1036 }
1037 }
1038 if (self->read) {
1039 num_read = _Unpickler_ReadFromFile(self, READ_WHOLE_LINE);
1040 if (num_read < 0)
1041 return -1;
1042 *result = self->input_buffer;
1043 self->next_read_idx = num_read;
1044 return num_read;
1045 }
1046
1047 /* If we get here, we've run off the end of the input string. Return the
1048 remaining string and let the caller figure it out. */
1049 *result = self->input_buffer + self->next_read_idx;
1050 num_read = i - self->next_read_idx;
1051 self->next_read_idx = i;
1052 return num_read;
1053}
1054
1055/* Returns -1 (with an exception set) on failure, 0 on success. The memo array
1056 will be modified in place. */
1057static int
1058_Unpickler_ResizeMemoList(UnpicklerObject *self, Py_ssize_t new_size)
1059{
1060 Py_ssize_t i;
1061 PyObject **memo;
1062
1063 assert(new_size > self->memo_size)(__builtin_expect(!(new_size > self->memo_size), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1063, "new_size > self->memo_size") : (void)0)
;
1064
1065 memo = PyMem_REALLOC_PyMem_DebugRealloc(self->memo, new_size * sizeof(PyObject *));
1066 if (memo == NULL((void*)0)) {
1067 PyErr_NoMemory();
1068 return -1;
1069 }
1070 self->memo = memo;
1071 for (i = self->memo_size; i < new_size; i++)
1072 self->memo[i] = NULL((void*)0);
1073 self->memo_size = new_size;
1074 return 0;
1075}
1076
1077/* Returns NULL if idx is out of bounds. */
1078static PyObject *
1079_Unpickler_MemoGet(UnpicklerObject *self, Py_ssize_t idx)
1080{
1081 if (idx < 0 || idx >= self->memo_size)
1082 return NULL((void*)0);
1083
1084 return self->memo[idx];
1085}
1086
1087/* Returns -1 (with an exception set) on failure, 0 on success.
1088 This takes its own reference to `value`. */
1089static int
1090_Unpickler_MemoPut(UnpicklerObject *self, Py_ssize_t idx, PyObject *value)
1091{
1092 PyObject *old_item;
1093
1094 if (idx >= self->memo_size) {
1095 if (_Unpickler_ResizeMemoList(self, idx * 2) < 0)
1096 return -1;
1097 assert(idx < self->memo_size)(__builtin_expect(!(idx < self->memo_size), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1097, "idx < self->memo_size") : (void)0)
;
1098 }
1099 Py_INCREF(value)( _Py_RefTotal++ , ((PyObject*)(value))->ob_refcnt++);
1100 old_item = self->memo[idx];
1101 self->memo[idx] = value;
1102 Py_XDECREF(old_item)do { if ((old_item) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(old_item))->ob_refcnt != 0) { if (((PyObject
*)old_item)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1102, (PyObject *)(old_item)); } else _Py_Dealloc((PyObject
*)(old_item)); } while (0); } while (0)
;
1103 return 0;
1104}
1105
1106static PyObject **
1107_Unpickler_NewMemo(Py_ssize_t new_size)
1108{
1109 PyObject **memo = PyMem_MALLOC_PyMem_DebugMalloc(new_size * sizeof(PyObject *));
1110 if (memo == NULL((void*)0))
1111 return NULL((void*)0);
1112 memset(memo, 0, new_size * sizeof(PyObject *))((__builtin_object_size (memo, 0) != (size_t) -1) ? __builtin___memset_chk
(memo, 0, new_size * sizeof(PyObject *), __builtin_object_size
(memo, 0)) : __inline_memset_chk (memo, 0, new_size * sizeof
(PyObject *)))
;
1113 return memo;
1114}
1115
1116/* Free the unpickler's memo, taking care to decref any items left in it. */
1117static void
1118_Unpickler_MemoCleanup(UnpicklerObject *self)
1119{
1120 Py_ssize_t i;
1121 PyObject **memo = self->memo;
1122
1123 if (self->memo == NULL((void*)0))
1124 return;
1125 self->memo = NULL((void*)0);
1126 i = self->memo_size;
1127 while (--i >= 0) {
1128 Py_XDECREF(memo[i])do { if ((memo[i]) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(memo[i]))->ob_refcnt != 0) { if (((PyObject
*)memo[i])->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1128, (PyObject *)(memo[i])); } else _Py_Dealloc((PyObject *
)(memo[i])); } while (0); } while (0)
;
1129 }
1130 PyMem_FREE_PyMem_DebugFree(memo);
1131}
1132
1133static UnpicklerObject *
1134_Unpickler_New(void)
1135{
1136 UnpicklerObject *self;
1137
1138 self = PyObject_GC_New(UnpicklerObject, &Unpickler_Type)( (UnpicklerObject *) _PyObject_GC_New(&Unpickler_Type) );
1139 if (self == NULL((void*)0))
1140 return NULL((void*)0);
1141
1142 self->stack = (Pdata *)Pdata_New();
1143 if (self->stack == NULL((void*)0)) {
1144 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1144, (
PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self)); }
while (0)
;
1145 return NULL((void*)0);
1146 }
1147 memset(&self->buffer, 0, sizeof(Py_buffer))((__builtin_object_size (&self->buffer, 0) != (size_t)
-1) ? __builtin___memset_chk (&self->buffer, 0, sizeof
(Py_buffer), __builtin_object_size (&self->buffer, 0))
: __inline_memset_chk (&self->buffer, 0, sizeof(Py_buffer
)))
;
1148
1149 self->memo_size = 32;
1150 self->memo = _Unpickler_NewMemo(self->memo_size);
1151 if (self->memo == NULL((void*)0)) {
1152 Py_DECREF(self)do { if (_Py_RefTotal-- , --((PyObject*)(self))->ob_refcnt
!= 0) { if (((PyObject*)self)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1152, (
PyObject *)(self)); } else _Py_Dealloc((PyObject *)(self)); }
while (0)
;
1153 return NULL((void*)0);
1154 }
1155
1156 self->arg = NULL((void*)0);
1157 self->pers_func = NULL((void*)0);
1158 self->input_buffer = NULL((void*)0);
1159 self->input_line = NULL((void*)0);
1160 self->input_len = 0;
1161 self->next_read_idx = 0;
1162 self->prefetched_idx = 0;
1163 self->read = NULL((void*)0);
1164 self->readline = NULL((void*)0);
1165 self->peek = NULL((void*)0);
1166 self->encoding = NULL((void*)0);
1167 self->errors = NULL((void*)0);
1168 self->marks = NULL((void*)0);
1169 self->num_marks = 0;
1170 self->marks_size = 0;
1171 self->proto = 0;
1172 self->fix_imports = 0;
1173
1174 return self;
1175}
1176
1177/* Returns -1 (with an exception set) on failure, 0 on success. This may
1178 be called once on a freshly created Pickler. */
1179static int
1180_Unpickler_SetInputStream(UnpicklerObject *self, PyObject *file)
1181{
1182 self->peek = PyObject_GetAttrString(file, "peek");
1183 if (self->peek == NULL((void*)0)) {
1184 if (PyErr_ExceptionMatches(PyExc_AttributeError))
1185 PyErr_Clear();
1186 else
1187 return -1;
1188 }
1189 self->read = PyObject_GetAttrString(file, "read");
1190 self->readline = PyObject_GetAttrString(file, "readline");
1191 if (self->readline == NULL((void*)0) || self->read == NULL((void*)0)) {
1192 if (PyErr_ExceptionMatches(PyExc_AttributeError))
1193 PyErr_SetString(PyExc_TypeError,
1194 "file must have 'read' and 'readline' attributes");
1195 Py_CLEAR(self->read)do { if (self->read) { PyObject *_py_tmp = (PyObject *)(self
->read); (self->read) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1195, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
1196 Py_CLEAR(self->readline)do { if (self->readline) { PyObject *_py_tmp = (PyObject *
)(self->readline); (self->readline) = ((void*)0); do { if
(_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0
) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1196, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
1197 Py_CLEAR(self->peek)do { if (self->peek) { PyObject *_py_tmp = (PyObject *)(self
->peek); (self->peek) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1197, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
1198 return -1;
1199 }
1200 return 0;
1201}
1202
1203/* Returns -1 (with an exception set) on failure, 0 on success. This may
1204 be called once on a freshly created Pickler. */
1205static int
1206_Unpickler_SetInputEncoding(UnpicklerObject *self,
1207 const char *encoding,
1208 const char *errors)
1209{
1210 if (encoding == NULL((void*)0))
1211 encoding = "ASCII";
1212 if (errors == NULL((void*)0))
1213 errors = "strict";
1214
1215 self->encoding = strdup(encoding);
1216 self->errors = strdup(errors);
1217 if (self->encoding == NULL((void*)0) || self->errors == NULL((void*)0)) {
1218 PyErr_NoMemory();
1219 return -1;
1220 }
1221 return 0;
1222}
1223
1224/* Generate a GET opcode for an object stored in the memo. */
1225static int
1226memo_get(PicklerObject *self, PyObject *key)
1227{
1228 long *value;
1229 char pdata[30];
1230 int len;
1231
1232 value = PyMemoTable_Get(self->memo, key);
1233 if (value == NULL((void*)0)) {
1234 PyErr_SetObject(PyExc_KeyError, key);
1235 return -1;
1236 }
1237
1238 if (!self->bin) {
1239 pdata[0] = GET;
1240 PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ld\n", *value);
1241 len = (int)strlen(pdata);
1242 }
1243 else {
1244 if (*value < 256) {
1245 pdata[0] = BINGET;
1246 pdata[1] = (unsigned char)(*value & 0xff);
1247 len = 2;
1248 }
1249 else if (*value <= 0xffffffffL) {
1250 pdata[0] = LONG_BINGET;
1251 pdata[1] = (unsigned char)(*value & 0xff);
1252 pdata[2] = (unsigned char)((*value >> 8) & 0xff);
1253 pdata[3] = (unsigned char)((*value >> 16) & 0xff);
1254 pdata[4] = (unsigned char)((*value >> 24) & 0xff);
1255 len = 5;
1256 }
1257 else { /* unlikely */
1258 PyErr_SetString(PicklingError,
1259 "memo id too large for LONG_BINGET");
1260 return -1;
1261 }
1262 }
1263
1264 if (_Pickler_Write(self, pdata, len) < 0)
1265 return -1;
1266
1267 return 0;
1268}
1269
1270/* Store an object in the memo, assign it a new unique ID based on the number
1271 of objects currently stored in the memo and generate a PUT opcode. */
1272static int
1273memo_put(PicklerObject *self, PyObject *obj)
1274{
1275 long x;
1276 char pdata[30];
1277 int len;
1278 int status = 0;
1279
1280 if (self->fast)
1281 return 0;
1282
1283 x = PyMemoTable_Size(self->memo);
1284 if (PyMemoTable_Set(self->memo, obj, x) < 0)
1285 goto error;
1286
1287 if (!self->bin) {
1288 pdata[0] = PUT;
1289 PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ld\n", x);
1290 len = strlen(pdata);
1291 }
1292 else {
1293 if (x < 256) {
1294 pdata[0] = BINPUT;
1295 pdata[1] = (unsigned char)x;
1296 len = 2;
1297 }
1298 else if (x <= 0xffffffffL) {
1299 pdata[0] = LONG_BINPUT;
1300 pdata[1] = (unsigned char)(x & 0xff);
1301 pdata[2] = (unsigned char)((x >> 8) & 0xff);
1302 pdata[3] = (unsigned char)((x >> 16) & 0xff);
1303 pdata[4] = (unsigned char)((x >> 24) & 0xff);
1304 len = 5;
1305 }
1306 else { /* unlikely */
1307 PyErr_SetString(PicklingError,
1308 "memo id too large for LONG_BINPUT");
1309 return -1;
1310 }
1311 }
1312
1313 if (_Pickler_Write(self, pdata, len) < 0)
1314 goto error;
1315
1316 if (0) {
1317 error:
1318 status = -1;
1319 }
1320
1321 return status;
1322}
1323
1324static PyObject *
1325whichmodule(PyObject *global, PyObject *global_name)
1326{
1327 Py_ssize_t i, j;
1328 static PyObject *module_str = NULL((void*)0);
1329 static PyObject *main_str = NULL((void*)0);
1330 PyObject *module_name;
1331 PyObject *modules_dict;
1332 PyObject *module;
1333 PyObject *obj;
1334
1335 if (module_str == NULL((void*)0)) {
1336 module_str = PyUnicode_InternFromString("__module__");
1337 if (module_str == NULL((void*)0))
1338 return NULL((void*)0);
1339 main_str = PyUnicode_InternFromString("__main__");
1340 if (main_str == NULL((void*)0))
1341 return NULL((void*)0);
1342 }
1343
1344 module_name = PyObject_GetAttr(global, module_str);
1345
1346 /* In some rare cases (e.g., bound methods of extension types),
1347 __module__ can be None. If it is so, then search sys.modules
1348 for the module of global. */
1349 if (module_name == Py_None(&_Py_NoneStruct)) {
1350 Py_DECREF(module_name)do { if (_Py_RefTotal-- , --((PyObject*)(module_name))->ob_refcnt
!= 0) { if (((PyObject*)module_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1350, (
PyObject *)(module_name)); } else _Py_Dealloc((PyObject *)(module_name
)); } while (0)
;
1351 goto search;
1352 }
1353
1354 if (module_name) {
1355 return module_name;
1356 }
1357 if (PyErr_ExceptionMatches(PyExc_AttributeError))
1358 PyErr_Clear();
1359 else
1360 return NULL((void*)0);
1361
1362 search:
1363 modules_dict = PySys_GetObject("modules");
1364 if (modules_dict == NULL((void*)0))
1365 return NULL((void*)0);
1366
1367 i = 0;
1368 module_name = NULL((void*)0);
1369 while ((j = PyDict_Next(modules_dict, &i, &module_name, &module))) {
1370 if (PyObject_RichCompareBool(module_name, main_str, Py_EQ2) == 1)
1371 continue;
1372
1373 obj = PyObject_GetAttr(module, global_name);
1374 if (obj == NULL((void*)0)) {
1375 if (PyErr_ExceptionMatches(PyExc_AttributeError))
1376 PyErr_Clear();
1377 else
1378 return NULL((void*)0);
1379 continue;
1380 }
1381
1382 if (obj != global) {
1383 Py_DECREF(obj)do { if (_Py_RefTotal-- , --((PyObject*)(obj))->ob_refcnt !=
0) { if (((PyObject*)obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1383, (
PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj)); } while
(0)
;
1384 continue;
1385 }
1386
1387 Py_DECREF(obj)do { if (_Py_RefTotal-- , --((PyObject*)(obj))->ob_refcnt !=
0) { if (((PyObject*)obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1387, (
PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj)); } while
(0)
;
1388 break;
1389 }
1390
1391 /* If no module is found, use __main__. */
1392 if (!j) {
1393 module_name = main_str;
1394 }
1395
1396 Py_INCREF(module_name)( _Py_RefTotal++ , ((PyObject*)(module_name))->ob_refcnt++
)
;
1397 return module_name;
1398}
1399
1400/* fast_save_enter() and fast_save_leave() are guards against recursive
1401 objects when Pickler is used with the "fast mode" (i.e., with object
1402 memoization disabled). If the nesting of a list or dict object exceed
1403 FAST_NESTING_LIMIT, these guards will start keeping an internal
1404 reference to the seen list or dict objects and check whether these objects
1405 are recursive. These are not strictly necessary, since save() has a
1406 hard-coded recursion limit, but they give a nicer error message than the
1407 typical RuntimeError. */
1408static int
1409fast_save_enter(PicklerObject *self, PyObject *obj)
1410{
1411 /* if fast_nesting < 0, we're doing an error exit. */
1412 if (++self->fast_nesting >= FAST_NESTING_LIMIT) {
1413 PyObject *key = NULL((void*)0);
1414 if (self->fast_memo == NULL((void*)0)) {
1415 self->fast_memo = PyDict_New();
1416 if (self->fast_memo == NULL((void*)0)) {
1417 self->fast_nesting = -1;
1418 return 0;
1419 }
1420 }
1421 key = PyLong_FromVoidPtr(obj);
1422 if (key == NULL((void*)0))
1423 return 0;
1424 if (PyDict_GetItem(self->fast_memo, key)) {
1425 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1425, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
1426 PyErr_Format(PyExc_ValueError,
1427 "fast mode: can't pickle cyclic objects "
1428 "including object type %.200s at %p",
1429 obj->ob_type->tp_name, obj);
1430 self->fast_nesting = -1;
1431 return 0;
1432 }
1433 if (PyDict_SetItem(self->fast_memo, key, Py_None(&_Py_NoneStruct)) < 0) {
1434 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1434, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
1435 self->fast_nesting = -1;
1436 return 0;
1437 }
1438 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1438, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
1439 }
1440 return 1;
1441}
1442
1443static int
1444fast_save_leave(PicklerObject *self, PyObject *obj)
1445{
1446 if (self->fast_nesting-- >= FAST_NESTING_LIMIT) {
1447 PyObject *key = PyLong_FromVoidPtr(obj);
1448 if (key == NULL((void*)0))
1449 return 0;
1450 if (PyDict_DelItem(self->fast_memo, key) < 0) {
1451 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1451, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
1452 return 0;
1453 }
1454 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1454, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
1455 }
1456 return 1;
1457}
1458
1459static int
1460save_none(PicklerObject *self, PyObject *obj)
1461{
1462 const char none_op = NONE;
1463 if (_Pickler_Write(self, &none_op, 1) < 0)
1464 return -1;
1465
1466 return 0;
1467}
1468
1469static int
1470save_bool(PicklerObject *self, PyObject *obj)
1471{
1472 static const char *buf[2] = { FALSE"I00\n", TRUE"I01\n" };
1473 const char len[2] = {sizeof(FALSE"I00\n") - 1, sizeof(TRUE"I01\n") - 1};
1474 int p = (obj == Py_True((PyObject *) &_Py_TrueStruct));
1475
1476 if (self->proto >= 2) {
1477 const char bool_op = p ? NEWTRUE : NEWFALSE;
1478 if (_Pickler_Write(self, &bool_op, 1) < 0)
1479 return -1;
1480 }
1481 else if (_Pickler_Write(self, buf[p], len[p]) < 0)
1482 return -1;
1483
1484 return 0;
1485}
1486
1487static int
1488save_int(PicklerObject *self, long x)
1489{
1490 char pdata[32];
1491 int len = 0;
1492
1493 if (!self->bin
1494#if SIZEOF_LONG8 > 4
1495 || x > 0x7fffffffL || x < -0x80000000L
1496#endif
1497 ) {
1498 /* Text-mode pickle, or long too big to fit in the 4-byte
1499 * signed BININT format: store as a string.
1500 */
1501 pdata[0] = LONG; /* use LONG for consistency with pickle.py */
1502 PyOS_snprintf(pdata + 1, sizeof(pdata) - 1, "%ldL\n", x);
1503 if (_Pickler_Write(self, pdata, strlen(pdata)) < 0)
1504 return -1;
1505 }
1506 else {
1507 /* Binary pickle and x fits in a signed 4-byte int. */
1508 pdata[1] = (unsigned char)(x & 0xff);
1509 pdata[2] = (unsigned char)((x >> 8) & 0xff);
1510 pdata[3] = (unsigned char)((x >> 16) & 0xff);
1511 pdata[4] = (unsigned char)((x >> 24) & 0xff);
1512
1513 if ((pdata[4] == 0) && (pdata[3] == 0)) {
1514 if (pdata[2] == 0) {
1515 pdata[0] = BININT1;
1516 len = 2;
1517 }
1518 else {
1519 pdata[0] = BININT2;
1520 len = 3;
1521 }
1522 }
1523 else {
1524 pdata[0] = BININT;
1525 len = 5;
1526 }
1527
1528 if (_Pickler_Write(self, pdata, len) < 0)
1529 return -1;
1530 }
1531
1532 return 0;
1533}
1534
1535static int
1536save_long(PicklerObject *self, PyObject *obj)
1537{
1538 PyObject *repr = NULL((void*)0);
1539 Py_ssize_t size;
1540 long val = PyLong_AsLong(obj);
1541 int status = 0;
1542
1543 const char long_op = LONG;
1544
1545 if (val == -1 && PyErr_Occurred()) {
1546 /* out of range for int pickling */
1547 PyErr_Clear();
1548 }
1549 else
1550 return save_int(self, val);
1551
1552 if (self->proto >= 2) {
1553 /* Linear-time pickling. */
1554 size_t nbits;
1555 size_t nbytes;
1556 unsigned char *pdata;
1557 char header[5];
1558 int i;
1559 int sign = _PyLong_Sign(obj);
1560
1561 if (sign == 0) {
1562 header[0] = LONG1;
1563 header[1] = 0; /* It's 0 -- an empty bytestring. */
1564 if (_Pickler_Write(self, header, 2) < 0)
1565 goto error;
1566 return 0;
1567 }
1568 nbits = _PyLong_NumBits(obj);
1569 if (nbits == (size_t)-1 && PyErr_Occurred())
1570 goto error;
1571 /* How many bytes do we need? There are nbits >> 3 full
1572 * bytes of data, and nbits & 7 leftover bits. If there
1573 * are any leftover bits, then we clearly need another
1574 * byte. Wnat's not so obvious is that we *probably*
1575 * need another byte even if there aren't any leftovers:
1576 * the most-significant bit of the most-significant byte
1577 * acts like a sign bit, and it's usually got a sense
1578 * opposite of the one we need. The exception is longs
1579 * of the form -(2**(8*j-1)) for j > 0. Such a long is
1580 * its own 256's-complement, so has the right sign bit
1581 * even without the extra byte. That's a pain to check
1582 * for in advance, though, so we always grab an extra
1583 * byte at the start, and cut it back later if possible.
1584 */
1585 nbytes = (nbits >> 3) + 1;
1586 if (nbytes > INT_MAX2147483647) {
1587 PyErr_SetString(PyExc_OverflowError,
1588 "long too large to pickle");
1589 goto error;
1590 }
1591 repr = PyBytes_FromStringAndSize(NULL((void*)0), (Py_ssize_t)nbytes);
1592 if (repr == NULL((void*)0))
1593 goto error;
1594 pdata = (unsigned char *)PyBytes_AS_STRING(repr)((__builtin_expect(!(((((((PyObject*)(repr))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1594,
"PyBytes_Check(repr)") : (void)0), (((PyBytesObject *)(repr)
)->ob_sval))
;
1595 i = _PyLong_AsByteArray((PyLongObject *)obj,
1596 pdata, nbytes,
1597 1 /* little endian */ , 1 /* signed */ );
1598 if (i < 0)
1599 goto error;
1600 /* If the long is negative, this may be a byte more than
1601 * needed. This is so iff the MSB is all redundant sign
1602 * bits.
1603 */
1604 if (sign < 0 &&
1605 nbytes > 1 &&
1606 pdata[nbytes - 1] == 0xff &&
1607 (pdata[nbytes - 2] & 0x80) != 0) {
1608 nbytes--;
1609 }
1610
1611 if (nbytes < 256) {
1612 header[0] = LONG1;
1613 header[1] = (unsigned char)nbytes;
1614 size = 2;
1615 }
1616 else {
1617 header[0] = LONG4;
1618 size = (int)nbytes;
1619 for (i = 1; i < 5; i++) {
1620 header[i] = (unsigned char)(size & 0xff);
1621 size >>= 8;
1622 }
1623 size = 5;
1624 }
1625 if (_Pickler_Write(self, header, size) < 0 ||
1626 _Pickler_Write(self, (char *)pdata, (int)nbytes) < 0)
1627 goto error;
1628 }
1629 else {
1630 char *string;
1631
1632 /* proto < 2: write the repr and newline. This is quadratic-time (in
1633 the number of digits), in both directions. We add a trailing 'L'
1634 to the repr, for compatibility with Python 2.x. */
1635
1636 repr = PyObject_Repr(obj);
1637 if (repr == NULL((void*)0))
1638 goto error;
1639
1640 string = _PyUnicode_AsStringAndSize(repr, &size);
1641 if (string == NULL((void*)0))
1642 goto error;
1643
1644 if (_Pickler_Write(self, &long_op, 1) < 0 ||
1645 _Pickler_Write(self, string, size) < 0 ||
1646 _Pickler_Write(self, "L\n", 2) < 0)
1647 goto error;
1648 }
1649
1650 if (0) {
1651 error:
1652 status = -1;
1653 }
1654 Py_XDECREF(repr)do { if ((repr) == ((void*)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(repr))->ob_refcnt != 0) { if (((PyObject
*)repr)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1654, (PyObject *)(repr)); } else _Py_Dealloc((PyObject *)(
repr)); } while (0); } while (0)
;
1655
1656 return status;
1657}
1658
1659static int
1660save_float(PicklerObject *self, PyObject *obj)
1661{
1662 double x = PyFloat_AS_DOUBLE((PyFloatObject *)obj)(((PyFloatObject *)((PyFloatObject *)obj))->ob_fval);
1663
1664 if (self->bin) {
1665 char pdata[9];
1666 pdata[0] = BINFLOAT;
1667 if (_PyFloat_Pack8(x, (unsigned char *)&pdata[1], 0) < 0)
1668 return -1;
1669 if (_Pickler_Write(self, pdata, 9) < 0)
1670 return -1;
1671 }
1672 else {
1673 int result = -1;
1674 char *buf = NULL((void*)0);
1675 char op = FLOAT;
1676
1677 if (_Pickler_Write(self, &op, 1) < 0)
1678 goto done;
1679
1680 buf = PyOS_double_to_string(x, 'g', 17, 0, NULL((void*)0));
1681 if (!buf) {
1682 PyErr_NoMemory();
1683 goto done;
1684 }
1685
1686 if (_Pickler_Write(self, buf, strlen(buf)) < 0)
1687 goto done;
1688
1689 if (_Pickler_Write(self, "\n", 1) < 0)
1690 goto done;
1691
1692 result = 0;
1693done:
1694 PyMem_Free(buf);
1695 return result;
1696 }
1697
1698 return 0;
1699}
1700
1701static int
1702save_bytes(PicklerObject *self, PyObject *obj)
1703{
1704 if (self->proto < 3) {
1705 /* Older pickle protocols do not have an opcode for pickling bytes
1706 objects. Therefore, we need to fake the copy protocol (i.e.,
1707 the __reduce__ method) to permit bytes object unpickling. */
1708 PyObject *reduce_value = NULL((void*)0);
1709 PyObject *bytelist = NULL((void*)0);
1710 int status;
1711
1712 bytelist = PySequence_List(obj);
1713 if (bytelist == NULL((void*)0))
1714 return -1;
1715
1716 reduce_value = Py_BuildValue("(O(O))", (PyObject *)&PyBytes_Type,
1717 bytelist);
1718 if (reduce_value == NULL((void*)0)) {
1719 Py_DECREF(bytelist)do { if (_Py_RefTotal-- , --((PyObject*)(bytelist))->ob_refcnt
!= 0) { if (((PyObject*)bytelist)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1719, (
PyObject *)(bytelist)); } else _Py_Dealloc((PyObject *)(bytelist
)); } while (0)
;
1720 return -1;
1721 }
1722
1723 /* save_reduce() will memoize the object automatically. */
1724 status = save_reduce(self, reduce_value, obj);
1725 Py_DECREF(reduce_value)do { if (_Py_RefTotal-- , --((PyObject*)(reduce_value))->ob_refcnt
!= 0) { if (((PyObject*)reduce_value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1725, (
PyObject *)(reduce_value)); } else _Py_Dealloc((PyObject *)(reduce_value
)); } while (0)
;
1726 Py_DECREF(bytelist)do { if (_Py_RefTotal-- , --((PyObject*)(bytelist))->ob_refcnt
!= 0) { if (((PyObject*)bytelist)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1726, (
PyObject *)(bytelist)); } else _Py_Dealloc((PyObject *)(bytelist
)); } while (0)
;
1727 return status;
1728 }
1729 else {
1730 Py_ssize_t size;
1731 char header[5];
1732 int len;
1733
1734 size = PyBytes_Size(obj);
1735 if (size < 0)
1736 return -1;
1737
1738 if (size < 256) {
1739 header[0] = SHORT_BINBYTES;
1740 header[1] = (unsigned char)size;
1741 len = 2;
1742 }
1743 else if (size <= 0xffffffffL) {
1744 header[0] = BINBYTES;
1745 header[1] = (unsigned char)(size & 0xff);
1746 header[2] = (unsigned char)((size >> 8) & 0xff);
1747 header[3] = (unsigned char)((size >> 16) & 0xff);
1748 header[4] = (unsigned char)((size >> 24) & 0xff);
1749 len = 5;
1750 }
1751 else {
1752 return -1; /* string too large */
1753 }
1754
1755 if (_Pickler_Write(self, header, len) < 0)
1756 return -1;
1757
1758 if (_Pickler_Write(self, PyBytes_AS_STRING(obj)((__builtin_expect(!(((((((PyObject*)(obj))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1758,
"PyBytes_Check(obj)") : (void)0), (((PyBytesObject *)(obj))->
ob_sval))
, size) < 0)
1759 return -1;
1760
1761 if (memo_put(self, obj) < 0)
1762 return -1;
1763
1764 return 0;
1765 }
1766}
1767
1768/* A copy of PyUnicode_EncodeRawUnicodeEscape() that also translates
1769 backslash and newline characters to \uXXXX escapes. */
1770static PyObject *
1771raw_unicode_escape(const Py_UNICODE *s, Py_ssize_t size)
1772{
1773 PyObject *repr, *result;
1774 char *p;
1775 char *q;
1776
1777 static const char *hexdigits = "0123456789abcdef";
1778
1779#ifdef Py_UNICODE_WIDE
1780 const Py_ssize_t expandsize = 10;
1781#else
1782 const Py_ssize_t expandsize = 6;
1783#endif
1784
1785 if (size > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) / expandsize)
1786 return PyErr_NoMemory();
1787
1788 repr = PyByteArray_FromStringAndSize(NULL((void*)0), expandsize * size);
1789 if (repr == NULL((void*)0))
1790 return NULL((void*)0);
1791 if (size == 0)
1792 goto done;
1793
1794 p = q = PyByteArray_AS_STRING(repr)((__builtin_expect(!(((((PyObject*)(repr))->ob_type) == (&
PyByteArray_Type) || PyType_IsSubtype((((PyObject*)(repr))->
ob_type), (&PyByteArray_Type)))), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1794,
"PyByteArray_Check(repr)") : (void)0), (((PyVarObject*)(repr
))->ob_size) ? ((PyByteArrayObject *)(repr))->ob_bytes :
_PyByteArray_empty_string)
;
1795 while (size-- > 0) {
1796 Py_UNICODE ch = *s++;
1797#ifdef Py_UNICODE_WIDE
1798 /* Map 32-bit characters to '\Uxxxxxxxx' */
1799 if (ch >= 0x10000) {
1800 *p++ = '\\';
1801 *p++ = 'U';
1802 *p++ = hexdigits[(ch >> 28) & 0xf];
1803 *p++ = hexdigits[(ch >> 24) & 0xf];
1804 *p++ = hexdigits[(ch >> 20) & 0xf];
1805 *p++ = hexdigits[(ch >> 16) & 0xf];
1806 *p++ = hexdigits[(ch >> 12) & 0xf];
1807 *p++ = hexdigits[(ch >> 8) & 0xf];
1808 *p++ = hexdigits[(ch >> 4) & 0xf];
1809 *p++ = hexdigits[ch & 15];
1810 }
1811 else
1812#else
1813 /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
1814 if (ch >= 0xD800 && ch < 0xDC00) {
1815 Py_UNICODE ch2;
1816 Py_UCS4 ucs;
1817
1818 ch2 = *s++;
1819 size--;
1820 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
1821 ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
1822 *p++ = '\\';
1823 *p++ = 'U';
1824 *p++ = hexdigits[(ucs >> 28) & 0xf];
1825 *p++ = hexdigits[(ucs >> 24) & 0xf];
1826 *p++ = hexdigits[(ucs >> 20) & 0xf];
1827 *p++ = hexdigits[(ucs >> 16) & 0xf];
1828 *p++ = hexdigits[(ucs >> 12) & 0xf];
1829 *p++ = hexdigits[(ucs >> 8) & 0xf];
1830 *p++ = hexdigits[(ucs >> 4) & 0xf];
1831 *p++ = hexdigits[ucs & 0xf];
1832 continue;
1833 }
1834 /* Fall through: isolated surrogates are copied as-is */
1835 s--;
1836 size++;
1837 }
1838#endif
1839 /* Map 16-bit characters to '\uxxxx' */
1840 if (ch >= 256 || ch == '\\' || ch == '\n') {
1841 *p++ = '\\';
1842 *p++ = 'u';
1843 *p++ = hexdigits[(ch >> 12) & 0xf];
1844 *p++ = hexdigits[(ch >> 8) & 0xf];
1845 *p++ = hexdigits[(ch >> 4) & 0xf];
1846 *p++ = hexdigits[ch & 15];
1847 }
1848 /* Copy everything else as-is */
1849 else
1850 *p++ = (char) ch;
1851 }
1852 size = p - q;
1853
1854 done:
1855 result = PyBytes_FromStringAndSize(PyByteArray_AS_STRING(repr)((__builtin_expect(!(((((PyObject*)(repr))->ob_type) == (&
PyByteArray_Type) || PyType_IsSubtype((((PyObject*)(repr))->
ob_type), (&PyByteArray_Type)))), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1855,
"PyByteArray_Check(repr)") : (void)0), (((PyVarObject*)(repr
))->ob_size) ? ((PyByteArrayObject *)(repr))->ob_bytes :
_PyByteArray_empty_string)
, size);
1856 Py_DECREF(repr)do { if (_Py_RefTotal-- , --((PyObject*)(repr))->ob_refcnt
!= 0) { if (((PyObject*)repr)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1856, (
PyObject *)(repr)); } else _Py_Dealloc((PyObject *)(repr)); }
while (0)
;
1857 return result;
1858}
1859
1860static int
1861save_unicode(PicklerObject *self, PyObject *obj)
1862{
1863 Py_ssize_t size;
1864 PyObject *encoded = NULL((void*)0);
1865
1866 if (self->bin) {
1867 char pdata[5];
1868
1869 encoded = PyUnicode_EncodeUTF8PyUnicodeUCS2_EncodeUTF8(PyUnicode_AS_UNICODE(obj)((__builtin_expect(!(((((((PyObject*)(obj))->ob_type))->
tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1869,
"PyUnicode_Check(obj)") : (void)0),(((PyUnicodeObject *)(obj
))->str))
,
1870 PyUnicode_GET_SIZE(obj)((__builtin_expect(!(((((((PyObject*)(obj))->ob_type))->
tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1870,
"PyUnicode_Check(obj)") : (void)0),(((PyUnicodeObject *)(obj
))->length))
,
1871 "surrogatepass");
1872 if (encoded == NULL((void*)0))
1873 goto error;
1874
1875 size = PyBytes_GET_SIZE(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1875, "PyBytes_Check(encoded)") : (void)0),(((PyVarObject*)
(encoded))->ob_size))
;
1876 if (size < 0 || size > 0xffffffffL)
1877 goto error; /* string too large */
1878
1879 pdata[0] = BINUNICODE;
1880 pdata[1] = (unsigned char)(size & 0xff);
1881 pdata[2] = (unsigned char)((size >> 8) & 0xff);
1882 pdata[3] = (unsigned char)((size >> 16) & 0xff);
1883 pdata[4] = (unsigned char)((size >> 24) & 0xff);
1884
1885 if (_Pickler_Write(self, pdata, 5) < 0)
1886 goto error;
1887
1888 if (_Pickler_Write(self, PyBytes_AS_STRING(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1888, "PyBytes_Check(encoded)") : (void)0), (((PyBytesObject
*)(encoded))->ob_sval))
, size) < 0)
1889 goto error;
1890 }
1891 else {
1892 const char unicode_op = UNICODE;
1893
1894 encoded = raw_unicode_escape(PyUnicode_AS_UNICODE(obj)((__builtin_expect(!(((((((PyObject*)(obj))->ob_type))->
tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1894,
"PyUnicode_Check(obj)") : (void)0),(((PyUnicodeObject *)(obj
))->str))
,
1895 PyUnicode_GET_SIZE(obj)((__builtin_expect(!(((((((PyObject*)(obj))->ob_type))->
tp_flags & ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1895,
"PyUnicode_Check(obj)") : (void)0),(((PyUnicodeObject *)(obj
))->length))
);
1896 if (encoded == NULL((void*)0))
1897 goto error;
1898
1899 if (_Pickler_Write(self, &unicode_op, 1) < 0)
1900 goto error;
1901
1902 size = PyBytes_GET_SIZE(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1902, "PyBytes_Check(encoded)") : (void)0),(((PyVarObject*)
(encoded))->ob_size))
;
1903 if (_Pickler_Write(self, PyBytes_AS_STRING(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1903, "PyBytes_Check(encoded)") : (void)0), (((PyBytesObject
*)(encoded))->ob_sval))
, size) < 0)
1904 goto error;
1905
1906 if (_Pickler_Write(self, "\n", 1) < 0)
1907 goto error;
1908 }
1909 if (memo_put(self, obj) < 0)
1910 goto error;
1911
1912 Py_DECREF(encoded)do { if (_Py_RefTotal-- , --((PyObject*)(encoded))->ob_refcnt
!= 0) { if (((PyObject*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 1912, (
PyObject *)(encoded)); } else _Py_Dealloc((PyObject *)(encoded
)); } while (0)
;
1913 return 0;
1914
1915 error:
1916 Py_XDECREF(encoded)do { if ((encoded) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(encoded))->ob_refcnt != 0) { if (((PyObject
*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1916, (PyObject *)(encoded)); } else _Py_Dealloc((PyObject *
)(encoded)); } while (0); } while (0)
;
1917 return -1;
1918}
1919
1920/* A helper for save_tuple. Push the len elements in tuple t on the stack. */
1921static int
1922store_tuple_elements(PicklerObject *self, PyObject *t, int len)
1923{
1924 int i;
1925
1926 assert(PyTuple_Size(t) == len)(__builtin_expect(!(PyTuple_Size(t) == len), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 1926, "PyTuple_Size(t) == len") : (void)0)
;
1927
1928 for (i = 0; i < len; i++) {
1929 PyObject *element = PyTuple_GET_ITEM(t, i)(((PyTupleObject *)(t))->ob_item[i]);
1930
1931 if (element == NULL((void*)0))
1932 return -1;
1933 if (save(self, element, 0) < 0)
1934 return -1;
1935 }
1936
1937 return 0;
1938}
1939
1940/* Tuples are ubiquitous in the pickle protocols, so many techniques are
1941 * used across protocols to minimize the space needed to pickle them.
1942 * Tuples are also the only builtin immutable type that can be recursive
1943 * (a tuple can be reached from itself), and that requires some subtle
1944 * magic so that it works in all cases. IOW, this is a long routine.
1945 */
1946static int
1947save_tuple(PicklerObject *self, PyObject *obj)
1948{
1949 int len, i;
1950
1951 const char mark_op = MARK;
1952 const char tuple_op = TUPLE;
1953 const char pop_op = POP;
1954 const char pop_mark_op = POP_MARK;
1955 const char len2opcode[] = {EMPTY_TUPLE, TUPLE1, TUPLE2, TUPLE3};
1956
1957 if ((len = PyTuple_Size(obj)) < 0)
1958 return -1;
1959
1960 if (len == 0) {
1961 char pdata[2];
1962
1963 if (self->proto) {
1964 pdata[0] = EMPTY_TUPLE;
1965 len = 1;
1966 }
1967 else {
1968 pdata[0] = MARK;
1969 pdata[1] = TUPLE;
1970 len = 2;
1971 }
1972 if (_Pickler_Write(self, pdata, len) < 0)
1973 return -1;
1974 return 0;
1975 }
1976
1977 /* The tuple isn't in the memo now. If it shows up there after
1978 * saving the tuple elements, the tuple must be recursive, in
1979 * which case we'll pop everything we put on the stack, and fetch
1980 * its value from the memo.
1981 */
1982 if (len <= 3 && self->proto >= 2) {
1983 /* Use TUPLE{1,2,3} opcodes. */
1984 if (store_tuple_elements(self, obj, len) < 0)
1985 return -1;
1986
1987 if (PyMemoTable_Get(self->memo, obj)) {
1988 /* pop the len elements */
1989 for (i = 0; i < len; i++)
1990 if (_Pickler_Write(self, &pop_op, 1) < 0)
1991 return -1;
1992 /* fetch from memo */
1993 if (memo_get(self, obj) < 0)
1994 return -1;
1995
1996 return 0;
1997 }
1998 else { /* Not recursive. */
1999 if (_Pickler_Write(self, len2opcode + len, 1) < 0)
2000 return -1;
2001 }
2002 goto memoize;
2003 }
2004
2005 /* proto < 2 and len > 0, or proto >= 2 and len > 3.
2006 * Generate MARK e1 e2 ... TUPLE
2007 */
2008 if (_Pickler_Write(self, &mark_op, 1) < 0)
2009 return -1;
2010
2011 if (store_tuple_elements(self, obj, len) < 0)
2012 return -1;
2013
2014 if (PyMemoTable_Get(self->memo, obj)) {
2015 /* pop the stack stuff we pushed */
2016 if (self->bin) {
2017 if (_Pickler_Write(self, &pop_mark_op, 1) < 0)
2018 return -1;
2019 }
2020 else {
2021 /* Note that we pop one more than len, to remove
2022 * the MARK too.
2023 */
2024 for (i = 0; i <= len; i++)
2025 if (_Pickler_Write(self, &pop_op, 1) < 0)
2026 return -1;
2027 }
2028 /* fetch from memo */
2029 if (memo_get(self, obj) < 0)
2030 return -1;
2031
2032 return 0;
2033 }
2034 else { /* Not recursive. */
2035 if (_Pickler_Write(self, &tuple_op, 1) < 0)
2036 return -1;
2037 }
2038
2039 memoize:
2040 if (memo_put(self, obj) < 0)
2041 return -1;
2042
2043 return 0;
2044}
2045
2046/* iter is an iterator giving items, and we batch up chunks of
2047 * MARK item item ... item APPENDS
2048 * opcode sequences. Calling code should have arranged to first create an
2049 * empty list, or list-like object, for the APPENDS to operate on.
2050 * Returns 0 on success, <0 on error.
2051 */
2052static int
2053batch_list(PicklerObject *self, PyObject *iter)
2054{
2055 PyObject *obj = NULL((void*)0);
2056 PyObject *firstitem = NULL((void*)0);
2057 int i, n;
2058
2059 const char mark_op = MARK;
2060 const char append_op = APPEND;
2061 const char appends_op = APPENDS;
2062
2063 assert(iter != NULL)(__builtin_expect(!(iter != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2063,
"iter != NULL") : (void)0)
;
2064
2065 /* XXX: I think this function could be made faster by avoiding the
2066 iterator interface and fetching objects directly from list using
2067 PyList_GET_ITEM.
2068 */
2069
2070 if (self->proto == 0) {
2071 /* APPENDS isn't available; do one at a time. */
2072 for (;;) {
2073 obj = PyIter_Next(iter);
2074 if (obj == NULL((void*)0)) {
2075 if (PyErr_Occurred())
2076 return -1;
2077 break;
2078 }
2079 i = save(self, obj, 0);
2080 Py_DECREF(obj)do { if (_Py_RefTotal-- , --((PyObject*)(obj))->ob_refcnt !=
0) { if (((PyObject*)obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2080, (
PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj)); } while
(0)
;
2081 if (i < 0)
2082 return -1;
2083 if (_Pickler_Write(self, &append_op, 1) < 0)
2084 return -1;
2085 }
2086 return 0;
2087 }
2088
2089 /* proto > 0: write in batches of BATCHSIZE. */
2090 do {
2091 /* Get first item */
2092 firstitem = PyIter_Next(iter);
2093 if (firstitem == NULL((void*)0)) {
2094 if (PyErr_Occurred())
2095 goto error;
2096
2097 /* nothing more to add */
2098 break;
2099 }
2100
2101 /* Try to get a second item */
2102 obj = PyIter_Next(iter);
2103 if (obj == NULL((void*)0)) {
2104 if (PyErr_Occurred())
2105 goto error;
2106
2107 /* Only one item to write */
2108 if (save(self, firstitem, 0) < 0)
2109 goto error;
2110 if (_Pickler_Write(self, &append_op, 1) < 0)
2111 goto error;
2112 Py_CLEAR(firstitem)do { if (firstitem) { PyObject *_py_tmp = (PyObject *)(firstitem
); (firstitem) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2112, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2113 break;
2114 }
2115
2116 /* More than one item to write */
2117
2118 /* Pump out MARK, items, APPENDS. */
2119 if (_Pickler_Write(self, &mark_op, 1) < 0)
2120 goto error;
2121
2122 if (save(self, firstitem, 0) < 0)
2123 goto error;
2124 Py_CLEAR(firstitem)do { if (firstitem) { PyObject *_py_tmp = (PyObject *)(firstitem
); (firstitem) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2124, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2125 n = 1;
2126
2127 /* Fetch and save up to BATCHSIZE items */
2128 while (obj) {
2129 if (save(self, obj, 0) < 0)
2130 goto error;
2131 Py_CLEAR(obj)do { if (obj) { PyObject *_py_tmp = (PyObject *)(obj); (obj) =
((void*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp
))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt
< 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2131, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2132 n += 1;
2133
2134 if (n == BATCHSIZE)
2135 break;
2136
2137 obj = PyIter_Next(iter);
2138 if (obj == NULL((void*)0)) {
2139 if (PyErr_Occurred())
2140 goto error;
2141 break;
2142 }
2143 }
2144
2145 if (_Pickler_Write(self, &appends_op, 1) < 0)
2146 goto error;
2147
2148 } while (n == BATCHSIZE);
2149 return 0;
2150
2151 error:
2152 Py_XDECREF(firstitem)do { if ((firstitem) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(firstitem))->ob_refcnt != 0) { if (((PyObject
*)firstitem)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2152, (PyObject *)(firstitem)); } else _Py_Dealloc((PyObject
*)(firstitem)); } while (0); } while (0)
;
2153 Py_XDECREF(obj)do { if ((obj) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(obj))->ob_refcnt != 0) { if (((PyObject*)obj
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2153, (PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj
)); } while (0); } while (0)
;
2154 return -1;
2155}
2156
2157/* This is a variant of batch_list() above, specialized for lists (with no
2158 * support for list subclasses). Like batch_list(), we batch up chunks of
2159 * MARK item item ... item APPENDS
2160 * opcode sequences. Calling code should have arranged to first create an
2161 * empty list, or list-like object, for the APPENDS to operate on.
2162 * Returns 0 on success, -1 on error.
2163 *
2164 * This version is considerably faster than batch_list(), if less general.
2165 *
2166 * Note that this only works for protocols > 0.
2167 */
2168static int
2169batch_list_exact(PicklerObject *self, PyObject *obj)
2170{
2171 PyObject *item = NULL((void*)0);
2172 int this_batch, total;
2173
2174 const char append_op = APPEND;
2175 const char appends_op = APPENDS;
2176 const char mark_op = MARK;
2177
2178 assert(obj != NULL)(__builtin_expect(!(obj != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2178,
"obj != NULL") : (void)0)
;
2179 assert(self->proto > 0)(__builtin_expect(!(self->proto > 0), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2179, "self->proto > 0") : (void)0)
;
2180 assert(PyList_CheckExact(obj))(__builtin_expect(!(((((PyObject*)(obj))->ob_type) == &
PyList_Type)), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2180, "PyList_CheckExact(obj)") : (void)0)
;
2181
2182 if (PyList_GET_SIZE(obj)(((PyVarObject*)(obj))->ob_size) == 1) {
2183 item = PyList_GET_ITEM(obj, 0)(((PyListObject *)(obj))->ob_item[0]);
2184 if (save(self, item, 0) < 0)
2185 return -1;
2186 if (_Pickler_Write(self, &append_op, 1) < 0)
2187 return -1;
2188 return 0;
2189 }
2190
2191 /* Write in batches of BATCHSIZE. */
2192 total = 0;
2193 do {
2194 this_batch = 0;
2195 if (_Pickler_Write(self, &mark_op, 1) < 0)
2196 return -1;
2197 while (total < PyList_GET_SIZE(obj)(((PyVarObject*)(obj))->ob_size)) {
2198 item = PyList_GET_ITEM(obj, total)(((PyListObject *)(obj))->ob_item[total]);
2199 if (save(self, item, 0) < 0)
2200 return -1;
2201 total++;
2202 if (++this_batch == BATCHSIZE)
2203 break;
2204 }
2205 if (_Pickler_Write(self, &appends_op, 1) < 0)
2206 return -1;
2207
2208 } while (total < PyList_GET_SIZE(obj)(((PyVarObject*)(obj))->ob_size));
2209
2210 return 0;
2211}
2212
2213static int
2214save_list(PicklerObject *self, PyObject *obj)
2215{
2216 char header[3];
2217 int len;
2218 int status = 0;
2219
2220 if (self->fast && !fast_save_enter(self, obj))
2221 goto error;
2222
2223 /* Create an empty list. */
2224 if (self->bin) {
2225 header[0] = EMPTY_LIST;
2226 len = 1;
2227 }
2228 else {
2229 header[0] = MARK;
2230 header[1] = LIST;
2231 len = 2;
2232 }
2233
2234 if (_Pickler_Write(self, header, len) < 0)
2235 goto error;
2236
2237 /* Get list length, and bow out early if empty. */
2238 if ((len = PyList_Size(obj)) < 0)
2239 goto error;
2240
2241 if (memo_put(self, obj) < 0)
2242 goto error;
2243
2244 if (len != 0) {
2245 /* Materialize the list elements. */
2246 if (PyList_CheckExact(obj)((((PyObject*)(obj))->ob_type) == &PyList_Type) && self->proto > 0) {
2247 if (Py_EnterRecursiveCall(" while pickling an object")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while pickling an object"
))
)
2248 goto error;
2249 status = batch_list_exact(self, obj);
2250 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < ((_Py_CheckRecursionLimit
> 100) ? (_Py_CheckRecursionLimit - 50) : (3 * (_Py_CheckRecursionLimit
>> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
2251 } else {
2252 PyObject *iter = PyObject_GetIter(obj);
2253 if (iter == NULL((void*)0))
2254 goto error;
2255
2256 if (Py_EnterRecursiveCall(" while pickling an object")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while pickling an object"
))
) {
2257 Py_DECREF(iter)do { if (_Py_RefTotal-- , --((PyObject*)(iter))->ob_refcnt
!= 0) { if (((PyObject*)iter)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2257, (
PyObject *)(iter)); } else _Py_Dealloc((PyObject *)(iter)); }
while (0)
;
2258 goto error;
2259 }
2260 status = batch_list(self, iter);
2261 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < ((_Py_CheckRecursionLimit
> 100) ? (_Py_CheckRecursionLimit - 50) : (3 * (_Py_CheckRecursionLimit
>> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
2262 Py_DECREF(iter)do { if (_Py_RefTotal-- , --((PyObject*)(iter))->ob_refcnt
!= 0) { if (((PyObject*)iter)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2262, (
PyObject *)(iter)); } else _Py_Dealloc((PyObject *)(iter)); }
while (0)
;
2263 }
2264 }
2265 if (0) {
2266 error:
2267 status = -1;
2268 }
2269
2270 if (self->fast && !fast_save_leave(self, obj))
2271 status = -1;
2272
2273 return status;
2274}
2275
2276/* iter is an iterator giving (key, value) pairs, and we batch up chunks of
2277 * MARK key value ... key value SETITEMS
2278 * opcode sequences. Calling code should have arranged to first create an
2279 * empty dict, or dict-like object, for the SETITEMS to operate on.
2280 * Returns 0 on success, <0 on error.
2281 *
2282 * This is very much like batch_list(). The difference between saving
2283 * elements directly, and picking apart two-tuples, is so long-winded at
2284 * the C level, though, that attempts to combine these routines were too
2285 * ugly to bear.
2286 */
2287static int
2288batch_dict(PicklerObject *self, PyObject *iter)
2289{
2290 PyObject *obj = NULL((void*)0);
2291 PyObject *firstitem = NULL((void*)0);
2292 int i, n;
2293
2294 const char mark_op = MARK;
2295 const char setitem_op = SETITEM;
2296 const char setitems_op = SETITEMS;
2297
2298 assert(iter != NULL)(__builtin_expect(!(iter != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2298,
"iter != NULL") : (void)0)
;
2299
2300 if (self->proto == 0) {
2301 /* SETITEMS isn't available; do one at a time. */
2302 for (;;) {
2303 obj = PyIter_Next(iter);
2304 if (obj == NULL((void*)0)) {
2305 if (PyErr_Occurred())
2306 return -1;
2307 break;
2308 }
2309 if (!PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1L<<
26))) != 0)
|| PyTuple_Size(obj) != 2) {
2310 PyErr_SetString(PyExc_TypeError, "dict items "
2311 "iterator must return 2-tuples");
2312 return -1;
2313 }
2314 i = save(self, PyTuple_GET_ITEM(obj, 0)(((PyTupleObject *)(obj))->ob_item[0]), 0);
2315 if (i >= 0)
2316 i = save(self, PyTuple_GET_ITEM(obj, 1)(((PyTupleObject *)(obj))->ob_item[1]), 0);
2317 Py_DECREF(obj)do { if (_Py_RefTotal-- , --((PyObject*)(obj))->ob_refcnt !=
0) { if (((PyObject*)obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2317, (
PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj)); } while
(0)
;
2318 if (i < 0)
2319 return -1;
2320 if (_Pickler_Write(self, &setitem_op, 1) < 0)
2321 return -1;
2322 }
2323 return 0;
2324 }
2325
2326 /* proto > 0: write in batches of BATCHSIZE. */
2327 do {
2328 /* Get first item */
2329 firstitem = PyIter_Next(iter);
2330 if (firstitem == NULL((void*)0)) {
2331 if (PyErr_Occurred())
2332 goto error;
2333
2334 /* nothing more to add */
2335 break;
2336 }
2337 if (!PyTuple_Check(firstitem)((((((PyObject*)(firstitem))->ob_type))->tp_flags &
((1L<<26))) != 0)
|| PyTuple_Size(firstitem) != 2) {
2338 PyErr_SetString(PyExc_TypeError, "dict items "
2339 "iterator must return 2-tuples");
2340 goto error;
2341 }
2342
2343 /* Try to get a second item */
2344 obj = PyIter_Next(iter);
2345 if (obj == NULL((void*)0)) {
2346 if (PyErr_Occurred())
2347 goto error;
2348
2349 /* Only one item to write */
2350 if (save(self, PyTuple_GET_ITEM(firstitem, 0)(((PyTupleObject *)(firstitem))->ob_item[0]), 0) < 0)
2351 goto error;
2352 if (save(self, PyTuple_GET_ITEM(firstitem, 1)(((PyTupleObject *)(firstitem))->ob_item[1]), 0) < 0)
2353 goto error;
2354 if (_Pickler_Write(self, &setitem_op, 1) < 0)
2355 goto error;
2356 Py_CLEAR(firstitem)do { if (firstitem) { PyObject *_py_tmp = (PyObject *)(firstitem
); (firstitem) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2356, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2357 break;
2358 }
2359
2360 /* More than one item to write */
2361
2362 /* Pump out MARK, items, SETITEMS. */
2363 if (_Pickler_Write(self, &mark_op, 1) < 0)
2364 goto error;
2365
2366 if (save(self, PyTuple_GET_ITEM(firstitem, 0)(((PyTupleObject *)(firstitem))->ob_item[0]), 0) < 0)
2367 goto error;
2368 if (save(self, PyTuple_GET_ITEM(firstitem, 1)(((PyTupleObject *)(firstitem))->ob_item[1]), 0) < 0)
2369 goto error;
2370 Py_CLEAR(firstitem)do { if (firstitem) { PyObject *_py_tmp = (PyObject *)(firstitem
); (firstitem) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2370, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2371 n = 1;
2372
2373 /* Fetch and save up to BATCHSIZE items */
2374 while (obj) {
2375 if (!PyTuple_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1L<<
26))) != 0)
|| PyTuple_Size(obj) != 2) {
2376 PyErr_SetString(PyExc_TypeError, "dict items "
2377 "iterator must return 2-tuples");
2378 goto error;
2379 }
2380 if (save(self, PyTuple_GET_ITEM(obj, 0)(((PyTupleObject *)(obj))->ob_item[0]), 0) < 0 ||
2381 save(self, PyTuple_GET_ITEM(obj, 1)(((PyTupleObject *)(obj))->ob_item[1]), 0) < 0)
2382 goto error;
2383 Py_CLEAR(obj)do { if (obj) { PyObject *_py_tmp = (PyObject *)(obj); (obj) =
((void*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp
))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt
< 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2383, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2384 n += 1;
2385
2386 if (n == BATCHSIZE)
2387 break;
2388
2389 obj = PyIter_Next(iter);
2390 if (obj == NULL((void*)0)) {
2391 if (PyErr_Occurred())
2392 goto error;
2393 break;
2394 }
2395 }
2396
2397 if (_Pickler_Write(self, &setitems_op, 1) < 0)
2398 goto error;
2399
2400 } while (n == BATCHSIZE);
2401 return 0;
2402
2403 error:
2404 Py_XDECREF(firstitem)do { if ((firstitem) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(firstitem))->ob_refcnt != 0) { if (((PyObject
*)firstitem)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2404, (PyObject *)(firstitem)); } else _Py_Dealloc((PyObject
*)(firstitem)); } while (0); } while (0)
;
2405 Py_XDECREF(obj)do { if ((obj) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(obj))->ob_refcnt != 0) { if (((PyObject*)obj
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2405, (PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj
)); } while (0); } while (0)
;
2406 return -1;
2407}
2408
2409/* This is a variant of batch_dict() above that specializes for dicts, with no
2410 * support for dict subclasses. Like batch_dict(), we batch up chunks of
2411 * MARK key value ... key value SETITEMS
2412 * opcode sequences. Calling code should have arranged to first create an
2413 * empty dict, or dict-like object, for the SETITEMS to operate on.
2414 * Returns 0 on success, -1 on error.
2415 *
2416 * Note that this currently doesn't work for protocol 0.
2417 */
2418static int
2419batch_dict_exact(PicklerObject *self, PyObject *obj)
2420{
2421 PyObject *key = NULL((void*)0), *value = NULL((void*)0);
2422 int i;
2423 Py_ssize_t dict_size, ppos = 0;
2424
2425 const char mark_op = MARK;
2426 const char setitem_op = SETITEM;
2427 const char setitems_op = SETITEMS;
2428
2429 assert(obj != NULL)(__builtin_expect(!(obj != ((void*)0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2429,
"obj != NULL") : (void)0)
;
2430 assert(self->proto > 0)(__builtin_expect(!(self->proto > 0), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2430, "self->proto > 0") : (void)0)
;
2431
2432 dict_size = PyDict_Size(obj);
2433
2434 /* Special-case len(d) == 1 to save space. */
2435 if (dict_size == 1) {
2436 PyDict_Next(obj, &ppos, &key, &value);
2437 if (save(self, key, 0) < 0)
2438 return -1;
2439 if (save(self, value, 0) < 0)
2440 return -1;
2441 if (_Pickler_Write(self, &setitem_op, 1) < 0)
2442 return -1;
2443 return 0;
2444 }
2445
2446 /* Write in batches of BATCHSIZE. */
2447 do {
2448 i = 0;
2449 if (_Pickler_Write(self, &mark_op, 1) < 0)
2450 return -1;
2451 while (PyDict_Next(obj, &ppos, &key, &value)) {
2452 if (save(self, key, 0) < 0)
2453 return -1;
2454 if (save(self, value, 0) < 0)
2455 return -1;
2456 if (++i == BATCHSIZE)
2457 break;
2458 }
2459 if (_Pickler_Write(self, &setitems_op, 1) < 0)
2460 return -1;
2461 if (PyDict_Size(obj) != dict_size) {
2462 PyErr_Format(
2463 PyExc_RuntimeError,
2464 "dictionary changed size during iteration");
2465 return -1;
2466 }
2467
2468 } while (i == BATCHSIZE);
2469 return 0;
2470}
2471
2472static int
2473save_dict(PicklerObject *self, PyObject *obj)
2474{
2475 PyObject *items, *iter;
2476 char header[3];
2477 int len;
2478 int status = 0;
2479
2480 if (self->fast && !fast_save_enter(self, obj))
2481 goto error;
2482
2483 /* Create an empty dict. */
2484 if (self->bin) {
2485 header[0] = EMPTY_DICT;
2486 len = 1;
2487 }
2488 else {
2489 header[0] = MARK;
2490 header[1] = DICT;
2491 len = 2;
2492 }
2493
2494 if (_Pickler_Write(self, header, len) < 0)
2495 goto error;
2496
2497 /* Get dict size, and bow out early if empty. */
2498 if ((len = PyDict_Size(obj)) < 0)
2499 goto error;
2500
2501 if (memo_put(self, obj) < 0)
2502 goto error;
2503
2504 if (len != 0) {
2505 /* Save the dict items. */
2506 if (PyDict_CheckExact(obj)((((PyObject*)(obj))->ob_type) == &PyDict_Type) && self->proto > 0) {
2507 /* We can take certain shortcuts if we know this is a dict and
2508 not a dict subclass. */
2509 if (Py_EnterRecursiveCall(" while pickling an object")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while pickling an object"
))
)
2510 goto error;
2511 status = batch_dict_exact(self, obj);
2512 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < ((_Py_CheckRecursionLimit
> 100) ? (_Py_CheckRecursionLimit - 50) : (3 * (_Py_CheckRecursionLimit
>> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
2513 } else {
2514 items = PyObject_CallMethod(obj, "items", "()");
2515 if (items == NULL((void*)0))
2516 goto error;
2517 iter = PyObject_GetIter(items);
2518 Py_DECREF(items)do { if (_Py_RefTotal-- , --((PyObject*)(items))->ob_refcnt
!= 0) { if (((PyObject*)items)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2518, (
PyObject *)(items)); } else _Py_Dealloc((PyObject *)(items));
} while (0)
;
2519 if (iter == NULL((void*)0))
2520 goto error;
2521 if (Py_EnterRecursiveCall(" while pickling an object")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while pickling an object"
))
) {
2522 Py_DECREF(iter)do { if (_Py_RefTotal-- , --((PyObject*)(iter))->ob_refcnt
!= 0) { if (((PyObject*)iter)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2522, (
PyObject *)(iter)); } else _Py_Dealloc((PyObject *)(iter)); }
while (0)
;
2523 goto error;
2524 }
2525 status = batch_dict(self, iter);
2526 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < ((_Py_CheckRecursionLimit
> 100) ? (_Py_CheckRecursionLimit - 50) : (3 * (_Py_CheckRecursionLimit
>> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
2527 Py_DECREF(iter)do { if (_Py_RefTotal-- , --((PyObject*)(iter))->ob_refcnt
!= 0) { if (((PyObject*)iter)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2527, (
PyObject *)(iter)); } else _Py_Dealloc((PyObject *)(iter)); }
while (0)
;
2528 }
2529 }
2530
2531 if (0) {
2532 error:
2533 status = -1;
2534 }
2535
2536 if (self->fast && !fast_save_leave(self, obj))
2537 status = -1;
2538
2539 return status;
2540}
2541
2542static int
2543save_global(PicklerObject *self, PyObject *obj, PyObject *name)
2544{
2545 static PyObject *name_str = NULL((void*)0);
2546 PyObject *global_name = NULL((void*)0);
2547 PyObject *module_name = NULL((void*)0);
2548 PyObject *module = NULL((void*)0);
2549 PyObject *cls;
2550 int status = 0;
2551
2552 const char global_op = GLOBAL;
2553
2554 if (name_str == NULL((void*)0)) {
2555 name_str = PyUnicode_InternFromString("__name__");
2556 if (name_str == NULL((void*)0))
2557 goto error;
2558 }
2559
2560 if (name) {
2561 global_name = name;
2562 Py_INCREF(global_name)( _Py_RefTotal++ , ((PyObject*)(global_name))->ob_refcnt++
)
;
2563 }
2564 else {
2565 global_name = PyObject_GetAttr(obj, name_str);
2566 if (global_name == NULL((void*)0))
2567 goto error;
2568 }
2569
2570 module_name = whichmodule(obj, global_name);
2571 if (module_name == NULL((void*)0))
2572 goto error;
2573
2574 /* XXX: Change to use the import C API directly with level=0 to disallow
2575 relative imports.
2576
2577 XXX: PyImport_ImportModuleLevel could be used. However, this bypasses
2578 builtins.__import__. Therefore, _pickle, unlike pickle.py, will ignore
2579 custom import functions (IMHO, this would be a nice security
2580 feature). The import C API would need to be extended to support the
2581 extra parameters of __import__ to fix that. */
2582 module = PyImport_Import(module_name);
2583 if (module == NULL((void*)0)) {
2584 PyErr_Format(PicklingError,
2585 "Can't pickle %R: import of module %R failed",
2586 obj, module_name);
2587 goto error;
2588 }
2589 cls = PyObject_GetAttr(module, global_name);
2590 if (cls == NULL((void*)0)) {
2591 PyErr_Format(PicklingError,
2592 "Can't pickle %R: attribute lookup %S.%S failed",
2593 obj, module_name, global_name);
2594 goto error;
2595 }
2596 if (cls != obj) {
2597 Py_DECREF(cls)do { if (_Py_RefTotal-- , --((PyObject*)(cls))->ob_refcnt !=
0) { if (((PyObject*)cls)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2597, (
PyObject *)(cls)); } else _Py_Dealloc((PyObject *)(cls)); } while
(0)
;
2598 PyErr_Format(PicklingError,
2599 "Can't pickle %R: it's not the same object as %S.%S",
2600 obj, module_name, global_name);
2601 goto error;
2602 }
2603 Py_DECREF(cls)do { if (_Py_RefTotal-- , --((PyObject*)(cls))->ob_refcnt !=
0) { if (((PyObject*)cls)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2603, (
PyObject *)(cls)); } else _Py_Dealloc((PyObject *)(cls)); } while
(0)
;
2604
2605 if (self->proto >= 2) {
2606 /* See whether this is in the extension registry, and if
2607 * so generate an EXT opcode.
2608 */
2609 PyObject *code_obj; /* extension code as Python object */
2610 long code; /* extension code as C value */
2611 char pdata[5];
2612 int n;
2613
2614 PyTuple_SET_ITEM(two_tuple, 0, module_name)(((PyTupleObject *)(two_tuple))->ob_item[0] = module_name);
2615 PyTuple_SET_ITEM(two_tuple, 1, global_name)(((PyTupleObject *)(two_tuple))->ob_item[1] = global_name);
2616 code_obj = PyDict_GetItem(extension_registry, two_tuple);
2617 /* The object is not registered in the extension registry.
2618 This is the most likely code path. */
2619 if (code_obj == NULL((void*)0))
2620 goto gen_global;
2621
2622 /* XXX: pickle.py doesn't check neither the type, nor the range
2623 of the value returned by the extension_registry. It should for
2624 consistency. */
2625
2626 /* Verify code_obj has the right type and value. */
2627 if (!PyLong_Check(code_obj)((((((PyObject*)(code_obj))->ob_type))->tp_flags & (
(1L<<24))) != 0)
) {
2628 PyErr_Format(PicklingError,
2629 "Can't pickle %R: extension code %R isn't an integer",
2630 obj, code_obj);
2631 goto error;
2632 }
2633 code = PyLong_AS_LONG(code_obj)PyLong_AsLong(code_obj);
2634 if (code <= 0 || code > 0x7fffffffL) {
2635 PyErr_Format(PicklingError,
2636 "Can't pickle %R: extension code %ld is out of range",
2637 obj, code);
2638 goto error;
2639 }
2640
2641 /* Generate an EXT opcode. */
2642 if (code <= 0xff) {
2643 pdata[0] = EXT1;
2644 pdata[1] = (unsigned char)code;
2645 n = 2;
2646 }
2647 else if (code <= 0xffff) {
2648 pdata[0] = EXT2;
2649 pdata[1] = (unsigned char)(code & 0xff);
2650 pdata[2] = (unsigned char)((code >> 8) & 0xff);
2651 n = 3;
2652 }
2653 else {
2654 pdata[0] = EXT4;
2655 pdata[1] = (unsigned char)(code & 0xff);
2656 pdata[2] = (unsigned char)((code >> 8) & 0xff);
2657 pdata[3] = (unsigned char)((code >> 16) & 0xff);
2658 pdata[4] = (unsigned char)((code >> 24) & 0xff);
2659 n = 5;
2660 }
2661
2662 if (_Pickler_Write(self, pdata, n) < 0)
2663 goto error;
2664 }
2665 else {
2666 /* Generate a normal global opcode if we are using a pickle
2667 protocol <= 2, or if the object is not registered in the
2668 extension registry. */
2669 PyObject *encoded;
2670 PyObject *(*unicode_encoder)(PyObject *);
2671
2672 gen_global:
2673 if (_Pickler_Write(self, &global_op, 1) < 0)
2674 goto error;
2675
2676 /* Since Python 3.0 now supports non-ASCII identifiers, we encode both
2677 the module name and the global name using UTF-8. We do so only when
2678 we are using the pickle protocol newer than version 3. This is to
2679 ensure compatibility with older Unpickler running on Python 2.x. */
2680 if (self->proto >= 3) {
2681 unicode_encoder = PyUnicode_AsUTF8StringPyUnicodeUCS2_AsUTF8String;
2682 }
2683 else {
2684 unicode_encoder = PyUnicode_AsASCIIStringPyUnicodeUCS2_AsASCIIString;
2685 }
2686
2687 /* For protocol < 3 and if the user didn't request against doing so,
2688 we convert module names to the old 2.x module names. */
2689 if (self->fix_imports) {
2690 PyObject *key;
2691 PyObject *item;
2692
2693 key = PyTuple_Pack(2, module_name, global_name);
2694 if (key == NULL((void*)0))
2695 goto error;
2696 item = PyDict_GetItemWithError(name_mapping_3to2, key);
2697 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2697, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
2698 if (item) {
2699 if (!PyTuple_Check(item)((((((PyObject*)(item))->ob_type))->tp_flags & ((1L
<<26))) != 0)
|| PyTuple_GET_SIZE(item)(((PyVarObject*)(item))->ob_size) != 2) {
2700 PyErr_Format(PyExc_RuntimeError,
2701 "_compat_pickle.REVERSE_NAME_MAPPING values "
2702 "should be 2-tuples, not %.200s",
2703 Py_TYPE(item)(((PyObject*)(item))->ob_type)->tp_name);
2704 goto error;
2705 }
2706 Py_CLEAR(module_name)do { if (module_name) { PyObject *_py_tmp = (PyObject *)(module_name
); (module_name) = ((void*)0); do { if (_Py_RefTotal-- , --((
PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2706, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2707 Py_CLEAR(global_name)do { if (global_name) { PyObject *_py_tmp = (PyObject *)(global_name
); (global_name) = ((void*)0); do { if (_Py_RefTotal-- , --((
PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2707, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2708 module_name = PyTuple_GET_ITEM(item, 0)(((PyTupleObject *)(item))->ob_item[0]);
2709 global_name = PyTuple_GET_ITEM(item, 1)(((PyTupleObject *)(item))->ob_item[1]);
2710 if (!PyUnicode_Check(module_name)((((((PyObject*)(module_name))->ob_type))->tp_flags &
((1L<<28))) != 0)
||
2711 !PyUnicode_Check(global_name)((((((PyObject*)(global_name))->ob_type))->tp_flags &
((1L<<28))) != 0)
) {
2712 PyErr_Format(PyExc_RuntimeError,
2713 "_compat_pickle.REVERSE_NAME_MAPPING values "
2714 "should be pairs of str, not (%.200s, %.200s)",
2715 Py_TYPE(module_name)(((PyObject*)(module_name))->ob_type)->tp_name,
2716 Py_TYPE(global_name)(((PyObject*)(global_name))->ob_type)->tp_name);
2717 goto error;
2718 }
2719 Py_INCREF(module_name)( _Py_RefTotal++ , ((PyObject*)(module_name))->ob_refcnt++
)
;
2720 Py_INCREF(global_name)( _Py_RefTotal++ , ((PyObject*)(global_name))->ob_refcnt++
)
;
2721 }
2722 else if (PyErr_Occurred()) {
2723 goto error;
2724 }
2725
2726 item = PyDict_GetItemWithError(import_mapping_3to2, module_name);
2727 if (item) {
2728 if (!PyUnicode_Check(item)((((((PyObject*)(item))->ob_type))->tp_flags & ((1L
<<28))) != 0)
) {
2729 PyErr_Format(PyExc_RuntimeError,
2730 "_compat_pickle.REVERSE_IMPORT_MAPPING values "
2731 "should be strings, not %.200s",
2732 Py_TYPE(item)(((PyObject*)(item))->ob_type)->tp_name);
2733 goto error;
2734 }
2735 Py_CLEAR(module_name)do { if (module_name) { PyObject *_py_tmp = (PyObject *)(module_name
); (module_name) = ((void*)0); do { if (_Py_RefTotal-- , --((
PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2735, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
2736 module_name = item;
2737 Py_INCREF(module_name)( _Py_RefTotal++ , ((PyObject*)(module_name))->ob_refcnt++
)
;
2738 }
2739 else if (PyErr_Occurred()) {
2740 goto error;
2741 }
2742 }
2743
2744 /* Save the name of the module. */
2745 encoded = unicode_encoder(module_name);
2746 if (encoded == NULL((void*)0)) {
2747 if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError))
2748 PyErr_Format(PicklingError,
2749 "can't pickle module identifier '%S' using "
2750 "pickle protocol %i", module_name, self->proto);
2751 goto error;
2752 }
2753 if (_Pickler_Write(self, PyBytes_AS_STRING(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2753, "PyBytes_Check(encoded)") : (void)0), (((PyBytesObject
*)(encoded))->ob_sval))
,
2754 PyBytes_GET_SIZE(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2754, "PyBytes_Check(encoded)") : (void)0),(((PyVarObject*)
(encoded))->ob_size))
) < 0) {
2755 Py_DECREF(encoded)do { if (_Py_RefTotal-- , --((PyObject*)(encoded))->ob_refcnt
!= 0) { if (((PyObject*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2755, (
PyObject *)(encoded)); } else _Py_Dealloc((PyObject *)(encoded
)); } while (0)
;
2756 goto error;
2757 }
2758 Py_DECREF(encoded)do { if (_Py_RefTotal-- , --((PyObject*)(encoded))->ob_refcnt
!= 0) { if (((PyObject*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2758, (
PyObject *)(encoded)); } else _Py_Dealloc((PyObject *)(encoded
)); } while (0)
;
2759 if(_Pickler_Write(self, "\n", 1) < 0)
2760 goto error;
2761
2762 /* Save the name of the module. */
2763 encoded = unicode_encoder(global_name);
2764 if (encoded == NULL((void*)0)) {
2765 if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError))
2766 PyErr_Format(PicklingError,
2767 "can't pickle global identifier '%S' using "
2768 "pickle protocol %i", global_name, self->proto);
2769 goto error;
2770 }
2771 if (_Pickler_Write(self, PyBytes_AS_STRING(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2771, "PyBytes_Check(encoded)") : (void)0), (((PyBytesObject
*)(encoded))->ob_sval))
,
2772 PyBytes_GET_SIZE(encoded)((__builtin_expect(!(((((((PyObject*)(encoded))->ob_type))
->tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2772, "PyBytes_Check(encoded)") : (void)0),(((PyVarObject*)
(encoded))->ob_size))
) < 0) {
2773 Py_DECREF(encoded)do { if (_Py_RefTotal-- , --((PyObject*)(encoded))->ob_refcnt
!= 0) { if (((PyObject*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2773, (
PyObject *)(encoded)); } else _Py_Dealloc((PyObject *)(encoded
)); } while (0)
;
2774 goto error;
2775 }
2776 Py_DECREF(encoded)do { if (_Py_RefTotal-- , --((PyObject*)(encoded))->ob_refcnt
!= 0) { if (((PyObject*)encoded)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2776, (
PyObject *)(encoded)); } else _Py_Dealloc((PyObject *)(encoded
)); } while (0)
;
2777 if(_Pickler_Write(self, "\n", 1) < 0)
2778 goto error;
2779
2780 /* Memoize the object. */
2781 if (memo_put(self, obj) < 0)
2782 goto error;
2783 }
2784
2785 if (0) {
2786 error:
2787 status = -1;
2788 }
2789 Py_XDECREF(module_name)do { if ((module_name) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(module_name))->ob_refcnt != 0) { if ((
(PyObject*)module_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2789, (
PyObject *)(module_name)); } else _Py_Dealloc((PyObject *)(module_name
)); } while (0); } while (0)
;
2790 Py_XDECREF(global_name)do { if ((global_name) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(global_name))->ob_refcnt != 0) { if ((
(PyObject*)global_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2790, (
PyObject *)(global_name)); } else _Py_Dealloc((PyObject *)(global_name
)); } while (0); } while (0)
;
2791 Py_XDECREF(module)do { if ((module) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(module))->ob_refcnt != 0) { if (((PyObject
*)module)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2791, (PyObject *)(module)); } else _Py_Dealloc((PyObject *
)(module)); } while (0); } while (0)
;
2792
2793 return status;
2794}
2795
2796static int
2797save_pers(PicklerObject *self, PyObject *obj, PyObject *func)
2798{
2799 PyObject *pid = NULL((void*)0);
2800 int status = 0;
2801
2802 const char persid_op = PERSID;
2803 const char binpersid_op = BINPERSID;
2804
2805 Py_INCREF(obj)( _Py_RefTotal++ , ((PyObject*)(obj))->ob_refcnt++);
2806 pid = _Pickler_FastCall(self, func, obj);
2807 if (pid == NULL((void*)0))
2808 return -1;
2809
2810 if (pid != Py_None(&_Py_NoneStruct)) {
2811 if (self->bin) {
2812 if (save(self, pid, 1) < 0 ||
2813 _Pickler_Write(self, &binpersid_op, 1) < 0)
2814 goto error;
2815 }
2816 else {
2817 PyObject *pid_str = NULL((void*)0);
2818 char *pid_ascii_bytes;
2819 Py_ssize_t size;
2820
2821 pid_str = PyObject_Str(pid);
2822 if (pid_str == NULL((void*)0))
2823 goto error;
2824
2825 /* XXX: Should it check whether the persistent id only contains
2826 ASCII characters? And what if the pid contains embedded
2827 newlines? */
2828 pid_ascii_bytes = _PyUnicode_AsStringAndSize(pid_str, &size);
2829 Py_DECREF(pid_str)do { if (_Py_RefTotal-- , --((PyObject*)(pid_str))->ob_refcnt
!= 0) { if (((PyObject*)pid_str)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2829, (
PyObject *)(pid_str)); } else _Py_Dealloc((PyObject *)(pid_str
)); } while (0)
;
2830 if (pid_ascii_bytes == NULL((void*)0))
2831 goto error;
2832
2833 if (_Pickler_Write(self, &persid_op, 1) < 0 ||
2834 _Pickler_Write(self, pid_ascii_bytes, size) < 0 ||
2835 _Pickler_Write(self, "\n", 1) < 0)
2836 goto error;
2837 }
2838 status = 1;
2839 }
2840
2841 if (0) {
2842 error:
2843 status = -1;
2844 }
2845 Py_XDECREF(pid)do { if ((pid) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(pid))->ob_refcnt != 0) { if (((PyObject*)pid
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 2845, (PyObject *)(pid)); } else _Py_Dealloc((PyObject *)(pid
)); } while (0); } while (0)
;
2846
2847 return status;
2848}
2849
2850/* We're saving obj, and args is the 2-thru-5 tuple returned by the
2851 * appropriate __reduce__ method for obj.
2852 */
2853static int
2854save_reduce(PicklerObject *self, PyObject *args, PyObject *obj)
2855{
2856 PyObject *callable;
2857 PyObject *argtup;
2858 PyObject *state = NULL((void*)0);
2859 PyObject *listitems = Py_None(&_Py_NoneStruct);
2860 PyObject *dictitems = Py_None(&_Py_NoneStruct);
2861 Py_ssize_t size;
2862
2863 int use_newobj = self->proto >= 2;
2864
2865 const char reduce_op = REDUCE;
2866 const char build_op = BUILD;
2867 const char newobj_op = NEWOBJ;
2868
2869 size = PyTuple_Size(args);
2870 if (size < 2 || size > 5) {
1
Taking false branch
2871 PyErr_SetString(PicklingError, "tuple returned by "
2872 "__reduce__ must contain 2 through 5 elements");
2873 return -1;
2874 }
2875
2876 if (!PyArg_UnpackTuple(args, "save_reduce", 2, 5,
2
Taking false branch
2877 &callable, &argtup, &state, &listitems, &dictitems))
2878 return -1;
2879
2880 if (!PyCallable_Check(callable)) {
3
Taking false branch
2881 PyErr_SetString(PicklingError, "first item of the tuple "
2882 "returned by __reduce__ must be callable");
2883 return -1;
2884 }
2885 if (!PyTuple_Check(argtup)((((((PyObject*)(argtup))->ob_type))->tp_flags & ((
1L<<26))) != 0)
) {
4
Taking false branch
2886 PyErr_SetString(PicklingError, "second item of the tuple "
2887 "returned by __reduce__ must be a tuple");
2888 return -1;
2889 }
2890
2891 if (state == Py_None(&_Py_NoneStruct))
5
Taking false branch
2892 state = NULL((void*)0);
2893
2894 if (listitems == Py_None(&_Py_NoneStruct))
6
Taking true branch
2895 listitems = NULL((void*)0);
2896 else if (!PyIter_Check(listitems)((listitems)->ob_type->tp_iternext != ((void*)0) &&
(listitems)->ob_type->tp_iternext != &_PyObject_NextNotImplemented
)
) {
2897 PyErr_Format(PicklingError, "Fourth element of tuple"
2898 "returned by __reduce__ must be an iterator, not %s",
2899 Py_TYPE(listitems)(((PyObject*)(listitems))->ob_type)->tp_name);
2900 return -1;
2901 }
2902
2903 if (dictitems == Py_None(&_Py_NoneStruct))
7
Taking true branch
2904 dictitems = NULL((void*)0);
2905 else if (!PyIter_Check(dictitems)((dictitems)->ob_type->tp_iternext != ((void*)0) &&
(dictitems)->ob_type->tp_iternext != &_PyObject_NextNotImplemented
)
) {
2906 PyErr_Format(PicklingError, "Fifth element of tuple"
2907 "returned by __reduce__ must be an iterator, not %s",
2908 Py_TYPE(dictitems)(((PyObject*)(dictitems))->ob_type)->tp_name);
2909 return -1;
2910 }
2911
2912 /* Protocol 2 special case: if callable's name is __newobj__, use
2913 NEWOBJ. */
2914 if (use_newobj) {
8
Taking true branch
2915 static PyObject *newobj_str = NULL((void*)0);
2916 PyObject *name_str;
2917
2918 if (newobj_str == NULL((void*)0)) {
9
Taking true branch
2919 newobj_str = PyUnicode_InternFromString("__newobj__");
2920 if (newobj_str == NULL((void*)0))
10
Taking false branch
2921 return -1;
2922 }
2923
2924 name_str = PyObject_GetAttrString(callable, "__name__");
2925 if (name_str == NULL((void*)0)) {
11
Taking false branch
2926 if (PyErr_ExceptionMatches(PyExc_AttributeError))
2927 PyErr_Clear();
2928 else
2929 return -1;
2930 use_newobj = 0;
2931 }
2932 else {
2933 use_newobj = PyUnicode_Check(name_str)((((((PyObject*)(name_str))->ob_type))->tp_flags & (
(1L<<28))) != 0)
&&
2934 PyUnicode_ComparePyUnicodeUCS2_Compare(name_str, newobj_str) == 0;
2935 Py_DECREF(name_str)do { if (_Py_RefTotal-- , --((PyObject*)(name_str))->ob_refcnt
!= 0) { if (((PyObject*)name_str)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2935, (
PyObject *)(name_str)); } else _Py_Dealloc((PyObject *)(name_str
)); } while (0)
;
2936 }
2937 }
2938 if (use_newobj) {
12
Taking true branch
2939 PyObject *cls;
2940 PyObject *newargtup;
2941 PyObject *obj_class;
2942 int p;
2943
2944 /* Sanity checks. */
2945 if (Py_SIZE(argtup)(((PyVarObject*)(argtup))->ob_size) < 1) {
13
Taking false branch
2946 PyErr_SetString(PicklingError, "__newobj__ arglist is empty");
2947 return -1;
2948 }
2949
2950 cls = PyTuple_GET_ITEM(argtup, 0)(((PyTupleObject *)(argtup))->ob_item[0]);
2951 if (!PyObject_HasAttrString(cls, "__new__")) {
14
Taking false branch
2952 PyErr_SetString(PicklingError, "args[0] from "
2953 "__newobj__ args has no __new__");
2954 return -1;
2955 }
2956
2957 if (obj != NULL((void*)0)) {
15
Taking true branch
2958 obj_class = PyObject_GetAttrString(obj, "__class__");
2959 if (obj_class == NULL((void*)0)) {
16
Taking true branch
2960 if (PyErr_ExceptionMatches(PyExc_AttributeError))
17
Taking true branch
2961 PyErr_Clear();
2962 else
2963 return -1;
2964 }
2965 p = obj_class != cls; /* true iff a problem */
2966 Py_DECREF(obj_class)do { if (_Py_RefTotal-- , --((PyObject*)(obj_class))->ob_refcnt
!= 0) { if (((PyObject*)obj_class)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 2966, (
PyObject *)(obj_class)); } else _Py_Dealloc((PyObject *)(obj_class
)); } while (0)
;
18
Within the expansion of the macro 'Py_DECREF':
a
Access to field 'ob_refcnt' results in a dereference of a null pointer (loaded from variable 'obj_class')
2967 if (p) {
2968 PyErr_SetString(PicklingError, "args[0] from "
2969 "__newobj__ args has the wrong class");
2970 return -1;
2971 }
2972 }
2973 /* XXX: These calls save() are prone to infinite recursion. Imagine
2974 what happen if the value returned by the __reduce__() method of
2975 some extension type contains another object of the same type. Ouch!
2976
2977 Here is a quick example, that I ran into, to illustrate what I
2978 mean:
2979
2980 >>> import pickle, copyreg
2981 >>> copyreg.dispatch_table.pop(complex)
2982 >>> pickle.dumps(1+2j)
2983 Traceback (most recent call last):
2984 ...
2985 RuntimeError: maximum recursion depth exceeded
2986
2987 Removing the complex class from copyreg.dispatch_table made the
2988 __reduce_ex__() method emit another complex object:
2989
2990 >>> (1+1j).__reduce_ex__(2)
2991 (<function __newobj__ at 0xb7b71c3c>,
2992 (<class 'complex'>, (1+1j)), None, None, None)
2993
2994 Thus when save() was called on newargstup (the 2nd item) recursion
2995 ensued. Of course, the bug was in the complex class which had a
2996 broken __getnewargs__() that emitted another complex object. But,
2997 the point, here, is it is quite easy to end up with a broken reduce
2998 function. */
2999
3000 /* Save the class and its __new__ arguments. */
3001 if (save(self, cls, 0) < 0)
3002 return -1;
3003
3004 newargtup = PyTuple_GetSlice(argtup, 1, Py_SIZE(argtup)(((PyVarObject*)(argtup))->ob_size));
3005 if (newargtup == NULL((void*)0))
3006 return -1;
3007
3008 p = save(self, newargtup, 0);
3009 Py_DECREF(newargtup)do { if (_Py_RefTotal-- , --((PyObject*)(newargtup))->ob_refcnt
!= 0) { if (((PyObject*)newargtup)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3009, (
PyObject *)(newargtup)); } else _Py_Dealloc((PyObject *)(newargtup
)); } while (0)
;
3010 if (p < 0)
3011 return -1;
3012
3013 /* Add NEWOBJ opcode. */
3014 if (_Pickler_Write(self, &newobj_op, 1) < 0)
3015 return -1;
3016 }
3017 else { /* Not using NEWOBJ. */
3018 if (save(self, callable, 0) < 0 ||
3019 save(self, argtup, 0) < 0 ||
3020 _Pickler_Write(self, &reduce_op, 1) < 0)
3021 return -1;
3022 }
3023
3024 /* obj can be NULL when save_reduce() is used directly. A NULL obj means
3025 the caller do not want to memoize the object. Not particularly useful,
3026 but that is to mimic the behavior save_reduce() in pickle.py when
3027 obj is None. */
3028 if (obj && memo_put(self, obj) < 0)
3029 return -1;
3030
3031 if (listitems && batch_list(self, listitems) < 0)
3032 return -1;
3033
3034 if (dictitems && batch_dict(self, dictitems) < 0)
3035 return -1;
3036
3037 if (state) {
3038 if (save(self, state, 0) < 0 ||
3039 _Pickler_Write(self, &build_op, 1) < 0)
3040 return -1;
3041 }
3042
3043 return 0;
3044}
3045
3046static int
3047save(PicklerObject *self, PyObject *obj, int pers_save)
3048{
3049 PyTypeObject *type;
3050 PyObject *reduce_func = NULL((void*)0);
3051 PyObject *reduce_value = NULL((void*)0);
3052 int status = 0;
3053
3054 if (Py_EnterRecursiveCall(" while pickling an object")((++(PyThreadState_Get()->recursion_depth) > _Py_CheckRecursionLimit
) && _Py_CheckRecursiveCall(" while pickling an object"
))
)
3055 return -1;
3056
3057 /* The extra pers_save argument is necessary to avoid calling save_pers()
3058 on its returned object. */
3059 if (!pers_save && self->pers_func) {
3060 /* save_pers() returns:
3061 -1 to signal an error;
3062 0 if it did nothing successfully;
3063 1 if a persistent id was saved.
3064 */
3065 if ((status = save_pers(self, obj, self->pers_func)) != 0)
3066 goto done;
3067 }
3068
3069 type = Py_TYPE(obj)(((PyObject*)(obj))->ob_type);
3070
3071 /* The old cPickle had an optimization that used switch-case statement
3072 dispatching on the first letter of the type name. This has was removed
3073 since benchmarks shown that this optimization was actually slowing
3074 things down. */
3075
3076 /* Atom types; these aren't memoized, so don't check the memo. */
3077
3078 if (obj == Py_None(&_Py_NoneStruct)) {
3079 status = save_none(self, obj);
3080 goto done;
3081 }
3082 else if (obj == Py_False((PyObject *) &_Py_FalseStruct) || obj == Py_True((PyObject *) &_Py_TrueStruct)) {
3083 status = save_bool(self, obj);
3084 goto done;
3085 }
3086 else if (type == &PyLong_Type) {
3087 status = save_long(self, obj);
3088 goto done;
3089 }
3090 else if (type == &PyFloat_Type) {
3091 status = save_float(self, obj);
3092 goto done;
3093 }
3094
3095 /* Check the memo to see if it has the object. If so, generate
3096 a GET (or BINGET) opcode, instead of pickling the object
3097 once again. */
3098 if (PyMemoTable_Get(self->memo, obj)) {
3099 if (memo_get(self, obj) < 0)
3100 goto error;
3101 goto done;
3102 }
3103
3104 if (type == &PyBytes_Type) {
3105 status = save_bytes(self, obj);
3106 goto done;
3107 }
3108 else if (type == &PyUnicode_Type) {
3109 status = save_unicode(self, obj);
3110 goto done;
3111 }
3112 else if (type == &PyDict_Type) {
3113 status = save_dict(self, obj);
3114 goto done;
3115 }
3116 else if (type == &PyList_Type) {
3117 status = save_list(self, obj);
3118 goto done;
3119 }
3120 else if (type == &PyTuple_Type) {
3121 status = save_tuple(self, obj);
3122 goto done;
3123 }
3124 else if (type == &PyType_Type) {
3125 status = save_global(self, obj, NULL((void*)0));
3126 goto done;
3127 }
3128 else if (type == &PyFunction_Type) {
3129 status = save_global(self, obj, NULL((void*)0));
3130 if (status < 0 && PyErr_ExceptionMatches(PickleError)) {
3131 /* fall back to reduce */
3132 PyErr_Clear();
3133 }
3134 else {
3135 goto done;
3136 }
3137 }
3138 else if (type == &PyCFunction_Type) {
3139 status = save_global(self, obj, NULL((void*)0));
3140 goto done;
3141 }
3142 else if (PyType_IsSubtype(type, &PyType_Type)) {
3143 status = save_global(self, obj, NULL((void*)0));
3144 goto done;
3145 }
3146
3147 /* XXX: This part needs some unit tests. */
3148
3149 /* Get a reduction callable, and call it. This may come from
3150 * copyreg.dispatch_table, the object's __reduce_ex__ method,
3151 * or the object's __reduce__ method.
3152 */
3153 reduce_func = PyDict_GetItem(dispatch_table, (PyObject *)type);
3154 if (reduce_func != NULL((void*)0)) {
3155 /* Here, the reference count of the reduce_func object returned by
3156 PyDict_GetItem needs to be increased to be consistent with the one
3157 returned by PyObject_GetAttr. This is allow us to blindly DECREF
3158 reduce_func at the end of the save() routine.
3159 */
3160 Py_INCREF(reduce_func)( _Py_RefTotal++ , ((PyObject*)(reduce_func))->ob_refcnt++
)
;
3161 Py_INCREF(obj)( _Py_RefTotal++ , ((PyObject*)(obj))->ob_refcnt++);
3162 reduce_value = _Pickler_FastCall(self, reduce_func, obj);
3163 }
3164 else {
3165 static PyObject *reduce_str = NULL((void*)0);
3166 static PyObject *reduce_ex_str = NULL((void*)0);
3167
3168 /* Cache the name of the reduce methods. */
3169 if (reduce_str == NULL((void*)0)) {
3170 reduce_str = PyUnicode_InternFromString("__reduce__");
3171 if (reduce_str == NULL((void*)0))
3172 goto error;
3173 reduce_ex_str = PyUnicode_InternFromString("__reduce_ex__");
3174 if (reduce_ex_str == NULL((void*)0))
3175 goto error;
3176 }
3177
3178 /* XXX: If the __reduce__ method is defined, __reduce_ex__ is
3179 automatically defined as __reduce__. While this is convenient, this
3180 make it impossible to know which method was actually called. Of
3181 course, this is not a big deal. But still, it would be nice to let
3182 the user know which method was called when something go
3183 wrong. Incidentally, this means if __reduce_ex__ is not defined, we
3184 don't actually have to check for a __reduce__ method. */
3185
3186 /* Check for a __reduce_ex__ method. */
3187 reduce_func = PyObject_GetAttr(obj, reduce_ex_str);
3188 if (reduce_func != NULL((void*)0)) {
3189 PyObject *proto;
3190 proto = PyLong_FromLong(self->proto);
3191 if (proto != NULL((void*)0)) {
3192 reduce_value = _Pickler_FastCall(self, reduce_func, proto);
3193 }
3194 }
3195 else {
3196 if (PyErr_ExceptionMatches(PyExc_AttributeError))
3197 PyErr_Clear();
3198 else
3199 goto error;
3200 /* Check for a __reduce__ method. */
3201 reduce_func = PyObject_GetAttr(obj, reduce_str);
3202 if (reduce_func != NULL((void*)0)) {
3203 reduce_value = PyObject_Call(reduce_func, empty_tuple, NULL((void*)0));
3204 }
3205 else {
3206 PyErr_Format(PicklingError, "can't pickle '%.200s' object: %R",
3207 type->tp_name, obj);
3208 goto error;
3209 }
3210 }
3211 }
3212
3213 if (reduce_value == NULL((void*)0))
3214 goto error;
3215
3216 if (PyUnicode_Check(reduce_value)((((((PyObject*)(reduce_value))->ob_type))->tp_flags &
((1L<<28))) != 0)
) {
3217 status = save_global(self, obj, reduce_value);
3218 goto done;
3219 }
3220
3221 if (!PyTuple_Check(reduce_value)((((((PyObject*)(reduce_value))->ob_type))->tp_flags &
((1L<<26))) != 0)
) {
3222 PyErr_SetString(PicklingError,
3223 "__reduce__ must return a string or tuple");
3224 goto error;
3225 }
3226
3227 status = save_reduce(self, reduce_value, obj);
3228
3229 if (0) {
3230 error:
3231 status = -1;
3232 }
3233 done:
3234 Py_LeaveRecursiveCall()do{ if((--(PyThreadState_Get()->recursion_depth) < ((_Py_CheckRecursionLimit
> 100) ? (_Py_CheckRecursionLimit - 50) : (3 * (_Py_CheckRecursionLimit
>> 2))))) PyThreadState_Get()->overflowed = 0; } while
(0)
;
3235 Py_XDECREF(reduce_func)do { if ((reduce_func) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(reduce_func))->ob_refcnt != 0) { if ((
(PyObject*)reduce_func)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3235, (
PyObject *)(reduce_func)); } else _Py_Dealloc((PyObject *)(reduce_func
)); } while (0); } while (0)
;
3236 Py_XDECREF(reduce_value)do { if ((reduce_value) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(reduce_value))->ob_refcnt != 0) { if (
((PyObject*)reduce_value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3236, (
PyObject *)(reduce_value)); } else _Py_Dealloc((PyObject *)(reduce_value
)); } while (0); } while (0)
;
3237
3238 return status;
3239}
3240
3241static int
3242dump(PicklerObject *self, PyObject *obj)
3243{
3244 const char stop_op = STOP;
3245
3246 if (self->proto >= 2) {
3247 char header[2];
3248
3249 header[0] = PROTO;
3250 assert(self->proto >= 0 && self->proto < 256)(__builtin_expect(!(self->proto >= 0 && self->
proto < 256), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3250, "self->proto >= 0 && self->proto < 256"
) : (void)0)
;
3251 header[1] = (unsigned char)self->proto;
3252 if (_Pickler_Write(self, header, 2) < 0)
3253 return -1;
3254 }
3255
3256 if (save(self, obj, 0) < 0 ||
3257 _Pickler_Write(self, &stop_op, 1) < 0)
3258 return -1;
3259
3260 return 0;
3261}
3262
3263PyDoc_STRVAR(Pickler_clear_memo_doc,static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3264"clear_memo() -> None. Clears the pickler's \"memo\"."static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3265"\n"static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3266"The memo is the data structure that remembers which objects the\n"static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3267"pickler has already seen, so that shared or recursive objects are\n"static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3268"pickled by reference and not by value. This method is useful when\n"static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
3269"re-using picklers.")static char Pickler_clear_memo_doc[] = "clear_memo() -> None. Clears the pickler's \"memo\"."
"\n""The memo is the data structure that remembers which objects the\n"
"pickler has already seen, so that shared or recursive objects are\n"
"pickled by reference and not by value. This method is useful when\n"
"re-using picklers."
;
3270
3271static PyObject *
3272Pickler_clear_memo(PicklerObject *self)
3273{
3274 if (self->memo)
3275 PyMemoTable_Clear(self->memo);
3276
3277 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
3278}
3279
3280PyDoc_STRVAR(Pickler_dump_doc,static char Pickler_dump_doc[] = "dump(obj) -> None. Write a pickled representation of obj to the open file."
3281"dump(obj) -> None. Write a pickled representation of obj to the open file.")static char Pickler_dump_doc[] = "dump(obj) -> None. Write a pickled representation of obj to the open file.";
3282
3283static PyObject *
3284Pickler_dump(PicklerObject *self, PyObject *args)
3285{
3286 PyObject *obj;
3287
3288 /* Check whether the Pickler was initialized correctly (issue3664).
3289 Developers often forget to call __init__() in their subclasses, which
3290 would trigger a segfault without this check. */
3291 if (self->write == NULL((void*)0)) {
3292 PyErr_Format(PicklingError,
3293 "Pickler.__init__() was not called by %s.__init__()",
3294 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_name);
3295 return NULL((void*)0);
3296 }
3297
3298 if (!PyArg_ParseTuple(args, "O:dump", &obj))
3299 return NULL((void*)0);
3300
3301 if (_Pickler_ClearBuffer(self) < 0)
3302 return NULL((void*)0);
3303
3304 if (dump(self, obj) < 0)
3305 return NULL((void*)0);
3306
3307 if (_Pickler_FlushToFile(self) < 0)
3308 return NULL((void*)0);
3309
3310 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
3311}
3312
3313static struct PyMethodDef Pickler_methods[] = {
3314 {"dump", (PyCFunction)Pickler_dump, METH_VARARGS0x0001,
3315 Pickler_dump_doc},
3316 {"clear_memo", (PyCFunction)Pickler_clear_memo, METH_NOARGS0x0004,
3317 Pickler_clear_memo_doc},
3318 {NULL((void*)0), NULL((void*)0)} /* sentinel */
3319};
3320
3321static void
3322Pickler_dealloc(PicklerObject *self)
3323{
3324 PyObject_GC_UnTrack(self);
3325
3326 Py_XDECREF(self->output_buffer)do { if ((self->output_buffer) == ((void*)0)) ; else do { if
(_Py_RefTotal-- , --((PyObject*)(self->output_buffer))->
ob_refcnt != 0) { if (((PyObject*)self->output_buffer)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3326, (PyObject *)(self->output_buffer)); } else _Py_Dealloc
((PyObject *)(self->output_buffer)); } while (0); } while (
0)
;
3327 Py_XDECREF(self->write)do { if ((self->write) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->write))->ob_refcnt != 0) { if
(((PyObject*)self->write)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3327, (
PyObject *)(self->write)); } else _Py_Dealloc((PyObject *)
(self->write)); } while (0); } while (0)
;
3328 Py_XDECREF(self->pers_func)do { if ((self->pers_func) == ((void*)0)) ; else do { if (
_Py_RefTotal-- , --((PyObject*)(self->pers_func))->ob_refcnt
!= 0) { if (((PyObject*)self->pers_func)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3328, (PyObject *)(self->pers_func)); } else _Py_Dealloc
((PyObject *)(self->pers_func)); } while (0); } while (0)
;
3329 Py_XDECREF(self->arg)do { if ((self->arg) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->arg))->ob_refcnt != 0) { if (
((PyObject*)self->arg)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3329, (
PyObject *)(self->arg)); } else _Py_Dealloc((PyObject *)(self
->arg)); } while (0); } while (0)
;
3330 Py_XDECREF(self->fast_memo)do { if ((self->fast_memo) == ((void*)0)) ; else do { if (
_Py_RefTotal-- , --((PyObject*)(self->fast_memo))->ob_refcnt
!= 0) { if (((PyObject*)self->fast_memo)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3330, (PyObject *)(self->fast_memo)); } else _Py_Dealloc
((PyObject *)(self->fast_memo)); } while (0); } while (0)
;
3331
3332 PyMemoTable_Del(self->memo);
3333
3334 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free((PyObject *)self);
3335}
3336
3337static int
3338Pickler_traverse(PicklerObject *self, visitproc visit, void *arg)
3339{
3340 Py_VISIT(self->write)do { if (self->write) { int vret = visit((PyObject *)(self
->write), arg); if (vret) return vret; } } while (0)
;
3341 Py_VISIT(self->pers_func)do { if (self->pers_func) { int vret = visit((PyObject *)(
self->pers_func), arg); if (vret) return vret; } } while (
0)
;
3342 Py_VISIT(self->arg)do { if (self->arg) { int vret = visit((PyObject *)(self->
arg), arg); if (vret) return vret; } } while (0)
;
3343 Py_VISIT(self->fast_memo)do { if (self->fast_memo) { int vret = visit((PyObject *)(
self->fast_memo), arg); if (vret) return vret; } } while (
0)
;
3344 return 0;
3345}
3346
3347static int
3348Pickler_clear(PicklerObject *self)
3349{
3350 Py_CLEAR(self->output_buffer)do { if (self->output_buffer) { PyObject *_py_tmp = (PyObject
*)(self->output_buffer); (self->output_buffer) = ((void
*)0); do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->
ob_refcnt != 0) { if (((PyObject*)_py_tmp)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3350, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
3351 Py_CLEAR(self->write)do { if (self->write) { PyObject *_py_tmp = (PyObject *)(self
->write); (self->write) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3351, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
3352 Py_CLEAR(self->pers_func)do { if (self->pers_func) { PyObject *_py_tmp = (PyObject *
)(self->pers_func); (self->pers_func) = ((void*)0); do {
if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt !=
0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3352, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
3353 Py_CLEAR(self->arg)do { if (self->arg) { PyObject *_py_tmp = (PyObject *)(self
->arg); (self->arg) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3353, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
3354 Py_CLEAR(self->fast_memo)do { if (self->fast_memo) { PyObject *_py_tmp = (PyObject *
)(self->fast_memo); (self->fast_memo) = ((void*)0); do {
if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt !=
0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3354, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
3355
3356 if (self->memo != NULL((void*)0)) {
3357 PyMemoTable *memo = self->memo;
3358 self->memo = NULL((void*)0);
3359 PyMemoTable_Del(memo);
3360 }
3361 return 0;
3362}
3363
3364
3365PyDoc_STRVAR(Pickler_doc,static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3366"Pickler(file, protocol=None)"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3367"\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3368"This takes a binary file for writing a pickle data stream.\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3369"\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3370"The optional protocol argument tells the pickler to use the\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3371"given protocol; supported protocols are 0, 1, 2, 3. The default\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3372"protocol is 3; a backward-incompatible protocol designed for\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3373"Python 3.0.\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3374"\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3375"Specifying a negative protocol version selects the highest\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3376"protocol version supported. The higher the protocol used, the\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3377"more recent the version of Python needed to read the pickle\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3378"produced.\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3379"\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3380"The file argument must have a write() method that accepts a single\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3381"bytes argument. It can thus be a file object opened for binary\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3382"writing, a io.BytesIO instance, or any other custom object that\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3383"meets this interface.\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3384"\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3385"If fix_imports is True and protocol is less than 3, pickle will try to\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3386"map the new Python 3.x names to the old module names used in Python\n"static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
3387"2.x, so that the pickle data stream is readable with Python 2.x.\n")static char Pickler_doc[] = "Pickler(file, protocol=None)""\n"
"This takes a binary file for writing a pickle data stream.\n"
"\n""The optional protocol argument tells the pickler to use the\n"
"given protocol; supported protocols are 0, 1, 2, 3. The default\n"
"protocol is 3; a backward-incompatible protocol designed for\n"
"Python 3.0.\n""\n""Specifying a negative protocol version selects the highest\n"
"protocol version supported. The higher the protocol used, the\n"
"more recent the version of Python needed to read the pickle\n"
"produced.\n""\n""The file argument must have a write() method that accepts a single\n"
"bytes argument. It can thus be a file object opened for binary\n"
"writing, a io.BytesIO instance, or any other custom object that\n"
"meets this interface.\n""\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python\n"
"2.x, so that the pickle data stream is readable with Python 2.x.\n"
;
3388
3389static int
3390Pickler_init(PicklerObject *self, PyObject *args, PyObject *kwds)
3391{
3392 static char *kwlist[] = {"file", "protocol", "fix_imports", 0};
3393 PyObject *file;
3394 PyObject *proto_obj = NULL((void*)0);
3395 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
3396
3397 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:Pickler",
3398 kwlist, &file, &proto_obj, &fix_imports))
3399 return -1;
3400
3401 /* In case of multiple __init__() calls, clear previous content. */
3402 if (self->write != NULL((void*)0))
3403 (void)Pickler_clear(self);
3404
3405 if (_Pickler_SetProtocol(self, proto_obj, fix_imports) < 0)
3406 return -1;
3407
3408 if (_Pickler_SetOutputStream(self, file) < 0)
3409 return -1;
3410
3411 /* memo and output_buffer may have already been created in _Pickler_New */
3412 if (self->memo == NULL((void*)0)) {
3413 self->memo = PyMemoTable_New();
3414 if (self->memo == NULL((void*)0))
3415 return -1;
3416 }
3417 self->output_len = 0;
3418 if (self->output_buffer == NULL((void*)0)) {
3419 self->max_output_len = WRITE_BUF_SIZE;
3420 self->output_buffer = PyBytes_FromStringAndSize(NULL((void*)0),
3421 self->max_output_len);
3422 if (self->output_buffer == NULL((void*)0))
3423 return -1;
3424 }
3425
3426 self->arg = NULL((void*)0);
3427 self->fast = 0;
3428 self->fast_nesting = 0;
3429 self->fast_memo = NULL((void*)0);
3430 self->pers_func = NULL((void*)0);
3431 if (PyObject_HasAttrString((PyObject *)self, "persistent_id")) {
3432 self->pers_func = PyObject_GetAttrString((PyObject *)self,
3433 "persistent_id");
3434 if (self->pers_func == NULL((void*)0))
3435 return -1;
3436 }
3437 return 0;
3438}
3439
3440/* Define a proxy object for the Pickler's internal memo object. This is to
3441 * avoid breaking code like:
3442 * pickler.memo.clear()
3443 * and
3444 * pickler.memo = saved_memo
3445 * Is this a good idea? Not really, but we don't want to break code that uses
3446 * it. Note that we don't implement the entire mapping API here. This is
3447 * intentional, as these should be treated as black-box implementation details.
3448 */
3449
3450typedef struct {
3451 PyObject_HEADPyObject ob_base;
3452 PicklerObject *pickler; /* Pickler whose memo table we're proxying. */
3453} PicklerMemoProxyObject;
3454
3455PyDoc_STRVAR(pmp_clear_doc,static char pmp_clear_doc[] = "memo.clear() -> None. Remove all items from memo."
3456"memo.clear() -> None. Remove all items from memo.")static char pmp_clear_doc[] = "memo.clear() -> None. Remove all items from memo.";
3457
3458static PyObject *
3459pmp_clear(PicklerMemoProxyObject *self)
3460{
3461 if (self->pickler->memo)
3462 PyMemoTable_Clear(self->pickler->memo);
3463 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
3464}
3465
3466PyDoc_STRVAR(pmp_copy_doc,static char pmp_copy_doc[] = "memo.copy() -> new_memo. Copy the memo to a new object."
3467"memo.copy() -> new_memo. Copy the memo to a new object.")static char pmp_copy_doc[] = "memo.copy() -> new_memo. Copy the memo to a new object.";
3468
3469static PyObject *
3470pmp_copy(PicklerMemoProxyObject *self)
3471{
3472 Py_ssize_t i;
3473 PyMemoTable *memo;
3474 PyObject *new_memo = PyDict_New();
3475 if (new_memo == NULL((void*)0))
3476 return NULL((void*)0);
3477
3478 memo = self->pickler->memo;
3479 for (i = 0; i < memo->mt_allocated; ++i) {
3480 PyMemoEntry entry = memo->mt_table[i];
3481 if (entry.me_key != NULL((void*)0)) {
3482 int status;
3483 PyObject *key, *value;
3484
3485 key = PyLong_FromVoidPtr(entry.me_key);
3486 value = Py_BuildValue("lO", entry.me_value, entry.me_key);
3487
3488 if (key == NULL((void*)0) || value == NULL((void*)0)) {
3489 Py_XDECREF(key)do { if ((key) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(key))->ob_refcnt != 0) { if (((PyObject*)key
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3489, (PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key
)); } while (0); } while (0)
;
3490 Py_XDECREF(value)do { if ((value) == ((void*)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(value))->ob_refcnt != 0) { if (((PyObject
*)value)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3490, (PyObject *)(value)); } else _Py_Dealloc((PyObject *)
(value)); } while (0); } while (0)
;
3491 goto error;
3492 }
3493 status = PyDict_SetItem(new_memo, key, value);
3494 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3494, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
3495 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3495, (
PyObject *)(value)); } else _Py_Dealloc((PyObject *)(value));
} while (0)
;
3496 if (status < 0)
3497 goto error;
3498 }
3499 }
3500 return new_memo;
3501
3502 error:
3503 Py_XDECREF(new_memo)do { if ((new_memo) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(new_memo))->ob_refcnt != 0) { if (((PyObject
*)new_memo)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3503, (PyObject *)(new_memo)); } else _Py_Dealloc((PyObject
*)(new_memo)); } while (0); } while (0)
;
3504 return NULL((void*)0);
3505}
3506
3507PyDoc_STRVAR(pmp_reduce_doc,static char pmp_reduce_doc[] = "memo.__reduce__(). Pickling support."
3508"memo.__reduce__(). Pickling support.")static char pmp_reduce_doc[] = "memo.__reduce__(). Pickling support.";
3509
3510static PyObject *
3511pmp_reduce(PicklerMemoProxyObject *self, PyObject *args)
3512{
3513 PyObject *reduce_value, *dict_args;
3514 PyObject *contents = pmp_copy(self);
3515 if (contents == NULL((void*)0))
3516 return NULL((void*)0);
3517
3518 reduce_value = PyTuple_New(2);
3519 if (reduce_value == NULL((void*)0)) {
3520 Py_DECREF(contents)do { if (_Py_RefTotal-- , --((PyObject*)(contents))->ob_refcnt
!= 0) { if (((PyObject*)contents)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3520, (
PyObject *)(contents)); } else _Py_Dealloc((PyObject *)(contents
)); } while (0)
;
3521 return NULL((void*)0);
3522 }
3523 dict_args = PyTuple_New(1);
3524 if (dict_args == NULL((void*)0)) {
3525 Py_DECREF(contents)do { if (_Py_RefTotal-- , --((PyObject*)(contents))->ob_refcnt
!= 0) { if (((PyObject*)contents)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3525, (
PyObject *)(contents)); } else _Py_Dealloc((PyObject *)(contents
)); } while (0)
;
3526 Py_DECREF(reduce_value)do { if (_Py_RefTotal-- , --((PyObject*)(reduce_value))->ob_refcnt
!= 0) { if (((PyObject*)reduce_value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3526, (
PyObject *)(reduce_value)); } else _Py_Dealloc((PyObject *)(reduce_value
)); } while (0)
;
3527 return NULL((void*)0);
3528 }
3529 PyTuple_SET_ITEM(dict_args, 0, contents)(((PyTupleObject *)(dict_args))->ob_item[0] = contents);
3530 Py_INCREF((PyObject *)&PyDict_Type)( _Py_RefTotal++ , ((PyObject*)((PyObject *)&PyDict_Type)
)->ob_refcnt++)
;
3531 PyTuple_SET_ITEM(reduce_value, 0, (PyObject *)&PyDict_Type)(((PyTupleObject *)(reduce_value))->ob_item[0] = (PyObject
*)&PyDict_Type)
;
3532 PyTuple_SET_ITEM(reduce_value, 1, dict_args)(((PyTupleObject *)(reduce_value))->ob_item[1] = dict_args
)
;
3533 return reduce_value;
3534}
3535
3536static PyMethodDef picklerproxy_methods[] = {
3537 {"clear", (PyCFunction)pmp_clear, METH_NOARGS0x0004, pmp_clear_doc},
3538 {"copy", (PyCFunction)pmp_copy, METH_NOARGS0x0004, pmp_copy_doc},
3539 {"__reduce__", (PyCFunction)pmp_reduce, METH_VARARGS0x0001, pmp_reduce_doc},
3540 {NULL((void*)0), NULL((void*)0)} /* sentinel */
3541};
3542
3543static void
3544PicklerMemoProxy_dealloc(PicklerMemoProxyObject *self)
3545{
3546 PyObject_GC_UnTrack(self);
3547 Py_XDECREF(self->pickler)do { if ((self->pickler) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->pickler))->ob_refcnt != 0) { if
(((PyObject*)self->pickler)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3547, (
PyObject *)(self->pickler)); } else _Py_Dealloc((PyObject *
)(self->pickler)); } while (0); } while (0)
;
3548 PyObject_GC_Del((PyObject *)self);
3549}
3550
3551static int
3552PicklerMemoProxy_traverse(PicklerMemoProxyObject *self,
3553 visitproc visit, void *arg)
3554{
3555 Py_VISIT(self->pickler)do { if (self->pickler) { int vret = visit((PyObject *)(self
->pickler), arg); if (vret) return vret; } } while (0)
;
3556 return 0;
3557}
3558
3559static int
3560PicklerMemoProxy_clear(PicklerMemoProxyObject *self)
3561{
3562 Py_CLEAR(self->pickler)do { if (self->pickler) { PyObject *_py_tmp = (PyObject *)
(self->pickler); (self->pickler) = ((void*)0); do { if (
_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0)
{ if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 3562, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
3563 return 0;
3564}
3565
3566static PyTypeObject PicklerMemoProxyType = {
3567 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
3568 "_pickle.PicklerMemoProxy", /*tp_name*/
3569 sizeof(PicklerMemoProxyObject), /*tp_basicsize*/
3570 0,
3571 (destructor)PicklerMemoProxy_dealloc, /* tp_dealloc */
3572 0, /* tp_print */
3573 0, /* tp_getattr */
3574 0, /* tp_setattr */
3575 0, /* tp_compare */
3576 0, /* tp_repr */
3577 0, /* tp_as_number */
3578 0, /* tp_as_sequence */
3579 0, /* tp_as_mapping */
3580 PyObject_HashNotImplemented, /* tp_hash */
3581 0, /* tp_call */
3582 0, /* tp_str */
3583 PyObject_GenericGetAttr, /* tp_getattro */
3584 PyObject_GenericSetAttr, /* tp_setattro */
3585 0, /* tp_as_buffer */
3586 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_BASETYPE(1L<<10) | Py_TPFLAGS_HAVE_GC(1L<<14),
3587 0, /* tp_doc */
3588 (traverseproc)PicklerMemoProxy_traverse, /* tp_traverse */
3589 (inquiry)PicklerMemoProxy_clear, /* tp_clear */
3590 0, /* tp_richcompare */
3591 0, /* tp_weaklistoffset */
3592 0, /* tp_iter */
3593 0, /* tp_iternext */
3594 picklerproxy_methods, /* tp_methods */
3595};
3596
3597static PyObject *
3598PicklerMemoProxy_New(PicklerObject *pickler)
3599{
3600 PicklerMemoProxyObject *self;
3601
3602 self = PyObject_GC_New(PicklerMemoProxyObject, &PicklerMemoProxyType)( (PicklerMemoProxyObject *) _PyObject_GC_New(&PicklerMemoProxyType
) )
;
3603 if (self == NULL((void*)0))
3604 return NULL((void*)0);
3605 Py_INCREF(pickler)( _Py_RefTotal++ , ((PyObject*)(pickler))->ob_refcnt++);
3606 self->pickler = pickler;
3607 PyObject_GC_Track(self);
3608 return (PyObject *)self;
3609}
3610
3611/*****************************************************************************/
3612
3613static PyObject *
3614Pickler_get_memo(PicklerObject *self)
3615{
3616 return PicklerMemoProxy_New(self);
3617}
3618
3619static int
3620Pickler_set_memo(PicklerObject *self, PyObject *obj)
3621{
3622 PyMemoTable *new_memo = NULL((void*)0);
3623
3624 if (obj == NULL((void*)0)) {
3625 PyErr_SetString(PyExc_TypeError,
3626 "attribute deletion is not supported");
3627 return -1;
3628 }
3629
3630 if (Py_TYPE(obj)(((PyObject*)(obj))->ob_type) == &PicklerMemoProxyType) {
3631 PicklerObject *pickler =
3632 ((PicklerMemoProxyObject *)obj)->pickler;
3633
3634 new_memo = PyMemoTable_Copy(pickler->memo);
3635 if (new_memo == NULL((void*)0))
3636 return -1;
3637 }
3638 else if (PyDict_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1L<<
29))) != 0)
) {
3639 Py_ssize_t i = 0;
3640 PyObject *key, *value;
3641
3642 new_memo = PyMemoTable_New();
3643 if (new_memo == NULL((void*)0))
3644 return -1;
3645
3646 while (PyDict_Next(obj, &i, &key, &value)) {
3647 long memo_id;
3648 PyObject *memo_obj;
3649
3650 if (!PyTuple_Check(value)((((((PyObject*)(value))->ob_type))->tp_flags & ((1L
<<26))) != 0)
|| Py_SIZE(value)(((PyVarObject*)(value))->ob_size) != 2) {
3651 PyErr_SetString(PyExc_TypeError,
3652 "'memo' values must be 2-item tuples");
3653 goto error;
3654 }
3655 memo_id = PyLong_AsLong(PyTuple_GET_ITEM(value, 0)(((PyTupleObject *)(value))->ob_item[0]));
3656 if (memo_id == -1 && PyErr_Occurred())
3657 goto error;
3658 memo_obj = PyTuple_GET_ITEM(value, 1)(((PyTupleObject *)(value))->ob_item[1]);
3659 if (PyMemoTable_Set(new_memo, memo_obj, memo_id) < 0)
3660 goto error;
3661 }
3662 }
3663 else {
3664 PyErr_Format(PyExc_TypeError,
3665 "'memo' attribute must be an PicklerMemoProxy object"
3666 "or dict, not %.200s", Py_TYPE(obj)(((PyObject*)(obj))->ob_type)->tp_name);
3667 return -1;
3668 }
3669
3670 PyMemoTable_Del(self->memo);
3671 self->memo = new_memo;
3672
3673 return 0;
3674
3675 error:
3676 if (new_memo)
3677 PyMemoTable_Del(new_memo);
3678 return -1;
3679}
3680
3681static PyObject *
3682Pickler_get_persid(PicklerObject *self)
3683{
3684 if (self->pers_func == NULL((void*)0))
3685 PyErr_SetString(PyExc_AttributeError, "persistent_id");
3686 else
3687 Py_INCREF(self->pers_func)( _Py_RefTotal++ , ((PyObject*)(self->pers_func))->ob_refcnt
++)
;
3688 return self->pers_func;
3689}
3690
3691static int
3692Pickler_set_persid(PicklerObject *self, PyObject *value)
3693{
3694 PyObject *tmp;
3695
3696 if (value == NULL((void*)0)) {
3697 PyErr_SetString(PyExc_TypeError,
3698 "attribute deletion is not supported");
3699 return -1;
3700 }
3701 if (!PyCallable_Check(value)) {
3702 PyErr_SetString(PyExc_TypeError,
3703 "persistent_id must be a callable taking one argument");
3704 return -1;
3705 }
3706
3707 tmp = self->pers_func;
3708 Py_INCREF(value)( _Py_RefTotal++ , ((PyObject*)(value))->ob_refcnt++);
3709 self->pers_func = value;
3710 Py_XDECREF(tmp)do { if ((tmp) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(tmp))->ob_refcnt != 0) { if (((PyObject*)tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3710, (PyObject *)(tmp)); } else _Py_Dealloc((PyObject *)(tmp
)); } while (0); } while (0)
; /* self->pers_func can be NULL, so be careful. */
3711
3712 return 0;
3713}
3714
3715static PyMemberDef Pickler_members[] = {
3716 {"bin", T_INT1, offsetof(PicklerObject, bin)__builtin_offsetof(PicklerObject, bin)},
3717 {"fast", T_INT1, offsetof(PicklerObject, fast)__builtin_offsetof(PicklerObject, fast)},
3718 {NULL((void*)0)}
3719};
3720
3721static PyGetSetDef Pickler_getsets[] = {
3722 {"memo", (getter)Pickler_get_memo,
3723 (setter)Pickler_set_memo},
3724 {"persistent_id", (getter)Pickler_get_persid,
3725 (setter)Pickler_set_persid},
3726 {NULL((void*)0)}
3727};
3728
3729static PyTypeObject Pickler_Type = {
3730 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
3731 "_pickle.Pickler" , /*tp_name*/
3732 sizeof(PicklerObject), /*tp_basicsize*/
3733 0, /*tp_itemsize*/
3734 (destructor)Pickler_dealloc, /*tp_dealloc*/
3735 0, /*tp_print*/
3736 0, /*tp_getattr*/
3737 0, /*tp_setattr*/
3738 0, /*tp_reserved*/
3739 0, /*tp_repr*/
3740 0, /*tp_as_number*/
3741 0, /*tp_as_sequence*/
3742 0, /*tp_as_mapping*/
3743 0, /*tp_hash*/
3744 0, /*tp_call*/
3745 0, /*tp_str*/
3746 0, /*tp_getattro*/
3747 0, /*tp_setattro*/
3748 0, /*tp_as_buffer*/
3749 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_BASETYPE(1L<<10) | Py_TPFLAGS_HAVE_GC(1L<<14),
3750 Pickler_doc, /*tp_doc*/
3751 (traverseproc)Pickler_traverse, /*tp_traverse*/
3752 (inquiry)Pickler_clear, /*tp_clear*/
3753 0, /*tp_richcompare*/
3754 0, /*tp_weaklistoffset*/
3755 0, /*tp_iter*/
3756 0, /*tp_iternext*/
3757 Pickler_methods, /*tp_methods*/
3758 Pickler_members, /*tp_members*/
3759 Pickler_getsets, /*tp_getset*/
3760 0, /*tp_base*/
3761 0, /*tp_dict*/
3762 0, /*tp_descr_get*/
3763 0, /*tp_descr_set*/
3764 0, /*tp_dictoffset*/
3765 (initproc)Pickler_init, /*tp_init*/
3766 PyType_GenericAlloc, /*tp_alloc*/
3767 PyType_GenericNew, /*tp_new*/
3768 PyObject_GC_Del, /*tp_free*/
3769 0, /*tp_is_gc*/
3770};
3771
3772/* Temporary helper for calling self.find_class().
3773
3774 XXX: It would be nice to able to avoid Python function call overhead, by
3775 using directly the C version of find_class(), when find_class() is not
3776 overridden by a subclass. Although, this could become rather hackish. A
3777 simpler optimization would be to call the C function when self is not a
3778 subclass instance. */
3779static PyObject *
3780find_class(UnpicklerObject *self, PyObject *module_name, PyObject *global_name)
3781{
3782 return PyObject_CallMethod((PyObject *)self, "find_class", "OO",
3783 module_name, global_name);
3784}
3785
3786static int
3787marker(UnpicklerObject *self)
3788{
3789 if (self->num_marks < 1) {
3790 PyErr_SetString(UnpicklingError, "could not find MARK");
3791 return -1;
3792 }
3793
3794 return self->marks[--self->num_marks];
3795}
3796
3797static int
3798load_none(UnpicklerObject *self)
3799{
3800 PDATA_APPEND(self->stack, Py_None, -1)do { ( _Py_RefTotal++ , ((PyObject*)(((&_Py_NoneStruct)))
)->ob_refcnt++); if (Pdata_push((self->stack), ((&_Py_NoneStruct
))) < 0) return (-1); } while(0)
;
3801 return 0;
3802}
3803
3804static int
3805bad_readline(void)
3806{
3807 PyErr_SetString(UnpicklingError, "pickle data was truncated");
3808 return -1;
3809}
3810
3811static int
3812load_int(UnpicklerObject *self)
3813{
3814 PyObject *value;
3815 char *endptr, *s;
3816 Py_ssize_t len;
3817 long x;
3818
3819 if ((len = _Unpickler_Readline(self, &s)) < 0)
3820 return -1;
3821 if (len < 2)
3822 return bad_readline();
3823
3824 errno(*__error()) = 0;
3825 /* XXX: Should the base argument of strtol() be explicitly set to 10?
3826 XXX(avassalotti): Should this uses PyOS_strtol()? */
3827 x = strtol(s, &endptr, 0);
3828
3829 if (errno(*__error()) || (*endptr != '\n' && *endptr != '\0')) {
3830 /* Hm, maybe we've got something long. Let's try reading
3831 * it as a Python long object. */
3832 errno(*__error()) = 0;
3833 /* XXX: Same thing about the base here. */
3834 value = PyLong_FromString(s, NULL((void*)0), 0);
3835 if (value == NULL((void*)0)) {
3836 PyErr_SetString(PyExc_ValueError,
3837 "could not convert string to int");
3838 return -1;
3839 }
3840 }
3841 else {
3842 if (len == 3 && (x == 0 || x == 1)) {
3843 if ((value = PyBool_FromLong(x)) == NULL((void*)0))
3844 return -1;
3845 }
3846 else {
3847 if ((value = PyLong_FromLong(x)) == NULL((void*)0))
3848 return -1;
3849 }
3850 }
3851
3852 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
3853 return 0;
3854}
3855
3856static int
3857load_bool(UnpicklerObject *self, PyObject *boolean)
3858{
3859 assert(boolean == Py_True || boolean == Py_False)(__builtin_expect(!(boolean == ((PyObject *) &_Py_TrueStruct
) || boolean == ((PyObject *) &_Py_FalseStruct)), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3859, "boolean == Py_True || boolean == Py_False") : (void)
0)
;
3860 PDATA_APPEND(self->stack, boolean, -1)do { ( _Py_RefTotal++ , ((PyObject*)((boolean)))->ob_refcnt
++); if (Pdata_push((self->stack), (boolean)) < 0) return
(-1); } while(0)
;
3861 return 0;
3862}
3863
3864/* s contains x bytes of a little-endian integer. Return its value as a
3865 * C int. Obscure: when x is 1 or 2, this is an unsigned little-endian
3866 * int, but when x is 4 it's a signed one. This is an historical source
3867 * of x-platform bugs.
3868 */
3869static long
3870calc_binint(char *bytes, int size)
3871{
3872 unsigned char *s = (unsigned char *)bytes;
3873 int i = size;
3874 long x = 0;
3875
3876 for (i = 0; i < size; i++) {
3877 x |= (long)s[i] << (i * 8);
3878 }
3879
3880 /* Unlike BININT1 and BININT2, BININT (more accurately BININT4)
3881 * is signed, so on a box with longs bigger than 4 bytes we need
3882 * to extend a BININT's sign bit to the full width.
3883 */
3884 if (SIZEOF_LONG8 > 4 && size == 4) {
3885 x |= -(x & (1L << 31));
3886 }
3887
3888 return x;
3889}
3890
3891static int
3892load_binintx(UnpicklerObject *self, char *s, int size)
3893{
3894 PyObject *value;
3895 long x;
3896
3897 x = calc_binint(s, size);
3898
3899 if ((value = PyLong_FromLong(x)) == NULL((void*)0))
3900 return -1;
3901
3902 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
3903 return 0;
3904}
3905
3906static int
3907load_binint(UnpicklerObject *self)
3908{
3909 char *s;
3910
3911 if (_Unpickler_Read(self, &s, 4) < 0)
3912 return -1;
3913
3914 return load_binintx(self, s, 4);
3915}
3916
3917static int
3918load_binint1(UnpicklerObject *self)
3919{
3920 char *s;
3921
3922 if (_Unpickler_Read(self, &s, 1) < 0)
3923 return -1;
3924
3925 return load_binintx(self, s, 1);
3926}
3927
3928static int
3929load_binint2(UnpicklerObject *self)
3930{
3931 char *s;
3932
3933 if (_Unpickler_Read(self, &s, 2) < 0)
3934 return -1;
3935
3936 return load_binintx(self, s, 2);
3937}
3938
3939static int
3940load_long(UnpicklerObject *self)
3941{
3942 PyObject *value;
3943 char *s;
3944 Py_ssize_t len;
3945
3946 if ((len = _Unpickler_Readline(self, &s)) < 0)
3947 return -1;
3948 if (len < 2)
3949 return bad_readline();
3950
3951 /* s[len-2] will usually be 'L' (and s[len-1] is '\n'); we need to remove
3952 the 'L' before calling PyLong_FromString. In order to maintain
3953 compatibility with Python 3.0.0, we don't actually *require*
3954 the 'L' to be present. */
3955 if (s[len-2] == 'L')
3956 s[len-2] = '\0';
3957 /* XXX: Should the base argument explicitly set to 10? */
3958 value = PyLong_FromString(s, NULL((void*)0), 0);
3959 if (value == NULL((void*)0))
3960 return -1;
3961
3962 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
3963 return 0;
3964}
3965
3966/* 'size' bytes contain the # of bytes of little-endian 256's-complement
3967 * data following.
3968 */
3969static int
3970load_counted_long(UnpicklerObject *self, int size)
3971{
3972 PyObject *value;
3973 char *nbytes;
3974 char *pdata;
3975
3976 assert(size == 1 || size == 4)(__builtin_expect(!(size == 1 || size == 4), 0) ? __assert_rtn
(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 3976, "size == 1 || size == 4") : (void)0)
;
3977 if (_Unpickler_Read(self, &nbytes, size) < 0)
3978 return -1;
3979
3980 size = calc_binint(nbytes, size);
3981 if (size < 0) {
3982 /* Corrupt or hostile pickle -- we never write one like this */
3983 PyErr_SetString(UnpicklingError,
3984 "LONG pickle has negative byte count");
3985 return -1;
3986 }
3987
3988 if (size == 0)
3989 value = PyLong_FromLong(0L);
3990 else {
3991 /* Read the raw little-endian bytes and convert. */
3992 if (_Unpickler_Read(self, &pdata, size) < 0)
3993 return -1;
3994 value = _PyLong_FromByteArray((unsigned char *)pdata, (size_t)size,
3995 1 /* little endian */ , 1 /* signed */ );
3996 }
3997 if (value == NULL((void*)0))
3998 return -1;
3999 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
4000 return 0;
4001}
4002
4003static int
4004load_float(UnpicklerObject *self)
4005{
4006 PyObject *value;
4007 char *endptr, *s;
4008 Py_ssize_t len;
4009 double d;
4010
4011 if ((len = _Unpickler_Readline(self, &s)) < 0)
4012 return -1;
4013 if (len < 2)
4014 return bad_readline();
4015
4016 errno(*__error()) = 0;
4017 d = PyOS_string_to_double(s, &endptr, PyExc_OverflowError);
4018 if (d == -1.0 && PyErr_Occurred())
4019 return -1;
4020 if ((endptr[0] != '\n') && (endptr[0] != '\0')) {
4021 PyErr_SetString(PyExc_ValueError, "could not convert string to float");
4022 return -1;
4023 }
4024 value = PyFloat_FromDouble(d);
4025 if (value == NULL((void*)0))
4026 return -1;
4027
4028 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
4029 return 0;
4030}
4031
4032static int
4033load_binfloat(UnpicklerObject *self)
4034{
4035 PyObject *value;
4036 double x;
4037 char *s;
4038
4039 if (_Unpickler_Read(self, &s, 8) < 0)
4040 return -1;
4041
4042 x = _PyFloat_Unpack8((unsigned char *)s, 0);
4043 if (x == -1.0 && PyErr_Occurred())
4044 return -1;
4045
4046 if ((value = PyFloat_FromDouble(x)) == NULL((void*)0))
4047 return -1;
4048
4049 PDATA_PUSH(self->stack, value, -1)do { if (Pdata_push((self->stack), (value)) < 0) return
(-1); } while(0)
;
4050 return 0;
4051}
4052
4053static int
4054load_string(UnpicklerObject *self)
4055{
4056 PyObject *bytes;
4057 PyObject *str = NULL((void*)0);
4058 Py_ssize_t len;
4059 char *s, *p;
4060
4061 if ((len = _Unpickler_Readline(self, &s)) < 0)
4062 return -1;
4063 if (len < 3)
4064 return bad_readline();
4065 if ((s = strdup(s)) == NULL((void*)0)) {
4066 PyErr_NoMemory();
4067 return -1;
4068 }
4069
4070 /* Strip outermost quotes */
4071 while (s[len - 1] <= ' ')
4072 len--;
4073 if (s[0] == '"' && s[len - 1] == '"') {
4074 s[len - 1] = '\0';
4075 p = s + 1;
4076 len -= 2;
4077 }
4078 else if (s[0] == '\'' && s[len - 1] == '\'') {
4079 s[len - 1] = '\0';
4080 p = s + 1;
4081 len -= 2;
4082 }
4083 else {
4084 free(s);
4085 PyErr_SetString(PyExc_ValueError, "insecure string pickle");
4086 return -1;
4087 }
4088
4089 /* Use the PyBytes API to decode the string, since that is what is used
4090 to encode, and then coerce the result to Unicode. */
4091 bytes = PyBytes_DecodeEscape(p, len, NULL((void*)0), 0, NULL((void*)0));
4092 free(s);
4093 if (bytes == NULL((void*)0))
4094 return -1;
4095 str = PyUnicode_FromEncodedObjectPyUnicodeUCS2_FromEncodedObject(bytes, self->encoding, self->errors);
4096 Py_DECREF(bytes)do { if (_Py_RefTotal-- , --((PyObject*)(bytes))->ob_refcnt
!= 0) { if (((PyObject*)bytes)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4096, (
PyObject *)(bytes)); } else _Py_Dealloc((PyObject *)(bytes));
} while (0)
;
4097 if (str == NULL((void*)0))
4098 return -1;
4099
4100 PDATA_PUSH(self->stack, str, -1)do { if (Pdata_push((self->stack), (str)) < 0) return (
-1); } while(0)
;
4101 return 0;
4102}
4103
4104static int
4105load_binbytes(UnpicklerObject *self)
4106{
4107 PyObject *bytes;
4108 long x;
4109 char *s;
4110
4111 if (_Unpickler_Read(self, &s, 4) < 0)
4112 return -1;
4113
4114 x = calc_binint(s, 4);
4115 if (x < 0) {
4116 PyErr_SetString(UnpicklingError,
4117 "BINBYTES pickle has negative byte count");
4118 return -1;
4119 }
4120
4121 if (_Unpickler_Read(self, &s, x) < 0)
4122 return -1;
4123 bytes = PyBytes_FromStringAndSize(s, x);
4124 if (bytes == NULL((void*)0))
4125 return -1;
4126
4127 PDATA_PUSH(self->stack, bytes, -1)do { if (Pdata_push((self->stack), (bytes)) < 0) return
(-1); } while(0)
;
4128 return 0;
4129}
4130
4131static int
4132load_short_binbytes(UnpicklerObject *self)
4133{
4134 PyObject *bytes;
4135 unsigned char x;
4136 char *s;
4137
4138 if (_Unpickler_Read(self, &s, 1) < 0)
4139 return -1;
4140
4141 x = (unsigned char)s[0];
4142
4143 if (_Unpickler_Read(self, &s, x) < 0)
4144 return -1;
4145
4146 bytes = PyBytes_FromStringAndSize(s, x);
4147 if (bytes == NULL((void*)0))
4148 return -1;
4149
4150 PDATA_PUSH(self->stack, bytes, -1)do { if (Pdata_push((self->stack), (bytes)) < 0) return
(-1); } while(0)
;
4151 return 0;
4152}
4153
4154static int
4155load_binstring(UnpicklerObject *self)
4156{
4157 PyObject *str;
4158 long x;
4159 char *s;
4160
4161 if (_Unpickler_Read(self, &s, 4) < 0)
4162 return -1;
4163
4164 x = calc_binint(s, 4);
4165 if (x < 0) {
4166 PyErr_SetString(UnpicklingError,
4167 "BINSTRING pickle has negative byte count");
4168 return -1;
4169 }
4170
4171 if (_Unpickler_Read(self, &s, x) < 0)
4172 return -1;
4173
4174 /* Convert Python 2.x strings to unicode. */
4175 str = PyUnicode_DecodePyUnicodeUCS2_Decode(s, x, self->encoding, self->errors);
4176 if (str == NULL((void*)0))
4177 return -1;
4178
4179 PDATA_PUSH(self->stack, str, -1)do { if (Pdata_push((self->stack), (str)) < 0) return (
-1); } while(0)
;
4180 return 0;
4181}
4182
4183static int
4184load_short_binstring(UnpicklerObject *self)
4185{
4186 PyObject *str;
4187 unsigned char x;
4188 char *s;
4189
4190 if (_Unpickler_Read(self, &s, 1) < 0)
4191 return -1;
4192
4193 x = (unsigned char)s[0];
4194
4195 if (_Unpickler_Read(self, &s, x) < 0)
4196 return -1;
4197
4198 /* Convert Python 2.x strings to unicode. */
4199 str = PyUnicode_DecodePyUnicodeUCS2_Decode(s, x, self->encoding, self->errors);
4200 if (str == NULL((void*)0))
4201 return -1;
4202
4203 PDATA_PUSH(self->stack, str, -1)do { if (Pdata_push((self->stack), (str)) < 0) return (
-1); } while(0)
;
4204 return 0;
4205}
4206
4207static int
4208load_unicode(UnpicklerObject *self)
4209{
4210 PyObject *str;
4211 Py_ssize_t len;
4212 char *s;
4213
4214 if ((len = _Unpickler_Readline(self, &s)) < 0)
4215 return -1;
4216 if (len < 1)
4217 return bad_readline();
4218
4219 str = PyUnicode_DecodeRawUnicodeEscapePyUnicodeUCS2_DecodeRawUnicodeEscape(s, len - 1, NULL((void*)0));
4220 if (str == NULL((void*)0))
4221 return -1;
4222
4223 PDATA_PUSH(self->stack, str, -1)do { if (Pdata_push((self->stack), (str)) < 0) return (
-1); } while(0)
;
4224 return 0;
4225}
4226
4227static int
4228load_binunicode(UnpicklerObject *self)
4229{
4230 PyObject *str;
4231 long size;
4232 char *s;
4233
4234 if (_Unpickler_Read(self, &s, 4) < 0)
4235 return -1;
4236
4237 size = calc_binint(s, 4);
4238 if (size < 0) {
4239 PyErr_SetString(UnpicklingError,
4240 "BINUNICODE pickle has negative byte count");
4241 return -1;
4242 }
4243
4244 if (_Unpickler_Read(self, &s, size) < 0)
4245 return -1;
4246
4247 str = PyUnicode_DecodeUTF8PyUnicodeUCS2_DecodeUTF8(s, size, "surrogatepass");
4248 if (str == NULL((void*)0))
4249 return -1;
4250
4251 PDATA_PUSH(self->stack, str, -1)do { if (Pdata_push((self->stack), (str)) < 0) return (
-1); } while(0)
;
4252 return 0;
4253}
4254
4255static int
4256load_tuple(UnpicklerObject *self)
4257{
4258 PyObject *tuple;
4259 int i;
4260
4261 if ((i = marker(self)) < 0)
4262 return -1;
4263
4264 tuple = Pdata_poptuple(self->stack, i);
4265 if (tuple == NULL((void*)0))
4266 return -1;
4267 PDATA_PUSH(self->stack, tuple, -1)do { if (Pdata_push((self->stack), (tuple)) < 0) return
(-1); } while(0)
;
4268 return 0;
4269}
4270
4271static int
4272load_counted_tuple(UnpicklerObject *self, int len)
4273{
4274 PyObject *tuple;
4275
4276 tuple = PyTuple_New(len);
4277 if (tuple == NULL((void*)0))
4278 return -1;
4279
4280 while (--len >= 0) {
4281 PyObject *item;
4282
4283 PDATA_POP(self->stack, item)do { (item) = Pdata_pop((self->stack)); } while (0);
4284 if (item == NULL((void*)0))
4285 return -1;
4286 PyTuple_SET_ITEM(tuple, len, item)(((PyTupleObject *)(tuple))->ob_item[len] = item);
4287 }
4288 PDATA_PUSH(self->stack, tuple, -1)do { if (Pdata_push((self->stack), (tuple)) < 0) return
(-1); } while(0)
;
4289 return 0;
4290}
4291
4292static int
4293load_empty_list(UnpicklerObject *self)
4294{
4295 PyObject *list;
4296
4297 if ((list = PyList_New(0)) == NULL((void*)0))
4298 return -1;
4299 PDATA_PUSH(self->stack, list, -1)do { if (Pdata_push((self->stack), (list)) < 0) return (
-1); } while(0)
;
4300 return 0;
4301}
4302
4303static int
4304load_empty_dict(UnpicklerObject *self)
4305{
4306 PyObject *dict;
4307
4308 if ((dict = PyDict_New()) == NULL((void*)0))
4309 return -1;
4310 PDATA_PUSH(self->stack, dict, -1)do { if (Pdata_push((self->stack), (dict)) < 0) return (
-1); } while(0)
;
4311 return 0;
4312}
4313
4314static int
4315load_list(UnpicklerObject *self)
4316{
4317 PyObject *list;
4318 int i;
4319
4320 if ((i = marker(self)) < 0)
4321 return -1;
4322
4323 list = Pdata_poplist(self->stack, i);
4324 if (list == NULL((void*)0))
4325 return -1;
4326 PDATA_PUSH(self->stack, list, -1)do { if (Pdata_push((self->stack), (list)) < 0) return (
-1); } while(0)
;
4327 return 0;
4328}
4329
4330static int
4331load_dict(UnpicklerObject *self)
4332{
4333 PyObject *dict, *key, *value;
4334 int i, j, k;
4335
4336 if ((i = marker(self)) < 0)
4337 return -1;
4338 j = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size);
4339
4340 if ((dict = PyDict_New()) == NULL((void*)0))
4341 return -1;
4342
4343 for (k = i + 1; k < j; k += 2) {
4344 key = self->stack->data[k - 1];
4345 value = self->stack->data[k];
4346 if (PyDict_SetItem(dict, key, value) < 0) {
4347 Py_DECREF(dict)do { if (_Py_RefTotal-- , --((PyObject*)(dict))->ob_refcnt
!= 0) { if (((PyObject*)dict)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4347, (
PyObject *)(dict)); } else _Py_Dealloc((PyObject *)(dict)); }
while (0)
;
4348 return -1;
4349 }
4350 }
4351 Pdata_clear(self->stack, i);
4352 PDATA_PUSH(self->stack, dict, -1)do { if (Pdata_push((self->stack), (dict)) < 0) return (
-1); } while(0)
;
4353 return 0;
4354}
4355
4356static PyObject *
4357instantiate(PyObject *cls, PyObject *args)
4358{
4359 PyObject *result = NULL((void*)0);
4360 /* Caller must assure args are a tuple. Normally, args come from
4361 Pdata_poptuple which packs objects from the top of the stack
4362 into a newly created tuple. */
4363 assert(PyTuple_Check(args))(__builtin_expect(!(((((((PyObject*)(args))->ob_type))->
tp_flags & ((1L<<26))) != 0)), 0) ? __assert_rtn(__func__
, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4363,
"PyTuple_Check(args)") : (void)0)
;
4364 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) > 0 || !PyType_Check(cls)((((((PyObject*)(cls))->ob_type))->tp_flags & ((1L<<
31))) != 0)
||
4365 PyObject_HasAttrString(cls, "__getinitargs__")) {
4366 result = PyObject_CallObject(cls, args);
4367 }
4368 else {
4369 result = PyObject_CallMethod(cls, "__new__", "O", cls);
4370 }
4371 return result;
4372}
4373
4374static int
4375load_obj(UnpicklerObject *self)
4376{
4377 PyObject *cls, *args, *obj = NULL((void*)0);
4378 int i;
4379
4380 if ((i = marker(self)) < 0)
4381 return -1;
4382
4383 args = Pdata_poptuple(self->stack, i + 1);
4384 if (args == NULL((void*)0))
4385 return -1;
4386
4387 PDATA_POP(self->stack, cls)do { (cls) = Pdata_pop((self->stack)); } while (0);
4388 if (cls) {
4389 obj = instantiate(cls, args);
4390 Py_DECREF(cls)do { if (_Py_RefTotal-- , --((PyObject*)(cls))->ob_refcnt !=
0) { if (((PyObject*)cls)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4390, (
PyObject *)(cls)); } else _Py_Dealloc((PyObject *)(cls)); } while
(0)
;
4391 }
4392 Py_DECREF(args)do { if (_Py_RefTotal-- , --((PyObject*)(args))->ob_refcnt
!= 0) { if (((PyObject*)args)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4392, (
PyObject *)(args)); } else _Py_Dealloc((PyObject *)(args)); }
while (0)
;
4393 if (obj == NULL((void*)0))
4394 return -1;
4395
4396 PDATA_PUSH(self->stack, obj, -1)do { if (Pdata_push((self->stack), (obj)) < 0) return (
-1); } while(0)
;
4397 return 0;
4398}
4399
4400static int
4401load_inst(UnpicklerObject *self)
4402{
4403 PyObject *cls = NULL((void*)0);
4404 PyObject *args = NULL((void*)0);
4405 PyObject *obj = NULL((void*)0);
4406 PyObject *module_name;
4407 PyObject *class_name;
4408 Py_ssize_t len;
4409 int i;
4410 char *s;
4411
4412 if ((i = marker(self)) < 0)
4413 return -1;
4414 if ((len = _Unpickler_Readline(self, &s)) < 0)
4415 return -1;
4416 if (len < 2)
4417 return bad_readline();
4418
4419 /* Here it is safe to use PyUnicode_DecodeASCII(), even though non-ASCII
4420 identifiers are permitted in Python 3.0, since the INST opcode is only
4421 supported by older protocols on Python 2.x. */
4422 module_name = PyUnicode_DecodeASCIIPyUnicodeUCS2_DecodeASCII(s, len - 1, "strict");
4423 if (module_name == NULL((void*)0))
4424 return -1;
4425
4426 if ((len = _Unpickler_Readline(self, &s)) >= 0) {
4427 if (len < 2)
4428 return bad_readline();
4429 class_name = PyUnicode_DecodeASCIIPyUnicodeUCS2_DecodeASCII(s, len - 1, "strict");
4430 if (class_name != NULL((void*)0)) {
4431 cls = find_class(self, module_name, class_name);
4432 Py_DECREF(class_name)do { if (_Py_RefTotal-- , --((PyObject*)(class_name))->ob_refcnt
!= 0) { if (((PyObject*)class_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4432, (
PyObject *)(class_name)); } else _Py_Dealloc((PyObject *)(class_name
)); } while (0)
;
4433 }
4434 }
4435 Py_DECREF(module_name)do { if (_Py_RefTotal-- , --((PyObject*)(module_name))->ob_refcnt
!= 0) { if (((PyObject*)module_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4435, (
PyObject *)(module_name)); } else _Py_Dealloc((PyObject *)(module_name
)); } while (0)
;
4436
4437 if (cls == NULL((void*)0))
4438 return -1;
4439
4440 if ((args = Pdata_poptuple(self->stack, i)) != NULL((void*)0)) {
4441 obj = instantiate(cls, args);
4442 Py_DECREF(args)do { if (_Py_RefTotal-- , --((PyObject*)(args))->ob_refcnt
!= 0) { if (((PyObject*)args)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4442, (
PyObject *)(args)); } else _Py_Dealloc((PyObject *)(args)); }
while (0)
;
4443 }
4444 Py_DECREF(cls)do { if (_Py_RefTotal-- , --((PyObject*)(cls))->ob_refcnt !=
0) { if (((PyObject*)cls)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4444, (
PyObject *)(cls)); } else _Py_Dealloc((PyObject *)(cls)); } while
(0)
;
4445
4446 if (obj == NULL((void*)0))
4447 return -1;
4448
4449 PDATA_PUSH(self->stack, obj, -1)do { if (Pdata_push((self->stack), (obj)) < 0) return (
-1); } while(0)
;
4450 return 0;
4451}
4452
4453static int
4454load_newobj(UnpicklerObject *self)
4455{
4456 PyObject *args = NULL((void*)0);
4457 PyObject *clsraw = NULL((void*)0);
4458 PyTypeObject *cls; /* clsraw cast to its true type */
4459 PyObject *obj;
4460
4461 /* Stack is ... cls argtuple, and we want to call
4462 * cls.__new__(cls, *argtuple).
4463 */
4464 PDATA_POP(self->stack, args)do { (args) = Pdata_pop((self->stack)); } while (0);
4465 if (args == NULL((void*)0))
4466 goto error;
4467 if (!PyTuple_Check(args)((((((PyObject*)(args))->ob_type))->tp_flags & ((1L
<<26))) != 0)
) {
4468 PyErr_SetString(UnpicklingError, "NEWOBJ expected an arg " "tuple.");
4469 goto error;
4470 }
4471
4472 PDATA_POP(self->stack, clsraw)do { (clsraw) = Pdata_pop((self->stack)); } while (0);
4473 cls = (PyTypeObject *)clsraw;
4474 if (cls == NULL((void*)0))
4475 goto error;
4476 if (!PyType_Check(cls)((((((PyObject*)(cls))->ob_type))->tp_flags & ((1L<<
31))) != 0)
) {
4477 PyErr_SetString(UnpicklingError, "NEWOBJ class argument "
4478 "isn't a type object");
4479 goto error;
4480 }
4481 if (cls->tp_new == NULL((void*)0)) {
4482 PyErr_SetString(UnpicklingError, "NEWOBJ class argument "
4483 "has NULL tp_new");
4484 goto error;
4485 }
4486
4487 /* Call __new__. */
4488 obj = cls->tp_new(cls, args, NULL((void*)0));
4489 if (obj == NULL((void*)0))
4490 goto error;
4491
4492 Py_DECREF(args)do { if (_Py_RefTotal-- , --((PyObject*)(args))->ob_refcnt
!= 0) { if (((PyObject*)args)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4492, (
PyObject *)(args)); } else _Py_Dealloc((PyObject *)(args)); }
while (0)
;
4493 Py_DECREF(clsraw)do { if (_Py_RefTotal-- , --((PyObject*)(clsraw))->ob_refcnt
!= 0) { if (((PyObject*)clsraw)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4493, (
PyObject *)(clsraw)); } else _Py_Dealloc((PyObject *)(clsraw)
); } while (0)
;
4494 PDATA_PUSH(self->stack, obj, -1)do { if (Pdata_push((self->stack), (obj)) < 0) return (
-1); } while(0)
;
4495 return 0;
4496
4497 error:
4498 Py_XDECREF(args)do { if ((args) == ((void*)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(args))->ob_refcnt != 0) { if (((PyObject
*)args)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 4498, (PyObject *)(args)); } else _Py_Dealloc((PyObject *)(
args)); } while (0); } while (0)
;
4499 Py_XDECREF(clsraw)do { if ((clsraw) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(clsraw))->ob_refcnt != 0) { if (((PyObject
*)clsraw)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 4499, (PyObject *)(clsraw)); } else _Py_Dealloc((PyObject *
)(clsraw)); } while (0); } while (0)
;
4500 return -1;
4501}
4502
4503static int
4504load_global(UnpicklerObject *self)
4505{
4506 PyObject *global = NULL((void*)0);
4507 PyObject *module_name;
4508 PyObject *global_name;
4509 Py_ssize_t len;
4510 char *s;
4511
4512 if ((len = _Unpickler_Readline(self, &s)) < 0)
4513 return -1;
4514 if (len < 2)
4515 return bad_readline();
4516 module_name = PyUnicode_DecodeUTF8PyUnicodeUCS2_DecodeUTF8(s, len - 1, "strict");
4517 if (!module_name)
4518 return -1;
4519
4520 if ((len = _Unpickler_Readline(self, &s)) >= 0) {
4521 if (len < 2) {
4522 Py_DECREF(module_name)do { if (_Py_RefTotal-- , --((PyObject*)(module_name))->ob_refcnt
!= 0) { if (((PyObject*)module_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4522, (
PyObject *)(module_name)); } else _Py_Dealloc((PyObject *)(module_name
)); } while (0)
;
4523 return bad_readline();
4524 }
4525 global_name = PyUnicode_DecodeUTF8PyUnicodeUCS2_DecodeUTF8(s, len - 1, "strict");
4526 if (global_name) {
4527 global = find_class(self, module_name, global_name);
4528 Py_DECREF(global_name)do { if (_Py_RefTotal-- , --((PyObject*)(global_name))->ob_refcnt
!= 0) { if (((PyObject*)global_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4528, (
PyObject *)(global_name)); } else _Py_Dealloc((PyObject *)(global_name
)); } while (0)
;
4529 }
4530 }
4531 Py_DECREF(module_name)do { if (_Py_RefTotal-- , --((PyObject*)(module_name))->ob_refcnt
!= 0) { if (((PyObject*)module_name)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4531, (
PyObject *)(module_name)); } else _Py_Dealloc((PyObject *)(module_name
)); } while (0)
;
4532
4533 if (global == NULL((void*)0))
4534 return -1;
4535 PDATA_PUSH(self->stack, global, -1)do { if (Pdata_push((self->stack), (global)) < 0) return
(-1); } while(0)
;
4536 return 0;
4537}
4538
4539static int
4540load_persid(UnpicklerObject *self)
4541{
4542 PyObject *pid;
4543 Py_ssize_t len;
4544 char *s;
4545
4546 if (self->pers_func) {
4547 if ((len = _Unpickler_Readline(self, &s)) < 0)
4548 return -1;
4549 if (len < 2)
4550 return bad_readline();
4551
4552 pid = PyBytes_FromStringAndSize(s, len - 1);
4553 if (pid == NULL((void*)0))
4554 return -1;
4555
4556 /* Ugh... this does not leak since _Unpickler_FastCall() steals the
4557 reference to pid first. */
4558 pid = _Unpickler_FastCall(self, self->pers_func, pid);
4559 if (pid == NULL((void*)0))
4560 return -1;
4561
4562 PDATA_PUSH(self->stack, pid, -1)do { if (Pdata_push((self->stack), (pid)) < 0) return (
-1); } while(0)
;
4563 return 0;
4564 }
4565 else {
4566 PyErr_SetString(UnpicklingError,
4567 "A load persistent id instruction was encountered,\n"
4568 "but no persistent_load function was specified.");
4569 return -1;
4570 }
4571}
4572
4573static int
4574load_binpersid(UnpicklerObject *self)
4575{
4576 PyObject *pid;
4577
4578 if (self->pers_func) {
4579 PDATA_POP(self->stack, pid)do { (pid) = Pdata_pop((self->stack)); } while (0);
4580 if (pid == NULL((void*)0))
4581 return -1;
4582
4583 /* Ugh... this does not leak since _Unpickler_FastCall() steals the
4584 reference to pid first. */
4585 pid = _Unpickler_FastCall(self, self->pers_func, pid);
4586 if (pid == NULL((void*)0))
4587 return -1;
4588
4589 PDATA_PUSH(self->stack, pid, -1)do { if (Pdata_push((self->stack), (pid)) < 0) return (
-1); } while(0)
;
4590 return 0;
4591 }
4592 else {
4593 PyErr_SetString(UnpicklingError,
4594 "A load persistent id instruction was encountered,\n"
4595 "but no persistent_load function was specified.");
4596 return -1;
4597 }
4598}
4599
4600static int
4601load_pop(UnpicklerObject *self)
4602{
4603 int len = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size);
4604
4605 /* Note that we split the (pickle.py) stack into two stacks,
4606 * an object stack and a mark stack. We have to be clever and
4607 * pop the right one. We do this by looking at the top of the
4608 * mark stack first, and only signalling a stack underflow if
4609 * the object stack is empty and the mark stack doesn't match
4610 * our expectations.
4611 */
4612 if (self->num_marks > 0 && self->marks[self->num_marks - 1] == len) {
4613 self->num_marks--;
4614 } else if (len > 0) {
4615 len--;
4616 Py_DECREF(self->stack->data[len])do { if (_Py_RefTotal-- , --((PyObject*)(self->stack->data
[len]))->ob_refcnt != 0) { if (((PyObject*)self->stack->
data[len])->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 4616, (PyObject *)(self->stack->data[len])); } else _Py_Dealloc
((PyObject *)(self->stack->data[len])); } while (0)
;
4617 Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) = len;
4618 } else {
4619 return stack_underflow();
4620 }
4621 return 0;
4622}
4623
4624static int
4625load_pop_mark(UnpicklerObject *self)
4626{
4627 int i;
4628
4629 if ((i = marker(self)) < 0)
4630 return -1;
4631
4632 Pdata_clear(self->stack, i);
4633
4634 return 0;
4635}
4636
4637static int
4638load_dup(UnpicklerObject *self)
4639{
4640 PyObject *last;
4641 int len;
4642
4643 if ((len = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size)) <= 0)
4644 return stack_underflow();
4645 last = self->stack->data[len - 1];
4646 PDATA_APPEND(self->stack, last, -1)do { ( _Py_RefTotal++ , ((PyObject*)((last)))->ob_refcnt++
); if (Pdata_push((self->stack), (last)) < 0) return (-
1); } while(0)
;
4647 return 0;
4648}
4649
4650static int
4651load_get(UnpicklerObject *self)
4652{
4653 PyObject *key, *value;
4654 Py_ssize_t idx;
4655 Py_ssize_t len;
4656 char *s;
4657
4658 if ((len = _Unpickler_Readline(self, &s)) < 0)
4659 return -1;
4660 if (len < 2)
4661 return bad_readline();
4662
4663 key = PyLong_FromString(s, NULL((void*)0), 10);
4664 if (key == NULL((void*)0))
4665 return -1;
4666 idx = PyLong_AsSsize_t(key);
4667 if (idx == -1 && PyErr_Occurred()) {
4668 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4668, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4669 return -1;
4670 }
4671
4672 value = _Unpickler_MemoGet(self, idx);
4673 if (value == NULL((void*)0)) {
4674 if (!PyErr_Occurred())
4675 PyErr_SetObject(PyExc_KeyError, key);
4676 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4676, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4677 return -1;
4678 }
4679 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4679, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4680
4681 PDATA_APPEND(self->stack, value, -1)do { ( _Py_RefTotal++ , ((PyObject*)((value)))->ob_refcnt++
); if (Pdata_push((self->stack), (value)) < 0) return (
-1); } while(0)
;
4682 return 0;
4683}
4684
4685static int
4686load_binget(UnpicklerObject *self)
4687{
4688 PyObject *value;
4689 Py_ssize_t idx;
4690 char *s;
4691
4692 if (_Unpickler_Read(self, &s, 1) < 0)
4693 return -1;
4694
4695 idx = Py_CHARMASK(s[0])((unsigned char)((s[0]) & 0xff));
4696
4697 value = _Unpickler_MemoGet(self, idx);
4698 if (value == NULL((void*)0)) {
4699 PyObject *key = PyLong_FromSsize_t(idx);
4700 if (!PyErr_Occurred())
4701 PyErr_SetObject(PyExc_KeyError, key);
4702 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4702, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4703 return -1;
4704 }
4705
4706 PDATA_APPEND(self->stack, value, -1)do { ( _Py_RefTotal++ , ((PyObject*)((value)))->ob_refcnt++
); if (Pdata_push((self->stack), (value)) < 0) return (
-1); } while(0)
;
4707 return 0;
4708}
4709
4710static int
4711load_long_binget(UnpicklerObject *self)
4712{
4713 PyObject *value;
4714 Py_ssize_t idx;
4715 char *s;
4716
4717 if (_Unpickler_Read(self, &s, 4) < 0)
4718 return -1;
4719
4720 idx = (long)Py_CHARMASK(s[0])((unsigned char)((s[0]) & 0xff));
4721 idx |= (long)Py_CHARMASK(s[1])((unsigned char)((s[1]) & 0xff)) << 8;
4722 idx |= (long)Py_CHARMASK(s[2])((unsigned char)((s[2]) & 0xff)) << 16;
4723 idx |= (long)Py_CHARMASK(s[3])((unsigned char)((s[3]) & 0xff)) << 24;
4724
4725 value = _Unpickler_MemoGet(self, idx);
4726 if (value == NULL((void*)0)) {
4727 PyObject *key = PyLong_FromSsize_t(idx);
4728 if (!PyErr_Occurred())
4729 PyErr_SetObject(PyExc_KeyError, key);
4730 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4730, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4731 return -1;
4732 }
4733
4734 PDATA_APPEND(self->stack, value, -1)do { ( _Py_RefTotal++ , ((PyObject*)((value)))->ob_refcnt++
); if (Pdata_push((self->stack), (value)) < 0) return (
-1); } while(0)
;
4735 return 0;
4736}
4737
4738/* Push an object from the extension registry (EXT[124]). nbytes is
4739 * the number of bytes following the opcode, holding the index (code) value.
4740 */
4741static int
4742load_extension(UnpicklerObject *self, int nbytes)
4743{
4744 char *codebytes; /* the nbytes bytes after the opcode */
4745 long code; /* calc_binint returns long */
4746 PyObject *py_code; /* code as a Python int */
4747 PyObject *obj; /* the object to push */
4748 PyObject *pair; /* (module_name, class_name) */
4749 PyObject *module_name, *class_name;
4750
4751 assert(nbytes == 1 || nbytes == 2 || nbytes == 4)(__builtin_expect(!(nbytes == 1 || nbytes == 2 || nbytes == 4
), 0) ? __assert_rtn(__func__, "/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 4751, "nbytes == 1 || nbytes == 2 || nbytes == 4") : (void)
0)
;
4752 if (_Unpickler_Read(self, &codebytes, nbytes) < 0)
4753 return -1;
4754 code = calc_binint(codebytes, nbytes);
4755 if (code <= 0) { /* note that 0 is forbidden */
4756 /* Corrupt or hostile pickle. */
4757 PyErr_SetString(UnpicklingError, "EXT specifies code <= 0");
4758 return -1;
4759 }
4760
4761 /* Look for the code in the cache. */
4762 py_code = PyLong_FromLong(code);
4763 if (py_code == NULL((void*)0))
4764 return -1;
4765 obj = PyDict_GetItem(extension_cache, py_code);
4766 if (obj != NULL((void*)0)) {
4767 /* Bingo. */
4768 Py_DECREF(py_code)do { if (_Py_RefTotal-- , --((PyObject*)(py_code))->ob_refcnt
!= 0) { if (((PyObject*)py_code)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4768, (
PyObject *)(py_code)); } else _Py_Dealloc((PyObject *)(py_code
)); } while (0)
;
4769 PDATA_APPEND(self->stack, obj, -1)do { ( _Py_RefTotal++ , ((PyObject*)((obj)))->ob_refcnt++)
; if (Pdata_push((self->stack), (obj)) < 0) return (-1)
; } while(0)
;
4770 return 0;
4771 }
4772
4773 /* Look up the (module_name, class_name) pair. */
4774 pair = PyDict_GetItem(inverted_registry, py_code);
4775 if (pair == NULL((void*)0)) {
4776 Py_DECREF(py_code)do { if (_Py_RefTotal-- , --((PyObject*)(py_code))->ob_refcnt
!= 0) { if (((PyObject*)py_code)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4776, (
PyObject *)(py_code)); } else _Py_Dealloc((PyObject *)(py_code
)); } while (0)
;
4777 PyErr_Format(PyExc_ValueError, "unregistered extension "
4778 "code %ld", code);
4779 return -1;
4780 }
4781 /* Since the extension registry is manipulable via Python code,
4782 * confirm that pair is really a 2-tuple of strings.
4783 */
4784 if (!PyTuple_Check(pair)((((((PyObject*)(pair))->ob_type))->tp_flags & ((1L
<<26))) != 0)
|| PyTuple_Size(pair) != 2 ||
4785 !PyUnicode_Check(module_name = PyTuple_GET_ITEM(pair, 0))((((((PyObject*)(module_name = (((PyTupleObject *)(pair))->
ob_item[0])))->ob_type))->tp_flags & ((1L<<28
))) != 0)
||
4786 !PyUnicode_Check(class_name = PyTuple_GET_ITEM(pair, 1))((((((PyObject*)(class_name = (((PyTupleObject *)(pair))->
ob_item[1])))->ob_type))->tp_flags & ((1L<<28
))) != 0)
) {
4787 Py_DECREF(py_code)do { if (_Py_RefTotal-- , --((PyObject*)(py_code))->ob_refcnt
!= 0) { if (((PyObject*)py_code)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4787, (
PyObject *)(py_code)); } else _Py_Dealloc((PyObject *)(py_code
)); } while (0)
;
4788 PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
4789 "isn't a 2-tuple of strings", code);
4790 return -1;
4791 }
4792 /* Load the object. */
4793 obj = find_class(self, module_name, class_name);
4794 if (obj == NULL((void*)0)) {
4795 Py_DECREF(py_code)do { if (_Py_RefTotal-- , --((PyObject*)(py_code))->ob_refcnt
!= 0) { if (((PyObject*)py_code)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4795, (
PyObject *)(py_code)); } else _Py_Dealloc((PyObject *)(py_code
)); } while (0)
;
4796 return -1;
4797 }
4798 /* Cache code -> obj. */
4799 code = PyDict_SetItem(extension_cache, py_code, obj);
4800 Py_DECREF(py_code)do { if (_Py_RefTotal-- , --((PyObject*)(py_code))->ob_refcnt
!= 0) { if (((PyObject*)py_code)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4800, (
PyObject *)(py_code)); } else _Py_Dealloc((PyObject *)(py_code
)); } while (0)
;
4801 if (code < 0) {
4802 Py_DECREF(obj)do { if (_Py_RefTotal-- , --((PyObject*)(obj))->ob_refcnt !=
0) { if (((PyObject*)obj)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4802, (
PyObject *)(obj)); } else _Py_Dealloc((PyObject *)(obj)); } while
(0)
;
4803 return -1;
4804 }
4805 PDATA_PUSH(self->stack, obj, -1)do { if (Pdata_push((self->stack), (obj)) < 0) return (
-1); } while(0)
;
4806 return 0;
4807}
4808
4809static int
4810load_put(UnpicklerObject *self)
4811{
4812 PyObject *key, *value;
4813 Py_ssize_t idx;
4814 Py_ssize_t len;
4815 char *s;
4816
4817 if ((len = _Unpickler_Readline(self, &s)) < 0)
4818 return -1;
4819 if (len < 2)
4820 return bad_readline();
4821 if (Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) <= 0)
4822 return stack_underflow();
4823 value = self->stack->data[Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 1];
4824
4825 key = PyLong_FromString(s, NULL((void*)0), 10);
4826 if (key == NULL((void*)0))
4827 return -1;
4828 idx = PyLong_AsSsize_t(key);
4829 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4829, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
4830 if (idx == -1 && PyErr_Occurred())
4831 return -1;
4832
4833 return _Unpickler_MemoPut(self, idx, value);
4834}
4835
4836static int
4837load_binput(UnpicklerObject *self)
4838{
4839 PyObject *value;
4840 Py_ssize_t idx;
4841 char *s;
4842
4843 if (_Unpickler_Read(self, &s, 1) < 0)
4844 return -1;
4845
4846 if (Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) <= 0)
4847 return stack_underflow();
4848 value = self->stack->data[Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 1];
4849
4850 idx = Py_CHARMASK(s[0])((unsigned char)((s[0]) & 0xff));
4851
4852 return _Unpickler_MemoPut(self, idx, value);
4853}
4854
4855static int
4856load_long_binput(UnpicklerObject *self)
4857{
4858 PyObject *value;
4859 Py_ssize_t idx;
4860 char *s;
4861
4862 if (_Unpickler_Read(self, &s, 4) < 0)
4863 return -1;
4864
4865 if (Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) <= 0)
4866 return stack_underflow();
4867 value = self->stack->data[Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 1];
4868
4869 idx = (long)Py_CHARMASK(s[0])((unsigned char)((s[0]) & 0xff));
4870 idx |= (long)Py_CHARMASK(s[1])((unsigned char)((s[1]) & 0xff)) << 8;
4871 idx |= (long)Py_CHARMASK(s[2])((unsigned char)((s[2]) & 0xff)) << 16;
4872 idx |= (long)Py_CHARMASK(s[3])((unsigned char)((s[3]) & 0xff)) << 24;
4873
4874 return _Unpickler_MemoPut(self, idx, value);
4875}
4876
4877static int
4878do_append(UnpicklerObject *self, int x)
4879{
4880 PyObject *value;
4881 PyObject *list;
4882 int len, i;
4883
4884 len = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size);
4885 if (x > len || x <= 0)
4886 return stack_underflow();
4887 if (len == x) /* nothing to do */
4888 return 0;
4889
4890 list = self->stack->data[x - 1];
4891
4892 if (PyList_Check(list)((((((PyObject*)(list))->ob_type))->tp_flags & ((1L
<<25))) != 0)
) {
4893 PyObject *slice;
4894 Py_ssize_t list_len;
4895
4896 slice = Pdata_poplist(self->stack, x);
4897 if (!slice)
4898 return -1;
4899 list_len = PyList_GET_SIZE(list)(((PyVarObject*)(list))->ob_size);
4900 i = PyList_SetSlice(list, list_len, list_len, slice);
4901 Py_DECREF(slice)do { if (_Py_RefTotal-- , --((PyObject*)(slice))->ob_refcnt
!= 0) { if (((PyObject*)slice)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4901, (
PyObject *)(slice)); } else _Py_Dealloc((PyObject *)(slice));
} while (0)
;
4902 return i;
4903 }
4904 else {
4905 PyObject *append_func;
4906
4907 append_func = PyObject_GetAttrString(list, "append");
4908 if (append_func == NULL((void*)0))
4909 return -1;
4910 for (i = x; i < len; i++) {
4911 PyObject *result;
4912
4913 value = self->stack->data[i];
4914 result = _Unpickler_FastCall(self, append_func, value);
4915 if (result == NULL((void*)0)) {
4916 Pdata_clear(self->stack, i + 1);
4917 Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) = x;
4918 return -1;
4919 }
4920 Py_DECREF(result)do { if (_Py_RefTotal-- , --((PyObject*)(result))->ob_refcnt
!= 0) { if (((PyObject*)result)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 4920, (
PyObject *)(result)); } else _Py_Dealloc((PyObject *)(result)
); } while (0)
;
4921 }
4922 Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) = x;
4923 }
4924
4925 return 0;
4926}
4927
4928static int
4929load_append(UnpicklerObject *self)
4930{
4931 return do_append(self, Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 1);
4932}
4933
4934static int
4935load_appends(UnpicklerObject *self)
4936{
4937 return do_append(self, marker(self));
4938}
4939
4940static int
4941do_setitems(UnpicklerObject *self, int x)
4942{
4943 PyObject *value, *key;
4944 PyObject *dict;
4945 int len, i;
4946 int status = 0;
4947
4948 len = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size);
4949 if (x > len || x <= 0)
4950 return stack_underflow();
4951 if (len == x) /* nothing to do */
4952 return 0;
4953 if ((len - x) % 2 != 0) {
4954 /* Currupt or hostile pickle -- we never write one like this. */
4955 PyErr_SetString(UnpicklingError, "odd number of items for SETITEMS");
4956 return -1;
4957 }
4958
4959 /* Here, dict does not actually need to be a PyDict; it could be anything
4960 that supports the __setitem__ attribute. */
4961 dict = self->stack->data[x - 1];
4962
4963 for (i = x + 1; i < len; i += 2) {
4964 key = self->stack->data[i - 1];
4965 value = self->stack->data[i];
4966 if (PyObject_SetItem(dict, key, value) < 0) {
4967 status = -1;
4968 break;
4969 }
4970 }
4971
4972 Pdata_clear(self->stack, x);
4973 return status;
4974}
4975
4976static int
4977load_setitem(UnpicklerObject *self)
4978{
4979 return do_setitems(self, Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 2);
4980}
4981
4982static int
4983load_setitems(UnpicklerObject *self)
4984{
4985 return do_setitems(self, marker(self));
4986}
4987
4988static int
4989load_build(UnpicklerObject *self)
4990{
4991 PyObject *state, *inst, *slotstate;
4992 PyObject *setstate;
4993 int status = 0;
4994
4995 /* Stack is ... instance, state. We want to leave instance at
4996 * the stack top, possibly mutated via instance.__setstate__(state).
4997 */
4998 if (Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) < 2)
4999 return stack_underflow();
5000
5001 PDATA_POP(self->stack, state)do { (state) = Pdata_pop((self->stack)); } while (0);
5002 if (state == NULL((void*)0))
5003 return -1;
5004
5005 inst = self->stack->data[Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size) - 1];
5006
5007 setstate = PyObject_GetAttrString(inst, "__setstate__");
5008 if (setstate == NULL((void*)0)) {
5009 if (PyErr_ExceptionMatches(PyExc_AttributeError))
5010 PyErr_Clear();
5011 else {
5012 Py_DECREF(state)do { if (_Py_RefTotal-- , --((PyObject*)(state))->ob_refcnt
!= 0) { if (((PyObject*)state)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5012, (
PyObject *)(state)); } else _Py_Dealloc((PyObject *)(state));
} while (0)
;
5013 return -1;
5014 }
5015 }
5016 else {
5017 PyObject *result;
5018
5019 /* The explicit __setstate__ is responsible for everything. */
5020 /* Ugh... this does not leak since _Unpickler_FastCall() steals the
5021 reference to state first. */
5022 result = _Unpickler_FastCall(self, setstate, state);
5023 Py_DECREF(setstate)do { if (_Py_RefTotal-- , --((PyObject*)(setstate))->ob_refcnt
!= 0) { if (((PyObject*)setstate)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5023, (
PyObject *)(setstate)); } else _Py_Dealloc((PyObject *)(setstate
)); } while (0)
;
5024 if (result == NULL((void*)0))
5025 return -1;
5026 Py_DECREF(result)do { if (_Py_RefTotal-- , --((PyObject*)(result))->ob_refcnt
!= 0) { if (((PyObject*)result)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5026, (
PyObject *)(result)); } else _Py_Dealloc((PyObject *)(result)
); } while (0)
;
5027 return 0;
5028 }
5029
5030 /* A default __setstate__. First see whether state embeds a
5031 * slot state dict too (a proto 2 addition).
5032 */
5033 if (PyTuple_Check(state)((((((PyObject*)(state))->ob_type))->tp_flags & ((1L
<<26))) != 0)
&& Py_SIZE(state)(((PyVarObject*)(state))->ob_size) == 2) {
5034 PyObject *tmp = state;
5035
5036 state = PyTuple_GET_ITEM(tmp, 0)(((PyTupleObject *)(tmp))->ob_item[0]);
5037 slotstate = PyTuple_GET_ITEM(tmp, 1)(((PyTupleObject *)(tmp))->ob_item[1]);
5038 Py_INCREF(state)( _Py_RefTotal++ , ((PyObject*)(state))->ob_refcnt++);
5039 Py_INCREF(slotstate)( _Py_RefTotal++ , ((PyObject*)(slotstate))->ob_refcnt++);
5040 Py_DECREF(tmp)do { if (_Py_RefTotal-- , --((PyObject*)(tmp))->ob_refcnt !=
0) { if (((PyObject*)tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5040, (
PyObject *)(tmp)); } else _Py_Dealloc((PyObject *)(tmp)); } while
(0)
;
5041 }
5042 else
5043 slotstate = NULL((void*)0);
5044
5045 /* Set inst.__dict__ from the state dict (if any). */
5046 if (state != Py_None(&_Py_NoneStruct)) {
5047 PyObject *dict;
5048 PyObject *d_key, *d_value;
5049 Py_ssize_t i;
5050
5051 if (!PyDict_Check(state)((((((PyObject*)(state))->ob_type))->tp_flags & ((1L
<<29))) != 0)
) {
5052 PyErr_SetString(UnpicklingError, "state is not a dictionary");
5053 goto error;
5054 }
5055 dict = PyObject_GetAttrString(inst, "__dict__");
5056 if (dict == NULL((void*)0))
5057 goto error;
5058
5059 i = 0;
5060 while (PyDict_Next(state, &i, &d_key, &d_value)) {
5061 /* normally the keys for instance attributes are
5062 interned. we should try to do that here. */
5063 Py_INCREF(d_key)( _Py_RefTotal++ , ((PyObject*)(d_key))->ob_refcnt++);
5064 if (PyUnicode_CheckExact(d_key)((((PyObject*)(d_key))->ob_type) == &PyUnicode_Type))
5065 PyUnicode_InternInPlace(&d_key);
5066 if (PyObject_SetItem(dict, d_key, d_value) < 0) {
5067 Py_DECREF(d_key)do { if (_Py_RefTotal-- , --((PyObject*)(d_key))->ob_refcnt
!= 0) { if (((PyObject*)d_key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5067, (
PyObject *)(d_key)); } else _Py_Dealloc((PyObject *)(d_key));
} while (0)
;
5068 goto error;
5069 }
5070 Py_DECREF(d_key)do { if (_Py_RefTotal-- , --((PyObject*)(d_key))->ob_refcnt
!= 0) { if (((PyObject*)d_key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5070, (
PyObject *)(d_key)); } else _Py_Dealloc((PyObject *)(d_key));
} while (0)
;
5071 }
5072 Py_DECREF(dict)do { if (_Py_RefTotal-- , --((PyObject*)(dict))->ob_refcnt
!= 0) { if (((PyObject*)dict)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5072, (
PyObject *)(dict)); } else _Py_Dealloc((PyObject *)(dict)); }
while (0)
;
5073 }
5074
5075 /* Also set instance attributes from the slotstate dict (if any). */
5076 if (slotstate != NULL((void*)0)) {
5077 PyObject *d_key, *d_value;
5078 Py_ssize_t i;
5079
5080 if (!PyDict_Check(slotstate)((((((PyObject*)(slotstate))->ob_type))->tp_flags &
((1L<<29))) != 0)
) {
5081 PyErr_SetString(UnpicklingError,
5082 "slot state is not a dictionary");
5083 goto error;
5084 }
5085 i = 0;
5086 while (PyDict_Next(slotstate, &i, &d_key, &d_value)) {
5087 if (PyObject_SetAttr(inst, d_key, d_value) < 0)
5088 goto error;
5089 }
5090 }
5091
5092 if (0) {
5093 error:
5094 status = -1;
5095 }
5096
5097 Py_DECREF(state)do { if (_Py_RefTotal-- , --((PyObject*)(state))->ob_refcnt
!= 0) { if (((PyObject*)state)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5097, (
PyObject *)(state)); } else _Py_Dealloc((PyObject *)(state));
} while (0)
;
5098 Py_XDECREF(slotstate)do { if ((slotstate) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(slotstate))->ob_refcnt != 0) { if (((PyObject
*)slotstate)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5098, (PyObject *)(slotstate)); } else _Py_Dealloc((PyObject
*)(slotstate)); } while (0); } while (0)
;
5099 return status;
5100}
5101
5102static int
5103load_mark(UnpicklerObject *self)
5104{
5105
5106 /* Note that we split the (pickle.py) stack into two stacks, an
5107 * object stack and a mark stack. Here we push a mark onto the
5108 * mark stack.
5109 */
5110
5111 if ((self->num_marks + 1) >= self->marks_size) {
5112 size_t alloc;
5113 int *marks;
5114
5115 /* Use the size_t type to check for overflow. */
5116 alloc = ((size_t)self->num_marks << 1) + 20;
5117 if (alloc > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1)) ||
5118 alloc <= ((size_t)self->num_marks + 1)) {
5119 PyErr_NoMemory();
5120 return -1;
5121 }
5122
5123 if (self->marks == NULL((void*)0))
5124 marks = (int *)PyMem_Malloc(alloc * sizeof(int));
5125 else
5126 marks = (int *)PyMem_Realloc(self->marks, alloc * sizeof(int));
5127 if (marks == NULL((void*)0)) {
5128 PyErr_NoMemory();
5129 return -1;
5130 }
5131 self->marks = marks;
5132 self->marks_size = (Py_ssize_t)alloc;
5133 }
5134
5135 self->marks[self->num_marks++] = Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size);
5136
5137 return 0;
5138}
5139
5140static int
5141load_reduce(UnpicklerObject *self)
5142{
5143 PyObject *callable = NULL((void*)0);
5144 PyObject *argtup = NULL((void*)0);
5145 PyObject *obj = NULL((void*)0);
5146
5147 PDATA_POP(self->stack, argtup)do { (argtup) = Pdata_pop((self->stack)); } while (0);
5148 if (argtup == NULL((void*)0))
5149 return -1;
5150 PDATA_POP(self->stack, callable)do { (callable) = Pdata_pop((self->stack)); } while (0);
5151 if (callable) {
5152 obj = PyObject_CallObject(callable, argtup);
5153 Py_DECREF(callable)do { if (_Py_RefTotal-- , --((PyObject*)(callable))->ob_refcnt
!= 0) { if (((PyObject*)callable)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5153, (
PyObject *)(callable)); } else _Py_Dealloc((PyObject *)(callable
)); } while (0)
;
5154 }
5155 Py_DECREF(argtup)do { if (_Py_RefTotal-- , --((PyObject*)(argtup))->ob_refcnt
!= 0) { if (((PyObject*)argtup)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5155, (
PyObject *)(argtup)); } else _Py_Dealloc((PyObject *)(argtup)
); } while (0)
;
5156
5157 if (obj == NULL((void*)0))
5158 return -1;
5159
5160 PDATA_PUSH(self->stack, obj, -1)do { if (Pdata_push((self->stack), (obj)) < 0) return (
-1); } while(0)
;
5161 return 0;
5162}
5163
5164/* Just raises an error if we don't know the protocol specified. PROTO
5165 * is the first opcode for protocols >= 2.
5166 */
5167static int
5168load_proto(UnpicklerObject *self)
5169{
5170 char *s;
5171 int i;
5172
5173 if (_Unpickler_Read(self, &s, 1) < 0)
5174 return -1;
5175
5176 i = (unsigned char)s[0];
5177 if (i <= HIGHEST_PROTOCOL) {
5178 self->proto = i;
5179 return 0;
5180 }
5181
5182 PyErr_Format(PyExc_ValueError, "unsupported pickle protocol: %d", i);
5183 return -1;
5184}
5185
5186static PyObject *
5187load(UnpicklerObject *self)
5188{
5189 PyObject *err;
5190 PyObject *value = NULL((void*)0);
5191 char *s;
5192
5193 self->num_marks = 0;
5194 if (Py_SIZE(self->stack)(((PyVarObject*)(self->stack))->ob_size))
5195 Pdata_clear(self->stack, 0);
5196
5197 /* Convenient macros for the dispatch while-switch loop just below. */
5198#define OP(opcode, load_func)case opcode: if (load_func(self) < 0) break; continue; \
5199 case opcode: if (load_func(self) < 0) break; continue;
5200
5201#define OP_ARG(opcode, load_func, arg)case opcode: if (load_func(self, (arg)) < 0) break; continue
;
\
5202 case opcode: if (load_func(self, (arg)) < 0) break; continue;
5203
5204 while (1) {
5205 if (_Unpickler_Read(self, &s, 1) < 0)
5206 break;
5207
5208 switch ((enum opcode)s[0]) {
5209 OP(NONE, load_none)case NONE: if (load_none(self) < 0) break; continue;
5210 OP(BININT, load_binint)case BININT: if (load_binint(self) < 0) break; continue;
5211 OP(BININT1, load_binint1)case BININT1: if (load_binint1(self) < 0) break; continue;
5212 OP(BININT2, load_binint2)case BININT2: if (load_binint2(self) < 0) break; continue;
5213 OP(INT, load_int)case INT: if (load_int(self) < 0) break; continue;
5214 OP(LONG, load_long)case LONG: if (load_long(self) < 0) break; continue;
5215 OP_ARG(LONG1, load_counted_long, 1)case LONG1: if (load_counted_long(self, (1)) < 0) break; continue
;
5216 OP_ARG(LONG4, load_counted_long, 4)case LONG4: if (load_counted_long(self, (4)) < 0) break; continue
;
5217 OP(FLOAT, load_float)case FLOAT: if (load_float(self) < 0) break; continue;
5218 OP(BINFLOAT, load_binfloat)case BINFLOAT: if (load_binfloat(self) < 0) break; continue
;
5219 OP(BINBYTES, load_binbytes)case BINBYTES: if (load_binbytes(self) < 0) break; continue
;
5220 OP(SHORT_BINBYTES, load_short_binbytes)case SHORT_BINBYTES: if (load_short_binbytes(self) < 0) break
; continue;
5221 OP(BINSTRING, load_binstring)case BINSTRING: if (load_binstring(self) < 0) break; continue
;
5222 OP(SHORT_BINSTRING, load_short_binstring)case SHORT_BINSTRING: if (load_short_binstring(self) < 0) break
; continue;
5223 OP(STRING, load_string)case STRING: if (load_string(self) < 0) break; continue;
5224 OP(UNICODE, load_unicode)case UNICODE: if (load_unicode(self) < 0) break; continue;
5225 OP(BINUNICODE, load_binunicode)case BINUNICODE: if (load_binunicode(self) < 0) break; continue
;
5226 OP_ARG(EMPTY_TUPLE, load_counted_tuple, 0)case EMPTY_TUPLE: if (load_counted_tuple(self, (0)) < 0) break
; continue;
5227 OP_ARG(TUPLE1, load_counted_tuple, 1)case TUPLE1: if (load_counted_tuple(self, (1)) < 0) break;
continue;
5228 OP_ARG(TUPLE2, load_counted_tuple, 2)case TUPLE2: if (load_counted_tuple(self, (2)) < 0) break;
continue;
5229 OP_ARG(TUPLE3, load_counted_tuple, 3)case TUPLE3: if (load_counted_tuple(self, (3)) < 0) break;
continue;
5230 OP(TUPLE, load_tuple)case TUPLE: if (load_tuple(self) < 0) break; continue;
5231 OP(EMPTY_LIST, load_empty_list)case EMPTY_LIST: if (load_empty_list(self) < 0) break; continue
;
5232 OP(LIST, load_list)case LIST: if (load_list(self) < 0) break; continue;
5233 OP(EMPTY_DICT, load_empty_dict)case EMPTY_DICT: if (load_empty_dict(self) < 0) break; continue
;
5234 OP(DICT, load_dict)case DICT: if (load_dict(self) < 0) break; continue;
5235 OP(OBJ, load_obj)case OBJ: if (load_obj(self) < 0) break; continue;
5236 OP(INST, load_inst)case INST: if (load_inst(self) < 0) break; continue;
5237 OP(NEWOBJ, load_newobj)case NEWOBJ: if (load_newobj(self) < 0) break; continue;
5238 OP(GLOBAL, load_global)case GLOBAL: if (load_global(self) < 0) break; continue;
5239 OP(APPEND, load_append)case APPEND: if (load_append(self) < 0) break; continue;
5240 OP(APPENDS, load_appends)case APPENDS: if (load_appends(self) < 0) break; continue;
5241 OP(BUILD, load_build)case BUILD: if (load_build(self) < 0) break; continue;
5242 OP(DUP, load_dup)case DUP: if (load_dup(self) < 0) break; continue;
5243 OP(BINGET, load_binget)case BINGET: if (load_binget(self) < 0) break; continue;
5244 OP(LONG_BINGET, load_long_binget)case LONG_BINGET: if (load_long_binget(self) < 0) break; continue
;
5245 OP(GET, load_get)case GET: if (load_get(self) < 0) break; continue;
5246 OP(MARK, load_mark)case MARK: if (load_mark(self) < 0) break; continue;
5247 OP(BINPUT, load_binput)case BINPUT: if (load_binput(self) < 0) break; continue;
5248 OP(LONG_BINPUT, load_long_binput)case LONG_BINPUT: if (load_long_binput(self) < 0) break; continue
;
5249 OP(PUT, load_put)case PUT: if (load_put(self) < 0) break; continue;
5250 OP(POP, load_pop)case POP: if (load_pop(self) < 0) break; continue;
5251 OP(POP_MARK, load_pop_mark)case POP_MARK: if (load_pop_mark(self) < 0) break; continue
;
5252 OP(SETITEM, load_setitem)case SETITEM: if (load_setitem(self) < 0) break; continue;
5253 OP(SETITEMS, load_setitems)case SETITEMS: if (load_setitems(self) < 0) break; continue
;
5254 OP(PERSID, load_persid)case PERSID: if (load_persid(self) < 0) break; continue;
5255 OP(BINPERSID, load_binpersid)case BINPERSID: if (load_binpersid(self) < 0) break; continue
;
5256 OP(REDUCE, load_reduce)case REDUCE: if (load_reduce(self) < 0) break; continue;
5257 OP(PROTO, load_proto)case PROTO: if (load_proto(self) < 0) break; continue;
5258 OP_ARG(EXT1, load_extension, 1)case EXT1: if (load_extension(self, (1)) < 0) break; continue
;
5259 OP_ARG(EXT2, load_extension, 2)case EXT2: if (load_extension(self, (2)) < 0) break; continue
;
5260 OP_ARG(EXT4, load_extension, 4)case EXT4: if (load_extension(self, (4)) < 0) break; continue
;
5261 OP_ARG(NEWTRUE, load_bool, Py_True)case NEWTRUE: if (load_bool(self, (((PyObject *) &_Py_TrueStruct
))) < 0) break; continue;
5262 OP_ARG(NEWFALSE, load_bool, Py_False)case NEWFALSE: if (load_bool(self, (((PyObject *) &_Py_FalseStruct
))) < 0) break; continue;
5263
5264 case STOP:
5265 break;
5266
5267 case '\0':
5268 PyErr_SetNone(PyExc_EOFError);
5269 return NULL((void*)0);
5270
5271 default:
5272 PyErr_Format(UnpicklingError,
5273 "invalid load key, '%c'.", s[0]);
5274 return NULL((void*)0);
5275 }
5276
5277 break; /* and we are done! */
5278 }
5279
5280 if (_Unpickler_SkipConsumed(self) < 0)
5281 return NULL((void*)0);
5282
5283 /* XXX: It is not clear what this is actually for. */
5284 if ((err = PyErr_Occurred())) {
5285 if (err == PyExc_EOFError) {
5286 PyErr_SetNone(PyExc_EOFError);
5287 }
5288 return NULL((void*)0);
5289 }
5290
5291 PDATA_POP(self->stack, value)do { (value) = Pdata_pop((self->stack)); } while (0);
5292 return value;
5293}
5294
5295PyDoc_STRVAR(Unpickler_load_doc,static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
5296"load() -> object. Load a pickle."static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
5297"\n"static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
5298"Read a pickled object representation from the open file object given in\n"static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
5299"the constructor, and return the reconstituted object hierarchy specified\n"static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
5300"therein.\n")static char Unpickler_load_doc[] = "load() -> object. Load a pickle."
"\n""Read a pickled object representation from the open file object given in\n"
"the constructor, and return the reconstituted object hierarchy specified\n"
"therein.\n"
;
5301
5302static PyObject *
5303Unpickler_load(UnpicklerObject *self)
5304{
5305 /* Check whether the Unpickler was initialized correctly. This prevents
5306 segfaulting if a subclass overridden __init__ with a function that does
5307 not call Unpickler.__init__(). Here, we simply ensure that self->read
5308 is not NULL. */
5309 if (self->read == NULL((void*)0)) {
5310 PyErr_Format(UnpicklingError,
5311 "Unpickler.__init__() was not called by %s.__init__()",
5312 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_name);
5313 return NULL((void*)0);
5314 }
5315
5316 return load(self);
5317}
5318
5319/* The name of find_class() is misleading. In newer pickle protocols, this
5320 function is used for loading any global (i.e., functions), not just
5321 classes. The name is kept only for backward compatibility. */
5322
5323PyDoc_STRVAR(Unpickler_find_class_doc,static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5324"find_class(module_name, global_name) -> object.\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5325"\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5326"Return an object from a specified module, importing the module if\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5327"necessary. Subclasses may override this method (e.g. to restrict\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5328"unpickling of arbitrary classes and functions).\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5329"\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5330"This method is called whenever a class or a function object is\n"static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
5331"needed. Both arguments passed are str objects.\n")static char Unpickler_find_class_doc[] = "find_class(module_name, global_name) -> object.\n"
"\n""Return an object from a specified module, importing the module if\n"
"necessary. Subclasses may override this method (e.g. to restrict\n"
"unpickling of arbitrary classes and functions).\n""\n""This method is called whenever a class or a function object is\n"
"needed. Both arguments passed are str objects.\n"
;
5332
5333static PyObject *
5334Unpickler_find_class(UnpicklerObject *self, PyObject *args)
5335{
5336 PyObject *global;
5337 PyObject *modules_dict;
5338 PyObject *module;
5339 PyObject *module_name, *global_name;
5340
5341 if (!PyArg_UnpackTuple(args, "find_class", 2, 2,
5342 &module_name, &global_name))
5343 return NULL((void*)0);
5344
5345 /* Try to map the old names used in Python 2.x to the new ones used in
5346 Python 3.x. We do this only with old pickle protocols and when the
5347 user has not disabled the feature. */
5348 if (self->proto < 3 && self->fix_imports) {
5349 PyObject *key;
5350 PyObject *item;
5351
5352 /* Check if the global (i.e., a function or a class) was renamed
5353 or moved to another module. */
5354 key = PyTuple_Pack(2, module_name, global_name);
5355 if (key == NULL((void*)0))
5356 return NULL((void*)0);
5357 item = PyDict_GetItemWithError(name_mapping_2to3, key);
5358 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5358, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
5359 if (item) {
5360 if (!PyTuple_Check(item)((((((PyObject*)(item))->ob_type))->tp_flags & ((1L
<<26))) != 0)
|| PyTuple_GET_SIZE(item)(((PyVarObject*)(item))->ob_size) != 2) {
5361 PyErr_Format(PyExc_RuntimeError,
5362 "_compat_pickle.NAME_MAPPING values should be "
5363 "2-tuples, not %.200s", Py_TYPE(item)(((PyObject*)(item))->ob_type)->tp_name);
5364 return NULL((void*)0);
5365 }
5366 module_name = PyTuple_GET_ITEM(item, 0)(((PyTupleObject *)(item))->ob_item[0]);
5367 global_name = PyTuple_GET_ITEM(item, 1)(((PyTupleObject *)(item))->ob_item[1]);
5368 if (!PyUnicode_Check(module_name)((((((PyObject*)(module_name))->ob_type))->tp_flags &
((1L<<28))) != 0)
||
5369 !PyUnicode_Check(global_name)((((((PyObject*)(global_name))->ob_type))->tp_flags &
((1L<<28))) != 0)
) {
5370 PyErr_Format(PyExc_RuntimeError,
5371 "_compat_pickle.NAME_MAPPING values should be "
5372 "pairs of str, not (%.200s, %.200s)",
5373 Py_TYPE(module_name)(((PyObject*)(module_name))->ob_type)->tp_name,
5374 Py_TYPE(global_name)(((PyObject*)(global_name))->ob_type)->tp_name);
5375 return NULL((void*)0);
5376 }
5377 }
5378 else if (PyErr_Occurred()) {
5379 return NULL((void*)0);
5380 }
5381
5382 /* Check if the module was renamed. */
5383 item = PyDict_GetItemWithError(import_mapping_2to3, module_name);
5384 if (item) {
5385 if (!PyUnicode_Check(item)((((((PyObject*)(item))->ob_type))->tp_flags & ((1L
<<28))) != 0)
) {
5386 PyErr_Format(PyExc_RuntimeError,
5387 "_compat_pickle.IMPORT_MAPPING values should be "
5388 "strings, not %.200s", Py_TYPE(item)(((PyObject*)(item))->ob_type)->tp_name);
5389 return NULL((void*)0);
5390 }
5391 module_name = item;
5392 }
5393 else if (PyErr_Occurred()) {
5394 return NULL((void*)0);
5395 }
5396 }
5397
5398 modules_dict = PySys_GetObject("modules");
5399 if (modules_dict == NULL((void*)0))
5400 return NULL((void*)0);
5401
5402 module = PyDict_GetItemWithError(modules_dict, module_name);
5403 if (module == NULL((void*)0)) {
5404 if (PyErr_Occurred())
5405 return NULL((void*)0);
5406 module = PyImport_Import(module_name);
5407 if (module == NULL((void*)0))
5408 return NULL((void*)0);
5409 global = PyObject_GetAttr(module, global_name);
5410 Py_DECREF(module)do { if (_Py_RefTotal-- , --((PyObject*)(module))->ob_refcnt
!= 0) { if (((PyObject*)module)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5410, (
PyObject *)(module)); } else _Py_Dealloc((PyObject *)(module)
); } while (0)
;
5411 }
5412 else {
5413 global = PyObject_GetAttr(module, global_name);
5414 }
5415 return global;
5416}
5417
5418static struct PyMethodDef Unpickler_methods[] = {
5419 {"load", (PyCFunction)Unpickler_load, METH_NOARGS0x0004,
5420 Unpickler_load_doc},
5421 {"find_class", (PyCFunction)Unpickler_find_class, METH_VARARGS0x0001,
5422 Unpickler_find_class_doc},
5423 {NULL((void*)0), NULL((void*)0)} /* sentinel */
5424};
5425
5426static void
5427Unpickler_dealloc(UnpicklerObject *self)
5428{
5429 PyObject_GC_UnTrack((PyObject *)self);
5430 Py_XDECREF(self->readline)do { if ((self->readline) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->readline))->ob_refcnt != 0) {
if (((PyObject*)self->readline)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5430, (
PyObject *)(self->readline)); } else _Py_Dealloc((PyObject
*)(self->readline)); } while (0); } while (0)
;
5431 Py_XDECREF(self->read)do { if ((self->read) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->read))->ob_refcnt != 0) { if (
((PyObject*)self->read)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5431, (
PyObject *)(self->read)); } else _Py_Dealloc((PyObject *)(
self->read)); } while (0); } while (0)
;
5432 Py_XDECREF(self->peek)do { if ((self->peek) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->peek))->ob_refcnt != 0) { if (
((PyObject*)self->peek)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5432, (
PyObject *)(self->peek)); } else _Py_Dealloc((PyObject *)(
self->peek)); } while (0); } while (0)
;
5433 Py_XDECREF(self->stack)do { if ((self->stack) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->stack))->ob_refcnt != 0) { if
(((PyObject*)self->stack)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5433, (
PyObject *)(self->stack)); } else _Py_Dealloc((PyObject *)
(self->stack)); } while (0); } while (0)
;
5434 Py_XDECREF(self->pers_func)do { if ((self->pers_func) == ((void*)0)) ; else do { if (
_Py_RefTotal-- , --((PyObject*)(self->pers_func))->ob_refcnt
!= 0) { if (((PyObject*)self->pers_func)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5434, (PyObject *)(self->pers_func)); } else _Py_Dealloc
((PyObject *)(self->pers_func)); } while (0); } while (0)
;
5435 Py_XDECREF(self->arg)do { if ((self->arg) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(self->arg))->ob_refcnt != 0) { if (
((PyObject*)self->arg)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5435, (
PyObject *)(self->arg)); } else _Py_Dealloc((PyObject *)(self
->arg)); } while (0); } while (0)
;
5436 if (self->buffer.buf != NULL((void*)0)) {
5437 PyBuffer_Release(&self->buffer);
5438 self->buffer.buf = NULL((void*)0);
5439 }
5440
5441 _Unpickler_MemoCleanup(self);
5442 PyMem_Free(self->marks);
5443 PyMem_Free(self->input_line);
5444 free(self->encoding);
5445 free(self->errors);
5446
5447 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_free((PyObject *)self);
5448}
5449
5450static int
5451Unpickler_traverse(UnpicklerObject *self, visitproc visit, void *arg)
5452{
5453 Py_VISIT(self->readline)do { if (self->readline) { int vret = visit((PyObject *)(self
->readline), arg); if (vret) return vret; } } while (0)
;
5454 Py_VISIT(self->read)do { if (self->read) { int vret = visit((PyObject *)(self->
read), arg); if (vret) return vret; } } while (0)
;
5455 Py_VISIT(self->peek)do { if (self->peek) { int vret = visit((PyObject *)(self->
peek), arg); if (vret) return vret; } } while (0)
;
5456 Py_VISIT(self->stack)do { if (self->stack) { int vret = visit((PyObject *)(self
->stack), arg); if (vret) return vret; } } while (0)
;
5457 Py_VISIT(self->pers_func)do { if (self->pers_func) { int vret = visit((PyObject *)(
self->pers_func), arg); if (vret) return vret; } } while (
0)
;
5458 Py_VISIT(self->arg)do { if (self->arg) { int vret = visit((PyObject *)(self->
arg), arg); if (vret) return vret; } } while (0)
;
5459 return 0;
5460}
5461
5462static int
5463Unpickler_clear(UnpicklerObject *self)
5464{
5465 Py_CLEAR(self->readline)do { if (self->readline) { PyObject *_py_tmp = (PyObject *
)(self->readline); (self->readline) = ((void*)0); do { if
(_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0
) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5465, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
5466 Py_CLEAR(self->read)do { if (self->read) { PyObject *_py_tmp = (PyObject *)(self
->read); (self->read) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5466, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
5467 Py_CLEAR(self->peek)do { if (self->peek) { PyObject *_py_tmp = (PyObject *)(self
->peek); (self->peek) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5467, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
5468 Py_CLEAR(self->stack)do { if (self->stack) { PyObject *_py_tmp = (PyObject *)(self
->stack); (self->stack) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5468, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
5469 Py_CLEAR(self->pers_func)do { if (self->pers_func) { PyObject *_py_tmp = (PyObject *
)(self->pers_func); (self->pers_func) = ((void*)0); do {
if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt !=
0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5469, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
5470 Py_CLEAR(self->arg)do { if (self->arg) { PyObject *_py_tmp = (PyObject *)(self
->arg); (self->arg) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5470, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
5471 if (self->buffer.buf != NULL((void*)0)) {
5472 PyBuffer_Release(&self->buffer);
5473 self->buffer.buf = NULL((void*)0);
5474 }
5475
5476 _Unpickler_MemoCleanup(self);
5477 PyMem_Free(self->marks);
5478 self->marks = NULL((void*)0);
5479 PyMem_Free(self->input_line);
5480 self->input_line = NULL((void*)0);
5481 free(self->encoding);
5482 self->encoding = NULL((void*)0);
5483 free(self->errors);
5484 self->errors = NULL((void*)0);
5485
5486 return 0;
5487}
5488
5489PyDoc_STRVAR(Unpickler_doc,static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5490"Unpickler(file, *, encoding='ASCII', errors='strict')"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5491"\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5492"This takes a binary file for reading a pickle data stream.\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5493"\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5494"The protocol version of the pickle is detected automatically, so no\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5495"proto argument is needed.\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5496"\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5497"The file-like object must have two methods, a read() method\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5498"that takes an integer argument, and a readline() method that\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5499"requires no arguments. Both methods should return bytes.\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5500"Thus file-like object can be a binary file object opened for\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5501"reading, a BytesIO object, or any other custom object that\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5502"meets this interface.\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5503"\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5504"Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5505"which are used to control compatiblity support for pickle stream\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5506"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5507"map the old Python 2.x names to the new names used in Python 3.x. The\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5508"*encoding* and *errors* tell pickle how to decode 8-bit string\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5509"instances pickled by Python 2.x; these default to 'ASCII' and\n"static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
5510"'strict', respectively.\n")static char Unpickler_doc[] = "Unpickler(file, *, encoding='ASCII', errors='strict')"
"\n""This takes a binary file for reading a pickle data stream.\n"
"\n""The protocol version of the pickle is detected automatically, so no\n"
"proto argument is needed.\n""\n""The file-like object must have two methods, a read() method\n"
"that takes an integer argument, and a readline() method that\n"
"requires no arguments. Both methods should return bytes.\n"
"Thus file-like object can be a binary file object opened for\n"
"reading, a BytesIO object, or any other custom object that\n"
"meets this interface.\n""\n""Optional keyword arguments are *fix_imports*, *encoding* and *errors*,\n"
"which are used to control compatiblity support for pickle stream\n"
"generated by Python 2.x. If *fix_imports* is True, pickle will try to\n"
"map the old Python 2.x names to the new names used in Python 3.x. The\n"
"*encoding* and *errors* tell pickle how to decode 8-bit string\n"
"instances pickled by Python 2.x; these default to 'ASCII' and\n"
"'strict', respectively.\n"
;
5511
5512static int
5513Unpickler_init(UnpicklerObject *self, PyObject *args, PyObject *kwds)
5514{
5515 static char *kwlist[] = {"file", "fix_imports", "encoding", "errors", 0};
5516 PyObject *file;
5517 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
5518 char *encoding = NULL((void*)0);
5519 char *errors = NULL((void*)0);
5520
5521 /* XXX: That is an horrible error message. But, I don't know how to do
5522 better... */
5523 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) != 1) {
5524 PyErr_Format(PyExc_TypeError,
5525 "%s takes exactly one positional argument (%zd given)",
5526 Py_TYPE(self)(((PyObject*)(self))->ob_type)->tp_name, Py_SIZE(args)(((PyVarObject*)(args))->ob_size));
5527 return -1;
5528 }
5529
5530 /* Arguments parsing needs to be done in the __init__() method to allow
5531 subclasses to define their own __init__() method, which may (or may
5532 not) support Unpickler arguments. However, this means we need to be
5533 extra careful in the other Unpickler methods, since a subclass could
5534 forget to call Unpickler.__init__() thus breaking our internal
5535 invariants. */
5536 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oss:Unpickler", kwlist,
5537 &file, &fix_imports, &encoding, &errors))
5538 return -1;
5539
5540 /* In case of multiple __init__() calls, clear previous content. */
5541 if (self->read != NULL((void*)0))
5542 (void)Unpickler_clear(self);
5543
5544 if (_Unpickler_SetInputStream(self, file) < 0)
5545 return -1;
5546
5547 if (_Unpickler_SetInputEncoding(self, encoding, errors) < 0)
5548 return -1;
5549
5550 self->fix_imports = PyObject_IsTrue(fix_imports);
5551 if (self->fix_imports == -1)
5552 return -1;
5553
5554 if (PyObject_HasAttrString((PyObject *)self, "persistent_load")) {
5555 self->pers_func = PyObject_GetAttrString((PyObject *)self,
5556 "persistent_load");
5557 if (self->pers_func == NULL((void*)0))
5558 return -1;
5559 }
5560 else {
5561 self->pers_func = NULL((void*)0);
5562 }
5563
5564 self->stack = (Pdata *)Pdata_New();
5565 if (self->stack == NULL((void*)0))
5566 return -1;
5567
5568 self->memo_size = 32;
5569 self->memo = _Unpickler_NewMemo(self->memo_size);
5570 if (self->memo == NULL((void*)0))
5571 return -1;
5572
5573 self->arg = NULL((void*)0);
5574 self->proto = 0;
5575
5576 return 0;
5577}
5578
5579/* Define a proxy object for the Unpickler's internal memo object. This is to
5580 * avoid breaking code like:
5581 * unpickler.memo.clear()
5582 * and
5583 * unpickler.memo = saved_memo
5584 * Is this a good idea? Not really, but we don't want to break code that uses
5585 * it. Note that we don't implement the entire mapping API here. This is
5586 * intentional, as these should be treated as black-box implementation details.
5587 *
5588 * We do, however, have to implement pickling/unpickling support because of
5589 * real-world code like cvs2svn.
5590 */
5591
5592typedef struct {
5593 PyObject_HEADPyObject ob_base;
5594 UnpicklerObject *unpickler;
5595} UnpicklerMemoProxyObject;
5596
5597PyDoc_STRVAR(ump_clear_doc,static char ump_clear_doc[] = "memo.clear() -> None. Remove all items from memo."
5598"memo.clear() -> None. Remove all items from memo.")static char ump_clear_doc[] = "memo.clear() -> None. Remove all items from memo.";
5599
5600static PyObject *
5601ump_clear(UnpicklerMemoProxyObject *self)
5602{
5603 _Unpickler_MemoCleanup(self->unpickler);
5604 self->unpickler->memo = _Unpickler_NewMemo(self->unpickler->memo_size);
5605 if (self->unpickler->memo == NULL((void*)0))
5606 return NULL((void*)0);
5607 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
5608}
5609
5610PyDoc_STRVAR(ump_copy_doc,static char ump_copy_doc[] = "memo.copy() -> new_memo. Copy the memo to a new object."
5611"memo.copy() -> new_memo. Copy the memo to a new object.")static char ump_copy_doc[] = "memo.copy() -> new_memo. Copy the memo to a new object.";
5612
5613static PyObject *
5614ump_copy(UnpicklerMemoProxyObject *self)
5615{
5616 Py_ssize_t i;
5617 PyObject *new_memo = PyDict_New();
5618 if (new_memo == NULL((void*)0))
5619 return NULL((void*)0);
5620
5621 for (i = 0; i < self->unpickler->memo_size; i++) {
5622 int status;
5623 PyObject *key, *value;
5624
5625 value = self->unpickler->memo[i];
5626 if (value == NULL((void*)0))
5627 continue;
5628
5629 key = PyLong_FromSsize_t(i);
5630 if (key == NULL((void*)0))
5631 goto error;
5632 status = PyDict_SetItem(new_memo, key, value);
5633 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5633, (
PyObject *)(key)); } else _Py_Dealloc((PyObject *)(key)); } while
(0)
;
5634 if (status < 0)
5635 goto error;
5636 }
5637 return new_memo;
5638
5639error:
5640 Py_DECREF(new_memo)do { if (_Py_RefTotal-- , --((PyObject*)(new_memo))->ob_refcnt
!= 0) { if (((PyObject*)new_memo)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5640, (
PyObject *)(new_memo)); } else _Py_Dealloc((PyObject *)(new_memo
)); } while (0)
;
5641 return NULL((void*)0);
5642}
5643
5644PyDoc_STRVAR(ump_reduce_doc,static char ump_reduce_doc[] = "memo.__reduce__(). Pickling support."
5645"memo.__reduce__(). Pickling support.")static char ump_reduce_doc[] = "memo.__reduce__(). Pickling support.";
5646
5647static PyObject *
5648ump_reduce(UnpicklerMemoProxyObject *self, PyObject *args)
5649{
5650 PyObject *reduce_value;
5651 PyObject *constructor_args;
5652 PyObject *contents = ump_copy(self);
5653 if (contents == NULL((void*)0))
5654 return NULL((void*)0);
5655
5656 reduce_value = PyTuple_New(2);
5657 if (reduce_value == NULL((void*)0)) {
5658 Py_DECREF(contents)do { if (_Py_RefTotal-- , --((PyObject*)(contents))->ob_refcnt
!= 0) { if (((PyObject*)contents)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5658, (
PyObject *)(contents)); } else _Py_Dealloc((PyObject *)(contents
)); } while (0)
;
5659 return NULL((void*)0);
5660 }
5661 constructor_args = PyTuple_New(1);
5662 if (constructor_args == NULL((void*)0)) {
5663 Py_DECREF(contents)do { if (_Py_RefTotal-- , --((PyObject*)(contents))->ob_refcnt
!= 0) { if (((PyObject*)contents)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5663, (
PyObject *)(contents)); } else _Py_Dealloc((PyObject *)(contents
)); } while (0)
;
5664 Py_DECREF(reduce_value)do { if (_Py_RefTotal-- , --((PyObject*)(reduce_value))->ob_refcnt
!= 0) { if (((PyObject*)reduce_value)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5664, (
PyObject *)(reduce_value)); } else _Py_Dealloc((PyObject *)(reduce_value
)); } while (0)
;
5665 return NULL((void*)0);
5666 }
5667 PyTuple_SET_ITEM(constructor_args, 0, contents)(((PyTupleObject *)(constructor_args))->ob_item[0] = contents
)
;
5668 Py_INCREF((PyObject *)&PyDict_Type)( _Py_RefTotal++ , ((PyObject*)((PyObject *)&PyDict_Type)
)->ob_refcnt++)
;
5669 PyTuple_SET_ITEM(reduce_value, 0, (PyObject *)&PyDict_Type)(((PyTupleObject *)(reduce_value))->ob_item[0] = (PyObject
*)&PyDict_Type)
;
5670 PyTuple_SET_ITEM(reduce_value, 1, constructor_args)(((PyTupleObject *)(reduce_value))->ob_item[1] = constructor_args
)
;
5671 return reduce_value;
5672}
5673
5674static PyMethodDef unpicklerproxy_methods[] = {
5675 {"clear", (PyCFunction)ump_clear, METH_NOARGS0x0004, ump_clear_doc},
5676 {"copy", (PyCFunction)ump_copy, METH_NOARGS0x0004, ump_copy_doc},
5677 {"__reduce__", (PyCFunction)ump_reduce, METH_VARARGS0x0001, ump_reduce_doc},
5678 {NULL((void*)0), NULL((void*)0)} /* sentinel */
5679};
5680
5681static void
5682UnpicklerMemoProxy_dealloc(UnpicklerMemoProxyObject *self)
5683{
5684 PyObject_GC_UnTrack(self);
5685 Py_XDECREF(self->unpickler)do { if ((self->unpickler) == ((void*)0)) ; else do { if (
_Py_RefTotal-- , --((PyObject*)(self->unpickler))->ob_refcnt
!= 0) { if (((PyObject*)self->unpickler)->ob_refcnt <
0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5685, (PyObject *)(self->unpickler)); } else _Py_Dealloc
((PyObject *)(self->unpickler)); } while (0); } while (0)
;
5686 PyObject_GC_Del((PyObject *)self);
5687}
5688
5689static int
5690UnpicklerMemoProxy_traverse(UnpicklerMemoProxyObject *self,
5691 visitproc visit, void *arg)
5692{
5693 Py_VISIT(self->unpickler)do { if (self->unpickler) { int vret = visit((PyObject *)(
self->unpickler), arg); if (vret) return vret; } } while (
0)
;
5694 return 0;
5695}
5696
5697static int
5698UnpicklerMemoProxy_clear(UnpicklerMemoProxyObject *self)
5699{
5700 Py_CLEAR(self->unpickler)do { if (self->unpickler) { PyObject *_py_tmp = (PyObject *
)(self->unpickler); (self->unpickler) = ((void*)0); do {
if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt !=
0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5700, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
5701 return 0;
5702}
5703
5704static PyTypeObject UnpicklerMemoProxyType = {
5705 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
5706 "_pickle.UnpicklerMemoProxy", /*tp_name*/
5707 sizeof(UnpicklerMemoProxyObject), /*tp_basicsize*/
5708 0,
5709 (destructor)UnpicklerMemoProxy_dealloc, /* tp_dealloc */
5710 0, /* tp_print */
5711 0, /* tp_getattr */
5712 0, /* tp_setattr */
5713 0, /* tp_compare */
5714 0, /* tp_repr */
5715 0, /* tp_as_number */
5716 0, /* tp_as_sequence */
5717 0, /* tp_as_mapping */
5718 PyObject_HashNotImplemented, /* tp_hash */
5719 0, /* tp_call */
5720 0, /* tp_str */
5721 PyObject_GenericGetAttr, /* tp_getattro */
5722 PyObject_GenericSetAttr, /* tp_setattro */
5723 0, /* tp_as_buffer */
5724 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_BASETYPE(1L<<10) | Py_TPFLAGS_HAVE_GC(1L<<14),
5725 0, /* tp_doc */
5726 (traverseproc)UnpicklerMemoProxy_traverse, /* tp_traverse */
5727 (inquiry)UnpicklerMemoProxy_clear, /* tp_clear */
5728 0, /* tp_richcompare */
5729 0, /* tp_weaklistoffset */
5730 0, /* tp_iter */
5731 0, /* tp_iternext */
5732 unpicklerproxy_methods, /* tp_methods */
5733};
5734
5735static PyObject *
5736UnpicklerMemoProxy_New(UnpicklerObject *unpickler)
5737{
5738 UnpicklerMemoProxyObject *self;
5739
5740 self = PyObject_GC_New(UnpicklerMemoProxyObject,( (UnpicklerMemoProxyObject *) _PyObject_GC_New(&UnpicklerMemoProxyType
) )
5741 &UnpicklerMemoProxyType)( (UnpicklerMemoProxyObject *) _PyObject_GC_New(&UnpicklerMemoProxyType
) )
;
5742 if (self == NULL((void*)0))
5743 return NULL((void*)0);
5744 Py_INCREF(unpickler)( _Py_RefTotal++ , ((PyObject*)(unpickler))->ob_refcnt++);
5745 self->unpickler = unpickler;
5746 PyObject_GC_Track(self);
5747 return (PyObject *)self;
5748}
5749
5750/*****************************************************************************/
5751
5752
5753static PyObject *
5754Unpickler_get_memo(UnpicklerObject *self)
5755{
5756 return UnpicklerMemoProxy_New(self);
5757}
5758
5759static int
5760Unpickler_set_memo(UnpicklerObject *self, PyObject *obj)
5761{
5762 PyObject **new_memo;
5763 Py_ssize_t new_memo_size = 0;
5764 Py_ssize_t i;
5765
5766 if (obj == NULL((void*)0)) {
5767 PyErr_SetString(PyExc_TypeError,
5768 "attribute deletion is not supported");
5769 return -1;
5770 }
5771
5772 if (Py_TYPE(obj)(((PyObject*)(obj))->ob_type) == &UnpicklerMemoProxyType) {
5773 UnpicklerObject *unpickler =
5774 ((UnpicklerMemoProxyObject *)obj)->unpickler;
5775
5776 new_memo_size = unpickler->memo_size;
5777 new_memo = _Unpickler_NewMemo(new_memo_size);
5778 if (new_memo == NULL((void*)0))
5779 return -1;
5780
5781 for (i = 0; i < new_memo_size; i++) {
5782 Py_XINCREF(unpickler->memo[i])do { if ((unpickler->memo[i]) == ((void*)0)) ; else ( _Py_RefTotal
++ , ((PyObject*)(unpickler->memo[i]))->ob_refcnt++); }
while (0)
;
5783 new_memo[i] = unpickler->memo[i];
5784 }
5785 }
5786 else if (PyDict_Check(obj)((((((PyObject*)(obj))->ob_type))->tp_flags & ((1L<<
29))) != 0)
) {
5787 Py_ssize_t i = 0;
5788 PyObject *key, *value;
5789
5790 new_memo_size = PyDict_Size(obj);
5791 new_memo = _Unpickler_NewMemo(new_memo_size);
5792 if (new_memo == NULL((void*)0))
5793 return -1;
5794
5795 while (PyDict_Next(obj, &i, &key, &value)) {
5796 Py_ssize_t idx;
5797 if (!PyLong_Check(key)((((((PyObject*)(key))->ob_type))->tp_flags & ((1L<<
24))) != 0)
) {
5798 PyErr_SetString(PyExc_TypeError,
5799 "memo key must be integers");
5800 goto error;
5801 }
5802 idx = PyLong_AsSsize_t(key);
5803 if (idx == -1 && PyErr_Occurred())
5804 goto error;
5805 if (_Unpickler_MemoPut(self, idx, value) < 0)
5806 goto error;
5807 }
5808 }
5809 else {
5810 PyErr_Format(PyExc_TypeError,
5811 "'memo' attribute must be an UnpicklerMemoProxy object"
5812 "or dict, not %.200s", Py_TYPE(obj)(((PyObject*)(obj))->ob_type)->tp_name);
5813 return -1;
5814 }
5815
5816 _Unpickler_MemoCleanup(self);
5817 self->memo_size = new_memo_size;
5818 self->memo = new_memo;
5819
5820 return 0;
5821
5822 error:
5823 if (new_memo_size) {
5824 i = new_memo_size;
5825 while (--i >= 0) {
5826 Py_XDECREF(new_memo[i])do { if ((new_memo[i]) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(new_memo[i]))->ob_refcnt != 0) { if ((
(PyObject*)new_memo[i])->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5826, (
PyObject *)(new_memo[i])); } else _Py_Dealloc((PyObject *)(new_memo
[i])); } while (0); } while (0)
;
5827 }
5828 PyMem_FREE_PyMem_DebugFree(new_memo);
5829 }
5830 return -1;
5831}
5832
5833static PyObject *
5834Unpickler_get_persload(UnpicklerObject *self)
5835{
5836 if (self->pers_func == NULL((void*)0))
5837 PyErr_SetString(PyExc_AttributeError, "persistent_load");
5838 else
5839 Py_INCREF(self->pers_func)( _Py_RefTotal++ , ((PyObject*)(self->pers_func))->ob_refcnt
++)
;
5840 return self->pers_func;
5841}
5842
5843static int
5844Unpickler_set_persload(UnpicklerObject *self, PyObject *value)
5845{
5846 PyObject *tmp;
5847
5848 if (value == NULL((void*)0)) {
5849 PyErr_SetString(PyExc_TypeError,
5850 "attribute deletion is not supported");
5851 return -1;
5852 }
5853 if (!PyCallable_Check(value)) {
5854 PyErr_SetString(PyExc_TypeError,
5855 "persistent_load must be a callable taking "
5856 "one argument");
5857 return -1;
5858 }
5859
5860 tmp = self->pers_func;
5861 Py_INCREF(value)( _Py_RefTotal++ , ((PyObject*)(value))->ob_refcnt++);
5862 self->pers_func = value;
5863 Py_XDECREF(tmp)do { if ((tmp) == ((void*)0)) ; else do { if (_Py_RefTotal-- ,
--((PyObject*)(tmp))->ob_refcnt != 0) { if (((PyObject*)tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5863, (PyObject *)(tmp)); } else _Py_Dealloc((PyObject *)(tmp
)); } while (0); } while (0)
; /* self->pers_func can be NULL, so be careful. */
5864
5865 return 0;
5866}
5867
5868static PyGetSetDef Unpickler_getsets[] = {
5869 {"memo", (getter)Unpickler_get_memo, (setter)Unpickler_set_memo},
5870 {"persistent_load", (getter)Unpickler_get_persload,
5871 (setter)Unpickler_set_persload},
5872 {NULL((void*)0)}
5873};
5874
5875static PyTypeObject Unpickler_Type = {
5876 PyVarObject_HEAD_INIT(NULL, 0){ { 0, 0, 1, ((void*)0) }, 0 },
5877 "_pickle.Unpickler", /*tp_name*/
5878 sizeof(UnpicklerObject), /*tp_basicsize*/
5879 0, /*tp_itemsize*/
5880 (destructor)Unpickler_dealloc, /*tp_dealloc*/
5881 0, /*tp_print*/
5882 0, /*tp_getattr*/
5883 0, /*tp_setattr*/
5884 0, /*tp_reserved*/
5885 0, /*tp_repr*/
5886 0, /*tp_as_number*/
5887 0, /*tp_as_sequence*/
5888 0, /*tp_as_mapping*/
5889 0, /*tp_hash*/
5890 0, /*tp_call*/
5891 0, /*tp_str*/
5892 0, /*tp_getattro*/
5893 0, /*tp_setattro*/
5894 0, /*tp_as_buffer*/
5895 Py_TPFLAGS_DEFAULT( 0 | (1L<<18) | 0) | Py_TPFLAGS_BASETYPE(1L<<10) | Py_TPFLAGS_HAVE_GC(1L<<14),
5896 Unpickler_doc, /*tp_doc*/
5897 (traverseproc)Unpickler_traverse, /*tp_traverse*/
5898 (inquiry)Unpickler_clear, /*tp_clear*/
5899 0, /*tp_richcompare*/
5900 0, /*tp_weaklistoffset*/
5901 0, /*tp_iter*/
5902 0, /*tp_iternext*/
5903 Unpickler_methods, /*tp_methods*/
5904 0, /*tp_members*/
5905 Unpickler_getsets, /*tp_getset*/
5906 0, /*tp_base*/
5907 0, /*tp_dict*/
5908 0, /*tp_descr_get*/
5909 0, /*tp_descr_set*/
5910 0, /*tp_dictoffset*/
5911 (initproc)Unpickler_init, /*tp_init*/
5912 PyType_GenericAlloc, /*tp_alloc*/
5913 PyType_GenericNew, /*tp_new*/
5914 PyObject_GC_Del, /*tp_free*/
5915 0, /*tp_is_gc*/
5916};
5917
5918PyDoc_STRVAR(pickle_dump_doc,static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5919"dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5920"\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5921"Write a pickled representation of obj to the open file object file. This\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5922"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5923"efficient.\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5924"\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5925"The optional protocol argument tells the pickler to use the given protocol;\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5926"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5927"backward-incompatible protocol designed for Python 3.0.\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5928"\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5929"Specifying a negative protocol version selects the highest protocol version\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5930"supported. The higher the protocol used, the more recent the version of\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5931"Python needed to read the pickle produced.\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5932"\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5933"The file argument must have a write() method that accepts a single bytes\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5934"argument. It can thus be a file object opened for binary writing, a\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5935"io.BytesIO instance, or any other custom object that meets this interface.\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5936"\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5937"If fix_imports is True and protocol is less than 3, pickle will try to\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5938"map the new Python 3.x names to the old module names used in Python 2.x,\n"static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5939"so that the pickle data stream is readable with Python 2.x.\n")static char pickle_dump_doc[] = "dump(obj, file, protocol=None, *, fix_imports=True) -> None\n"
"\n""Write a pickled representation of obj to the open file object file. This\n"
"is equivalent to ``Pickler(file, protocol).dump(obj)``, but may be more\n"
"efficient.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""The file argument must have a write() method that accepts a single bytes\n"
"argument. It can thus be a file object opened for binary writing, a\n"
"io.BytesIO instance, or any other custom object that meets this interface.\n"
"\n""If fix_imports is True and protocol is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
;
5940
5941static PyObject *
5942pickle_dump(PyObject *self, PyObject *args, PyObject *kwds)
5943{
5944 static char *kwlist[] = {"obj", "file", "protocol", "fix_imports", 0};
5945 PyObject *obj;
5946 PyObject *file;
5947 PyObject *proto = NULL((void*)0);
5948 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
5949 PicklerObject *pickler;
5950
5951 /* fix_imports is a keyword-only argument. */
5952 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) > 3) {
5953 PyErr_Format(PyExc_TypeError,
5954 "pickle.dump() takes at most 3 positional "
5955 "argument (%zd given)", Py_SIZE(args)(((PyVarObject*)(args))->ob_size));
5956 return NULL((void*)0);
5957 }
5958
5959 if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|OO:dump", kwlist,
5960 &obj, &file, &proto, &fix_imports))
5961 return NULL((void*)0);
5962
5963 pickler = _Pickler_New();
5964 if (pickler == NULL((void*)0))
5965 return NULL((void*)0);
5966
5967 if (_Pickler_SetProtocol(pickler, proto, fix_imports) < 0)
5968 goto error;
5969
5970 if (_Pickler_SetOutputStream(pickler, file) < 0)
5971 goto error;
5972
5973 if (dump(pickler, obj) < 0)
5974 goto error;
5975
5976 if (_Pickler_FlushToFile(pickler) < 0)
5977 goto error;
5978
5979 Py_DECREF(pickler)do { if (_Py_RefTotal-- , --((PyObject*)(pickler))->ob_refcnt
!= 0) { if (((PyObject*)pickler)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 5979, (
PyObject *)(pickler)); } else _Py_Dealloc((PyObject *)(pickler
)); } while (0)
;
5980 Py_RETURN_NONEreturn ( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct))
)->ob_refcnt++), (&_Py_NoneStruct)
;
5981
5982 error:
5983 Py_XDECREF(pickler)do { if ((pickler) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(pickler))->ob_refcnt != 0) { if (((PyObject
*)pickler)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 5983, (PyObject *)(pickler)); } else _Py_Dealloc((PyObject *
)(pickler)); } while (0); } while (0)
;
5984 return NULL((void*)0);
5985}
5986
5987PyDoc_STRVAR(pickle_dumps_doc,static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5988"dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5989"\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5990"Return the pickled representation of the object as a bytes\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5991"object, instead of writing it to a file.\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5992"\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5993"The optional protocol argument tells the pickler to use the given protocol;\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5994"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5995"backward-incompatible protocol designed for Python 3.0.\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5996"\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5997"Specifying a negative protocol version selects the highest protocol version\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5998"supported. The higher the protocol used, the more recent the version of\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
5999"Python needed to read the pickle produced.\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
6000"\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
6001"If fix_imports is True and *protocol* is less than 3, pickle will try to\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
6002"map the new Python 3.x names to the old module names used in Python 2.x,\n"static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
6003"so that the pickle data stream is readable with Python 2.x.\n")static char pickle_dumps_doc[] = "dumps(obj, protocol=None, *, fix_imports=True) -> bytes\n"
"\n""Return the pickled representation of the object as a bytes\n"
"object, instead of writing it to a file.\n""\n""The optional protocol argument tells the pickler to use the given protocol;\n"
"supported protocols are 0, 1, 2, 3. The default protocol is 3; a\n"
"backward-incompatible protocol designed for Python 3.0.\n""\n"
"Specifying a negative protocol version selects the highest protocol version\n"
"supported. The higher the protocol used, the more recent the version of\n"
"Python needed to read the pickle produced.\n""\n""If fix_imports is True and *protocol* is less than 3, pickle will try to\n"
"map the new Python 3.x names to the old module names used in Python 2.x,\n"
"so that the pickle data stream is readable with Python 2.x.\n"
;
6004
6005static PyObject *
6006pickle_dumps(PyObject *self, PyObject *args, PyObject *kwds)
6007{
6008 static char *kwlist[] = {"obj", "protocol", "fix_imports", 0};
6009 PyObject *obj;
6010 PyObject *proto = NULL((void*)0);
6011 PyObject *result;
6012 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
6013 PicklerObject *pickler;
6014
6015 /* fix_imports is a keyword-only argument. */
6016 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) > 2) {
6017 PyErr_Format(PyExc_TypeError,
6018 "pickle.dumps() takes at most 2 positional "
6019 "argument (%zd given)", Py_SIZE(args)(((PyVarObject*)(args))->ob_size));
6020 return NULL((void*)0);
6021 }
6022
6023 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|OO:dumps", kwlist,
6024 &obj, &proto, &fix_imports))
6025 return NULL((void*)0);
6026
6027 pickler = _Pickler_New();
6028 if (pickler == NULL((void*)0))
6029 return NULL((void*)0);
6030
6031 if (_Pickler_SetProtocol(pickler, proto, fix_imports) < 0)
6032 goto error;
6033
6034 if (dump(pickler, obj) < 0)
6035 goto error;
6036
6037 result = _Pickler_GetString(pickler);
6038 Py_DECREF(pickler)do { if (_Py_RefTotal-- , --((PyObject*)(pickler))->ob_refcnt
!= 0) { if (((PyObject*)pickler)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6038, (
PyObject *)(pickler)); } else _Py_Dealloc((PyObject *)(pickler
)); } while (0)
;
6039 return result;
6040
6041 error:
6042 Py_XDECREF(pickler)do { if ((pickler) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(pickler))->ob_refcnt != 0) { if (((PyObject
*)pickler)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6042, (PyObject *)(pickler)); } else _Py_Dealloc((PyObject *
)(pickler)); } while (0); } while (0)
;
6043 return NULL((void*)0);
6044}
6045
6046PyDoc_STRVAR(pickle_load_doc,static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6047"load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6048"\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6049"Read a pickled object representation from the open file object file and\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6050"return the reconstituted object hierarchy specified therein. This is\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6051"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6052"\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6053"The protocol version of the pickle is detected automatically, so no protocol\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6054"argument is needed. Bytes past the pickled object's representation are\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6055"ignored.\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6056"\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6057"The argument file must have two methods, a read() method that takes an\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6058"integer argument, and a readline() method that requires no arguments. Both\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6059"methods should return bytes. Thus *file* can be a binary file object opened\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6060"for reading, a BytesIO object, or any other custom object that meets this\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6061"interface.\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6062"\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6063"Optional keyword arguments are fix_imports, encoding and errors,\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6064"which are used to control compatiblity support for pickle stream generated\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6065"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6066"Python 2.x names to the new names used in Python 3.x. The encoding and\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6067"errors tell pickle how to decode 8-bit string instances pickled by Python\n"static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6068"2.x; these default to 'ASCII' and 'strict', respectively.\n")static char pickle_load_doc[] = "load(file, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object representation from the open file object file and\n"
"return the reconstituted object hierarchy specified therein. This is\n"
"equivalent to ``Unpickler(file).load()``, but may be more efficient.\n"
"\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""The argument file must have two methods, a read() method that takes an\n"
"integer argument, and a readline() method that requires no arguments. Both\n"
"methods should return bytes. Thus *file* can be a binary file object opened\n"
"for reading, a BytesIO object, or any other custom object that meets this\n"
"interface.\n""\n""Optional keyword arguments are fix_imports, encoding and errors,\n"
"which are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
;
6069
6070static PyObject *
6071pickle_load(PyObject *self, PyObject *args, PyObject *kwds)
6072{
6073 static char *kwlist[] = {"file", "fix_imports", "encoding", "errors", 0};
6074 PyObject *file;
6075 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
6076 PyObject *result;
6077 char *encoding = NULL((void*)0);
6078 char *errors = NULL((void*)0);
6079 UnpicklerObject *unpickler;
6080
6081 /* fix_imports, encoding and errors are a keyword-only argument. */
6082 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) != 1) {
6083 PyErr_Format(PyExc_TypeError,
6084 "pickle.load() takes exactly one positional "
6085 "argument (%zd given)", Py_SIZE(args)(((PyVarObject*)(args))->ob_size));
6086 return NULL((void*)0);
6087 }
6088
6089 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oss:load", kwlist,
6090 &file, &fix_imports, &encoding, &errors))
6091 return NULL((void*)0);
6092
6093 unpickler = _Unpickler_New();
6094 if (unpickler == NULL((void*)0))
6095 return NULL((void*)0);
6096
6097 if (_Unpickler_SetInputStream(unpickler, file) < 0)
6098 goto error;
6099
6100 if (_Unpickler_SetInputEncoding(unpickler, encoding, errors) < 0)
6101 goto error;
6102
6103 unpickler->fix_imports = PyObject_IsTrue(fix_imports);
6104 if (unpickler->fix_imports == -1)
6105 goto error;
6106
6107 result = load(unpickler);
6108 Py_DECREF(unpickler)do { if (_Py_RefTotal-- , --((PyObject*)(unpickler))->ob_refcnt
!= 0) { if (((PyObject*)unpickler)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6108, (
PyObject *)(unpickler)); } else _Py_Dealloc((PyObject *)(unpickler
)); } while (0)
;
6109 return result;
6110
6111 error:
6112 Py_XDECREF(unpickler)do { if ((unpickler) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(unpickler))->ob_refcnt != 0) { if (((PyObject
*)unpickler)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6112, (PyObject *)(unpickler)); } else _Py_Dealloc((PyObject
*)(unpickler)); } while (0); } while (0)
;
6113 return NULL((void*)0);
6114}
6115
6116PyDoc_STRVAR(pickle_loads_doc,static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6117"loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6118"\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6119"Read a pickled object hierarchy from a bytes object and return the\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6120"reconstituted object hierarchy specified therein\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6121"\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6122"The protocol version of the pickle is detected automatically, so no protocol\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6123"argument is needed. Bytes past the pickled object's representation are\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6124"ignored.\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6125"\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6126"Optional keyword arguments are fix_imports, encoding and errors, which\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6127"are used to control compatiblity support for pickle stream generated\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6128"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6129"Python 2.x names to the new names used in Python 3.x. The encoding and\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6130"errors tell pickle how to decode 8-bit string instances pickled by Python\n"static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
6131"2.x; these default to 'ASCII' and 'strict', respectively.\n")static char pickle_loads_doc[] = "loads(input, *, fix_imports=True, encoding='ASCII', errors='strict') -> object\n"
"\n""Read a pickled object hierarchy from a bytes object and return the\n"
"reconstituted object hierarchy specified therein\n""\n""The protocol version of the pickle is detected automatically, so no protocol\n"
"argument is needed. Bytes past the pickled object's representation are\n"
"ignored.\n""\n""Optional keyword arguments are fix_imports, encoding and errors, which\n"
"are used to control compatiblity support for pickle stream generated\n"
"by Python 2.x. If fix_imports is True, pickle will try to map the old\n"
"Python 2.x names to the new names used in Python 3.x. The encoding and\n"
"errors tell pickle how to decode 8-bit string instances pickled by Python\n"
"2.x; these default to 'ASCII' and 'strict', respectively.\n"
;
6132
6133static PyObject *
6134pickle_loads(PyObject *self, PyObject *args, PyObject *kwds)
6135{
6136 static char *kwlist[] = {"input", "fix_imports", "encoding", "errors", 0};
6137 PyObject *input;
6138 PyObject *fix_imports = Py_True((PyObject *) &_Py_TrueStruct);
6139 PyObject *result;
6140 char *encoding = NULL((void*)0);
6141 char *errors = NULL((void*)0);
6142 UnpicklerObject *unpickler;
6143
6144 /* fix_imports, encoding and errors are a keyword-only argument. */
6145 if (Py_SIZE(args)(((PyVarObject*)(args))->ob_size) != 1) {
6146 PyErr_Format(PyExc_TypeError,
6147 "pickle.loads() takes exactly one positional "
6148 "argument (%zd given)", Py_SIZE(args)(((PyVarObject*)(args))->ob_size));
6149 return NULL((void*)0);
6150 }
6151
6152 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|Oss:loads", kwlist,
6153 &input, &fix_imports, &encoding, &errors))
6154 return NULL((void*)0);
6155
6156 unpickler = _Unpickler_New();
6157 if (unpickler == NULL((void*)0))
6158 return NULL((void*)0);
6159
6160 if (_Unpickler_SetStringInput(unpickler, input) < 0)
6161 goto error;
6162
6163 if (_Unpickler_SetInputEncoding(unpickler, encoding, errors) < 0)
6164 goto error;
6165
6166 unpickler->fix_imports = PyObject_IsTrue(fix_imports);
6167 if (unpickler->fix_imports == -1)
6168 goto error;
6169
6170 result = load(unpickler);
6171 Py_DECREF(unpickler)do { if (_Py_RefTotal-- , --((PyObject*)(unpickler))->ob_refcnt
!= 0) { if (((PyObject*)unpickler)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6171, (
PyObject *)(unpickler)); } else _Py_Dealloc((PyObject *)(unpickler
)); } while (0)
;
6172 return result;
6173
6174 error:
6175 Py_XDECREF(unpickler)do { if ((unpickler) == ((void*)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(unpickler))->ob_refcnt != 0) { if (((PyObject
*)unpickler)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6175, (PyObject *)(unpickler)); } else _Py_Dealloc((PyObject
*)(unpickler)); } while (0); } while (0)
;
6176 return NULL((void*)0);
6177}
6178
6179
6180static struct PyMethodDef pickle_methods[] = {
6181 {"dump", (PyCFunction)pickle_dump, METH_VARARGS0x0001|METH_KEYWORDS0x0002,
6182 pickle_dump_doc},
6183 {"dumps", (PyCFunction)pickle_dumps, METH_VARARGS0x0001|METH_KEYWORDS0x0002,
6184 pickle_dumps_doc},
6185 {"load", (PyCFunction)pickle_load, METH_VARARGS0x0001|METH_KEYWORDS0x0002,
6186 pickle_load_doc},
6187 {"loads", (PyCFunction)pickle_loads, METH_VARARGS0x0001|METH_KEYWORDS0x0002,
6188 pickle_loads_doc},
6189 {NULL((void*)0), NULL((void*)0)} /* sentinel */
6190};
6191
6192static int
6193initmodule(void)
6194{
6195 PyObject *copyreg = NULL((void*)0);
6196 PyObject *compat_pickle = NULL((void*)0);
6197
6198 /* XXX: We should ensure that the types of the dictionaries imported are
6199 exactly PyDict objects. Otherwise, it is possible to crash the pickle
6200 since we use the PyDict API directly to access these dictionaries. */
6201
6202 copyreg = PyImport_ImportModule("copyreg");
6203 if (!copyreg)
6204 goto error;
6205 dispatch_table = PyObject_GetAttrString(copyreg, "dispatch_table");
6206 if (!dispatch_table)
6207 goto error;
6208 extension_registry = \
6209 PyObject_GetAttrString(copyreg, "_extension_registry");
6210 if (!extension_registry)
6211 goto error;
6212 inverted_registry = PyObject_GetAttrString(copyreg, "_inverted_registry");
6213 if (!inverted_registry)
6214 goto error;
6215 extension_cache = PyObject_GetAttrString(copyreg, "_extension_cache");
6216 if (!extension_cache)
6217 goto error;
6218 Py_CLEAR(copyreg)do { if (copyreg) { PyObject *_py_tmp = (PyObject *)(copyreg)
; (copyreg) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6218, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6219
6220 /* Load the 2.x -> 3.x stdlib module mapping tables */
6221 compat_pickle = PyImport_ImportModule("_compat_pickle");
6222 if (!compat_pickle)
6223 goto error;
6224 name_mapping_2to3 = PyObject_GetAttrString(compat_pickle, "NAME_MAPPING");
6225 if (!name_mapping_2to3)
6226 goto error;
6227 if (!PyDict_CheckExact(name_mapping_2to3)((((PyObject*)(name_mapping_2to3))->ob_type) == &PyDict_Type
)
) {
6228 PyErr_Format(PyExc_RuntimeError,
6229 "_compat_pickle.NAME_MAPPING should be a dict, not %.200s",
6230 Py_TYPE(name_mapping_2to3)(((PyObject*)(name_mapping_2to3))->ob_type)->tp_name);
6231 goto error;
6232 }
6233 import_mapping_2to3 = PyObject_GetAttrString(compat_pickle,
6234 "IMPORT_MAPPING");
6235 if (!import_mapping_2to3)
6236 goto error;
6237 if (!PyDict_CheckExact(import_mapping_2to3)((((PyObject*)(import_mapping_2to3))->ob_type) == &PyDict_Type
)
) {
6238 PyErr_Format(PyExc_RuntimeError,
6239 "_compat_pickle.IMPORT_MAPPING should be a dict, "
6240 "not %.200s", Py_TYPE(import_mapping_2to3)(((PyObject*)(import_mapping_2to3))->ob_type)->tp_name);
6241 goto error;
6242 }
6243 /* ... and the 3.x -> 2.x mapping tables */
6244 name_mapping_3to2 = PyObject_GetAttrString(compat_pickle,
6245 "REVERSE_NAME_MAPPING");
6246 if (!name_mapping_3to2)
6247 goto error;
6248 if (!PyDict_CheckExact(name_mapping_3to2)((((PyObject*)(name_mapping_3to2))->ob_type) == &PyDict_Type
)
) {
6249 PyErr_Format(PyExc_RuntimeError,
6250 "_compat_pickle.REVERSE_NAME_MAPPING shouldbe a dict, "
6251 "not %.200s", Py_TYPE(name_mapping_3to2)(((PyObject*)(name_mapping_3to2))->ob_type)->tp_name);
6252 goto error;
6253 }
6254 import_mapping_3to2 = PyObject_GetAttrString(compat_pickle,
6255 "REVERSE_IMPORT_MAPPING");
6256 if (!import_mapping_3to2)
6257 goto error;
6258 if (!PyDict_CheckExact(import_mapping_3to2)((((PyObject*)(import_mapping_3to2))->ob_type) == &PyDict_Type
)
) {
6259 PyErr_Format(PyExc_RuntimeError,
6260 "_compat_pickle.REVERSE_IMPORT_MAPPING should be a dict, "
6261 "not %.200s", Py_TYPE(import_mapping_3to2)(((PyObject*)(import_mapping_3to2))->ob_type)->tp_name);
6262 goto error;
6263 }
6264 Py_CLEAR(compat_pickle)do { if (compat_pickle) { PyObject *_py_tmp = (PyObject *)(compat_pickle
); (compat_pickle) = ((void*)0); do { if (_Py_RefTotal-- , --
((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)
_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6264, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6265
6266 empty_tuple = PyTuple_New(0);
6267 if (empty_tuple == NULL((void*)0))
6268 goto error;
6269 two_tuple = PyTuple_New(2);
6270 if (two_tuple == NULL((void*)0))
6271 goto error;
6272 /* We use this temp container with no regard to refcounts, or to
6273 * keeping containees alive. Exempt from GC, because we don't
6274 * want anything looking at two_tuple() by magic.
6275 */
6276 PyObject_GC_UnTrack(two_tuple);
6277
6278 return 0;
6279
6280 error:
6281 Py_CLEAR(copyreg)do { if (copyreg) { PyObject *_py_tmp = (PyObject *)(copyreg)
; (copyreg) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6281, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6282 Py_CLEAR(dispatch_table)do { if (dispatch_table) { PyObject *_py_tmp = (PyObject *)(dispatch_table
); (dispatch_table) = ((void*)0); do { if (_Py_RefTotal-- , --
((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)
_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6282, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6283 Py_CLEAR(extension_registry)do { if (extension_registry) { PyObject *_py_tmp = (PyObject *
)(extension_registry); (extension_registry) = ((void*)0); do {
if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt !=
0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6283, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6284 Py_CLEAR(inverted_registry)do { if (inverted_registry) { PyObject *_py_tmp = (PyObject *
)(inverted_registry); (inverted_registry) = ((void*)0); do { if
(_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0
) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6284, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6285 Py_CLEAR(extension_cache)do { if (extension_cache) { PyObject *_py_tmp = (PyObject *)(
extension_cache); (extension_cache) = ((void*)0); do { if (_Py_RefTotal
-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject
*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6285, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6286 Py_CLEAR(compat_pickle)do { if (compat_pickle) { PyObject *_py_tmp = (PyObject *)(compat_pickle
); (compat_pickle) = ((void*)0); do { if (_Py_RefTotal-- , --
((PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)
_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6286, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6287 Py_CLEAR(name_mapping_2to3)do { if (name_mapping_2to3) { PyObject *_py_tmp = (PyObject *
)(name_mapping_2to3); (name_mapping_2to3) = ((void*)0); do { if
(_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0
) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6287, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6288 Py_CLEAR(import_mapping_2to3)do { if (import_mapping_2to3) { PyObject *_py_tmp = (PyObject
*)(import_mapping_2to3); (import_mapping_2to3) = ((void*)0);
do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt
!= 0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6288, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6289 Py_CLEAR(name_mapping_3to2)do { if (name_mapping_3to2) { PyObject *_py_tmp = (PyObject *
)(name_mapping_3to2); (name_mapping_3to2) = ((void*)0); do { if
(_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt != 0
) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6289, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6290 Py_CLEAR(import_mapping_3to2)do { if (import_mapping_3to2) { PyObject *_py_tmp = (PyObject
*)(import_mapping_3to2); (import_mapping_3to2) = ((void*)0);
do { if (_Py_RefTotal-- , --((PyObject*)(_py_tmp))->ob_refcnt
!= 0) { if (((PyObject*)_py_tmp)->ob_refcnt < 0) _Py_NegativeRefcount
("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c", 6290, (
PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *)(_py_tmp
)); } while (0); } } while (0)
;
6291 Py_CLEAR(empty_tuple)do { if (empty_tuple) { PyObject *_py_tmp = (PyObject *)(empty_tuple
); (empty_tuple) = ((void*)0); do { if (_Py_RefTotal-- , --((
PyObject*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp
)->ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6291, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6292 Py_CLEAR(two_tuple)do { if (two_tuple) { PyObject *_py_tmp = (PyObject *)(two_tuple
); (two_tuple) = ((void*)0); do { if (_Py_RefTotal-- , --((PyObject
*)(_py_tmp))->ob_refcnt != 0) { if (((PyObject*)_py_tmp)->
ob_refcnt < 0) _Py_NegativeRefcount("/Users/brett/Dev/python/3.x/py3k/Modules/_pickle.c"
, 6292, (PyObject *)(_py_tmp)); } else _Py_Dealloc((PyObject *
)(_py_tmp)); } while (0); } } while (0)
;
6293 return -1;
6294}
6295
6296static struct PyModuleDef _picklemodule = {
6297 PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void*)0) }, ((void*)0), 0, ((void*)0), },
6298 "_pickle",
6299 pickle_module_doc,
6300 -1,
6301 pickle_methods,
6302 NULL((void*)0),
6303 NULL((void*)0),
6304 NULL((void*)0),
6305 NULL((void*)0)
6306};
6307
6308PyMODINIT_FUNCPyObject*
6309PyInit__pickle(void)
6310{
6311 PyObject *m;
6312
6313 if (PyType_Ready(&Unpickler_Type) < 0)
6314 return NULL((void*)0);
6315 if (PyType_Ready(&Pickler_Type) < 0)
6316 return NULL((void*)0);
6317 if (PyType_Ready(&Pdata_Type) < 0)
6318 return NULL((void*)0);
6319 if (PyType_Ready(&PicklerMemoProxyType) < 0)
6320 return NULL((void*)0);
6321 if (PyType_Ready(&UnpicklerMemoProxyType) < 0)
6322 return NULL((void*)0);
6323
6324 /* Create the module and add the functions. */
6325 m = PyModule_Create(&_picklemodule)PyModule_Create2TraceRefs(&_picklemodule, 1013);
6326 if (m == NULL((void*)0))
6327 return NULL((void*)0);
6328
6329 if (PyModule_AddObject(m, "Pickler", (PyObject *)&Pickler_Type) < 0)
6330 return NULL((void*)0);
6331 if (PyModule_AddObject(m, "Unpickler", (PyObject *)&Unpickler_Type) < 0)
6332 return NULL((void*)0);
6333
6334 /* Initialize the exceptions. */
6335 PickleError = PyErr_NewException("_pickle.PickleError", NULL((void*)0), NULL((void*)0));
6336 if (PickleError == NULL((void*)0))
6337 return NULL((void*)0);
6338 PicklingError = \
6339 PyErr_NewException("_pickle.PicklingError", PickleError, NULL((void*)0));
6340 if (PicklingError == NULL((void*)0))
6341 return NULL((void*)0);
6342 UnpicklingError = \
6343 PyErr_NewException("_pickle.UnpicklingError", PickleError, NULL((void*)0));
6344 if (UnpicklingError == NULL((void*)0))
6345 return NULL((void*)0);
6346
6347 if (PyModule_AddObject(m, "PickleError", PickleError) < 0)
6348 return NULL((void*)0);
6349 if (PyModule_AddObject(m, "PicklingError", PicklingError) < 0)
6350 return NULL((void*)0);
6351 if (PyModule_AddObject(m, "UnpicklingError", UnpicklingError) < 0)
6352 return NULL((void*)0);
6353
6354 if (initmodule() < 0)
6355 return NULL((void*)0);
6356
6357 return m;
6358}