annotate Modules/cPickle.c @ 54294:dba767bc3155 legacy-trunk

remove mention of old ctypes version
author Benjamin Peterson <benjamin@python.org>
date Sat, 23 May 2009 20:59:09 +0000
parents e54141d63e01
children c74967feb021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 #include "Python.h"
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2 #include "cStringIO.h"
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3 #include "structmember.h"
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
5 PyDoc_STRVAR(cPickle_module_documentation,
27579
6ffb5c8e6538 The module docstring had an RCS ID from 1999 embedded in it. Enough
Tim Peters <tim.peters@gmail.com>
parents: 27578
diff changeset
6 "C implementation and optimization of the Python pickle module.");
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
7
5991
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
8 #ifndef Py_eval_input
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
9 #include <graminit.h>
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
10 #define Py_eval_input eval_input
6130
2d9582eee112 Added /**/ around #end tags
Guido van Rossum <guido@python.org>
parents: 6120
diff changeset
11 #endif /* Py_eval_input */
5991
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
12
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
13 #define DEL_LIST_SLICE(list, from, to) (PyList_SetSlice(list, from, to, NULL))
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
14
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
15 #define WRITE_BUF_SIZE 256
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
16
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
17 /* Bump this when new opcodes are added to the pickle protocol. */
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
18 #define HIGHEST_PROTOCOL 2
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
19
27577
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
20 /*
50522
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
21 * Note: The UNICODE macro controls the TCHAR meaning of the win32 API. Since
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
22 * all headers have already been included here, we can safely redefine it.
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
23 */
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
24 #ifdef UNICODE
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
25 # undef UNICODE
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
26 #endif
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
27
ee9ced92843a Merged revisions 68133-68134,68141-68142,68145-68146,68148-68149,68159-68162,68166,68171-68174,68179,68195-68196,68210,68214-68215,68217-68222 via svnmerge from
Georg Brandl <georg@python.org>
parents: 50290
diff changeset
28 /*
27577
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
29 * Pickle opcodes. These must be kept in synch with pickle.py. Extensive
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
30 * docs are in pickletools.py.
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
31 */
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
32 #define MARK '('
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
33 #define STOP '.'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
34 #define POP '0'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
35 #define POP_MARK '1'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
36 #define DUP '2'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
37 #define FLOAT 'F'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
38 #define BINFLOAT 'G'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
39 #define INT 'I'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
40 #define BININT 'J'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
41 #define BININT1 'K'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
42 #define LONG 'L'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
43 #define BININT2 'M'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
44 #define NONE 'N'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
45 #define PERSID 'P'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
46 #define BINPERSID 'Q'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
47 #define REDUCE 'R'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
48 #define STRING 'S'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
49 #define BINSTRING 'T'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
50 #define SHORT_BINSTRING 'U'
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
51 #define UNICODE 'V'
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
52 #define BINUNICODE 'X'
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
53 #define APPEND 'a'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
54 #define BUILD 'b'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
55 #define GLOBAL 'c'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
56 #define DICT 'd'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
57 #define EMPTY_DICT '}'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
58 #define APPENDS 'e'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
59 #define GET 'g'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
60 #define BINGET 'h'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
61 #define INST 'i'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
62 #define LONG_BINGET 'j'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
63 #define LIST 'l'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
64 #define EMPTY_LIST ']'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
65 #define OBJ 'o'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
66 #define PUT 'p'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
67 #define BINPUT 'q'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
68 #define LONG_BINPUT 'r'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
69 #define SETITEM 's'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
70 #define TUPLE 't'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
71 #define EMPTY_TUPLE ')'
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
72 #define SETITEMS 'u'
27577
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
73
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
74 /* Protocol 2. */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
75 #define PROTO '\x80' /* identify pickle protocol */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
76 #define NEWOBJ '\x81' /* build object by applying cls.__new__ to argtuple */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
77 #define EXT1 '\x82' /* push object from extension registry; 1-byte index */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
78 #define EXT2 '\x83' /* ditto, but 2-byte index */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
79 #define EXT4 '\x84' /* ditto, but 4-byte index */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
80 #define TUPLE1 '\x85' /* build 1-tuple from stack top */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
81 #define TUPLE2 '\x86' /* build 2-tuple from two topmost stack items */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
82 #define TUPLE3 '\x87' /* build 3-tuple from three topmost stack items */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
83 #define NEWTRUE '\x88' /* push True */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
84 #define NEWFALSE '\x89' /* push False */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
85 #define LONG1 '\x8a' /* push long from < 256 bytes */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
86 #define LONG4 '\x8b' /* push really big long */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
87
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
88 /* There aren't opcodes -- they're ways to pickle bools before protocol 2,
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
89 * so that unpicklers written before bools were introduced unpickle them
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
90 * as ints, but unpicklers after can recognize that bools were intended.
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
91 * Note that protocol 2 added direct ways to pickle bools.
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
92 */
24014
2e5a1e8c0b48 Undefine TRUE and FALSE before redefining them.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23832
diff changeset
93 #undef TRUE
22851
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
94 #define TRUE "I01\n"
24014
2e5a1e8c0b48 Undefine TRUE and FALSE before redefining them.
Jack Jansen <jack.jansen@cwi.nl>
parents: 23832
diff changeset
95 #undef FALSE
22851
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
96 #define FALSE "I00\n"
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
97
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
98 /* Keep in synch with pickle.Pickler._BATCHSIZE. This is how many elements
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
99 * batch_list/dict() pumps out before doing APPENDS/SETITEMS. Nothing will
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
100 * break if this gets out of synch with pickle.py, but it's unclear that
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
101 * would help anything either.
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
102 */
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
103 #define BATCHSIZE 1000
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
104
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 static char MARKv = MARK;
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
10946
1abc2785b344 Jim Fulton writes:
Guido van Rossum <guido@python.org>
parents: 10622
diff changeset
107 static PyObject *PickleError;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 static PyObject *PicklingError;
10946
1abc2785b344 Jim Fulton writes:
Guido van Rossum <guido@python.org>
parents: 10622
diff changeset
109 static PyObject *UnpickleableError;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 static PyObject *UnpicklingError;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
111 static PyObject *BadPickleGet;
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
112
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
113 /* As the name says, an empty tuple. */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
114 static PyObject *empty_tuple;
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
115
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
116 /* copy_reg.dispatch_table, {type_object: pickling_function} */
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
117 static PyObject *dispatch_table;
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
118
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
119 /* For EXT[124] opcodes. */
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
120 /* copy_reg._extension_registry, {(module_name, function_name): code} */
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
121 static PyObject *extension_registry;
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
122 /* copy_reg._inverted_registry, {code: (module_name, function_name)} */
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
123 static PyObject *inverted_registry;
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
124 /* copy_reg._extension_cache, {code: object} */
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
125 static PyObject *extension_cache;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
126
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
127 /* For looking up name pairs in copy_reg._extension_registry. */
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
128 static PyObject *two_tuple;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
129
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
130 static PyObject *__class___str, *__getinitargs___str, *__dict___str,
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
131 *__getstate___str, *__setstate___str, *__name___str, *__reduce___str,
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
132 *__reduce_ex___str,
27573
674f3eecffc5 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents: 27566
diff changeset
133 *write_str, *append_str,
37555
231e42d0362e Fix some warnings on HP-UX when using cc/aCC
Neal Norwitz <nnorwitz@gmail.com>
parents: 36675
diff changeset
134 *read_str, *readline_str, *__main___str,
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
135 *copyreg_str, *dispatch_table_str;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
136
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
137 /*************************************************************************
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
138 Internal Data type for pickle data. */
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
139
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
140 typedef struct {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
141 PyObject_HEAD
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
142 int length; /* number of initial slots in data currently used */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
143 int size; /* number of slots in data allocated */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
144 PyObject **data;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
145 } Pdata;
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
146
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
147 static void
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
148 Pdata_dealloc(Pdata *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
149 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
150 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
151 PyObject **p;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
152
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
153 for (i = self->length, p = self->data; --i >= 0; p++) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
154 Py_DECREF(*p);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
155 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
156 if (self->data)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
157 free(self->data);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
158 PyObject_Del(self);
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
159 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
160
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
161 static PyTypeObject PdataType = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 41525
diff changeset
162 PyVarObject_HEAD_INIT(NULL, 0) "cPickle.Pdata", sizeof(Pdata), 0,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
163 (destructor)Pdata_dealloc,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
164 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L,0L,0L,0L, ""
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
165 };
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
166
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
167 #define Pdata_Check(O) (Py_TYPE(O) == &PdataType)
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
168
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
169 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
170 Pdata_New(void)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
171 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
172 Pdata *self;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
173
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
174 if (!(self = PyObject_New(Pdata, &PdataType)))
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
175 return NULL;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
176 self->size = 8;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
177 self->length = 0;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
178 self->data = malloc(self->size * sizeof(PyObject*));
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
179 if (self->data)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
180 return (PyObject*)self;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
181 Py_DECREF(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
182 return PyErr_NoMemory();
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
183 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
184
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
185 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
186 stackUnderflow(void)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
187 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
188 PyErr_SetString(UnpicklingError, "unpickling stack underflow");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
189 return -1;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
190 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
191
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
192 /* Retain only the initial clearto items. If clearto >= the current
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
193 * number of items, this is a (non-erroneous) NOP.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
194 */
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
195 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
196 Pdata_clear(Pdata *self, int clearto)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
197 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
198 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
199 PyObject **p;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
200
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
201 if (clearto < 0) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
202 if (clearto >= self->length) return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
203
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
204 for (i = self->length, p = self->data + clearto;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
205 --i >= clearto;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
206 p++) {
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
207 Py_CLEAR(*p);
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
208 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
209 self->length = clearto;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
210
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
211 return 0;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
212 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
213
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
214 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
215 Pdata_grow(Pdata *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
216 {
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
217 int bigger;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
218 size_t nbytes;
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
219 PyObject **tmp;
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
220
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
221 bigger = self->size << 1;
27643
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
222 if (bigger <= 0) /* was 0, or new value overflows */
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
223 goto nomemory;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
224 if ((int)(size_t)bigger != bigger)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
225 goto nomemory;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
226 nbytes = (size_t)bigger * sizeof(PyObject *);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
227 if (nbytes / sizeof(PyObject *) != (size_t)bigger)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
228 goto nomemory;
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
229 tmp = realloc(self->data, nbytes);
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
230 if (tmp == NULL)
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
231 goto nomemory;
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
232 self->data = tmp;
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
233 self->size = bigger;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
234 return 0;
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
235
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
236 nomemory:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
237 PyErr_NoMemory();
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
238 return -1;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
239 }
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
240
27643
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
241 /* D is a Pdata*. Pop the topmost element and store it into V, which
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
242 * must be an lvalue holding PyObject*. On stack underflow, UnpicklingError
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
243 * is raised and V is set to NULL. D and V may be evaluated several times.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
244 */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
245 #define PDATA_POP(D, V) { \
27643
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
246 if ((D)->length) \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
247 (V) = (D)->data[--((D)->length)]; \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
248 else { \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
249 PyErr_SetString(UnpicklingError, "bad pickle data"); \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
250 (V) = NULL; \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
251 } \
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
252 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
253
27643
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
254 /* PDATA_PUSH and PDATA_APPEND both push rvalue PyObject* O on to Pdata*
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
255 * D. If the Pdata stack can't be grown to hold the new value, both
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
256 * raise MemoryError and execute "return ER". The difference is in ownership
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
257 * of O after: _PUSH transfers ownership of O from the caller to the stack
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
258 * (no incref of O is done, and in case of error O is decrefed), while
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
259 * _APPEND pushes a new reference.
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
260 */
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
261
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
262 /* Push O on stack D, giving ownership of O to the stack. */
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
263 #define PDATA_PUSH(D, O, ER) { \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
264 if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
265 Pdata_grow((Pdata*)(D)) < 0) { \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
266 Py_DECREF(O); \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
267 return ER; \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
268 } \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
269 ((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O); \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
270 }
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
271
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
272 /* Push O on stack D, pushing a new reference. */
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
273 #define PDATA_APPEND(D, O, ER) { \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
274 if (((Pdata*)(D))->length == ((Pdata*)(D))->size && \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
275 Pdata_grow((Pdata*)(D)) < 0) \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
276 return ER; \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
277 Py_INCREF(O); \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
278 ((Pdata*)(D))->data[((Pdata*)(D))->length++] = (O); \
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
279 }
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
280
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
281
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
282 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
283 Pdata_popTuple(Pdata *self, int start)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
284 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
285 PyObject *r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
286 int i, j, l;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
287
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
288 l = self->length-start;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
289 r = PyTuple_New(l);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
290 if (r == NULL)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
291 return NULL;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
292 for (i = start, j = 0 ; j < l; i++, j++)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
293 PyTuple_SET_ITEM(r, j, self->data[i]);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
294
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
295 self->length = start;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
296 return r;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
297 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
298
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
299 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
300 Pdata_popList(Pdata *self, int start)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
301 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
302 PyObject *r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
303 int i, j, l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
304
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
305 l=self->length-start;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
306 if (!( r=PyList_New(l))) return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
307 for (i=start, j=0 ; j < l; i++, j++)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
308 PyList_SET_ITEM(r, j, self->data[i]);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
309
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
310 self->length=start;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
311 return r;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
312 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
313
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
314 /*************************************************************************/
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
315
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
316 #define ARG_TUP(self, o) { \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
317 if (self->arg || (self->arg=PyTuple_New(1))) { \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
318 Py_XDECREF(PyTuple_GET_ITEM(self->arg,0)); \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
319 PyTuple_SET_ITEM(self->arg,0,o); \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
320 } \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
321 else { \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
322 Py_DECREF(o); \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
323 } \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
324 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
325
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
326 #define FREE_ARG_TUP(self) { \
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
327 if (Py_REFCNT(self->arg) > 1) { \
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
328 Py_DECREF(self->arg); \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
329 self->arg=NULL; \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
330 } \
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
331 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
332
13666
36de7b6ab7eb ANSIfication: add proper prototypes to function-pointers and declarations.
Thomas Wouters <thomas@python.org>
parents: 13576
diff changeset
333 typedef struct Picklerobject {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
334 PyObject_HEAD
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
335 FILE *fp;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
336 PyObject *write;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
337 PyObject *file;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
338 PyObject *memo;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
339 PyObject *arg;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
340 PyObject *pers_func;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
341 PyObject *inst_pers_func;
27577
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
342
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
343 /* pickle protocol number, >= 0 */
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
344 int proto;
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
345
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
346 /* bool, true if proto > 0 */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
347 int bin;
27577
9bc1c84b23e6 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
Tim Peters <tim.peters@gmail.com>
parents: 27573
diff changeset
348
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
349 int fast; /* Fast mode doesn't save in memo, don't use if circ ref */
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
350 int (*write_func)(struct Picklerobject *, const char *, Py_ssize_t);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
351 char *write_buf;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
352 int buf_size;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
353 PyObject *dispatch_table;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
354 int fast_container; /* count nested container dumps */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
355 PyObject *fast_memo;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
356 } Picklerobject;
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
357
21522
cb55f15b2730 Merge of the release22 branch changes back into the trunk.
Barry Warsaw <barry@python.org>
parents: 21486
diff changeset
358 #ifndef PY_CPICKLE_FAST_LIMIT
cb55f15b2730 Merge of the release22 branch changes back into the trunk.
Barry Warsaw <barry@python.org>
parents: 21486
diff changeset
359 #define PY_CPICKLE_FAST_LIMIT 50
cb55f15b2730 Merge of the release22 branch changes back into the trunk.
Barry Warsaw <barry@python.org>
parents: 21486
diff changeset
360 #endif
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
361
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24252
diff changeset
362 static PyTypeObject Picklertype;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
363
13666
36de7b6ab7eb ANSIfication: add proper prototypes to function-pointers and declarations.
Thomas Wouters <thomas@python.org>
parents: 13576
diff changeset
364 typedef struct Unpicklerobject {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
365 PyObject_HEAD
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
366 FILE *fp;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
367 PyObject *file;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
368 PyObject *readline;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
369 PyObject *read;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
370 PyObject *memo;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
371 PyObject *arg;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
372 Pdata *stack;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
373 PyObject *mark;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
374 PyObject *pers_func;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
375 PyObject *last_string;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
376 int *marks;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
377 int num_marks;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
378 int marks_size;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
379 Py_ssize_t (*read_func)(struct Unpicklerobject *, char **, Py_ssize_t);
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
380 Py_ssize_t (*readline_func)(struct Unpicklerobject *, char **);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
381 int buf_size;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
382 char *buf;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
383 PyObject *find_class;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 } Unpicklerobject;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
385
24280
1598a1e473e2 staticforward bites the dust.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24252
diff changeset
386 static PyTypeObject Unpicklertype;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
387
13687
63832ede577f ... and yet more ANSIfications...
Thomas Wouters <thomas@python.org>
parents: 13666
diff changeset
388 /* Forward decls that need the above structs */
63832ede577f ... and yet more ANSIfications...
Thomas Wouters <thomas@python.org>
parents: 13666
diff changeset
389 static int save(Picklerobject *, PyObject *, int);
63832ede577f ... and yet more ANSIfications...
Thomas Wouters <thomas@python.org>
parents: 13666
diff changeset
390 static int put2(Picklerobject *, PyObject *);
63832ede577f ... and yet more ANSIfications...
Thomas Wouters <thomas@python.org>
parents: 13666
diff changeset
391
5283
82a3fbda3363 Give PyErr_Format a new name and make it static.
Guido van Rossum <guido@python.org>
parents: 5281
diff changeset
392 static
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
393 PyObject *
13666
36de7b6ab7eb ANSIfication: add proper prototypes to function-pointers and declarations.
Thomas Wouters <thomas@python.org>
parents: 13576
diff changeset
394 cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...)
36de7b6ab7eb ANSIfication: add proper prototypes to function-pointers and declarations.
Thomas Wouters <thomas@python.org>
parents: 13576
diff changeset
395 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
396 va_list va;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
397 PyObject *args=0, *retval=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
398 va_start(va, format);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
399
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
400 if (format) args = Py_VaBuildValue(format, va);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
401 va_end(va);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
402 if (format && ! args) return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
403 if (stringformat && !(retval=PyString_FromString(stringformat)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
404 return NULL;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
405
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
406 if (retval) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
407 if (args) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
408 PyObject *v;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
409 v=PyString_Format(retval, args);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
410 Py_DECREF(retval);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
411 Py_DECREF(args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
412 if (! v) return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
413 retval=v;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
414 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
415 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
416 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
417 if (args) retval=args;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
418 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
419 PyErr_SetObject(ErrType,Py_None);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
420 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
421 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
422 PyErr_SetObject(ErrType,retval);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
423 Py_DECREF(retval);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
424 return NULL;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
425 }
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
426
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
427 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
428 write_file(Picklerobject *self, const char *s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
429 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
430 size_t nbyteswritten;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
431
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
432 if (s == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
433 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
434 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
435
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
436 if (n > INT_MAX) {
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
437 /* String too large */
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
438 return -1;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
439 }
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
440
46337
2d95f7a983d8 Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
441 PyFile_IncUseCount((PyFileObject *)self->file);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
442 Py_BEGIN_ALLOW_THREADS
24302
c4bf45ca4d55 Fix indentation.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24280
diff changeset
443 nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
444 Py_END_ALLOW_THREADS
46337
2d95f7a983d8 Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
445 PyFile_DecUseCount((PyFileObject *)self->file);
24302
c4bf45ca4d55 Fix indentation.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24280
diff changeset
446 if (nbyteswritten != (size_t)n) {
c4bf45ca4d55 Fix indentation.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24280
diff changeset
447 PyErr_SetFromErrno(PyExc_IOError);
c4bf45ca4d55 Fix indentation.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24280
diff changeset
448 return -1;
c4bf45ca4d55 Fix indentation.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24280
diff changeset
449 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
450
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
451 return (int)n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
452 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
453
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
454 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
455 write_cStringIO(Picklerobject *self, const char *s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
456 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
457 if (s == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
458 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
459 }
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
460
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
461 if (PycStringIO->cwrite((PyObject *)self->file, s, n) != n) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
462 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
463 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
464
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
465 return (int)n;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
466 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
467
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
468 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
469 write_none(Picklerobject *self, const char *s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
470 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
471 if (s == NULL) return 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
472 if (n > INT_MAX) return -1;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
473 return (int)n;
5991
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
474 }
a5737dd96979 cPickle release 0.3 from Jim Fulton
Guido van Rossum <guido@python.org>
parents: 5544
diff changeset
475
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
476 static int
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
477 write_other(Picklerobject *self, const char *s, Py_ssize_t _n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
478 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
479 PyObject *py_str = 0, *junk = 0;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
480 int n;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
481
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
482 if (_n > INT_MAX)
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
483 return -1;
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
484 n = (int)_n;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
485 if (s == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
486 if (!( self->buf_size )) return 0;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
487 py_str = PyString_FromStringAndSize(self->write_buf,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
488 self->buf_size);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
489 if (!py_str)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
490 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
491 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
492 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
493 if (self->buf_size && (n + self->buf_size) > WRITE_BUF_SIZE) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
494 if (write_other(self, NULL, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
495 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
496 }
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
497
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
498 if (n > WRITE_BUF_SIZE) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
499 if (!( py_str =
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
500 PyString_FromStringAndSize(s, n)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
501 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
502 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
503 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
504 memcpy(self->write_buf + self->buf_size, s, n);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
505 self->buf_size += n;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
506 return n;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
507 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
508 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
509
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
510 if (self->write) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
511 /* object with write method */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
512 ARG_TUP(self, py_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
513 if (self->arg) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
514 junk = PyObject_Call(self->write, self->arg, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
515 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
516 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
517 if (junk) Py_DECREF(junk);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
518 else return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
519 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
520 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
521 PDATA_PUSH(self->file, py_str, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
522
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
523 self->buf_size = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
524 return n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
525 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
526
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
527
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
528 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
529 read_file(Unpicklerobject *self, char **s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
530 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
531 size_t nbytesread;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
532
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
533 if (self->buf_size == 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
534 int size;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
535
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
536 size = ((n < 32) ? 32 : n);
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
537 if (!( self->buf = (char *)malloc(size))) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
538 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
539 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
540 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
541
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
542 self->buf_size = size;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
543 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
544 else if (n > self->buf_size) {
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
545 char *newbuf = (char *)realloc(self->buf, n);
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
546 if (!newbuf) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
547 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
548 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
549 }
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
550 self->buf = newbuf;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
551 self->buf_size = n;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
552 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
553
46337
2d95f7a983d8 Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
554 PyFile_IncUseCount((PyFileObject *)self->file);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
555 Py_BEGIN_ALLOW_THREADS
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
556 nbytesread = fread(self->buf, sizeof(char), n, self->fp);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
557 Py_END_ALLOW_THREADS
46337
2d95f7a983d8 Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly
Gregory P. Smith <greg@mad-scientist.com>
parents: 44350
diff changeset
558 PyFile_DecUseCount((PyFileObject *)self->file);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
559 if (nbytesread != (size_t)n) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
560 if (feof(self->fp)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
561 PyErr_SetNone(PyExc_EOFError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
562 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
563 }
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
564
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
565 PyErr_SetFromErrno(PyExc_IOError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
566 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
567 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
568
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
569 *s = self->buf;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
570
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
571 return n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
572 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
573
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
574
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
575 static Py_ssize_t
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
576 readline_file(Unpicklerobject *self, char **s)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
577 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
578 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
579
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
580 if (self->buf_size == 0) {
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
581 if (!( self->buf = (char *)malloc(40))) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
582 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
583 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
584 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
585 self->buf_size = 40;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
586 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
587
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
588 i = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
589 while (1) {
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
590 int bigger;
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
591 char *newbuf;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
592 for (; i < (self->buf_size - 1); i++) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
593 if (feof(self->fp) ||
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
594 (self->buf[i] = getc(self->fp)) == '\n') {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
595 self->buf[i + 1] = '\0';
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
596 *s = self->buf;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
597 return i + 1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
598 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
599 }
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
600 bigger = self->buf_size << 1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
601 if (bigger <= 0) { /* overflow */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
602 PyErr_NoMemory();
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
603 return -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
604 }
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
605 newbuf = (char *)realloc(self->buf, bigger);
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
606 if (!newbuf) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
607 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
608 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
609 }
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
610 self->buf = newbuf;
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
611 self->buf_size = bigger;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
612 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
613 }
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
614
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
615
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
616 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
617 read_cStringIO(Unpicklerobject *self, char **s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
618 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
619 char *ptr;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
620
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
621 if (PycStringIO->cread((PyObject *)self->file, &ptr, n) != n) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
622 PyErr_SetNone(PyExc_EOFError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
623 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
624 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
625
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
626 *s = ptr;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
627
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
628 return n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
629 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
630
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
631
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
632 static Py_ssize_t
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
633 readline_cStringIO(Unpicklerobject *self, char **s)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
634 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
635 Py_ssize_t n;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
636 char *ptr;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
637
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
638 if ((n = PycStringIO->creadline((PyObject *)self->file, &ptr)) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
639 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
640 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
641
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
642 *s = ptr;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
643
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
644 return n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
645 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
646
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
647
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
648 static Py_ssize_t
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
649 read_other(Unpicklerobject *self, char **s, Py_ssize_t n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
650 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
651 PyObject *bytes, *str=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
652
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
653 if (!( bytes = PyInt_FromSsize_t(n))) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
654
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
655 ARG_TUP(self, bytes);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
656 if (self->arg) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
657 str = PyObject_Call(self->read, self->arg, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
658 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
659 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
660 if (! str) return -1;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
661
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
662 Py_XDECREF(self->last_string);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
663 self->last_string = str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
664
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
665 if (! (*s = PyString_AsString(str))) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
666 return n;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
668
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
669
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
670 static Py_ssize_t
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
671 readline_other(Unpicklerobject *self, char **s)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
672 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
673 PyObject *str;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
674 Py_ssize_t str_size;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
675
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
676 if (!( str = PyObject_CallObject(self->readline, empty_tuple))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
677 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
678 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
679
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
680 if ((str_size = PyString_Size(str)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
681 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
682
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
683 Py_XDECREF(self->last_string);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
684 self->last_string = str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
685
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
686 if (! (*s = PyString_AsString(str)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
687 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
688
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
689 return str_size;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
690 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
691
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
692 /* Copy the first n bytes from s into newly malloc'ed memory, plus a
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
693 * trailing 0 byte. Return a pointer to that, or NULL if out of memory.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
694 * The caller is responsible for free()'ing the return value.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
695 */
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
696 static char *
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 34126
diff changeset
697 pystrndup(const char *s, int n)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
698 {
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
699 char *r = (char *)malloc(n+1);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
700 if (r == NULL)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
701 return (char*)PyErr_NoMemory();
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
702 memcpy(r, s, n);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
703 r[n] = 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
704 return r;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
705 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
706
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
707
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
708 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
709 get(Picklerobject *self, PyObject *id)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
710 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
711 PyObject *value, *mv;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
712 long c_value;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
713 char s[30];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
714 size_t len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
715
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
716 if (!( mv = PyDict_GetItem(self->memo, id))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
717 PyErr_SetObject(PyExc_KeyError, id);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
718 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
719 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
720
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
721 if (!( value = PyTuple_GetItem(mv, 0)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
722 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
723
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
724 if (!( PyInt_Check(value))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
725 PyErr_SetString(PicklingError, "no int where int expected in memo");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
726 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
727 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
728 c_value = PyInt_AS_LONG((PyIntObject*)value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
729
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
730 if (!self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
731 s[0] = GET;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
732 PyOS_snprintf(s + 1, sizeof(s) - 1, "%ld\n", c_value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
733 len = strlen(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
734 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
735 else if (Pdata_Check(self->file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
736 if (write_other(self, NULL, 0) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
737 PDATA_APPEND(self->file, mv, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
738 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
739 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
740 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
741 if (c_value < 256) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
742 s[0] = BINGET;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
743 s[1] = (int)(c_value & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
744 len = 2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
745 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
746 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
747 s[0] = LONG_BINGET;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
748 s[1] = (int)(c_value & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
749 s[2] = (int)((c_value >> 8) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
750 s[3] = (int)((c_value >> 16) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
751 s[4] = (int)((c_value >> 24) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
752 len = 5;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
753 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
754 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
755
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
756 if (self->write_func(self, s, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
757 return -1;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
758
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
759 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
760 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
761
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
762
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
763 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
764 put(Picklerobject *self, PyObject *ob)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
765 {
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
766 if (Py_REFCNT(ob) < 2 || self->fast)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
767 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
768
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
769 return put2(self, ob);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
770 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
771
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
772
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
773 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
774 put2(Picklerobject *self, PyObject *ob)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
775 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
776 char c_str[30];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
777 int p;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
778 size_t len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
779 int res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
780 PyObject *py_ob_id = 0, *memo_len = 0, *t = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
781
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
782 if (self->fast)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
783 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
784
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
785 if ((p = PyDict_Size(self->memo)) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
786 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
787
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
788 /* Make sure memo keys are positive! */
27596
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27594
diff changeset
789 /* XXX Why?
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27594
diff changeset
790 * XXX And does "positive" really mean non-negative?
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27594
diff changeset
791 * XXX pickle.py starts with PUT index 0, not 1. This makes for
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27594
diff changeset
792 * XXX gratuitous differences between the pickling modules.
72228a25daaa Beefed up the tests by putting in more "for proto in protocols:" outer
Tim Peters <tim.peters@gmail.com>
parents: 27594
diff changeset
793 */
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
794 p++;
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
795
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
796 if (!( py_ob_id = PyLong_FromVoidPtr(ob)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
797 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
798
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
799 if (!( memo_len = PyInt_FromLong(p)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
800 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
801
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
802 if (!( t = PyTuple_New(2)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
803 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
804
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
805 PyTuple_SET_ITEM(t, 0, memo_len);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
806 Py_INCREF(memo_len);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
807 PyTuple_SET_ITEM(t, 1, ob);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
808 Py_INCREF(ob);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
809
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
810 if (PyDict_SetItem(self->memo, py_ob_id, t) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
811 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
812
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
813 if (!self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
814 c_str[0] = PUT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
815 PyOS_snprintf(c_str + 1, sizeof(c_str) - 1, "%d\n", p);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
816 len = strlen(c_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
817 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
818 else if (Pdata_Check(self->file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
819 if (write_other(self, NULL, 0) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
820 PDATA_APPEND(self->file, memo_len, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
821 res=0; /* Job well done ;) */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
822 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
823 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
824 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
825 if (p >= 256) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
826 c_str[0] = LONG_BINPUT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
827 c_str[1] = (int)(p & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
828 c_str[2] = (int)((p >> 8) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
829 c_str[3] = (int)((p >> 16) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
830 c_str[4] = (int)((p >> 24) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
831 len = 5;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
832 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
833 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
834 c_str[0] = BINPUT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
835 c_str[1] = p;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
836 len = 2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
837 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
838 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
839
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
840 if (self->write_func(self, c_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
841 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
842
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
843 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
844
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
845 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
846 Py_XDECREF(py_ob_id);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
847 Py_XDECREF(memo_len);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
848 Py_XDECREF(t);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
849
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
850 return res;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
851 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
852
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
853 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
854 whichmodule(PyObject *global, PyObject *global_name)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
855 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
856 Py_ssize_t i, j;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
857 PyObject *module = 0, *modules_dict = 0,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
858 *global_name_attr = 0, *name = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
859
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
860 module = PyObject_GetAttrString(global, "__module__");
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
861 if (module)
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
862 return module;
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
863 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
864 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
865 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
866 return NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
867
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
868 if (!( modules_dict = PySys_GetObject("modules")))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
869 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
870
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
871 i = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
872 while ((j = PyDict_Next(modules_dict, &i, &name, &module))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
873
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
874 if (PyObject_Compare(name, __main___str)==0) continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
875
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
876 global_name_attr = PyObject_GetAttr(module, global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
877 if (!global_name_attr) {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
878 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
879 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
880 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
881 return NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
882 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
883 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
884
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
885 if (global_name_attr != global) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
886 Py_DECREF(global_name_attr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
887 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
888 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
889
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
890 Py_DECREF(global_name_attr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
891
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
892 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
893 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
894
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
895 /* The following implements the rule in pickle.py added in 1.5
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
896 that used __main__ if no module is found. I don't actually
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
897 like this rule. jlf
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
898 */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
899 if (!j) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
900 j=1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
901 name=__main___str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
902 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
903
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
904 Py_INCREF(name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
905 return name;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
906 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
907
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
908
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
909 static int
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
910 fast_save_enter(Picklerobject *self, PyObject *obj)
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
911 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
912 /* if fast_container < 0, we're doing an error exit. */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
913 if (++self->fast_container >= PY_CPICKLE_FAST_LIMIT) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
914 PyObject *key = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
915 if (self->fast_memo == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
916 self->fast_memo = PyDict_New();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
917 if (self->fast_memo == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
918 self->fast_container = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
919 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
920 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
921 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
922 key = PyLong_FromVoidPtr(obj);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
923 if (key == NULL)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
924 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
925 if (PyDict_GetItem(self->fast_memo, key)) {
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
926 Py_DECREF(key);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
927 PyErr_Format(PyExc_ValueError,
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
928 "fast mode: can't pickle cyclic objects "
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
929 "including object type %s at %p",
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
930 Py_TYPE(obj)->tp_name, obj);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
931 self->fast_container = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
932 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
933 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
934 if (PyDict_SetItem(self->fast_memo, key, Py_None) < 0) {
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
935 Py_DECREF(key);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
936 self->fast_container = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
937 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
938 }
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
939 Py_DECREF(key);
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
940 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
941 return 1;
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
942 }
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
943
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
944 int
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
945 fast_save_leave(Picklerobject *self, PyObject *obj)
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
946 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
947 if (self->fast_container-- >= PY_CPICKLE_FAST_LIMIT) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
948 PyObject *key = PyLong_FromVoidPtr(obj);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
949 if (key == NULL)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
950 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
951 if (PyDict_DelItem(self->fast_memo, key) < 0) {
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
952 Py_DECREF(key);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
953 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
954 }
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
955 Py_DECREF(key);
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
956 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
957 return 1;
20443
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
958 }
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
959
03624d7484fa Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20385
diff changeset
960 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
961 save_none(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
962 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
963 static char none = NONE;
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
964 if (self->write_func(self, &none, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
965 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
966
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
967 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
968 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
969
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
970 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
971 save_bool(Picklerobject *self, PyObject *args)
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
972 {
35999
9541369b0dca Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 34126
diff changeset
973 static const char *buf[2] = {FALSE, TRUE};
22851
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
974 static char len[2] = {sizeof(FALSE)-1, sizeof(TRUE)-1};
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
975 long l = PyInt_AS_LONG((PyIntObject *)args);
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
976
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
977 if (self->proto >= 2) {
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
978 char opcode = l ? NEWTRUE : NEWFALSE;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
979 if (self->write_func(self, &opcode, 1) < 0)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
980 return -1;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
981 }
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
982 else if (self->write_func(self, buf[l], len[l]) < 0)
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
983 return -1;
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
984 return 0;
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
985 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
986
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
987 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
988 save_int(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
989 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
990 char c_str[32];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
991 long l = PyInt_AS_LONG((PyIntObject *)args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
992 int len = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
993
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
994 if (!self->bin
5498
9a1225923918 Use compile-time test for 64-bit hardware instead of run-time test.
Guido van Rossum <guido@python.org>
parents: 5438
diff changeset
995 #if SIZEOF_LONG > 4
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
996 || l > 0x7fffffffL
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
997 || l < -0x80000000L
5498
9a1225923918 Use compile-time test for 64-bit hardware instead of run-time test.
Guido van Rossum <guido@python.org>
parents: 5438
diff changeset
998 #endif
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
999 ) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1000 /* Text-mode pickle, or long too big to fit in the 4-byte
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1001 * signed BININT format: store as a string.
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1002 */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1003 c_str[0] = INT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1004 PyOS_snprintf(c_str + 1, sizeof(c_str) - 1, "%ld\n", l);
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1005 if (self->write_func(self, c_str, strlen(c_str)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1006 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1007 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1008 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1009 /* Binary pickle and l fits in a signed 4-byte int. */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1010 c_str[1] = (int)( l & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1011 c_str[2] = (int)((l >> 8) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1012 c_str[3] = (int)((l >> 16) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1013 c_str[4] = (int)((l >> 24) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1014
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1015 if ((c_str[4] == 0) && (c_str[3] == 0)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1016 if (c_str[2] == 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1017 c_str[0] = BININT1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1018 len = 2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1019 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1020 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1021 c_str[0] = BININT2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1022 len = 3;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1023 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1024 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1025 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1026 c_str[0] = BININT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1027 len = 5;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1028 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1029
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1030 if (self->write_func(self, c_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1031 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1032 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1033
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1034 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1035 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1036
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1037
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1038 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1039 save_long(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1040 {
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1041 Py_ssize_t size;
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1042 int res = -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1043 PyObject *repr = NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1044
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1045 static char l = LONG;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1046
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1047 if (self->proto >= 2) {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1048 /* Linear-time pickling. */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1049 size_t nbits;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1050 size_t nbytes;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1051 unsigned char *pdata;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1052 char c_str[5];
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1053 int i;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1054 int sign = _PyLong_Sign(args);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1055
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1056 if (sign == 0) {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1057 /* It's 0 -- an empty bytestring. */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1058 c_str[0] = LONG1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1059 c_str[1] = 0;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1060 i = self->write_func(self, c_str, 2);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1061 if (i < 0) goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1062 res = 0;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1063 goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1064 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1065 nbits = _PyLong_NumBits(args);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1066 if (nbits == (size_t)-1 && PyErr_Occurred())
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1067 goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1068 /* How many bytes do we need? There are nbits >> 3 full
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1069 * bytes of data, and nbits & 7 leftover bits. If there
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1070 * are any leftover bits, then we clearly need another
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1071 * byte. Wnat's not so obvious is that we *probably*
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1072 * need another byte even if there aren't any leftovers:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1073 * the most-significant bit of the most-significant byte
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1074 * acts like a sign bit, and it's usually got a sense
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1075 * opposite of the one we need. The exception is longs
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1076 * of the form -(2**(8*j-1)) for j > 0. Such a long is
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1077 * its own 256's-complement, so has the right sign bit
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1078 * even without the extra byte. That's a pain to check
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1079 * for in advance, though, so we always grab an extra
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1080 * byte at the start, and cut it back later if possible.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1081 */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1082 nbytes = (nbits >> 3) + 1;
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1083 if (nbytes > INT_MAX) {
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1084 PyErr_SetString(PyExc_OverflowError, "long too large "
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1085 "to pickle");
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1086 goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1087 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1088 repr = PyString_FromStringAndSize(NULL, (int)nbytes);
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1089 if (repr == NULL) goto finally;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1090 pdata = (unsigned char *)PyString_AS_STRING(repr);
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1091 i = _PyLong_AsByteArray((PyLongObject *)args,
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1092 pdata, nbytes,
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1093 1 /* little endian */, 1 /* signed */);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1094 if (i < 0) goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1095 /* If the long is negative, this may be a byte more than
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1096 * needed. This is so iff the MSB is all redundant sign
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1097 * bits.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1098 */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1099 if (sign < 0 && nbytes > 1 && pdata[nbytes - 1] == 0xff &&
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1100 (pdata[nbytes - 2] & 0x80) != 0)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1101 --nbytes;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1102
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1103 if (nbytes < 256) {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1104 c_str[0] = LONG1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1105 c_str[1] = (char)nbytes;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1106 size = 2;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1107 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1108 else {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1109 c_str[0] = LONG4;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1110 size = (int)nbytes;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1111 for (i = 1; i < 5; i++) {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1112 c_str[i] = (char)(size & 0xff);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1113 size >>= 8;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1114 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1115 size = 5;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1116 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1117 i = self->write_func(self, c_str, size);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1118 if (i < 0) goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1119 i = self->write_func(self, (char *)pdata, (int)nbytes);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1120 if (i < 0) goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1121 res = 0;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1122 goto finally;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1123 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1124
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1125 /* proto < 2: write the repr and newline. This is quadratic-time
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1126 * (in the number of digits), in both directions.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
1127 */
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1128 if (!( repr = PyObject_Repr(args)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1129 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1130
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1131 if ((size = PyString_Size(repr)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1132 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1133
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1134 if (self->write_func(self, &l, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1135 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1136
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1137 if (self->write_func(self,
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1138 PyString_AS_STRING((PyStringObject *)repr),
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1139 size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1140 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1141
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1142 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1143 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1144
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1145 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1146
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1147 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1148 Py_XDECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1149 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1150 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1151
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1152
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1153 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1154 save_float(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1155 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1156 double x = PyFloat_AS_DOUBLE((PyFloatObject *)args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1157
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1158 if (self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1159 char str[9];
28335
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
1160 str[0] = BINFLOAT;
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
1161 if (_PyFloat_Pack8(x, (unsigned char *)&str[1], 0) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1162 return -1;
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1163 if (self->write_func(self, str, 9) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1164 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1165 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1166 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1167 char c_str[250];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1168 c_str[0] = FLOAT;
53442
6947bc3dd433 Issue #5835, deprecate PyOS_ascii_formatd.
Eric Smith <eric@trueblade.com>
parents: 51020
diff changeset
1169 _PyOS_double_to_string(c_str + 1, sizeof(c_str) - 2, x, 'g',
6947bc3dd433 Issue #5835, deprecate PyOS_ascii_formatd.
Eric Smith <eric@trueblade.com>
parents: 51020
diff changeset
1170 17, 0, NULL);
38055
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 37756
diff changeset
1171 /* Extend the formatted string with a newline character */
fcc61835c6ac Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents: 37756
diff changeset
1172 strcat(c_str, "\n");
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1173
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1174 if (self->write_func(self, c_str, strlen(c_str)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1175 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1176 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1177
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1178 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1179 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1180
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1181
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1182 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1183 save_string(Picklerobject *self, PyObject *args, int doput)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1184 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1185 int size, len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1186 PyObject *repr=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1187
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1188 if ((size = PyString_Size(args)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1189 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1190
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1191 if (!self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1192 char *repr_str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1193
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1194 static char string = STRING;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1195
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1196 if (!( repr = PyObject_Repr(args)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1197 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1198
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1199 if ((len = PyString_Size(repr)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1200 goto err;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1201 repr_str = PyString_AS_STRING((PyStringObject *)repr);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1202
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1203 if (self->write_func(self, &string, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1204 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1205
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1206 if (self->write_func(self, repr_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1207 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1208
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1209 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1210 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1211
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1212 Py_XDECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1213 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1214 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1215 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1216 char c_str[5];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1217
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1218 if ((size = PyString_Size(args)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1219 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1220
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1221 if (size < 256) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1222 c_str[0] = SHORT_BINSTRING;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1223 c_str[1] = size;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1224 len = 2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1225 }
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1226 else if (size <= INT_MAX) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1227 c_str[0] = BINSTRING;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1228 for (i = 1; i < 5; i++)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1229 c_str[i] = (int)(size >> ((i - 1) * 8));
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1230 len = 5;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1231 }
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1232 else
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1233 return -1; /* string too large */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1234
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1235 if (self->write_func(self, c_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1236 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1237
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1238 if (size > 128 && Pdata_Check(self->file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1239 if (write_other(self, NULL, 0) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1240 PDATA_APPEND(self->file, args, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1241 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1242 else {
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1243 if (self->write_func(self,
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1244 PyString_AS_STRING(
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1245 (PyStringObject *)args),
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1246 size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1247 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1248 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1249 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1250
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1251 if (doput)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1252 if (put(self, args) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1253 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1254
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1255 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1256
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1257 err:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1258 Py_XDECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1259 return -1;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1260 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1261
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
1262
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
1263 #ifdef Py_USING_UNICODE
15607
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1264 /* A copy of PyUnicode_EncodeRawUnicodeEscape() that also translates
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1265 backslash and newline characters to \uXXXX escapes. */
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1266 static PyObject *
50290
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1267 modified_EncodeRawUnicodeEscape(const Py_UNICODE *s, Py_ssize_t size)
15607
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1268 {
50290
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1269 PyObject *repr;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1270 char *p;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1271 char *q;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1272
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1273 static const char *hexdigit = "0123456789abcdef";
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1274 #ifdef Py_UNICODE_WIDE
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1275 const Py_ssize_t expandsize = 10;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1276 #else
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1277 const Py_ssize_t expandsize = 6;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1278 #endif
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1279
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1280 if (size > PY_SSIZE_T_MAX / expandsize)
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1281 return PyErr_NoMemory();
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1282
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1283 repr = PyString_FromStringAndSize(NULL, expandsize * size);
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1284 if (repr == NULL)
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1285 return NULL;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1286 if (size == 0)
15607
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1287 return repr;
50290
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1288
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1289 p = q = PyString_AS_STRING(repr);
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1290 while (size-- > 0) {
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1291 Py_UNICODE ch = *s++;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1292 #ifdef Py_UNICODE_WIDE
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1293 /* Map 32-bit characters to '\Uxxxxxxxx' */
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1294 if (ch >= 0x10000) {
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1295 *p++ = '\\';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1296 *p++ = 'U';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1297 *p++ = hexdigit[(ch >> 28) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1298 *p++ = hexdigit[(ch >> 24) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1299 *p++ = hexdigit[(ch >> 20) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1300 *p++ = hexdigit[(ch >> 16) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1301 *p++ = hexdigit[(ch >> 12) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1302 *p++ = hexdigit[(ch >> 8) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1303 *p++ = hexdigit[(ch >> 4) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1304 *p++ = hexdigit[ch & 15];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1305 }
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1306 else
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1307 #else
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1308 /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1309 if (ch >= 0xD800 && ch < 0xDC00) {
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1310 Py_UNICODE ch2;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1311 Py_UCS4 ucs;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1312
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1313 ch2 = *s++;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1314 size--;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1315 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) {
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1316 ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1317 *p++ = '\\';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1318 *p++ = 'U';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1319 *p++ = hexdigit[(ucs >> 28) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1320 *p++ = hexdigit[(ucs >> 24) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1321 *p++ = hexdigit[(ucs >> 20) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1322 *p++ = hexdigit[(ucs >> 16) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1323 *p++ = hexdigit[(ucs >> 12) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1324 *p++ = hexdigit[(ucs >> 8) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1325 *p++ = hexdigit[(ucs >> 4) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1326 *p++ = hexdigit[ucs & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1327 continue;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1328 }
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1329 /* Fall through: isolated surrogates are copied as-is */
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1330 s--;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1331 size++;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1332 }
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1333 #endif
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1334 /* Map 16-bit characters to '\uxxxx' */
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1335 if (ch >= 256 || ch == '\\' || ch == '\n') {
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1336 *p++ = '\\';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1337 *p++ = 'u';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1338 *p++ = hexdigit[(ch >> 12) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1339 *p++ = hexdigit[(ch >> 8) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1340 *p++ = hexdigit[(ch >> 4) & 0xf];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1341 *p++ = hexdigit[ch & 15];
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1342 }
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1343 /* Copy everything else as-is */
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1344 else
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1345 *p++ = (char) ch;
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1346 }
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1347 *p = '\0';
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1348 _PyString_Resize(&repr, p - q);
d27024755593 Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 49609
diff changeset
1349 return repr;
15607
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1350 }
59bfbbe581c2 Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents: 15011
diff changeset
1351
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1352 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1353 save_unicode(Picklerobject *self, PyObject *args, int doput)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1354 {
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1355 Py_ssize_t size, len;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1356 PyObject *repr=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1357
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1358 if (!PyUnicode_Check(args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1359 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1360
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1361 if (!self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1362 char *repr_str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1363 static char string = UNICODE;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1364
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1365 repr = modified_EncodeRawUnicodeEscape(
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1366 PyUnicode_AS_UNICODE(args), PyUnicode_GET_SIZE(args));
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1367 if (!repr)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1368 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1369
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1370 if ((len = PyString_Size(repr)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1371 goto err;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1372 repr_str = PyString_AS_STRING((PyStringObject *)repr);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1373
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1374 if (self->write_func(self, &string, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1375 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1376
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1377 if (self->write_func(self, repr_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1378 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1379
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1380 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1381 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1382
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1383 Py_XDECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1384 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1385 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1386 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1387 char c_str[5];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1388
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1389 if (!( repr = PyUnicode_AsUTF8String(args)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1390 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1391
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1392 if ((size = PyString_Size(repr)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1393 goto err;
39995
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1394 if (size > INT_MAX)
6ba402b60041 Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents: 39348
diff changeset
1395 return -1; /* string too large */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1396
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1397 c_str[0] = BINUNICODE;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1398 for (i = 1; i < 5; i++)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1399 c_str[i] = (int)(size >> ((i - 1) * 8));
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1400 len = 5;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1401
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1402 if (self->write_func(self, c_str, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1403 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1404
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1405 if (size > 128 && Pdata_Check(self->file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1406 if (write_other(self, NULL, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1407 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1408 PDATA_APPEND(self->file, repr, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1409 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1410 else {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1411 if (self->write_func(self, PyString_AS_STRING(repr),
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1412 size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1413 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1414 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1415
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1416 Py_DECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1417 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1418
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1419 if (doput)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1420 if (put(self, args) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1421 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1422
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1423 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1424
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1425 err:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1426 Py_XDECREF(repr);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1427 return -1;
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1428 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
1429 #endif
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1430
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1431 /* A helper for save_tuple. Push the len elements in tuple t on the stack. */
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
1432 static int
27687
20b803cf219d Typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
1433 store_tuple_elements(Picklerobject *self, PyObject *t, int len)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1434 {
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1435 int i;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1436 int res = -1; /* guilty until proved innocent */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1437
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1438 assert(PyTuple_Size(t) == len);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1439
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1440 for (i = 0; i < len; i++) {
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1441 PyObject *element = PyTuple_GET_ITEM(t, i);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1442
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1443 if (element == NULL)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1444 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1445 if (save(self, element, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1446 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1447 }
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1448 res = 0;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1449
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1450 finally:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1451 return res;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1452 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1453
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1454 /* Tuples are ubiquitous in the pickle protocols, so many techniques are
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1455 * used across protocols to minimize the space needed to pickle them.
27687
20b803cf219d Typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
1456 * Tuples are also the only builtin immutable type that can be recursive
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1457 * (a tuple can be reached from itself), and that requires some subtle
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1458 * magic so that it works in all cases. IOW, this is a long routine.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1459 */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1460 static int
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1461 save_tuple(Picklerobject *self, PyObject *args)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1462 {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1463 PyObject *py_tuple_id = NULL;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1464 int len, i;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1465 int res = -1;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1466
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1467 static char tuple = TUPLE;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1468 static char pop = POP;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1469 static char pop_mark = POP_MARK;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1470 static char len2opcode[] = {EMPTY_TUPLE, TUPLE1, TUPLE2, TUPLE3};
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1471
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1472 if ((len = PyTuple_Size(args)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1473 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1474
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1475 if (len == 0) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1476 char c_str[2];
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1477
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1478 if (self->proto) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1479 c_str[0] = EMPTY_TUPLE;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1480 len = 1;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1481 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1482 else {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1483 c_str[0] = MARK;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1484 c_str[1] = TUPLE;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1485 len = 2;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1486 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1487 if (self->write_func(self, c_str, len) >= 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1488 res = 0;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1489 /* Don't memoize an empty tuple. */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1490 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1491 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1492
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1493 /* A non-empty tuple. */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1494
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1495 /* id(tuple) isn't in the memo now. If it shows up there after
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1496 * saving the tuple elements, the tuple must be recursive, in
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1497 * which case we'll pop everything we put on the stack, and fetch
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1498 * its value from the memo.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1499 */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1500 py_tuple_id = PyLong_FromVoidPtr(args);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1501 if (py_tuple_id == NULL)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1502 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1503
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1504 if (len <= 3 && self->proto >= 2) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1505 /* Use TUPLE{1,2,3} opcodes. */
27687
20b803cf219d Typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
1506 if (store_tuple_elements(self, args, len) < 0)
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1507 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1508 if (PyDict_GetItem(self->memo, py_tuple_id)) {
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1509 /* pop the len elements */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1510 for (i = 0; i < len; ++i)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1511 if (self->write_func(self, &pop, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1512 goto finally;
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1513 /* fetch from memo */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1514 if (get(self, py_tuple_id) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1515 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1516 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1517 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1518 }
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1519 /* Not recursive. */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1520 if (self->write_func(self, len2opcode + len, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1521 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1522 goto memoize;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1523 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1524
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1525 /* proto < 2 and len > 0, or proto >= 2 and len > 3.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1526 * Generate MARK elt1 elt2 ... TUPLE
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1527 */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1528 if (self->write_func(self, &MARKv, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1529 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1530
27687
20b803cf219d Typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27686
diff changeset
1531 if (store_tuple_elements(self, args, len) < 0)
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1532 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1533
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1534 if (PyDict_GetItem(self->memo, py_tuple_id)) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1535 /* pop the stack stuff we pushed */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1536 if (self->bin) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1537 if (self->write_func(self, &pop_mark, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1538 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1539 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1540 else {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1541 /* Note that we pop one more than len, to remove
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1542 * the MARK too.
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1543 */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1544 for (i = 0; i <= len; i++)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1545 if (self->write_func(self, &pop, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1546 goto finally;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1547 }
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1548 /* fetch from memo */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1549 if (get(self, py_tuple_id) >= 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1550 res = 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1551 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1552 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1553
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1554 /* Not recursive. */
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1555 if (self->write_func(self, &tuple, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1556 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1557
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1558 memoize:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1559 if (put(self, args) >= 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
1560 res = 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1561
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1562 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1563 Py_XDECREF(py_tuple_id);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1564 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1565 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1566
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1567 /* iter is an iterator giving items, and we batch up chunks of
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1568 * MARK item item ... item APPENDS
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1569 * opcode sequences. Calling code should have arranged to first create an
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1570 * empty list, or list-like object, for the APPENDS to operate on.
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1571 * Returns 0 on success, <0 on error.
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1572 */
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1573 static int
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1574 batch_list(Picklerobject *self, PyObject *iter)
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1575 {
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1576 PyObject *obj = NULL;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1577 PyObject *firstitem = NULL;
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1578 int i, n;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1579
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1580 static char append = APPEND;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1581 static char appends = APPENDS;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1582
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1583 assert(iter != NULL);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1584
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1585 if (self->proto == 0) {
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1586 /* APPENDS isn't available; do one at a time. */
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1587 for (;;) {
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1588 obj = PyIter_Next(iter);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1589 if (obj == NULL) {
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1590 if (PyErr_Occurred())
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1591 return -1;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1592 break;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1593 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1594 i = save(self, obj, 0);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1595 Py_DECREF(obj);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1596 if (i < 0)
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1597 return -1;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1598 if (self->write_func(self, &append, 1) < 0)
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1599 return -1;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1600 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1601 return 0;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1602 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1603
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1604 /* proto > 0: write in batches of BATCHSIZE. */
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1605 do {
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1606 /* Get first item */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1607 firstitem = PyIter_Next(iter);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1608 if (firstitem == NULL) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1609 if (PyErr_Occurred())
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1610 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1611
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1612 /* nothing more to add */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1613 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1614 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1615
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1616 /* Try to get a second item */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1617 obj = PyIter_Next(iter);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1618 if (obj == NULL) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1619 if (PyErr_Occurred())
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1620 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1621
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1622 /* Only one item to write */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1623 if (save(self, firstitem, 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1624 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1625 if (self->write_func(self, &append, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1626 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1627 Py_CLEAR(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1628 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1629 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1630
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1631 /* More than one item to write */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1632
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1633 /* Pump out MARK, items, APPENDS. */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1634 if (self->write_func(self, &MARKv, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1635 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1636
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1637 if (save(self, firstitem, 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1638 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1639 Py_CLEAR(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1640 n = 1;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1641
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1642 /* Fetch and save up to BATCHSIZE items */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1643 while (obj) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1644 if (save(self, obj, 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1645 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1646 Py_CLEAR(obj);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1647 n += 1;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1648
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1649 if (n == BATCHSIZE)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1650 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1651
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1652 obj = PyIter_Next(iter);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1653 if (obj == NULL) {
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1654 if (PyErr_Occurred())
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1655 goto BatchFailed;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1656 break;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1657 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1658 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1659
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1660 if (self->write_func(self, &appends, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1661 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1662
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1663 } while (n == BATCHSIZE);
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1664 return 0;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1665
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1666 BatchFailed:
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1667 Py_XDECREF(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1668 Py_XDECREF(obj);
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1669 return -1;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1670 }
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1671
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1672 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1673 save_list(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1674 {
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1675 int res = -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1676 char s[3];
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1677 int len;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1678 PyObject *iter;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1679
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1680 if (self->fast && !fast_save_enter(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1681 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1682
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1683 /* Create an empty list. */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1684 if (self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1685 s[0] = EMPTY_LIST;
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1686 len = 1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1687 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1688 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1689 s[0] = MARK;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1690 s[1] = LIST;
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1691 len = 2;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1692 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1693
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1694 if (self->write_func(self, s, len) < 0)
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1695 goto finally;
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1696
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1697 /* Get list length, and bow out early if empty. */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1698 if ((len = PyList_Size(args)) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1699 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1700
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1701 /* Memoize. */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1702 if (len == 0) {
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1703 if (put(self, args) >= 0)
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1704 res = 0;
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1705 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1706 }
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1707 if (put2(self, args) < 0)
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1708 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1709
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1710 /* Materialize the list elements. */
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1711 iter = PyObject_GetIter(args);
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1712 if (iter == NULL)
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1713 goto finally;
47856
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1714
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1715 if (Py_EnterRecursiveCall(" while pickling an object") == 0)
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1716 {
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1717 res = batch_list(self, iter);
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1718 Py_LeaveRecursiveCall();
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1719 }
27822
19ac12ac8041 Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27688
diff changeset
1720 Py_DECREF(iter);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1721
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1722 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1723 if (self->fast && !fast_save_leave(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1724 res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1725
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1726 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1727 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1728
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1729
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1730 /* iter is an iterator giving (key, value) pairs, and we batch up chunks of
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1731 * MARK key value ... key value SETITEMS
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1732 * opcode sequences. Calling code should have arranged to first create an
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1733 * empty dict, or dict-like object, for the SETITEMS to operate on.
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1734 * Returns 0 on success, <0 on error.
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1735 *
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1736 * This is very much like batch_list(). The difference between saving
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1737 * elements directly, and picking apart two-tuples, is so long-winded at
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1738 * the C level, though, that attempts to combine these routines were too
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1739 * ugly to bear.
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1740 */
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1741 static int
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1742 batch_dict(Picklerobject *self, PyObject *iter)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1743 {
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1744 PyObject *p = NULL;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1745 PyObject *firstitem = NULL;
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1746 int i, n;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1747
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1748 static char setitem = SETITEM;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1749 static char setitems = SETITEMS;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1750
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1751 assert(iter != NULL);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1752
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1753 if (self->proto == 0) {
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1754 /* SETITEMS isn't available; do one at a time. */
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1755 for (;;) {
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1756 p = PyIter_Next(iter);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1757 if (p == NULL) {
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1758 if (PyErr_Occurred())
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1759 return -1;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1760 break;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1761 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1762 if (!PyTuple_Check(p) || PyTuple_Size(p) != 2) {
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1763 PyErr_SetString(PyExc_TypeError, "dict items "
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1764 "iterator must return 2-tuples");
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1765 return -1;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1766 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1767 i = save(self, PyTuple_GET_ITEM(p, 0), 0);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1768 if (i >= 0)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1769 i = save(self, PyTuple_GET_ITEM(p, 1), 0);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1770 Py_DECREF(p);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1771 if (i < 0)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1772 return -1;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1773 if (self->write_func(self, &setitem, 1) < 0)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1774 return -1;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1775 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1776 return 0;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1777 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1778
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1779 /* proto > 0: write in batches of BATCHSIZE. */
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1780 do {
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1781 /* Get first item */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1782 firstitem = PyIter_Next(iter);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1783 if (firstitem == NULL) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1784 if (PyErr_Occurred())
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1785 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1786
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1787 /* nothing more to add */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1788 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1789 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1790 if (!PyTuple_Check(firstitem) || PyTuple_Size(firstitem) != 2) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1791 PyErr_SetString(PyExc_TypeError, "dict items "
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1792 "iterator must return 2-tuples");
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1793 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1794 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1795
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1796 /* Try to get a second item */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1797 p = PyIter_Next(iter);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1798 if (p == NULL) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1799 if (PyErr_Occurred())
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1800 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1801
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1802 /* Only one item to write */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1803 if (save(self, PyTuple_GET_ITEM(firstitem, 0), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1804 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1805 if (save(self, PyTuple_GET_ITEM(firstitem, 1), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1806 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1807 if (self->write_func(self, &setitem, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1808 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1809 Py_CLEAR(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1810 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1811 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1812
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1813 /* More than one item to write */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1814
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1815 /* Pump out MARK, items, SETITEMS. */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1816 if (self->write_func(self, &MARKv, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1817 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1818
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1819 if (save(self, PyTuple_GET_ITEM(firstitem, 0), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1820 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1821 if (save(self, PyTuple_GET_ITEM(firstitem, 1), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1822 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1823 Py_CLEAR(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1824 n = 1;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1825
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1826 /* Fetch and save up to BATCHSIZE items */
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1827 while (p) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1828 if (!PyTuple_Check(p) || PyTuple_Size(p) != 2) {
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1829 PyErr_SetString(PyExc_TypeError, "dict items "
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1830 "iterator must return 2-tuples");
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1831 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1832 }
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1833 if (save(self, PyTuple_GET_ITEM(p, 0), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1834 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1835 if (save(self, PyTuple_GET_ITEM(p, 1), 0) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1836 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1837 Py_CLEAR(p);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1838 n += 1;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1839
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1840 if (n == BATCHSIZE)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1841 break;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1842
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1843 p = PyIter_Next(iter);
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1844 if (p == NULL) {
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1845 if (PyErr_Occurred())
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1846 goto BatchFailed;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1847 break;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1848 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1849 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1850
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1851 if (self->write_func(self, &setitems, 1) < 0)
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1852 goto BatchFailed;
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1853
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1854 } while (n == BATCHSIZE);
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1855 return 0;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1856
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1857 BatchFailed:
49148
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1858 Py_XDECREF(firstitem);
0ef7cb35b216 #3640: Correct a crash in cPickle on 64bit platforms, in the case of deeply nested lists or dicts.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 47856
diff changeset
1859 Py_XDECREF(p);
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1860 return -1;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1861 }
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1862
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1863 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1864 save_dict(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1865 {
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1866 int res = -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1867 char s[3];
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1868 int len;
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1869 PyObject *iter;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1870
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1871 if (self->fast && !fast_save_enter(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1872 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1873
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1874 /* Create an empty dict. */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1875 if (self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1876 s[0] = EMPTY_DICT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1877 len = 1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1878 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1879 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1880 s[0] = MARK;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1881 s[1] = DICT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1882 len = 2;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1883 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1884
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1885 if (self->write_func(self, s, len) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1886 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1887
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1888 /* Get dict size, and bow out early if empty. */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1889 if ((len = PyDict_Size(args)) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1890 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1891
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1892 if (len == 0) {
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1893 if (put(self, args) >= 0)
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1894 res = 0;
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1895 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1896 }
27832
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1897 if (put2(self, args) < 0)
7f171f9db8af Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents: 27825
diff changeset
1898 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1899
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1900 /* Materialize the dict items. */
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1901 iter = PyObject_CallMethod(args, "iteritems", "()");
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1902 if (iter == NULL)
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1903 goto finally;
47856
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1904 if (Py_EnterRecursiveCall(" while pickling an object") == 0)
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1905 {
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1906 res = batch_dict(self, iter);
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1907 Py_LeaveRecursiveCall();
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
1908 }
27825
011f734258db Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents: 27822
diff changeset
1909 Py_DECREF(iter);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1910
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1911 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1912 if (self->fast && !fast_save_leave(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1913 res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1914
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1915 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1916 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1917
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
1918
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
1919 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1920 save_inst(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1921 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1922 PyObject *class = 0, *module = 0, *name = 0, *state = 0,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1923 *getinitargs_func = 0, *getstate_func = 0, *class_args = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1924 char *module_str, *name_str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1925 int module_size, name_size, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1926
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1927 static char inst = INST, obj = OBJ, build = BUILD;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1928
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1929 if (self->fast && !fast_save_enter(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1930 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1931
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1932 if (self->write_func(self, &MARKv, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1933 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1934
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1935 if (!( class = PyObject_GetAttr(args, __class___str)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1936 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1937
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1938 if (self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1939 if (save(self, class, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1940 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1941 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1942
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1943 if ((getinitargs_func = PyObject_GetAttr(args, __getinitargs___str))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1944 PyObject *element = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1945 int i, len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1946
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1947 if (!( class_args =
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1948 PyObject_Call(getinitargs_func, empty_tuple, NULL)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1949 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1950
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1951 if ((len = PyObject_Size(class_args)) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1952 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1953
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1954 for (i = 0; i < len; i++) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1955 if (!( element = PySequence_GetItem(class_args, i)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1956 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1957
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1958 if (save(self, element, 0) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1959 Py_DECREF(element);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1960 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1961 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1962
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1963 Py_DECREF(element);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1964 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1965 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1966 else {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
1967 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
1968 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
1969 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
1970 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1971 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1972
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1973 if (!self->bin) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1974 if (!( name = ((PyClassObject *)class)->cl_name )) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1975 PyErr_SetString(PicklingError, "class has no name");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1976 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1977 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1978
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
1979 if (!( module = whichmodule(class, name)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1980 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1981
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1982
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1983 if ((module_size = PyString_Size(module)) < 0 ||
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1984 (name_size = PyString_Size(name)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1985 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1986
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1987 module_str = PyString_AS_STRING((PyStringObject *)module);
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
1988 name_str = PyString_AS_STRING((PyStringObject *)name);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1989
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1990 if (self->write_func(self, &inst, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1991 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1992
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1993 if (self->write_func(self, module_str, module_size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1994 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1995
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1996 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1997 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
1998
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
1999 if (self->write_func(self, name_str, name_size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2000 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2001
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2002 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2003 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2004 }
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2005 else if (self->write_func(self, &obj, 1) < 0) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2006 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2007 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2008
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2009 if ((getstate_func = PyObject_GetAttr(args, __getstate___str))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2010 state = PyObject_Call(getstate_func, empty_tuple, NULL);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2011 if (!state)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2012 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2013 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2014 else {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2015 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2016 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2017 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2018 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2019
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2020 if (!( state = PyObject_GetAttr(args, __dict___str))) {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2021 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2022 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2023 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2024 goto finally;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2025 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2026 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2027 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2028 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2029
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2030 if (!PyDict_Check(state)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2031 if (put2(self, args) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2032 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2033 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2034 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2035 if (put(self, args) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2036 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2037 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2038
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2039 if (save(self, state, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2040 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2041
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2042 if (self->write_func(self, &build, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2043 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2044
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2045 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2046
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2047 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2048 if (self->fast && !fast_save_leave(self, args))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2049 res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2050
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2051 Py_XDECREF(module);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2052 Py_XDECREF(class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2053 Py_XDECREF(state);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2054 Py_XDECREF(getinitargs_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2055 Py_XDECREF(getstate_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2056 Py_XDECREF(class_args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2057
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2058 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2059 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2060
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2061
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2062 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2063 save_global(Picklerobject *self, PyObject *args, PyObject *name)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2064 {
24209
a546593968d6 remove decl of unused variable
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24208
diff changeset
2065 PyObject *global_name = 0, *module = 0, *mod = 0, *klass = 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2066 char *name_str, *module_str;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2067 int module_size, name_size, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2068
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2069 static char global = GLOBAL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2070
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2071 if (name) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2072 global_name = name;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2073 Py_INCREF(global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2074 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2075 else {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2076 if (!( global_name = PyObject_GetAttr(args, __name___str)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2077 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2078 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2079
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2080 if (!( module = whichmodule(args, global_name)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2081 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2082
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2083 if ((module_size = PyString_Size(module)) < 0 ||
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2084 (name_size = PyString_Size(global_name)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2085 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2086
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2087 module_str = PyString_AS_STRING((PyStringObject *)module);
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2088 name_str = PyString_AS_STRING((PyStringObject *)global_name);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2089
26790
89c9c6c405ef Add an XXX comment about relative imports.
Guido van Rossum <guido@python.org>
parents: 26561
diff changeset
2090 /* XXX This can be doing a relative import. Clearly it shouldn't,
89c9c6c405ef Add an XXX comment about relative imports.
Guido van Rossum <guido@python.org>
parents: 26561
diff changeset
2091 but I don't know how to stop it. :-( */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2092 mod = PyImport_ImportModule(module_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2093 if (mod == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2094 cPickle_ErrFormat(PicklingError,
27944
a6962f52f239 save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents: 27903
diff changeset
2095 "Can't pickle %s: import of module %s "
a6962f52f239 save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents: 27903
diff changeset
2096 "failed",
a6962f52f239 save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents: 27903
diff changeset
2097 "OS", args, module);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2098 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2099 }
24208
efabc1511dc2 Do more robust test of whether global objects are accessible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24014
diff changeset
2100 klass = PyObject_GetAttrString(mod, name_str);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2101 if (klass == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2102 cPickle_ErrFormat(PicklingError,
27944
a6962f52f239 save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents: 27903
diff changeset
2103 "Can't pickle %s: attribute lookup %s.%s "
a6962f52f239 save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents: 27903
diff changeset
2104 "failed",
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2105 "OSS", args, module, global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2106 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2107 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2108 if (klass != args) {
24208
efabc1511dc2 Do more robust test of whether global objects are accessible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24014
diff changeset
2109 Py_DECREF(klass);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2110 cPickle_ErrFormat(PicklingError,
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2111 "Can't pickle %s: it's not the same object "
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2112 "as %s.%s",
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2113 "OSS", args, module, global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2114 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2115 }
24208
efabc1511dc2 Do more robust test of whether global objects are accessible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24014
diff changeset
2116 Py_DECREF(klass);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2117
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2118 if (self->proto >= 2) {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2119 /* See whether this is in the extension registry, and if
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2120 * so generate an EXT opcode.
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2121 */
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2122 PyObject *py_code; /* extension code as Python object */
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
2123 long code; /* extension code as C value */
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2124 char c_str[5];
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2125 int n;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2126
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2127 PyTuple_SET_ITEM(two_tuple, 0, module);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2128 PyTuple_SET_ITEM(two_tuple, 1, global_name);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2129 py_code = PyDict_GetItem(extension_registry, two_tuple);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2130 if (py_code == NULL)
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2131 goto gen_global; /* not registered */
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2132
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2133 /* Verify py_code has the right type and value. */
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2134 if (!PyInt_Check(py_code)) {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2135 cPickle_ErrFormat(PicklingError, "Can't pickle %s: "
27688
4c7b1b7d7f31 More typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27687
diff changeset
2136 "extension code %s isn't an integer",
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2137 "OO", args, py_code);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2138 goto finally;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2139 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2140 code = PyInt_AS_LONG(py_code);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2141 if (code <= 0 || code > 0x7fffffffL) {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2142 cPickle_ErrFormat(PicklingError, "Can't pickle %s: "
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2143 "extension code %ld is out of range",
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2144 "Ol", args, code);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2145 goto finally;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2146 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2147
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2148 /* Generate an EXT opcode. */
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2149 if (code <= 0xff) {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2150 c_str[0] = EXT1;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2151 c_str[1] = (char)code;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2152 n = 2;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2153 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2154 else if (code <= 0xffff) {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2155 c_str[0] = EXT2;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2156 c_str[1] = (char)(code & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2157 c_str[2] = (char)((code >> 8) & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2158 n = 3;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2159 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2160 else {
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2161 c_str[0] = EXT4;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2162 c_str[1] = (char)(code & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2163 c_str[2] = (char)((code >> 8) & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2164 c_str[3] = (char)((code >> 16) & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2165 c_str[4] = (char)((code >> 24) & 0xff);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2166 n = 5;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2167 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2168
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2169 if (self->write_func(self, c_str, n) >= 0)
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2170 res = 0;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2171 goto finally; /* and don't memoize */
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2172 }
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2173
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
2174 gen_global:
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2175 if (self->write_func(self, &global, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2176 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2177
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2178 if (self->write_func(self, module_str, module_size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2179 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2180
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2181 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2182 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2183
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2184 if (self->write_func(self, name_str, name_size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2185 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2186
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2187 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2188 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2189
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2190 if (put(self, args) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2191 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2192
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2193 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2194
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2195 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2196 Py_XDECREF(module);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2197 Py_XDECREF(global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2198 Py_XDECREF(mod);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2199
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2200 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2201 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2202
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2203 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2204 save_pers(Picklerobject *self, PyObject *args, PyObject *f)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2205 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2206 PyObject *pid = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2207 int size, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2208
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2209 static char persid = PERSID, binpersid = BINPERSID;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2210
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2211 Py_INCREF(args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2212 ARG_TUP(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2213 if (self->arg) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2214 pid = PyObject_Call(f, self->arg, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2215 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2216 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2217 if (! pid) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2218
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2219 if (pid != Py_None) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2220 if (!self->bin) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2221 if (!PyString_Check(pid)) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2222 PyErr_SetString(PicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2223 "persistent id must be string");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2224 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2225 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2226
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2227 if (self->write_func(self, &persid, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2228 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2229
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2230 if ((size = PyString_Size(pid)) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2231 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2232
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2233 if (self->write_func(self,
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2234 PyString_AS_STRING(
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2235 (PyStringObject *)pid),
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2236 size) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2237 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2238
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2239 if (self->write_func(self, "\n", 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2240 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2241
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2242 res = 1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2243 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2244 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2245 else if (save(self, pid, 1) >= 0) {
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
2246 if (self->write_func(self, &binpersid, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2247 res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2248 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2249 res = 1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2250 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2251
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2252 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2253 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2254
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2255 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2256
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2257 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2258 Py_XDECREF(pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2259
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2260 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2261 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2262
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2263 /* We're saving ob, and args is the 2-thru-5 tuple returned by the
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2264 * appropriate __reduce__ method for ob.
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2265 */
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
2266 static int
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2267 save_reduce(Picklerobject *self, PyObject *args, PyObject *fn, PyObject *ob)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2268 {
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2269 PyObject *callable;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2270 PyObject *argtup;
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2271 PyObject *state = NULL;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2272 PyObject *listitems = Py_None;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2273 PyObject *dictitems = Py_None;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2274 Py_ssize_t size;
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2275
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2276 int use_newobj = self->proto >= 2;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2277
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2278 static char reduce = REDUCE;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2279 static char build = BUILD;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2280 static char newobj = NEWOBJ;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2281
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2282 size = PyTuple_Size(args);
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2283 if (size < 2 || size > 5) {
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2284 cPickle_ErrFormat(PicklingError, "tuple returned by "
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2285 "%s must contain 2 through 5 elements",
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2286 "O", fn);
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2287 return -1;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2288 }
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2289
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2290 if (! PyArg_UnpackTuple(args, "save_reduce", 2, 5,
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2291 &callable,
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2292 &argtup,
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2293 &state,
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2294 &listitems,
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2295 &dictitems))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2296 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2297
34126
79066ea38c50 Eliminate the deprecated option to return None instead of a tuple of arguments in __reduce__().
Raymond Hettinger <python@rcn.com>
parents: 32829
diff changeset
2298 if (!PyTuple_Check(argtup)) {
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2299 cPickle_ErrFormat(PicklingError, "Second element of "
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2300 "tuple returned by %s must be a tuple",
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2301 "O", fn);
34126
79066ea38c50 Eliminate the deprecated option to return None instead of a tuple of arguments in __reduce__().
Raymond Hettinger <python@rcn.com>
parents: 32829
diff changeset
2302 return -1;
79066ea38c50 Eliminate the deprecated option to return None instead of a tuple of arguments in __reduce__().
Raymond Hettinger <python@rcn.com>
parents: 32829
diff changeset
2303 }
79066ea38c50 Eliminate the deprecated option to return None instead of a tuple of arguments in __reduce__().
Raymond Hettinger <python@rcn.com>
parents: 32829
diff changeset
2304
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2305 if (state == Py_None)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2306 state = NULL;
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2307
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2308 if (listitems == Py_None)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2309 listitems = NULL;
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2310 else if (!PyIter_Check(listitems)) {
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2311 cPickle_ErrFormat(PicklingError, "Fourth element of "
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2312 "tuple returned by %s must be an iterator, not %s",
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2313 "Os", fn, Py_TYPE(listitems)->tp_name);
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2314 return -1;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2315 }
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2316
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2317 if (dictitems == Py_None)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2318 dictitems = NULL;
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2319 else if (!PyIter_Check(dictitems)) {
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2320 cPickle_ErrFormat(PicklingError, "Fifth element of "
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2321 "tuple returned by %s must be an iterator, not %s",
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2322 "Os", fn, Py_TYPE(dictitems)->tp_name);
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2323 return -1;
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2324 }
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2325
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2326 /* Protocol 2 special case: if callable's name is __newobj__, use
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2327 * NEWOBJ. This consumes a lot of code.
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2328 */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2329 if (use_newobj) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2330 PyObject *temp = PyObject_GetAttr(callable, __name___str);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2331
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2332 if (temp == NULL) {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2333 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2334 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2335 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2336 return -1;
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2337 use_newobj = 0;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2338 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2339 else {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2340 use_newobj = PyString_Check(temp) &&
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2341 strcmp(PyString_AS_STRING(temp),
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2342 "__newobj__") == 0;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2343 Py_DECREF(temp);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2344 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2345 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2346 if (use_newobj) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2347 PyObject *cls;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2348 PyObject *newargtup;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2349 int n, i;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2350
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2351 /* Sanity checks. */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2352 n = PyTuple_Size(argtup);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2353 if (n < 1) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2354 PyErr_SetString(PicklingError, "__newobj__ arglist "
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2355 "is empty");
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2356 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2357 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2358
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2359 cls = PyTuple_GET_ITEM(argtup, 0);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2360 if (! PyObject_HasAttrString(cls, "__new__")) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2361 PyErr_SetString(PicklingError, "args[0] from "
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2362 "__newobj__ args has no __new__");
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2363 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2364 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2365
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2366 /* XXX How could ob be NULL? */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2367 if (ob != NULL) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2368 PyObject *ob_dot_class;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2369
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2370 ob_dot_class = PyObject_GetAttr(ob, __class___str);
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2371 if (ob_dot_class == NULL) {
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2372 if (PyErr_ExceptionMatches(
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2373 PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2374 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2375 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2376 return -1;
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2377 }
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2378 i = ob_dot_class != cls; /* true iff a problem */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2379 Py_XDECREF(ob_dot_class);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2380 if (i) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2381 PyErr_SetString(PicklingError, "args[0] from "
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2382 "__newobj__ args has the wrong class");
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2383 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2384 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2385 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2386
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2387 /* Save the class and its __new__ arguments. */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2388 if (save(self, cls, 0) < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2389 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2390
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2391 newargtup = PyTuple_New(n-1); /* argtup[1:] */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2392 if (newargtup == NULL)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2393 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2394 for (i = 1; i < n; ++i) {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2395 PyObject *temp = PyTuple_GET_ITEM(argtup, i);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2396 Py_INCREF(temp);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2397 PyTuple_SET_ITEM(newargtup, i-1, temp);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2398 }
43472
1bea6fafcc50 Fix Coverity #159.
Neal Norwitz <nnorwitz@gmail.com>
parents: 42333
diff changeset
2399 i = save(self, newargtup, 0);
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2400 Py_DECREF(newargtup);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2401 if (i < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2402 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2403
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2404 /* Add NEWOBJ opcode. */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2405 if (self->write_func(self, &newobj, 1) < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2406 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2407 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2408 else {
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2409 /* Not using NEWOBJ. */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2410 if (save(self, callable, 0) < 0 ||
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2411 save(self, argtup, 0) < 0 ||
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2412 self->write_func(self, &reduce, 1) < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2413 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2414 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2415
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2416 /* Memoize. */
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2417 /* XXX How can ob be NULL? */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2418 if (ob != NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2419 if (state && !PyDict_Check(state)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2420 if (put2(self, ob) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2421 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2422 }
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2423 else if (put(self, ob) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2424 return -1;
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2425 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2426
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2427
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2428 if (listitems && batch_list(self, listitems) < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2429 return -1;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2430
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2431 if (dictitems && batch_dict(self, dictitems) < 0)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2432 return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2433
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2434 if (state) {
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2435 if (save(self, state, 0) < 0 ||
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2436 self->write_func(self, &build, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2437 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2438 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2439
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2440 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2441 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2442
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2443 static int
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
2444 save(Picklerobject *self, PyObject *args, int pers_save)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2445 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2446 PyTypeObject *type;
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2447 PyObject *py_ob_id = 0, *__reduce__ = 0, *t = 0;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2448 int res = -1;
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2449 int tmp;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2450
47856
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
2451 if (Py_EnterRecursiveCall(" while pickling an object"))
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
2452 return -1;
24532
82c48653861b Add recursion counter for pickling. Fixes #576084.
Martin v. Löwis <martin@v.loewis.de>
parents: 24471
diff changeset
2453
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2454 if (!pers_save && self->pers_func) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2455 if ((tmp = save_pers(self, args, self->pers_func)) != 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2456 res = tmp;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2457 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2458 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2459 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2460
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2461 if (args == Py_None) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2462 res = save_none(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2463 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2464 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2465
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
2466 type = Py_TYPE(args);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2467
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2468 switch (type->tp_name[0]) {
22785
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2469 case 'b':
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2470 if (args == Py_False || args == Py_True) {
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2471 res = save_bool(self, args);
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2472 goto finally;
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2473 }
aa8d59823add Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents: 22732
diff changeset
2474 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2475 case 'i':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2476 if (type == &PyInt_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2477 res = save_int(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2478 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2479 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2480 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2481
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2482 case 'l':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2483 if (type == &PyLong_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2484 res = save_long(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2485 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2486 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2487 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2488
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2489 case 'f':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2490 if (type == &PyFloat_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2491 res = save_float(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2492 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2493 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2494 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2495
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2496 case 't':
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
2497 if (type == &PyTuple_Type && PyTuple_Size(args) == 0) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
2498 res = save_tuple(self, args);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2499 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2500 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2501 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2502
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2503 case 's':
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2504 if ((type == &PyString_Type) && (PyString_GET_SIZE(args) < 2)) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2505 res = save_string(self, args, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2506 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2507 }
47803
8b6c2856dbe5 Issue 3164. Small fix to don't repeat a comparation
Facundo Batista <facundobatista@gmail.com>
parents: 47587
diff changeset
2508 break;
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2509
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
2510 #ifdef Py_USING_UNICODE
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2511 case 'u':
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2512 if ((type == &PyUnicode_Type) && (PyString_GET_SIZE(args) < 2)) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2513 res = save_unicode(self, args, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2514 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2515 }
47803
8b6c2856dbe5 Issue 3164. Small fix to don't repeat a comparation
Facundo Batista <facundobatista@gmail.com>
parents: 47587
diff changeset
2516 break;
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
2517 #endif
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2518 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2519
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
2520 if (Py_REFCNT(args) > 1) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2521 if (!( py_ob_id = PyLong_FromVoidPtr(args)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2522 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2523
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2524 if (PyDict_GetItem(self->memo, py_ob_id)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2525 if (get(self, py_ob_id) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2526 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2527
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2528 res = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2529 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2530 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2531 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2532
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2533 switch (type->tp_name[0]) {
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2534 case 's':
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2535 if (type == &PyString_Type) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2536 res = save_string(self, args, 1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2537 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2538 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2539 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2540
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
2541 #ifdef Py_USING_UNICODE
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2542 case 'u':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2543 if (type == &PyUnicode_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2544 res = save_unicode(self, args, 1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2545 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2546 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2547 break;
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
2548 #endif
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
2549
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2550 case 't':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2551 if (type == &PyTuple_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2552 res = save_tuple(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2553 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2554 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2555 if (type == &PyType_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2556 res = save_global(self, args, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2557 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2558 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2559 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2560
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2561 case 'l':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2562 if (type == &PyList_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2563 res = save_list(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2564 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2565 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2566 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2567
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2568 case 'd':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2569 if (type == &PyDict_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2570 res = save_dict(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2571 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2572 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2573 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2574
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2575 case 'i':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2576 if (type == &PyInstance_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2577 res = save_inst(self, args);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2578 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2579 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2580 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2581
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2582 case 'c':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2583 if (type == &PyClass_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2584 res = save_global(self, args, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2585 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2586 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2587 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2588
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2589 case 'f':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2590 if (type == &PyFunction_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2591 res = save_global(self, args, NULL);
31592
c6753db9c6af made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents: 30683
diff changeset
2592 if (res && PyErr_ExceptionMatches(PickleError)) {
c6753db9c6af made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents: 30683
diff changeset
2593 /* fall back to reduce */
c6753db9c6af made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents: 30683
diff changeset
2594 PyErr_Clear();
c6753db9c6af made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents: 30683
diff changeset
2595 break;
c6753db9c6af made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents: 30683
diff changeset
2596 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2597 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2598 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2599 break;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2600
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2601 case 'b':
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2602 if (type == &PyCFunction_Type) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2603 res = save_global(self, args, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2604 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2605 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2606 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2607
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2608 if (!pers_save && self->inst_pers_func) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2609 if ((tmp = save_pers(self, args, self->inst_pers_func)) != 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2610 res = tmp;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2611 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2612 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2613 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2614
24252
5542bf0bbce2 Given the persistent id code a shot at a class before calling save_global().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24209
diff changeset
2615 if (PyType_IsSubtype(type, &PyType_Type)) {
5542bf0bbce2 Given the persistent id code a shot at a class before calling save_global().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24209
diff changeset
2616 res = save_global(self, args, NULL);
5542bf0bbce2 Given the persistent id code a shot at a class before calling save_global().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24209
diff changeset
2617 goto finally;
5542bf0bbce2 Given the persistent id code a shot at a class before calling save_global().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24209
diff changeset
2618 }
5542bf0bbce2 Given the persistent id code a shot at a class before calling save_global().
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 24209
diff changeset
2619
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2620 /* Get a reduction callable, and call it. This may come from
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
2621 * copy_reg.dispatch_table, the object's __reduce_ex__ method,
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2622 * or the object's __reduce__ method.
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2623 */
27876
8789e9822aa4 save(): Reformat tail end just for clarity.
Tim Peters <tim.peters@gmail.com>
parents: 27869
diff changeset
2624 __reduce__ = PyDict_GetItem(dispatch_table, (PyObject *)type);
8789e9822aa4 save(): Reformat tail end just for clarity.
Tim Peters <tim.peters@gmail.com>
parents: 27869
diff changeset
2625 if (__reduce__ != NULL) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2626 Py_INCREF(__reduce__);
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2627 Py_INCREF(args);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2628 ARG_TUP(self, args);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2629 if (self->arg) {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2630 t = PyObject_Call(__reduce__, self->arg, NULL);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2631 FREE_ARG_TUP(self);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2632 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2633 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2634 else {
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2635 /* Check for a __reduce_ex__ method. */
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2636 __reduce__ = PyObject_GetAttr(args, __reduce_ex___str);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2637 if (__reduce__ != NULL) {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2638 t = PyInt_FromLong(self->proto);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2639 if (t != NULL) {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2640 ARG_TUP(self, t);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2641 t = NULL;
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2642 if (self->arg) {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2643 t = PyObject_Call(__reduce__,
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2644 self->arg, NULL);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2645 FREE_ARG_TUP(self);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2646 }
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2647 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2648 }
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2649 else {
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2650 if (PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2651 PyErr_Clear();
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2652 else
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
2653 goto finally;
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2654 /* Check for a __reduce__ method. */
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2655 __reduce__ = PyObject_GetAttr(args, __reduce___str);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2656 if (__reduce__ != NULL) {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2657 t = PyObject_Call(__reduce__,
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2658 empty_tuple, NULL);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2659 }
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2660 else {
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2661 PyErr_SetObject(UnpickleableError, args);
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2662 goto finally;
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
2663 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2664 }
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2665 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2666
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2667 if (t == NULL)
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2668 goto finally;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2669
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2670 if (PyString_Check(t)) {
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2671 res = save_global(self, args, t);
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2672 goto finally;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2673 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2674
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2675 if (!PyTuple_Check(t)) {
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2676 cPickle_ErrFormat(PicklingError, "Value returned by "
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2677 "%s must be string or tuple",
27876
8789e9822aa4 save(): Reformat tail end just for clarity.
Tim Peters <tim.peters@gmail.com>
parents: 27869
diff changeset
2678 "O", __reduce__);
27899
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2679 goto finally;
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2680 }
d0f4f3cd4fe4 cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents: 27882
diff changeset
2681
49609
b3df58f76e49 Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 49148
diff changeset
2682 res = save_reduce(self, t, __reduce__, args);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2683
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2684 finally:
47856
e14739c58401 Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents: 47828
diff changeset
2685 Py_LeaveRecursiveCall();
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2686 Py_XDECREF(py_ob_id);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2687 Py_XDECREF(__reduce__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2688 Py_XDECREF(t);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2689
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2690 return res;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2691 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2692
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2693
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2694 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2695 dump(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2696 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2697 static char stop = STOP;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2698
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2699 if (self->proto >= 2) {
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2700 char bytes[2];
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2701
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2702 bytes[0] = PROTO;
27593
57bdf4bac435 dump(): Added asserts that self->proto is sane.
Tim Peters <tim.peters@gmail.com>
parents: 27592
diff changeset
2703 assert(self->proto >= 0 && self->proto < 256);
57bdf4bac435 dump(): Added asserts that self->proto is sane.
Tim Peters <tim.peters@gmail.com>
parents: 27592
diff changeset
2704 bytes[1] = (char)self->proto;
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2705 if (self->write_func(self, bytes, 2) < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2706 return -1;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2707 }
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2708
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2709 if (save(self, args, 0) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2710 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2711
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2712 if (self->write_func(self, &stop, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2713 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2714
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
2715 if (self->write_func(self, NULL, 0) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2716 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2717
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2718 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2719 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2720
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2721 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2722 Pickle_clear_memo(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2723 {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2724 if (self->memo)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2725 PyDict_Clear(self->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2726 Py_INCREF(Py_None);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2727 return Py_None;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2728 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2729
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2730 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2731 Pickle_getvalue(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2732 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2733 int l, i, rsize, ssize, clear=1, lm;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2734 long ik;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2735 PyObject *k, *r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2736 char *s, *p, *have_get;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2737 Pdata *data;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2738
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2739 /* Can be called by Python code or C code */
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2740 if (args && !PyArg_ParseTuple(args, "|i:getvalue", &clear))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2741 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2742
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2743 /* Check to make sure we are based on a list */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2744 if (! Pdata_Check(self->file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2745 PyErr_SetString(PicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2746 "Attempt to getvalue() a non-list-based pickler");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2747 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2748 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2749
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2750 /* flush write buffer */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2751 if (write_other(self, NULL, 0) < 0) return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2752
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2753 data=(Pdata*)self->file;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2754 l=data->length;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2755
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2756 /* set up an array to hold get/put status */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2757 lm = PyDict_Size(self->memo);
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2758 if (lm < 0) return NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2759 lm++;
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2760 have_get = malloc(lm);
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2761 if (have_get == NULL) return PyErr_NoMemory();
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2762 memset(have_get, 0, lm);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2763
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2764 /* Scan for gets. */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2765 for (rsize = 0, i = l; --i >= 0; ) {
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2766 k = data->data[i];
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2767
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2768 if (PyString_Check(k))
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2769 rsize += PyString_GET_SIZE(k);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2770
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2771 else if (PyInt_Check(k)) { /* put */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2772 ik = PyInt_AS_LONG((PyIntObject*)k);
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2773 if (ik >= lm || ik == 0) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2774 PyErr_SetString(PicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2775 "Invalid get data");
39143
0e0a97ced8e9 Fix memory leaks spotted by Klocwork #37.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39135
diff changeset
2776 goto err;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2777 }
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2778 if (have_get[ik]) /* with matching get */
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2779 rsize += ik < 256 ? 2 : 5;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2780 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2781
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2782 else if (! (PyTuple_Check(k) &&
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2783 PyTuple_GET_SIZE(k) == 2 &&
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2784 PyInt_Check((k = PyTuple_GET_ITEM(k, 0))))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2785 ) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2786 PyErr_SetString(PicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2787 "Unexpected data in internal list");
39143
0e0a97ced8e9 Fix memory leaks spotted by Klocwork #37.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39135
diff changeset
2788 goto err;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2789 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2790
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2791 else { /* put */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2792 ik = PyInt_AS_LONG((PyIntObject *)k);
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2793 if (ik >= lm || ik == 0) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2794 PyErr_SetString(PicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2795 "Invalid get data");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2796 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2797 }
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2798 have_get[ik] = 1;
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2799 rsize += ik < 256 ? 2 : 5;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2800 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2801 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2802
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2803 /* Now generate the result */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2804 r = PyString_FromStringAndSize(NULL, rsize);
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2805 if (r == NULL) goto err;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2806 s = PyString_AS_STRING((PyStringObject *)r);
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2807
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2808 for (i = 0; i < l; i++) {
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2809 k = data->data[i];
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2810
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2811 if (PyString_Check(k)) {
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2812 ssize = PyString_GET_SIZE(k);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2813 if (ssize) {
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
2814 p=PyString_AS_STRING((PyStringObject *)k);
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2815 while (--ssize >= 0)
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2816 *s++ = *p++;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2817 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2818 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2819
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2820 else if (PyTuple_Check(k)) { /* get */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2821 ik = PyInt_AS_LONG((PyIntObject *)
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2822 PyTuple_GET_ITEM(k, 0));
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2823 if (ik < 256) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2824 *s++ = BINGET;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2825 *s++ = (int)(ik & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2826 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2827 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2828 *s++ = LONG_BINGET;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2829 *s++ = (int)(ik & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2830 *s++ = (int)((ik >> 8) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2831 *s++ = (int)((ik >> 16) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2832 *s++ = (int)((ik >> 24) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2833 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2834 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2835
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2836 else { /* put */
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2837 ik = PyInt_AS_LONG((PyIntObject*)k);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2838
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2839 if (have_get[ik]) { /* with matching get */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2840 if (ik < 256) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2841 *s++ = BINPUT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2842 *s++ = (int)(ik & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2843 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2844 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2845 *s++ = LONG_BINPUT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2846 *s++ = (int)(ik & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2847 *s++ = (int)((ik >> 8) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2848 *s++ = (int)((ik >> 16) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2849 *s++ = (int)((ik >> 24) & 0xff);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2850 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2851 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2852 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2853 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2854
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2855 if (clear) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2856 PyDict_Clear(self->memo);
27600
313e944a2c88 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents: 27599
diff changeset
2857 Pdata_clear(data, 0);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2858 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2859
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2860 free(have_get);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2861 return r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2862 err:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2863 free(have_get);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2864 return NULL;
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2865 }
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2866
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
2867 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2868 Pickler_dump(Picklerobject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2869 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2870 PyObject *ob;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2871 int get=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2872
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2873 if (!( PyArg_ParseTuple(args, "O|i:dump", &ob, &get)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2874 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2875
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2876 if (dump(self, ob) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2877 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2878
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2879 if (get) return Pickle_getvalue(self, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2880
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2881 /* XXX Why does dump() return self? */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2882 Py_INCREF(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2883 return (PyObject*)self;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2884 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2885
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
2886
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2887 static struct PyMethodDef Pickler_methods[] =
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2888 {
22706
14ebd7610902 Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents: 22464
diff changeset
2889 {"dump", (PyCFunction)Pickler_dump, METH_VARARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
2890 PyDoc_STR("dump(object) -- "
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
2891 "Write an object in pickle format to the object's pickle stream")},
23332
c1d1ae15de92 Pickler_clear_memo(): convert to METH_NOARGS.
Fred Drake <fdrake@acm.org>
parents: 23295
diff changeset
2892 {"clear_memo", (PyCFunction)Pickle_clear_memo, METH_NOARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
2893 PyDoc_STR("clear_memo() -- Clear the picklers memo")},
22706
14ebd7610902 Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents: 22464
diff changeset
2894 {"getvalue", (PyCFunction)Pickle_getvalue, METH_VARARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
2895 PyDoc_STR("getvalue() -- Finish picking a list-based pickle")},
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2896 {NULL, NULL} /* sentinel */
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2897 };
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2898
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2899
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
2900 static Picklerobject *
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2901 newPicklerobject(PyObject *file, int proto)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2902 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2903 Picklerobject *self;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2904
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2905 if (proto < 0)
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
2906 proto = HIGHEST_PROTOCOL;
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
2907 if (proto > HIGHEST_PROTOCOL) {
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2908 PyErr_Format(PyExc_ValueError, "pickle protocol %d asked for; "
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2909 "the highest available protocol is %d",
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
2910 proto, HIGHEST_PROTOCOL);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2911 return NULL;
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2912 }
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2913
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
2914 self = PyObject_GC_New(Picklerobject, &Picklertype);
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2915 if (self == NULL)
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2916 return NULL;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2917 self->proto = proto;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2918 self->bin = proto > 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2919 self->fp = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2920 self->write = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2921 self->memo = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2922 self->arg = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2923 self->pers_func = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2924 self->inst_pers_func = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2925 self->write_buf = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2926 self->fast = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2927 self->fast_container = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2928 self->fast_memo = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2929 self->buf_size = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2930 self->dispatch_table = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2931
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2932 self->file = NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2933 if (file)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2934 Py_INCREF(file);
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2935 else {
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2936 file = Pdata_New();
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2937 if (file == NULL)
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2938 goto err;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2939 }
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2940 self->file = file;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2941
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2942 if (!( self->memo = PyDict_New()))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2943 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2944
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2945 if (PyFile_Check(file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2946 self->fp = PyFile_AsFile(file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2947 if (self->fp == NULL) {
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2948 PyErr_SetString(PyExc_ValueError,
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2949 "I/O operation on closed file");
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2950 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2951 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2952 self->write_func = write_file;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2953 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2954 else if (PycStringIO_OutputCheck(file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2955 self->write_func = write_cStringIO;
10496
ba1a27d73cdb Protection against picling to/from closed (real) file.
Guido van Rossum <guido@python.org>
parents: 10126
diff changeset
2956 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2957 else if (file == Py_None) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2958 self->write_func = write_none;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2959 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2960 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2961 self->write_func = write_other;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2962
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2963 if (! Pdata_Check(file)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2964 self->write = PyObject_GetAttr(file, write_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2965 if (!self->write) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2966 PyErr_Clear();
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
2967 PyErr_SetString(PyExc_TypeError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2968 "argument must have 'write' "
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2969 "attribute");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2970 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2971 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2972 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2973
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2974 self->write_buf = (char *)PyMem_Malloc(WRITE_BUF_SIZE);
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
2975 if (self->write_buf == NULL) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2976 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2977 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2978 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2979 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2980
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2981 if (PyEval_GetRestricted()) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2982 /* Restricted execution, get private tables */
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
2983 PyObject *m = PyImport_Import(copyreg_str);
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2984
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2985 if (m == NULL)
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2986 goto err;
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2987 self->dispatch_table = PyObject_GetAttr(m, dispatch_table_str);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2988 Py_DECREF(m);
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2989 if (self->dispatch_table == NULL)
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2990 goto err;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2991 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2992 else {
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
2993 self->dispatch_table = dispatch_table;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2994 Py_INCREF(dispatch_table);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2995 }
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
2996 PyObject_GC_Track(self);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2997
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2998 return self;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
2999
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3000 err:
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3001 Py_DECREF(self);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3002 return NULL;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3003 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3004
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3005
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3006 static PyObject *
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
3007 get_Pickler(PyObject *self, PyObject *args, PyObject *kwds)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3008 {
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
3009 static char *kwlist[] = {"file", "protocol", NULL};
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3010 PyObject *file = NULL;
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3011 int proto = 0;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3012
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3013 /* XXX
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
3014 * The documented signature is Pickler(file, protocol=0), but this
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3015 * accepts Pickler() and Pickler(integer) too. The meaning then
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3016 * is clear as mud, undocumented, and not supported by pickle.py.
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3017 * I'm told Zope uses this, but I haven't traced into this code
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3018 * far enough to figure out what it means.
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3019 */
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3020 if (!PyArg_ParseTuple(args, "|i:Pickler", &proto)) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3021 PyErr_Clear();
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3022 proto = 0;
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
3023 if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|i:Pickler",
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
3024 kwlist, &file, &proto))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3025 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3026 }
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3027 return (PyObject *)newPicklerobject(file, proto);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3028 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3029
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3030
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3031 static void
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3032 Pickler_dealloc(Picklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3033 {
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3034 PyObject_GC_UnTrack(self);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3035 Py_XDECREF(self->write);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3036 Py_XDECREF(self->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3037 Py_XDECREF(self->fast_memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3038 Py_XDECREF(self->arg);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3039 Py_XDECREF(self->file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3040 Py_XDECREF(self->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3041 Py_XDECREF(self->inst_pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3042 Py_XDECREF(self->dispatch_table);
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
3043 PyMem_Free(self->write_buf);
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
3044 Py_TYPE(self)->tp_free((PyObject *)self);
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3045 }
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3046
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3047 static int
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3048 Pickler_traverse(Picklerobject *self, visitproc visit, void *arg)
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3049 {
37756
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3050 Py_VISIT(self->write);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3051 Py_VISIT(self->memo);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3052 Py_VISIT(self->fast_memo);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3053 Py_VISIT(self->arg);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3054 Py_VISIT(self->file);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3055 Py_VISIT(self->pers_func);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3056 Py_VISIT(self->inst_pers_func);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
3057 Py_VISIT(self->dispatch_table);
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3058 return 0;
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3059 }
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3060
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3061 static int
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3062 Pickler_clear(Picklerobject *self)
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3063 {
37748
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3064 Py_CLEAR(self->write);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3065 Py_CLEAR(self->memo);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3066 Py_CLEAR(self->fast_memo);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3067 Py_CLEAR(self->arg);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3068 Py_CLEAR(self->file);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3069 Py_CLEAR(self->pers_func);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3070 Py_CLEAR(self->inst_pers_func);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
3071 Py_CLEAR(self->dispatch_table);
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3072 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3073 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3074
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3075 static PyObject *
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3076 Pickler_get_pers_func(Picklerobject *p)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3077 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3078 if (p->pers_func == NULL)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3079 PyErr_SetString(PyExc_AttributeError, "persistent_id");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3080 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3081 Py_INCREF(p->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3082 return p->pers_func;
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3083 }
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3084
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3085 static int
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3086 Pickler_set_pers_func(Picklerobject *p, PyObject *v)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3087 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3088 if (v == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3089 PyErr_SetString(PyExc_TypeError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3090 "attribute deletion is not supported");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3091 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3092 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3093 Py_XDECREF(p->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3094 Py_INCREF(v);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3095 p->pers_func = v;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3096 return 0;
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3097 }
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3098
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3099 static int
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3100 Pickler_set_inst_pers_func(Picklerobject *p, PyObject *v)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3101 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3102 if (v == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3103 PyErr_SetString(PyExc_TypeError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3104 "attribute deletion is not supported");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3105 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3106 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3107 Py_XDECREF(p->inst_pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3108 Py_INCREF(v);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3109 p->inst_pers_func = v;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3110 return 0;
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3111 }
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3112
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3113 static PyObject *
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3114 Pickler_get_memo(Picklerobject *p)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3115 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3116 if (p->memo == NULL)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3117 PyErr_SetString(PyExc_AttributeError, "memo");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3118 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3119 Py_INCREF(p->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3120 return p->memo;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3121 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3122
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3123 static int
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3124 Pickler_set_memo(Picklerobject *p, PyObject *v)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3125 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3126 if (v == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3127 PyErr_SetString(PyExc_TypeError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3128 "attribute deletion is not supported");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3129 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3130 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3131 if (!PyDict_Check(v)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3132 PyErr_SetString(PyExc_TypeError, "memo must be a dictionary");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3133 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3134 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3135 Py_XDECREF(p->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3136 Py_INCREF(v);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3137 p->memo = v;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3138 return 0;
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3139 }
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3140
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3141 static PyObject *
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3142 Pickler_get_error(Picklerobject *p)
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3143 {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3144 /* why is this an attribute on the Pickler? */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3145 Py_INCREF(PicklingError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3146 return PicklingError;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3147 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3148
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3149 static PyMemberDef Pickler_members[] = {
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3150 {"binary", T_INT, offsetof(Picklerobject, bin)},
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3151 {"fast", T_INT, offsetof(Picklerobject, fast)},
20458
a96235b2ca62 Must terminate the Pickler_members[] and Pickler_getsets with NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20443
diff changeset
3152 {NULL}
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3153 };
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3154
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3155 static PyGetSetDef Pickler_getsets[] = {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3156 {"persistent_id", (getter)Pickler_get_pers_func,
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3157 (setter)Pickler_set_pers_func},
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3158 {"inst_persistent_id", NULL, (setter)Pickler_set_inst_pers_func},
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3159 {"memo", (getter)Pickler_get_memo, (setter)Pickler_set_memo},
20458
a96235b2ca62 Must terminate the Pickler_members[] and Pickler_getsets with NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20443
diff changeset
3160 {"PicklingError", (getter)Pickler_get_error, NULL},
a96235b2ca62 Must terminate the Pickler_members[] and Pickler_getsets with NULL.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 20443
diff changeset
3161 {NULL}
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3162 };
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3163
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
3164 PyDoc_STRVAR(Picklertype__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
3165 "Objects that know how to pickle objects\n");
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3166
6774
0ef23f513a65 Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 6740
diff changeset
3167 static PyTypeObject Picklertype = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 41525
diff changeset
3168 PyVarObject_HEAD_INIT(NULL, 0)
21313
91dd223829c6 Patch supplied by Burton Radons for his own SF bug #487390: Modifying
Guido van Rossum <guido@python.org>
parents: 21093
diff changeset
3169 "cPickle.Pickler", /*tp_name*/
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3170 sizeof(Picklerobject), /*tp_basicsize*/
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3171 0,
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3172 (destructor)Pickler_dealloc, /* tp_dealloc */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3173 0, /* tp_print */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3174 0, /* tp_getattr */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3175 0, /* tp_setattr */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3176 0, /* tp_compare */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3177 0, /* tp_repr */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3178 0, /* tp_as_number */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3179 0, /* tp_as_sequence */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3180 0, /* tp_as_mapping */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3181 0, /* tp_hash */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3182 0, /* tp_call */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3183 0, /* tp_str */
27104
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 26790
diff changeset
3184 PyObject_GenericGetAttr, /* tp_getattro */
2443c557cbc3 Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents: 26790
diff changeset
3185 PyObject_GenericSetAttr, /* tp_setattro */
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3186 0, /* tp_as_buffer */
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3187 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3188 Picklertype__doc__, /* tp_doc */
28567
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3189 (traverseproc)Pickler_traverse, /* tp_traverse */
bc8923fdd83b Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28335
diff changeset
3190 (inquiry)Pickler_clear, /* tp_clear */
20385
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3191 0, /* tp_richcompare */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3192 0, /* tp_weaklistoffset */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3193 0, /* tp_iter */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3194 0, /* tp_iternext */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3195 Pickler_methods, /* tp_methods */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3196 Pickler_members, /* tp_members */
be58eee69a94 Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 19543
diff changeset
3197 Pickler_getsets, /* tp_getset */
6774
0ef23f513a65 Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 6740
diff changeset
3198 };
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3199
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3200 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3201 find_class(PyObject *py_module_name, PyObject *py_global_name, PyObject *fc)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3202 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3203 PyObject *global = 0, *module;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3204
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3205 if (fc) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3206 if (fc==Py_None) {
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3207 PyErr_SetString(UnpicklingError, "Global and instance "
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
3208 "pickles are not supported.");
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3209 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3210 }
38314
1fdf29a88f0e Replace PyObject_CallFunction calls with only object args
Georg Brandl <georg@python.org>
parents: 38055
diff changeset
3211 return PyObject_CallFunctionObjArgs(fc, py_module_name,
1fdf29a88f0e Replace PyObject_CallFunction calls with only object args
Georg Brandl <georg@python.org>
parents: 38055
diff changeset
3212 py_global_name, NULL);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3213 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3214
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3215 module = PySys_GetObject("modules");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3216 if (module == NULL)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3217 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3218
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3219 module = PyDict_GetItem(module, py_module_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3220 if (module == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3221 module = PyImport_Import(py_module_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3222 if (!module)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3223 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3224 global = PyObject_GetAttr(module, py_global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3225 Py_DECREF(module);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3226 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3227 else
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3228 global = PyObject_GetAttr(module, py_global_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3229 return global;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3230 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3231
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3232 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3233 marker(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3234 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3235 if (self->num_marks < 1) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3236 PyErr_SetString(UnpicklingError, "could not find MARK");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3237 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3238 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3239
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3240 return self->marks[--self->num_marks];
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3241 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3242
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3243
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3244 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3245 load_none(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3246 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3247 PDATA_APPEND(self->stack, Py_None, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3248 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3249 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3250
10097
f5f1b5e9814a Jim Fulton: this fixes seg faults with bad pickles like "c".
Guido van Rossum <guido@python.org>
parents: 9948
diff changeset
3251 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3252 bad_readline(void)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3253 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3254 PyErr_SetString(UnpicklingError, "pickle data was truncated");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3255 return -1;
10097
f5f1b5e9814a Jim Fulton: this fixes seg faults with bad pickles like "c".
Guido van Rossum <guido@python.org>
parents: 9948
diff changeset
3256 }
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3257
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3258 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3259 load_int(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3260 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3261 PyObject *py_int = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3262 char *endptr, *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3263 int len, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3264 long l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3265
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3266 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3267 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3268 if (!( s=pystrndup(s,len))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3269
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3270 errno = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3271 l = strtol(s, &endptr, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3272
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3273 if (errno || (*endptr != '\n') || (endptr[1] != '\0')) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3274 /* Hm, maybe we've got something long. Let's try reading
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3275 it as a Python long object. */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3276 errno = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3277 py_int = PyLong_FromString(s, NULL, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3278 if (py_int == NULL) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3279 PyErr_SetString(PyExc_ValueError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3280 "could not convert string to int");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3281 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3282 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3283 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3284 else {
22851
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3285 if (len == 3 && (l == 0 || l == 1)) {
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3286 if (!( py_int = PyBool_FromLong(l))) goto finally;
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3287 }
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3288 else {
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3289 if (!( py_int = PyInt_FromLong(l))) goto finally;
ed03806d88cd Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents: 22805
diff changeset
3290 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3291 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3292
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3293 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3294 PDATA_PUSH(self->stack, py_int, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3295 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3296
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3297 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3298 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3299
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3300 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3301 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3302
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3303 static int
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3304 load_bool(Unpicklerobject *self, PyObject *boolean)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3305 {
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3306 assert(boolean == Py_True || boolean == Py_False);
27643
934a2b497d1d PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
Tim Peters <tim.peters@gmail.com>
parents: 27615
diff changeset
3307 PDATA_APPEND(self->stack, boolean, -1);
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3308 return 0;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3309 }
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
3310
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3311 /* s contains x bytes of a little-endian integer. Return its value as a
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3312 * C int. Obscure: when x is 1 or 2, this is an unsigned little-endian
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3313 * int, but when x is 4 it's a signed one. This is an historical source
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3314 * of x-platform bugs.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3315 */
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3316 static long
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3317 calc_binint(char *s, int x)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3318 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3319 unsigned char c;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3320 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3321 long l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3322
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3323 for (i = 0, l = 0L; i < x; i++) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3324 c = (unsigned char)s[i];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3325 l |= (long)c << (i * 8);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3326 }
17361
ca565e3d3cc5 Critical fix: if cPickle on a sizeof(long)==8 box is used to read a
Tim Peters <tim.peters@gmail.com>
parents: 17152
diff changeset
3327 #if SIZEOF_LONG > 4
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3328 /* Unlike BININT1 and BININT2, BININT (more accurately BININT4)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3329 * is signed, so on a box with longs bigger than 4 bytes we need
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3330 * to extend a BININT's sign bit to the full width.
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3331 */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3332 if (x == 4 && l & (1L << 31))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3333 l |= (~0L) << 32;
17361
ca565e3d3cc5 Critical fix: if cPickle on a sizeof(long)==8 box is used to read a
Tim Peters <tim.peters@gmail.com>
parents: 17152
diff changeset
3334 #endif
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3335 return l;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3336 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3337
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3338
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3339 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3340 load_binintx(Unpicklerobject *self, char *s, int x)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3341 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3342 PyObject *py_int = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3343 long l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3344
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3345 l = calc_binint(s, x);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3346
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3347 if (!( py_int = PyInt_FromLong(l)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3348 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3349
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3350 PDATA_PUSH(self->stack, py_int, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3351 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3352 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3353
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3354
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3355 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3356 load_binint(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3357 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3358 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3359
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3360 if (self->read_func(self, &s, 4) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3361 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3362
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3363 return load_binintx(self, s, 4);
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3364 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3365
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3366
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3367 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3368 load_binint1(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3369 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3370 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3371
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3372 if (self->read_func(self, &s, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3373 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3374
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3375 return load_binintx(self, s, 1);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3376 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3377
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3378
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3379 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3380 load_binint2(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3381 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3382 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3383
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3384 if (self->read_func(self, &s, 2) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3385 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3386
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3387 return load_binintx(self, s, 2);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3388 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3389
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3390 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3391 load_long(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3392 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3393 PyObject *l = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3394 char *end, *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3395 int len, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3396
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3397 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3398 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3399 if (!( s=pystrndup(s,len))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3400
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3401 if (!( l = PyLong_FromString(s, &end, 0)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3402 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3403
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3404 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3405 PDATA_PUSH(self->stack, l, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3406 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3407
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3408 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3409 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3410
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3411 return res;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3412 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3413
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3414 /* 'size' bytes contain the # of bytes of little-endian 256's-complement
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3415 * data following.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3416 */
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3417 static int
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3418 load_counted_long(Unpicklerobject *self, int size)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3419 {
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
3420 Py_ssize_t i;
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3421 char *nbytes;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3422 unsigned char *pdata;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3423 PyObject *along;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3424
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3425 assert(size == 1 || size == 4);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3426 i = self->read_func(self, &nbytes, size);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3427 if (i < 0) return -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3428
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3429 size = calc_binint(nbytes, size);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3430 if (size < 0) {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3431 /* Corrupt or hostile pickle -- we never write one like
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3432 * this.
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3433 */
27656
ba3eaff49b7a load_counted_long(): Changed a ValueError to an UnpicklingError, just
Tim Peters <tim.peters@gmail.com>
parents: 27643
diff changeset
3434 PyErr_SetString(UnpicklingError, "LONG pickle has negative "
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3435 "byte count");
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3436 return -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3437 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3438
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3439 if (size == 0)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3440 along = PyLong_FromLong(0L);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3441 else {
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3442 /* Read the raw little-endian bytes & convert. */
27594
e5d181120303 Fix compiler warning
Neal Norwitz <nnorwitz@gmail.com>
parents: 27593
diff changeset
3443 i = self->read_func(self, (char **)&pdata, size);
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3444 if (i < 0) return -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3445 along = _PyLong_FromByteArray(pdata, (size_t)size,
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3446 1 /* little endian */, 1 /* signed */);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3447 }
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3448 if (along == NULL)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3449 return -1;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3450 PDATA_PUSH(self->stack, along, -1);
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3451 return 0;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
3452 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3453
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3454 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3455 load_float(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3456 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3457 PyObject *py_float = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3458 char *endptr, *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3459 int len, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3460 double d;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3461
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3462 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3463 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3464 if (!( s=pystrndup(s,len))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3465
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3466 errno = 0;
32305
13656d58d450 Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents: 31592
diff changeset
3467 d = PyOS_ascii_strtod(s, &endptr);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3468
51020
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
3469 if ((errno == ERANGE && !(fabs(d) <= 1.0)) ||
0139648526d9 Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents: 50522
diff changeset
3470 (endptr[0] != '\n') || (endptr[1] != '\0')) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3471 PyErr_SetString(PyExc_ValueError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3472 "could not convert string to float");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3473 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3474 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3475
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3476 if (!( py_float = PyFloat_FromDouble(d)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3477 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3478
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3479 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3480 PDATA_PUSH(self->stack, py_float, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3481 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3482
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3483 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3484 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3485
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3486 return res;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3487 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3488
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3489 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3490 load_binfloat(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3491 {
28335
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3492 PyObject *py_float;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3493 double x;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3494 char *p;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3495
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3496 if (self->read_func(self, &p, 8) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3497 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3498
28335
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3499 x = _PyFloat_Unpack8((unsigned char *)p, 0);
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3500 if (x == -1.0 && PyErr_Occurred())
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3501 return -1;
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3502
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3503 py_float = PyFloat_FromDouble(x);
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3504 if (py_float == NULL)
70003b0cb837 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents: 28334
diff changeset
3505 return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3506
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3507 PDATA_PUSH(self->stack, py_float, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3508 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3509 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3510
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3511 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3512 load_string(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3513 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3514 PyObject *str = 0;
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3515 int len, res = -1;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3516 char *s, *p;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3517
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3518 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3519 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3520 if (!( s=pystrndup(s,len))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3521
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3522
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3523 /* Strip outermost quotes */
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3524 while (s[len-1] <= ' ')
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3525 len--;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3526 if(s[0]=='"' && s[len-1]=='"'){
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3527 s[len-1] = '\0';
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3528 p = s + 1 ;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3529 len -= 2;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3530 } else if(s[0]=='\'' && s[len-1]=='\''){
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3531 s[len-1] = '\0';
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3532 p = s + 1 ;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3533 len -= 2;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3534 } else
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3535 goto insecure;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3536 /********************************************/
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3537
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3538 str = PyString_DecodeEscape(p, len, NULL, 0, NULL);
39348
7d6b97158180 Prevent memory leak on error.
Neal Norwitz <nnorwitz@gmail.com>
parents: 39143
diff changeset
3539 free(s);
24808
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3540 if (str) {
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3541 PDATA_PUSH(self->stack, str, -1);
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3542 res = 0;
ab63af3ec349 Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 24796
diff changeset
3543 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3544 return res;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3545
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3546 insecure:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3547 free(s);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3548 PyErr_SetString(PyExc_ValueError,"insecure string pickle");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3549 return -1;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3550 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3551
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3552
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3553 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3554 load_binstring(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3555 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3556 PyObject *py_string = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3557 long l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3558 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3559
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3560 if (self->read_func(self, &s, 4) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3561
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3562 l = calc_binint(s, 4);
47587
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3563 if (l < 0) {
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3564 /* Corrupt or hostile pickle -- we never write one like
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3565 * this.
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3566 */
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3567 PyErr_SetString(UnpicklingError,
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3568 "BINSTRING pickle has negative byte count");
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3569 return -1;
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3570 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3571
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3572 if (self->read_func(self, &s, l) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3573 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3574
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3575 if (!( py_string = PyString_FromStringAndSize(s, l)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3576 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3577
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3578 PDATA_PUSH(self->stack, py_string, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3579 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3580 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3581
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3582
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3583 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3584 load_short_binstring(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3585 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3586 PyObject *py_string = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3587 unsigned char l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3588 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3589
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3590 if (self->read_func(self, &s, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3591 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3592
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3593 l = (unsigned char)s[0];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3594
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3595 if (self->read_func(self, &s, l) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3596
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3597 if (!( py_string = PyString_FromStringAndSize(s, l))) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3598
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3599 PDATA_PUSH(self->stack, py_string, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3600 return 0;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3601 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3602
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3603
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3604 #ifdef Py_USING_UNICODE
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3605 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3606 load_unicode(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3607 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3608 PyObject *str = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3609 int len, res = -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3610 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3611
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3612 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3613 if (len < 1) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3614
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3615 if (!( str = PyUnicode_DecodeRawUnicodeEscape(s, len - 1, NULL)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3616 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3617
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3618 PDATA_PUSH(self->stack, str, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3619 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3620
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3621 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3622 return res;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3623 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3624 #endif
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3625
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3626
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3627 #ifdef Py_USING_UNICODE
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
3628 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3629 load_binunicode(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3630 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3631 PyObject *unicode;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3632 long l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3633 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3634
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3635 if (self->read_func(self, &s, 4) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3636
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3637 l = calc_binint(s, 4);
47587
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3638 if (l < 0) {
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3639 /* Corrupt or hostile pickle -- we never write one like
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3640 * this.
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3641 */
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3642 PyErr_SetString(UnpicklingError,
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3643 "BINUNICODE pickle has negative byte count");
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3644 return -1;
1c964ed35ef9 Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47527
diff changeset
3645 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3646
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3647 if (self->read_func(self, &s, l) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3648 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3649
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3650 if (!( unicode = PyUnicode_DecodeUTF8(s, l, NULL)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3651 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3652
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3653 PDATA_PUSH(self->stack, unicode, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3654 return 0;
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
3655 }
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
3656 #endif
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
3657
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
3658
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
3659 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3660 load_tuple(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3661 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3662 PyObject *tup;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3663 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3664
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3665 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3666 if (!( tup=Pdata_popTuple(self->stack, i))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3667 PDATA_PUSH(self->stack, tup, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3668 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3669 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3670
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3671 static int
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3672 load_counted_tuple(Unpicklerobject *self, int len)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3673 {
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3674 PyObject *tup = PyTuple_New(len);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3675
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3676 if (tup == NULL)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3677 return -1;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3678
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3679 while (--len >= 0) {
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3680 PyObject *element;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3681
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3682 PDATA_POP(self->stack, element);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3683 if (element == NULL)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3684 return -1;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3685 PyTuple_SET_ITEM(tup, len, element);
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
3686 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3687 PDATA_PUSH(self->stack, tup, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3688 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3689 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3690
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3691 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3692 load_empty_list(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3693 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3694 PyObject *list;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3695
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3696 if (!( list=PyList_New(0))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3697 PDATA_PUSH(self->stack, list, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3698 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3699 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3700
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3701 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3702 load_empty_dict(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3703 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3704 PyObject *dict;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3705
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3706 if (!( dict=PyDict_New())) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3707 PDATA_PUSH(self->stack, dict, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3708 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3709 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3710
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3711
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3712 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3713 load_list(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3714 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3715 PyObject *list = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3716 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3717
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3718 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3719 if (!( list=Pdata_popList(self->stack, i))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3720 PDATA_PUSH(self->stack, list, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3721 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3722 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3723
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3724 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3725 load_dict(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3726 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3727 PyObject *dict, *key, *value;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3728 int i, j, k;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3729
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3730 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3731 j=self->stack->length;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3733 if (!( dict = PyDict_New())) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3734
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3735 for (k = i+1; k < j; k += 2) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3736 key =self->stack->data[k-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3737 value=self->stack->data[k ];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3738 if (PyDict_SetItem(dict, key, value) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3739 Py_DECREF(dict);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3740 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3741 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3742 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3743 Pdata_clear(self->stack, i);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3744 PDATA_PUSH(self->stack, dict, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3745 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3746 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3747
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3748 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3749 Instance_New(PyObject *cls, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3750 {
27573
674f3eecffc5 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents: 27566
diff changeset
3751 PyObject *r = 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3752
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3753 if (PyClass_Check(cls)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3754 int l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3755
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3756 if ((l=PyObject_Size(args)) < 0) goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3757 if (!( l )) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3758 PyObject *__getinitargs__;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3759
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3760 __getinitargs__ = PyObject_GetAttr(cls,
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
3761 __getinitargs___str);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3762 if (!__getinitargs__) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3763 /* We have a class with no __getinitargs__,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3764 so bypass usual construction */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3765 PyObject *inst;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3766
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3767 PyErr_Clear();
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3768 if (!( inst=PyInstance_NewRaw(cls, NULL)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3769 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3770 return inst;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3771 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3772 Py_DECREF(__getinitargs__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3773 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3774
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3775 if ((r=PyInstance_New(cls, args, NULL))) return r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3776 else goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3777 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3778
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3779 if ((r=PyObject_CallObject(cls, args))) return r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3780
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3781 err:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3782 {
38949
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3783 PyObject *tp, *v, *tb, *tmp_value;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3784
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3785 PyErr_Fetch(&tp, &v, &tb);
38949
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3786 tmp_value = v;
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3787 /* NULL occurs when there was a KeyboardInterrupt */
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3788 if (tmp_value == NULL)
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3789 tmp_value = Py_None;
56bf56f5c821 Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents: 38489
diff changeset
3790 if ((r = PyTuple_Pack(3, tmp_value, cls, args))) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3791 Py_XDECREF(v);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3792 v=r;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3793 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3794 PyErr_Restore(tp,v,tb);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3795 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3796 return NULL;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
3797 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
3798
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3799
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3800 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3801 load_obj(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3802 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3803 PyObject *class, *tup, *obj=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3804 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3805
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3806 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3807 if (!( tup=Pdata_popTuple(self->stack, i+1))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3808 PDATA_POP(self->stack, class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3809 if (class) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3810 obj = Instance_New(class, tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3811 Py_DECREF(class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3812 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3813 Py_DECREF(tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3814
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3815 if (! obj) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3816 PDATA_PUSH(self->stack, obj, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3817 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3818 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3819
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3820
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3821 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3822 load_inst(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3823 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3824 PyObject *tup, *class=0, *obj=0, *module_name, *class_name;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3825 int i, len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3826 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3827
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3828 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3829
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3830 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3831 if (len < 2) return bad_readline();
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3832 module_name = PyString_FromStringAndSize(s, len - 1);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3833 if (!module_name) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3834
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3835 if ((len = self->readline_func(self, &s)) >= 0) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3836 if (len < 2) return bad_readline();
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3837 if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3838 class = find_class(module_name, class_name,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3839 self->find_class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3840 Py_DECREF(class_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3841 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3842 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3843 Py_DECREF(module_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3844
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3845 if (! class) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3846
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3847 if ((tup=Pdata_popTuple(self->stack, i))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3848 obj = Instance_New(class, tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3849 Py_DECREF(tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3850 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3851 Py_DECREF(class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3852
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3853 if (! obj) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3854
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3855 PDATA_PUSH(self->stack, obj, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3856 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3857 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3858
27869
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3859 static int
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3860 load_newobj(Unpicklerobject *self)
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3861 {
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3862 PyObject *args = NULL;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3863 PyObject *clsraw = NULL;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3864 PyTypeObject *cls; /* clsraw cast to its true type */
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3865 PyObject *obj;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3866
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3867 /* Stack is ... cls argtuple, and we want to call
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3868 * cls.__new__(cls, *argtuple).
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3869 */
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3870 PDATA_POP(self->stack, args);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3871 if (args == NULL) goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3872 if (! PyTuple_Check(args)) {
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3873 PyErr_SetString(UnpicklingError, "NEWOBJ expected an arg "
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3874 "tuple.");
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3875 goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3876 }
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3877
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3878 PDATA_POP(self->stack, clsraw);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3879 cls = (PyTypeObject *)clsraw;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3880 if (cls == NULL) goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3881 if (! PyType_Check(cls)) {
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3882 PyErr_SetString(UnpicklingError, "NEWOBJ class argument "
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3883 "isn't a type object");
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3884 goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3885 }
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3886 if (cls->tp_new == NULL) {
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3887 PyErr_SetString(UnpicklingError, "NEWOBJ class argument "
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3888 "has NULL tp_new");
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3889 goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3890 }
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3891
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3892 /* Call __new__. */
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3893 obj = cls->tp_new(cls, args, NULL);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3894 if (obj == NULL) goto Fail;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3895
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3896 Py_DECREF(args);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3897 Py_DECREF(clsraw);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3898 PDATA_PUSH(self->stack, obj, -1);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3899 return 0;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3900
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3901 Fail:
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3902 Py_XDECREF(args);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3903 Py_XDECREF(clsraw);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3904 return -1;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
3905 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3906
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3907 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3908 load_global(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3909 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3910 PyObject *class = 0, *module_name = 0, *class_name = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3911 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3912 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3913
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3914 if ((len = self->readline_func(self, &s)) < 0) return -1;
10097
f5f1b5e9814a Jim Fulton: this fixes seg faults with bad pickles like "c".
Guido van Rossum <guido@python.org>
parents: 9948
diff changeset
3915 if (len < 2) return bad_readline();
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3916 module_name = PyString_FromStringAndSize(s, len - 1);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3917 if (!module_name) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3918
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3919 if ((len = self->readline_func(self, &s)) >= 0) {
26561
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
3920 if (len < 2) {
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
3921 Py_DECREF(module_name);
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
3922 return bad_readline();
12bc4a3e45af A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents: 25290
diff changeset
3923 }
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3924 if ((class_name = PyString_FromStringAndSize(s, len - 1))) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3925 class = find_class(module_name, class_name,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3926 self->find_class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3927 Py_DECREF(class_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3928 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3929 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3930 Py_DECREF(module_name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3931
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3932 if (! class) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3933 PDATA_PUSH(self->stack, class, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3934 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3935 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3936
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3937
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
3938 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3939 load_persid(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3940 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3941 PyObject *pid = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3942 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3943 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3944
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3945 if (self->pers_func) {
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
3946 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3947 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3948
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
3949 pid = PyString_FromStringAndSize(s, len - 1);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3950 if (!pid) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3951
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3952 if (PyList_Check(self->pers_func)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3953 if (PyList_Append(self->pers_func, pid) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3954 Py_DECREF(pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3955 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3956 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3957 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3958 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3959 ARG_TUP(self, pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3960 if (self->arg) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3961 pid = PyObject_Call(self->pers_func, self->arg,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3962 NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3963 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3964 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3965 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3966
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3967 if (! pid) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3968
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3969 PDATA_PUSH(self->stack, pid, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3970 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3971 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3972 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3973 PyErr_SetString(UnpicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3974 "A load persistent id instruction was encountered,\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3975 "but no persistent_load function was specified.");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3976 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3977 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3978 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3979
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3980 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
3981 load_binpersid(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3982 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3983 PyObject *pid = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3984
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3985 if (self->pers_func) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3986 PDATA_POP(self->stack, pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3987 if (! pid) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3988
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3989 if (PyList_Check(self->pers_func)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3990 if (PyList_Append(self->pers_func, pid) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3991 Py_DECREF(pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3992 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3993 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3994 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3995 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3996 ARG_TUP(self, pid);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3997 if (self->arg) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3998 pid = PyObject_Call(self->pers_func, self->arg,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
3999 NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4000 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4001 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4002 if (! pid) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4003 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4004
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4005 PDATA_PUSH(self->stack, pid, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4006 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4007 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4008 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4009 PyErr_SetString(UnpicklingError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4010 "A load persistent id instruction was encountered,\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4011 "but no persistent_load function was specified.");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4012 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4013 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4014 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4015
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4016
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4017 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4018 load_pop(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4019 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4020 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4021
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4022 if (!( (len=self->stack->length) > 0 )) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4023
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4024 /* Note that we split the (pickle.py) stack into two stacks,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4025 an object stack and a mark stack. We have to be clever and
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4026 pop the right one. We do this by looking at the top of the
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4027 mark stack.
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4028 */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4029
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4030 if ((self->num_marks > 0) &&
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4031 (self->marks[self->num_marks - 1] == len))
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4032 self->num_marks--;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4033 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4034 len--;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4035 Py_DECREF(self->stack->data[len]);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4036 self->stack->length=len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4037 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4038
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4039 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4040 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4041
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4042
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4043 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4044 load_pop_mark(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4045 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4046 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4047
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4048 if ((i = marker(self)) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4049 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4050
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4051 Pdata_clear(self->stack, i);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4052
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4053 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4054 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4055
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4056
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4057 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4058 load_dup(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4059 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4060 PyObject *last;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4061 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4062
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4063 if ((len = self->stack->length) <= 0) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4064 last=self->stack->data[len-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4065 Py_INCREF(last);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4066 PDATA_PUSH(self->stack, last, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4067 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4068 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4069
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4070
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4071 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4072 load_get(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4073 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4074 PyObject *py_str = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4075 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4076 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4077 int rc;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4078
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4079 if ((len = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4080 if (len < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4081
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
4082 if (!( py_str = PyString_FromStringAndSize(s, len - 1))) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4083
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4084 value = PyDict_GetItem(self->memo, py_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4085 if (! value) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4086 PyErr_SetObject(BadPickleGet, py_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4087 rc = -1;
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4088 }
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4089 else {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4090 PDATA_APPEND(self->stack, value, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4091 rc = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4092 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4093
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4094 Py_DECREF(py_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4095 return rc;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4096 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4097
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4098
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4099 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4100 load_binget(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4101 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4102 PyObject *py_key = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4103 unsigned char key;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4104 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4105 int rc;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4106
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4107 if (self->read_func(self, &s, 1) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4108
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4109 key = (unsigned char)s[0];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4110 if (!( py_key = PyInt_FromLong((long)key))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4111
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4112 value = PyDict_GetItem(self->memo, py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4113 if (! value) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4114 PyErr_SetObject(BadPickleGet, py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4115 rc = -1;
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4116 }
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4117 else {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4118 PDATA_APPEND(self->stack, value, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4119 rc = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4120 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4121
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4122 Py_DECREF(py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4123 return rc;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4124 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4125
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4126
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4127 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4128 load_long_binget(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4129 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4130 PyObject *py_key = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4131 unsigned char c;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4132 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4133 long key;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4134 int rc;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4135
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4136 if (self->read_func(self, &s, 4) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4137
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4138 c = (unsigned char)s[0];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4139 key = (long)c;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4140 c = (unsigned char)s[1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4141 key |= (long)c << 8;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4142 c = (unsigned char)s[2];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4143 key |= (long)c << 16;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4144 c = (unsigned char)s[3];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4145 key |= (long)c << 24;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4146
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4147 if (!( py_key = PyInt_FromLong((long)key))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4148
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4149 value = PyDict_GetItem(self->memo, py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4150 if (! value) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4151 PyErr_SetObject(BadPickleGet, py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4152 rc = -1;
27882
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4153 }
46659675d7f7 Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents: 27879
diff changeset
4154 else {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4155 PDATA_APPEND(self->stack, value, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4156 rc = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4157 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4158
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4159 Py_DECREF(py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4160 return rc;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4161 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4162
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4163 /* Push an object from the extension registry (EXT[124]). nbytes is
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4164 * the number of bytes following the opcode, holding the index (code) value.
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4165 */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4166 static int
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4167 load_extension(Unpicklerobject *self, int nbytes)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4168 {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4169 char *codebytes; /* the nbytes bytes after the opcode */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4170 long code; /* calc_binint returns long */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4171 PyObject *py_code; /* code as a Python int */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4172 PyObject *obj; /* the object to push */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4173 PyObject *pair; /* (module_name, class_name) */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4174 PyObject *module_name, *class_name;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4175
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4176 assert(nbytes == 1 || nbytes == 2 || nbytes == 4);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4177 if (self->read_func(self, &codebytes, nbytes) < 0) return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4178 code = calc_binint(codebytes, nbytes);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4179 if (code <= 0) { /* note that 0 is forbidden */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4180 /* Corrupt or hostile pickle. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4181 PyErr_SetString(UnpicklingError, "EXT specifies code <= 0");
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4182 return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4183 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4184
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4185 /* Look for the code in the cache. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4186 py_code = PyInt_FromLong(code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4187 if (py_code == NULL) return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4188 obj = PyDict_GetItem(extension_cache, py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4189 if (obj != NULL) {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4190 /* Bingo. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4191 Py_DECREF(py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4192 PDATA_APPEND(self->stack, obj, -1);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4193 return 0;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4194 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4195
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4196 /* Look up the (module_name, class_name) pair. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4197 pair = PyDict_GetItem(inverted_registry, py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4198 if (pair == NULL) {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4199 Py_DECREF(py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4200 PyErr_Format(PyExc_ValueError, "unregistered extension "
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4201 "code %ld", code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4202 return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4203 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4204 /* Since the extension registry is manipulable via Python code,
27667
f62ec2405e9f Typo in comment.
Tim Peters <tim.peters@gmail.com>
parents: 27666
diff changeset
4205 * confirm that pair is really a 2-tuple of strings.
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4206 */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4207 if (!PyTuple_Check(pair) || PyTuple_Size(pair) != 2 ||
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
4208 !PyString_Check(module_name = PyTuple_GET_ITEM(pair, 0)) ||
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
4209 !PyString_Check(class_name = PyTuple_GET_ITEM(pair, 1))) {
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4210 Py_DECREF(py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4211 PyErr_Format(PyExc_ValueError, "_inverted_registry[%ld] "
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4212 "isn't a 2-tuple of strings", code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4213 return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4214 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4215 /* Load the object. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4216 obj = find_class(module_name, class_name, self->find_class);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4217 if (obj == NULL) {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4218 Py_DECREF(py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4219 return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4220 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4221 /* Cache code -> obj. */
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4222 code = PyDict_SetItem(extension_cache, py_code, obj);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4223 Py_DECREF(py_code);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4224 if (code < 0) {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4225 Py_DECREF(obj);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4226 return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4227 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4228 PDATA_PUSH(self->stack, obj, -1);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4229 return 0;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4230 }
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4231
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4232 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4233 load_put(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4234 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4235 PyObject *py_str = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4236 int len, l;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4237 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4238
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4239 if ((l = self->readline_func(self, &s)) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4240 if (l < 2) return bad_readline();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4241 if (!( len=self->stack->length )) return stackUnderflow();
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
4242 if (!( py_str = PyString_FromStringAndSize(s, l - 1))) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4243 value=self->stack->data[len-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4244 l=PyDict_SetItem(self->memo, py_str, value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4245 Py_DECREF(py_str);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4246 return l;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4247 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4248
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4249
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4250 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4251 load_binput(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4252 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4253 PyObject *py_key = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4254 unsigned char key;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4255 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4256 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4257
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4258 if (self->read_func(self, &s, 1) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4259 if (!( (len=self->stack->length) > 0 )) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4260
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4261 key = (unsigned char)s[0];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4262
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4263 if (!( py_key = PyInt_FromLong((long)key))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4264 value=self->stack->data[len-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4265 len=PyDict_SetItem(self->memo, py_key, value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4266 Py_DECREF(py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4267 return len;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4268 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4269
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4270
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4271 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4272 load_long_binput(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4273 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4274 PyObject *py_key = 0, *value = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4275 long key;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4276 unsigned char c;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4277 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4278 int len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4279
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4280 if (self->read_func(self, &s, 4) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4281 if (!( len=self->stack->length )) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4282
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4283 c = (unsigned char)s[0];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4284 key = (long)c;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4285 c = (unsigned char)s[1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4286 key |= (long)c << 8;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4287 c = (unsigned char)s[2];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4288 key |= (long)c << 16;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4289 c = (unsigned char)s[3];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4290 key |= (long)c << 24;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4291
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4292 if (!( py_key = PyInt_FromLong(key))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4293 value=self->stack->data[len-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4294 len=PyDict_SetItem(self->memo, py_key, value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4295 Py_DECREF(py_key);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4296 return len;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4297 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4298
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4299
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
4300 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4301 do_append(Unpicklerobject *self, int x)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4302 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4303 PyObject *value = 0, *list = 0, *append_method = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4304 int len, i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4305
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4306 len=self->stack->length;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4307 if (!( len >= x && x > 0 )) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4308 /* nothing to do */
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4309 if (len==x) return 0;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4310
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4311 list=self->stack->data[x-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4312
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4313 if (PyList_Check(list)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4314 PyObject *slice;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4315 int list_len;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4316
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4317 slice=Pdata_popList(self->stack, x);
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
4318 if (! slice) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4319 list_len = PyList_GET_SIZE(list);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4320 i=PyList_SetSlice(list, list_len, list_len, slice);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4321 Py_DECREF(slice);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4322 return i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4323 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4324 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4325
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4326 if (!( append_method = PyObject_GetAttr(list, append_str)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4327 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4328
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4329 for (i = x; i < len; i++) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4330 PyObject *junk;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4331
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4332 value=self->stack->data[i];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4333 junk=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4334 ARG_TUP(self, value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4335 if (self->arg) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4336 junk = PyObject_Call(append_method, self->arg,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4337 NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4338 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4339 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4340 if (! junk) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4341 Pdata_clear(self->stack, i+1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4342 self->stack->length=x;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4343 Py_DECREF(append_method);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4344 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4345 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4346 Py_DECREF(junk);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4347 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4348 self->stack->length=x;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4349 Py_DECREF(append_method);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4350 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4351
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4352 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4353 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4354
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
4355
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4356 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4357 load_append(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4358 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4359 return do_append(self, self->stack->length - 1);
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4360 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4361
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4362
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4363 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4364 load_appends(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4365 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4366 return do_append(self, marker(self));
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4367 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4368
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4369
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4370 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4371 do_setitems(Unpicklerobject *self, int x)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4372 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4373 PyObject *value = 0, *key = 0, *dict = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4374 int len, i, r=0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4375
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4376 if (!( (len=self->stack->length) >= x
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4377 && x > 0 )) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4378
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4379 dict=self->stack->data[x-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4380
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4381 for (i = x+1; i < len; i += 2) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4382 key =self->stack->data[i-1];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4383 value=self->stack->data[i ];
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4384 if (PyObject_SetItem(dict, key, value) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4385 r=-1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4386 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4387 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4388 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4389
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4390 Pdata_clear(self->stack, x);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4391
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4392 return r;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4393 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4394
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4395
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4396 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4397 load_setitem(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4398 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4399 return do_setitems(self, self->stack->length - 2);
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4400 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4401
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4402 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4403 load_setitems(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4404 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4405 return do_setitems(self, marker(self));
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4406 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4407
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4408
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4409 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4410 load_build(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4411 {
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4412 PyObject *state, *inst, *slotstate;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4413 PyObject *__setstate__;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4414 PyObject *d_key, *d_value;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
4415 Py_ssize_t i;
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4416 int res = -1;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4417
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4418 /* Stack is ... instance, state. We want to leave instance at
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4419 * the stack top, possibly mutated via instance.__setstate__(state).
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4420 */
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4421 if (self->stack->length < 2)
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4422 return stackUnderflow();
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4423 PDATA_POP(self->stack, state);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4424 if (state == NULL)
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4425 return -1;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4426 inst = self->stack->data[self->stack->length - 1];
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4427
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4428 __setstate__ = PyObject_GetAttr(inst, __setstate___str);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4429 if (__setstate__ != NULL) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4430 PyObject *junk = NULL;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4431
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4432 /* The explicit __setstate__ is responsible for everything. */
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4433 ARG_TUP(self, state);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4434 if (self->arg) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4435 junk = PyObject_Call(__setstate__, self->arg, NULL);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4436 FREE_ARG_TUP(self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4437 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4438 Py_DECREF(__setstate__);
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4439 if (junk == NULL)
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4440 return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4441 Py_DECREF(junk);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4442 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4443 }
29499
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
4444 if (!PyErr_ExceptionMatches(PyExc_AttributeError))
d0d4d696ab24 Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29201
diff changeset
4445 return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4446 PyErr_Clear();
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4447
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4448 /* A default __setstate__. First see whether state embeds a
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4449 * slot state dict too (a proto 2 addition).
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4450 */
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4451 if (PyTuple_Check(state) && PyTuple_Size(state) == 2) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4452 PyObject *temp = state;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4453 state = PyTuple_GET_ITEM(temp, 0);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4454 slotstate = PyTuple_GET_ITEM(temp, 1);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4455 Py_INCREF(state);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4456 Py_INCREF(slotstate);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4457 Py_DECREF(temp);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4458 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4459 else
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4460 slotstate = NULL;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4461
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4462 /* Set inst.__dict__ from the state dict (if any). */
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4463 if (state != Py_None) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4464 PyObject *dict;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4465 if (! PyDict_Check(state)) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4466 PyErr_SetString(UnpicklingError, "state is not a "
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4467 "dictionary");
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4468 goto finally;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4469 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4470 dict = PyObject_GetAttr(inst, __dict___str);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4471 if (dict == NULL)
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4472 goto finally;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4473
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4474 i = 0;
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4475 while (PyDict_Next(state, &i, &d_key, &d_value)) {
53693
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4476 /* normally the keys for instance attributes are
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4477 interned. we should try to do that here. */
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4478 Py_INCREF(d_key);
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4479 if (PyString_CheckExact(d_key))
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4480 PyString_InternInPlace(&d_key);
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4481 if (PyObject_SetItem(dict, d_key, d_value) < 0) {
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4482 Py_DECREF(d_key);
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4483 goto finally;
53693
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4484 }
e54141d63e01 Isue #5084: unpickling now interns the attribute names of pickled objects,
Antoine Pitrou <solipsis@pitrou.net>
parents: 53442
diff changeset
4485 Py_DECREF(d_key);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4486 }
27901
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4487 Py_DECREF(dict);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4488 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4489
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4490 /* Also set instance attributes from the slotstate dict (if any). */
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4491 if (slotstate != NULL) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4492 if (! PyDict_Check(slotstate)) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4493 PyErr_SetString(UnpicklingError, "slot state is not "
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4494 "a dictionary");
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4495 goto finally;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4496 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4497 i = 0;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4498 while (PyDict_Next(slotstate, &i, &d_key, &d_value)) {
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4499 if (PyObject_SetAttr(inst, d_key, d_value) < 0)
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4500 goto finally;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4501 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4502 }
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4503 res = 0;
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4504
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4505 finally:
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4506 Py_DECREF(state);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4507 Py_XDECREF(slotstate);
55adf08a213a cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents: 27899
diff changeset
4508 return res;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4509 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4510
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4511
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4512 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4513 load_mark(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4514 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4515 int s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4516
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4517 /* Note that we split the (pickle.py) stack into two stacks, an
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4518 object stack and a mark stack. Here we push a mark onto the
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4519 mark stack.
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4520 */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4521
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4522 if ((self->num_marks + 1) >= self->marks_size) {
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
4523 int *marks;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4524 s=self->marks_size+20;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4525 if (s <= self->num_marks) s=self->num_marks + 1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4526 if (self->marks == NULL)
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
4527 marks=(int *)malloc(s * sizeof(int));
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4528 else
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
4529 marks=(int *)realloc(self->marks,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4530 s * sizeof(int));
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
4531 if (!marks) {
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4532 PyErr_NoMemory();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4533 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4534 }
41525
b68272449df4 Merge change 54909 from release25-maint: Fix several minor issues discovered using code analysis in VisualStudio 2005 Team Edition
Kristján Valur Jónsson <kristjan@ccpgames.com>
parents: 39995
diff changeset
4535 self->marks = marks;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4536 self->marks_size = s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4537 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4538
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4539 self->marks[self->num_marks++] = self->stack->length;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4540
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4541 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4542 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4543
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4544 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4545 load_reduce(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4546 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4547 PyObject *callable = 0, *arg_tup = 0, *ob = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4548
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4549 PDATA_POP(self->stack, arg_tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4550 if (! arg_tup) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4551 PDATA_POP(self->stack, callable);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4552 if (callable) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4553 ob = Instance_New(callable, arg_tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4554 Py_DECREF(callable);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4555 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4556 Py_DECREF(arg_tup);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4557
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4558 if (! ob) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4559
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4560 PDATA_PUSH(self->stack, ob, -1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4561 return 0;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4562 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
4563
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4564 /* Just raises an error if we don't know the protocol specified. PROTO
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4565 * is the first opcode for protocols >= 2.
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4566 */
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4567 static int
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4568 load_proto(Unpicklerobject *self)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4569 {
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4570 int i;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4571 char *protobyte;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4572
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4573 i = self->read_func(self, &protobyte, 1);
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4574 if (i < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4575 return -1;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4576
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4577 i = calc_binint(protobyte, 1);
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4578 /* No point checking for < 0, since calc_binint returns an unsigned
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4579 * int when chewing on 1 byte.
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4580 */
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4581 assert(i >= 0);
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
4582 if (i <= HIGHEST_PROTOCOL)
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4583 return 0;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4584
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4585 PyErr_Format(PyExc_ValueError, "unsupported pickle protocol: %d", i);
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4586 return -1;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4587 }
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4588
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4589 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4590 load(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4591 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4592 PyObject *err = 0, *val = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4593 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4594
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4595 self->num_marks = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4596 if (self->stack->length) Pdata_clear(self->stack, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4597
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4598 while (1) {
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4599 if (self->read_func(self, &s, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4600 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4601
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4602 switch (s[0]) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4603 case NONE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4604 if (load_none(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4605 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4606 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4607
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4608 case BININT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4609 if (load_binint(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4610 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4611 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4612
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4613 case BININT1:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4614 if (load_binint1(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4615 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4616 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4617
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4618 case BININT2:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4619 if (load_binint2(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4620 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4621 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4622
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4623 case INT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4624 if (load_int(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4625 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4626 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4627
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4628 case LONG:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4629 if (load_long(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4630 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4631 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4632
27585
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4633 case LONG1:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4634 if (load_counted_long(self, 1) < 0)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4635 break;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4636 continue;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4637
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4638 case LONG4:
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4639 if (load_counted_long(self, 4) < 0)
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4640 break;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4641 continue;
a05814184e8c cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents: 27584
diff changeset
4642
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4643 case FLOAT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4644 if (load_float(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4645 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4646 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4647
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4648 case BINFLOAT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4649 if (load_binfloat(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4650 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4651 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4652
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4653 case BINSTRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4654 if (load_binstring(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4655 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4656 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4657
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4658 case SHORT_BINSTRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4659 if (load_short_binstring(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4660 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4661 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4662
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4663 case STRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4664 if (load_string(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4665 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4666 continue;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
4667
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
4668 #ifdef Py_USING_UNICODE
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4669 case UNICODE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4670 if (load_unicode(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4671 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4672 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4673
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4674 case BINUNICODE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4675 if (load_binunicode(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4676 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4677 continue;
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
4678 #endif
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
4679
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4680 case EMPTY_TUPLE:
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4681 if (load_counted_tuple(self, 0) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4682 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4683 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4684
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4685 case TUPLE1:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4686 if (load_counted_tuple(self, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4687 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4688 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4689
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4690 case TUPLE2:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4691 if (load_counted_tuple(self, 2) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4692 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4693 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4694
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4695 case TUPLE3:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
4696 if (load_counted_tuple(self, 3) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4697 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4698 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4699
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4700 case TUPLE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4701 if (load_tuple(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4702 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4703 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4704
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4705 case EMPTY_LIST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4706 if (load_empty_list(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4707 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4708 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4709
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4710 case LIST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4711 if (load_list(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4712 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4713 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4714
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4715 case EMPTY_DICT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4716 if (load_empty_dict(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4717 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4718 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4719
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4720 case DICT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4721 if (load_dict(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4722 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4723 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4724
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4725 case OBJ:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4726 if (load_obj(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4727 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4728 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4729
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4730 case INST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4731 if (load_inst(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4732 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4733 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4734
27869
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4735 case NEWOBJ:
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4736 if (load_newobj(self) < 0)
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4737 break;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4738 continue;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4739
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4740 case GLOBAL:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4741 if (load_global(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4742 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4743 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4744
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4745 case APPEND:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4746 if (load_append(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4747 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4748 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4749
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4750 case APPENDS:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4751 if (load_appends(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4752 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4753 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4754
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4755 case BUILD:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4756 if (load_build(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4757 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4758 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4759
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4760 case DUP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4761 if (load_dup(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4762 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4763 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4764
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4765 case BINGET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4766 if (load_binget(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4767 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4768 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4769
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4770 case LONG_BINGET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4771 if (load_long_binget(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4772 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4773 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4774
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4775 case GET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4776 if (load_get(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4777 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4778 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4779
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4780 case EXT1:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4781 if (load_extension(self, 1) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4782 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4783 continue;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4784
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4785 case EXT2:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4786 if (load_extension(self, 2) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4787 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4788 continue;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4789
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4790 case EXT4:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4791 if (load_extension(self, 4) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4792 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4793 continue;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4794 case MARK:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4795 if (load_mark(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4796 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4797 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4798
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4799 case BINPUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4800 if (load_binput(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4801 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4802 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4803
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4804 case LONG_BINPUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4805 if (load_long_binput(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4806 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4807 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4808
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4809 case PUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4810 if (load_put(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4811 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4812 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4813
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4814 case POP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4815 if (load_pop(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4816 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4817 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4818
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4819 case POP_MARK:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4820 if (load_pop_mark(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4821 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4822 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4823
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4824 case SETITEM:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4825 if (load_setitem(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4826 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4827 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4828
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4829 case SETITEMS:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4830 if (load_setitems(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4831 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4832 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4833
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4834 case STOP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4835 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4836
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4837 case PERSID:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4838 if (load_persid(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4839 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4840 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4841
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4842 case BINPERSID:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4843 if (load_binpersid(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4844 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4845 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4846
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4847 case REDUCE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4848 if (load_reduce(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4849 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4850 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4851
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4852 case PROTO:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4853 if (load_proto(self) < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4854 break;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4855 continue;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
4856
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4857 case NEWTRUE:
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4858 if (load_bool(self, Py_True) < 0)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4859 break;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4860 continue;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4861
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4862 case NEWFALSE:
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4863 if (load_bool(self, Py_False) < 0)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4864 break;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4865 continue;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
4866
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4867 case '\0':
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4868 /* end of file */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4869 PyErr_SetNone(PyExc_EOFError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4870 break;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4871
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4872 default:
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4873 cPickle_ErrFormat(UnpicklingError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4874 "invalid load key, '%s'.",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4875 "c", s[0]);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4876 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4877 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4878
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4879 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4880 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4881
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4882 if ((err = PyErr_Occurred())) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4883 if (err == PyExc_EOFError) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4884 PyErr_SetNone(PyExc_EOFError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4885 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4886 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4887 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4888
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4889 PDATA_POP(self->stack, val);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4890 return val;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4891 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
4892
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
4893
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4894 /* No-load functions to support noload, which is used to
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4895 find persistent references. */
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4896
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4897 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4898 noload_obj(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4899 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4900 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4901
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4902 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4903 return Pdata_clear(self->stack, i+1);
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4904 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4905
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4906
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4907 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4908 noload_inst(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4909 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4910 int i;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4911 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4912
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4913 if ((i = marker(self)) < 0) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4914 Pdata_clear(self->stack, i);
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4915 if (self->readline_func(self, &s) < 0) return -1;
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4916 if (self->readline_func(self, &s) < 0) return -1;
27869
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4917 PDATA_APPEND(self->stack, Py_None, -1);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4918 return 0;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4919 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4920
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4921 static int
27869
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4922 noload_newobj(Unpicklerobject *self)
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4923 {
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4924 PyObject *obj;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4925
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4926 PDATA_POP(self->stack, obj); /* pop argtuple */
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4927 if (obj == NULL) return -1;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4928 Py_DECREF(obj);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4929
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4930 PDATA_POP(self->stack, obj); /* pop cls */
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4931 if (obj == NULL) return -1;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4932 Py_DECREF(obj);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4933
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4934 PDATA_APPEND(self->stack, Py_None, -1);
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4935 return 0;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4936 }
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4937
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
4938 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4939 noload_global(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4940 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4941 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4942
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4943 if (self->readline_func(self, &s) < 0) return -1;
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4944 if (self->readline_func(self, &s) < 0) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4945 PDATA_APPEND(self->stack, Py_None,-1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4946 return 0;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4947 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4948
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4949 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4950 noload_reduce(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4951 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4952
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4953 if (self->stack->length < 2) return stackUnderflow();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4954 Pdata_clear(self->stack, self->stack->length-2);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4955 PDATA_APPEND(self->stack, Py_None,-1);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4956 return 0;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4957 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4958
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4959 static int
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4960 noload_build(Unpicklerobject *self) {
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4961
9522
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
4962 if (self->stack->length < 1) return stackUnderflow();
a1a8df73bfff New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 8999
diff changeset
4963 Pdata_clear(self->stack, self->stack->length-1);
9587
5a9ca2e937b5 Fix two small bugs; add DL_EXPORT() to initcPickle decl.
Guido van Rossum <guido@python.org>
parents: 9522
diff changeset
4964 return 0;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4965 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4966
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4967 static int
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4968 noload_extension(Unpicklerobject *self, int nbytes)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4969 {
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4970 char *codebytes;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4971
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4972 assert(nbytes == 1 || nbytes == 2 || nbytes == 4);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4973 if (self->read_func(self, &codebytes, nbytes) < 0) return -1;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4974 PDATA_APPEND(self->stack, Py_None, -1);
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4975 return 0;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4976 }
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
4977
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4978
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
4979 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
4980 noload(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4981 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4982 PyObject *err = 0, *val = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4983 char *s;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4984
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4985 self->num_marks = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4986 Pdata_clear(self->stack, 0);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4987
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4988 while (1) {
27601
9a3b8443d5a6 Massive edits. If p is a pointer to a struct, and p->f is a pointer to
Tim Peters <tim.peters@gmail.com>
parents: 27600
diff changeset
4989 if (self->read_func(self, &s, 1) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4990 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4991
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4992 switch (s[0]) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4993 case NONE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4994 if (load_none(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4995 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4996 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4997
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4998 case BININT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
4999 if (load_binint(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5000 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5001 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5002
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5003 case BININT1:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5004 if (load_binint1(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5005 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5006 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5007
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5008 case BININT2:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5009 if (load_binint2(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5010 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5011 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5012
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5013 case INT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5014 if (load_int(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5015 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5016 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5017
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5018 case LONG:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5019 if (load_long(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5020 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5021 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5022
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5023 case LONG1:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5024 if (load_counted_long(self, 1) < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5025 break;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5026 continue;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5027
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5028 case LONG4:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5029 if (load_counted_long(self, 4) < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5030 break;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5031 continue;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5032
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5033 case FLOAT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5034 if (load_float(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5035 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5036 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5037
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5038 case BINFLOAT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5039 if (load_binfloat(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5040 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5041 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5042
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5043 case BINSTRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5044 if (load_binstring(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5045 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5046 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5047
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5048 case SHORT_BINSTRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5049 if (load_short_binstring(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5050 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5051 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5052
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5053 case STRING:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5054 if (load_string(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5055 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5056 continue;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5057
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
5058 #ifdef Py_USING_UNICODE
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5059 case UNICODE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5060 if (load_unicode(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5061 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5062 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5063
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5064 case BINUNICODE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5065 if (load_binunicode(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5066 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5067 continue;
19343
7257e87e0720 Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents: 18933
diff changeset
5068 #endif
11982
a13294aef02e Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents: 11882
diff changeset
5069
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5070 case EMPTY_TUPLE:
27615
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5071 if (load_counted_tuple(self, 0) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5072 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5073 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5074
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5075 case TUPLE1:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5076 if (load_counted_tuple(self, 1) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5077 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5078 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5079
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5080 case TUPLE2:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5081 if (load_counted_tuple(self, 2) < 0)
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5082 break;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5083 continue;
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5084
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5085 case TUPLE3:
45ad77a43d87 cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents: 27601
diff changeset
5086 if (load_counted_tuple(self, 3) < 0)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5087 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5088 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5089
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5090 case TUPLE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5091 if (load_tuple(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5092 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5093 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5094
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5095 case EMPTY_LIST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5096 if (load_empty_list(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5097 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5098 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5099
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5100 case LIST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5101 if (load_list(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5102 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5103 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5104
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5105 case EMPTY_DICT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5106 if (load_empty_dict(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5107 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5108 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5109
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5110 case DICT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5111 if (load_dict(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5112 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5113 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5114
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5115 case OBJ:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5116 if (noload_obj(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5117 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5118 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5119
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5120 case INST:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5121 if (noload_inst(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5122 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5123 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5124
27869
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
5125 case NEWOBJ:
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
5126 if (noload_newobj(self) < 0)
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
5127 break;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
5128 continue;
870cf14add2a Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents: 27864
diff changeset
5129
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5130 case GLOBAL:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5131 if (noload_global(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5132 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5133 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5134
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5135 case APPEND:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5136 if (load_append(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5137 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5138 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5139
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5140 case APPENDS:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5141 if (load_appends(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5142 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5143 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5144
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5145 case BUILD:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5146 if (noload_build(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5147 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5148 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5149
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5150 case DUP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5151 if (load_dup(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5152 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5153 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5154
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5155 case BINGET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5156 if (load_binget(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5157 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5158 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5159
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5160 case LONG_BINGET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5161 if (load_long_binget(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5162 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5163 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5164
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5165 case GET:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5166 if (load_get(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5167 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5168 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5169
27666
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5170 case EXT1:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5171 if (noload_extension(self, 1) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5172 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5173 continue;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5174
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5175 case EXT2:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5176 if (noload_extension(self, 2) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5177 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5178 continue;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5179
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5180 case EXT4:
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5181 if (noload_extension(self, 4) < 0)
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5182 break;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5183 continue;
5d7888fbea00 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
Tim Peters <tim.peters@gmail.com>
parents: 27665
diff changeset
5184
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5185 case MARK:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5186 if (load_mark(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5187 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5188 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5189
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5190 case BINPUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5191 if (load_binput(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5192 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5193 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5194
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5195 case LONG_BINPUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5196 if (load_long_binput(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5197 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5198 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5199
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5200 case PUT:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5201 if (load_put(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5202 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5203 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5204
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5205 case POP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5206 if (load_pop(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5207 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5208 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5209
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5210 case POP_MARK:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5211 if (load_pop_mark(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5212 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5213 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5214
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5215 case SETITEM:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5216 if (load_setitem(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5217 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5218 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5219
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5220 case SETITEMS:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5221 if (load_setitems(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5222 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5223 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5224
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5225 case STOP:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5226 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5227
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5228 case PERSID:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5229 if (load_persid(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5230 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5231 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5232
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5233 case BINPERSID:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5234 if (load_binpersid(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5235 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5236 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5237
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5238 case REDUCE:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5239 if (noload_reduce(self) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5240 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5241 continue;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5242
27591
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5243 case PROTO:
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5244 if (load_proto(self) < 0)
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5245 break;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5246 continue;
d6b65e3855a2 Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents: 27585
diff changeset
5247
27599
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5248 case NEWTRUE:
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5249 if (load_bool(self, Py_True) < 0)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5250 break;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5251 continue;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5252
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5253 case NEWFALSE:
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5254 if (load_bool(self, Py_False) < 0)
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5255 break;
d158d10ef4ae Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27596
diff changeset
5256 continue;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5257 default:
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5258 cPickle_ErrFormat(UnpicklingError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5259 "invalid load key, '%s'.",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5260 "c", s[0]);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5261 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5262 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5263
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5264 break;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5265 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5266
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5267 if ((err = PyErr_Occurred())) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5268 if (err == PyExc_EOFError) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5269 PyErr_SetNone(PyExc_EOFError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5270 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5271 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5272 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5273
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5274 PDATA_POP(self->stack, val);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5275 return val;
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5276 }
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
5277
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5278
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5279 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5280 Unpickler_load(Unpicklerobject *self, PyObject *unused)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5281 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5282 return load(self);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5283 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5284
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5285 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5286 Unpickler_noload(Unpicklerobject *self, PyObject *unused)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5287 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5288 return noload(self);
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5289 }
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5290
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5291
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5292 static struct PyMethodDef Unpickler_methods[] = {
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5293 {"load", (PyCFunction)Unpickler_load, METH_NOARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
5294 PyDoc_STR("load() -- Load a pickle")
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5295 },
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5296 {"noload", (PyCFunction)Unpickler_noload, METH_NOARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
5297 PyDoc_STR(
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5298 "noload() -- not load a pickle, but go through most of the motions\n"
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5299 "\n"
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5300 "This function can be used to read past a pickle without instantiating\n"
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5301 "any objects or importing any modules. It can also be used to find all\n"
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5302 "persistent references without instantiating any objects or importing\n"
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
5303 "any modules.\n")
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5304 },
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5305 {NULL, NULL} /* sentinel */
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5306 };
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5307
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5308
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5309 static Unpicklerobject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5310 newUnpicklerobject(PyObject *f)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5311 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5312 Unpicklerobject *self;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5313
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5314 if (!( self = PyObject_GC_New(Unpicklerobject, &Unpicklertype)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5315 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5316
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5317 self->file = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5318 self->arg = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5319 self->stack = (Pdata*)Pdata_New();
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5320 self->pers_func = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5321 self->last_string = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5322 self->marks = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5323 self->num_marks = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5324 self->marks_size = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5325 self->buf_size = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5326 self->read = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5327 self->readline = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5328 self->find_class = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5329
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5330 if (!( self->memo = PyDict_New()))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5331 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5332
39135
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
5333 if (!self->stack)
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
5334 goto err;
12e973bdfeee Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents: 38949
diff changeset
5335
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5336 Py_INCREF(f);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5337 self->file = f;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5338
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5339 /* Set read, readline based on type of f */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5340 if (PyFile_Check(f)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5341 self->fp = PyFile_AsFile(f);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5342 if (self->fp == NULL) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5343 PyErr_SetString(PyExc_ValueError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5344 "I/O operation on closed file");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5345 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5346 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5347 self->read_func = read_file;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5348 self->readline_func = readline_file;
10496
ba1a27d73cdb Protection against picling to/from closed (real) file.
Guido van Rossum <guido@python.org>
parents: 10126
diff changeset
5349 }
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5350 else if (PycStringIO_InputCheck(f)) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5351 self->fp = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5352 self->read_func = read_cStringIO;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5353 self->readline_func = readline_cStringIO;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5354 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5355 else {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5356
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5357 self->fp = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5358 self->read_func = read_other;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5359 self->readline_func = readline_other;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5360
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5361 if (!( (self->readline = PyObject_GetAttr(f, readline_str)) &&
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5362 (self->read = PyObject_GetAttr(f, read_str)))) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5363 PyErr_Clear();
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5364 PyErr_SetString( PyExc_TypeError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5365 "argument must have 'read' and "
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5366 "'readline' attributes" );
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5367 goto err;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5368 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5369 }
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5370 PyObject_GC_Track(self);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5371
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5372 return self;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5373
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5374 err:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5375 Py_DECREF((PyObject *)self);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5376 return NULL;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5377 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5378
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5379
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5380 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5381 get_Unpickler(PyObject *self, PyObject *file)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5382 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5383 return (PyObject *)newUnpicklerobject(file);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5384 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5385
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5386
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5387 static void
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5388 Unpickler_dealloc(Unpicklerobject *self)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5389 {
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5390 PyObject_GC_UnTrack((PyObject *)self);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5391 Py_XDECREF(self->readline);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5392 Py_XDECREF(self->read);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5393 Py_XDECREF(self->file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5394 Py_XDECREF(self->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5395 Py_XDECREF(self->stack);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5396 Py_XDECREF(self->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5397 Py_XDECREF(self->arg);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5398 Py_XDECREF(self->last_string);
29816
ed43155b1d3c The Unpickler forget about its find_class attribute.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 29499
diff changeset
5399 Py_XDECREF(self->find_class);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5400
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5401 if (self->marks) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5402 free(self->marks);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5403 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5404
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5405 if (self->buf_size) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5406 free(self->buf);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5407 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5408
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
5409 Py_TYPE(self)->tp_free((PyObject *)self);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5410 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5411
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5412 static int
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5413 Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg)
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5414 {
37756
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5415 Py_VISIT(self->readline);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5416 Py_VISIT(self->read);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5417 Py_VISIT(self->file);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5418 Py_VISIT(self->memo);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5419 Py_VISIT(self->stack);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5420 Py_VISIT(self->pers_func);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5421 Py_VISIT(self->arg);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5422 Py_VISIT(self->last_string);
7b2e436a4a21 Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents: 37748
diff changeset
5423 Py_VISIT(self->find_class);
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5424 return 0;
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5425 }
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5426
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5427 static int
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5428 Unpickler_clear(Unpicklerobject *self)
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5429 {
37748
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5430 Py_CLEAR(self->readline);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5431 Py_CLEAR(self->read);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5432 Py_CLEAR(self->file);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5433 Py_CLEAR(self->memo);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5434 Py_CLEAR(self->stack);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5435 Py_CLEAR(self->pers_func);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5436 Py_CLEAR(self->arg);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5437 Py_CLEAR(self->last_string);
d1547426ab61 Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents: 37555
diff changeset
5438 Py_CLEAR(self->find_class);
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5439 return 0;
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5440 }
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5441
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5442 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5443 Unpickler_getattr(Unpicklerobject *self, char *name)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5444 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5445 if (!strcmp(name, "persistent_load")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5446 if (!self->pers_func) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5447 PyErr_SetString(PyExc_AttributeError, name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5448 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5449 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5450
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5451 Py_INCREF(self->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5452 return self->pers_func;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5453 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5454
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5455 if (!strcmp(name, "find_global")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5456 if (!self->find_class) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5457 PyErr_SetString(PyExc_AttributeError, name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5458 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5459 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5460
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5461 Py_INCREF(self->find_class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5462 return self->find_class;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5463 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5464
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5465 if (!strcmp(name, "memo")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5466 if (!self->memo) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5467 PyErr_SetString(PyExc_AttributeError, name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5468 return NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5469 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5470
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5471 Py_INCREF(self->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5472 return self->memo;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5473 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5474
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5475 if (!strcmp(name, "UnpicklingError")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5476 Py_INCREF(UnpicklingError);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5477 return UnpicklingError;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5478 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5479
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5480 return Py_FindMethod(Unpickler_methods, (PyObject *)self, name);
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5481 }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5482
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5483
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5484 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5485 Unpickler_setattr(Unpicklerobject *self, char *name, PyObject *value)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5486 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5487
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5488 if (!strcmp(name, "persistent_load")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5489 Py_XDECREF(self->pers_func);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5490 self->pers_func = value;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5491 Py_XINCREF(value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5492 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5493 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5494
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5495 if (!strcmp(name, "find_global")) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5496 Py_XDECREF(self->find_class);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5497 self->find_class = value;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5498 Py_XINCREF(value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5499 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5500 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5501
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5502 if (! value) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5503 PyErr_SetString(PyExc_TypeError,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5504 "attribute deletion is not supported");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5505 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5506 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5507
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5508 if (strcmp(name, "memo") == 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5509 if (!PyDict_Check(value)) {
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5510 PyErr_SetString(PyExc_TypeError,
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5511 "memo must be a dictionary");
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5512 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5513 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5514 Py_XDECREF(self->memo);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5515 self->memo = value;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5516 Py_INCREF(value);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5517 return 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5518 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5519
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5520 PyErr_SetString(PyExc_AttributeError, name);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5521 return -1;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5522 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5523
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5524 /* ---------------------------------------------------------------------------
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5525 * Module-level functions.
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5526 */
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5527
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5528 /* dump(obj, file, protocol=0). */
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5529 static PyObject *
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5530 cpm_dump(PyObject *self, PyObject *args, PyObject *kwds)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5531 {
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
5532 static char *kwlist[] = {"obj", "file", "protocol", NULL};
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5533 PyObject *ob, *file, *res = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5534 Picklerobject *pickler = 0;
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5535 int proto = 0;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5536
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5537 if (!( PyArg_ParseTupleAndKeywords(args, kwds, "OO|i", kwlist,
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5538 &ob, &file, &proto)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5539 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5540
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5541 if (!( pickler = newPicklerobject(file, proto)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5542 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5543
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5544 if (dump(pickler, ob) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5545 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5546
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5547 Py_INCREF(Py_None);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5548 res = Py_None;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5549
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5550 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5551 Py_XDECREF(pickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5552
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5553 return res;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5554 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5555
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5556
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5557 /* dumps(obj, protocol=0). */
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5558 static PyObject *
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5559 cpm_dumps(PyObject *self, PyObject *args, PyObject *kwds)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5560 {
36675
dba6494735d0 Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents: 36501
diff changeset
5561 static char *kwlist[] = {"obj", "protocol", NULL};
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5562 PyObject *ob, *file = 0, *res = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5563 Picklerobject *pickler = 0;
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5564 int proto = 0;
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5565
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5566 if (!( PyArg_ParseTupleAndKeywords(args, kwds, "O|i:dumps", kwlist,
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5567 &ob, &proto)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5568 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5569
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5570 if (!( file = PycStringIO->NewOutput(128)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5571 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5572
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5573 if (!( pickler = newPicklerobject(file, proto)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5574 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5575
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5576 if (dump(pickler, ob) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5577 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5578
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5579 res = PycStringIO->cgetvalue(file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5580
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5581 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5582 Py_XDECREF(pickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5583 Py_XDECREF(file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5584
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5585 return res;
17062
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
5586 }
33c8680b3b35 SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents: 15607
diff changeset
5587
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5588
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5589 /* load(fileobj). */
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5590 static PyObject *
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5591 cpm_load(PyObject *self, PyObject *ob)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5592 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5593 Unpicklerobject *unpickler = 0;
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5594 PyObject *res = NULL;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5595
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5596 if (!( unpickler = newUnpicklerobject(ob)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5597 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5598
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5599 res = load(unpickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5600
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5601 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5602 Py_XDECREF(unpickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5603
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5604 return res;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5605 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5606
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5607
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5608 /* loads(string) */
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5609 static PyObject *
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5610 cpm_loads(PyObject *self, PyObject *args)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5611 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5612 PyObject *ob, *file = 0, *res = NULL;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5613 Unpicklerobject *unpickler = 0;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5614
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5615 if (!( PyArg_ParseTuple(args, "S:loads", &ob)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5616 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5617
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5618 if (!( file = PycStringIO->NewInput(ob)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5619 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5620
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5621 if (!( unpickler = newUnpicklerobject(file)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5622 goto finally;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5623
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5624 res = load(unpickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5625
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5626 finally:
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5627 Py_XDECREF(file);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5628 Py_XDECREF(unpickler);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5629
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5630 return res;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5631 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5632
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5633
23832
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
5634 PyDoc_STRVAR(Unpicklertype__doc__,
ed1ba37a46b7 Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents: 23332
diff changeset
5635 "Objects that know how to unpickle");
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5636
6774
0ef23f513a65 Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 6740
diff changeset
5637 static PyTypeObject Unpicklertype = {
42333
6620a510e9a9 PEP 3123: Provide forward compatibility with Python 3.0, while keeping
Martin v. Löwis <martin@v.loewis.de>
parents: 41525
diff changeset
5638 PyVarObject_HEAD_INIT(NULL, 0)
28568
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5639 "cPickle.Unpickler", /*tp_name*/
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5640 sizeof(Unpicklerobject), /*tp_basicsize*/
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5641 0,
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5642 (destructor)Unpickler_dealloc, /* tp_dealloc */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5643 0, /* tp_print */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5644 (getattrfunc)Unpickler_getattr, /* tp_getattr */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5645 (setattrfunc)Unpickler_setattr, /* tp_setattr */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5646 0, /* tp_compare */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5647 0, /* tp_repr */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5648 0, /* tp_as_number */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5649 0, /* tp_as_sequence */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5650 0, /* tp_as_mapping */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5651 0, /* tp_hash */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5652 0, /* tp_call */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5653 0, /* tp_str */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5654 0, /* tp_getattro */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5655 0, /* tp_setattro */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5656 0, /* tp_as_buffer */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5657 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC,
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5658 Unpicklertype__doc__, /* tp_doc */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5659 (traverseproc)Unpickler_traverse, /* tp_traverse */
d08d7b4be532 Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents: 28567
diff changeset
5660 (inquiry)Unpickler_clear, /* tp_clear */
6774
0ef23f513a65 Jim Fulton:
Guido van Rossum <guido@python.org>
parents: 6740
diff changeset
5661 };
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5662
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5663 static struct PyMethodDef cPickle_methods[] = {
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5664 {"dump", (PyCFunction)cpm_dump, METH_VARARGS | METH_KEYWORDS,
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5665 PyDoc_STR("dump(obj, file, protocol=0) -- "
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5666 "Write an object in pickle format to the given file.\n"
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5667 "\n"
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5668 "See the Pickler docstring for the meaning of optional argument proto.")
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5669 },
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5670
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5671 {"dumps", (PyCFunction)cpm_dumps, METH_VARARGS | METH_KEYWORDS,
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5672 PyDoc_STR("dumps(obj, protocol=0) -- "
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5673 "Return a string containing an object in pickle format.\n"
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5674 "\n"
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5675 "See the Pickler docstring for the meaning of optional argument proto.")
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5676 },
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5677
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5678 {"load", (PyCFunction)cpm_load, METH_O,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
5679 PyDoc_STR("load(file) -- Load a pickle from the given file")},
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5680
22706
14ebd7610902 Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents: 22464
diff changeset
5681 {"loads", (PyCFunction)cpm_loads, METH_VARARGS,
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24532
diff changeset
5682 PyDoc_STR("loads(string) -- Load a pickle from the given string")},
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5683
32829
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5684 {"Pickler", (PyCFunction)get_Pickler, METH_VARARGS | METH_KEYWORDS,
cbd4ae74890d Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents: 32305
diff changeset
5685 PyDoc_STR("Pickler(file, protocol=0) -- Create a pickler.\n"
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5686 "\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5687 "This takes a file-like object for writing a pickle data stream.\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5688 "The optional proto argument tells the pickler to use the given\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5689 "protocol; supported protocols are 0, 1, 2. The default\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5690 "protocol is 0, to be backwards compatible. (Protocol 0 is the\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5691 "only protocol that can be written to a file opened in text\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5692 "mode and read back successfully. When using a protocol higher\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5693 "than 0, make sure the file is opened in binary mode, both when\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5694 "pickling and unpickling.)\n"
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5695 "\n"
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5696 "Protocol 1 is more efficient than protocol 0; protocol 2 is\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5697 "more efficient than protocol 1.\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5698 "\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5699 "Specifying a negative protocol version selects the highest\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5700 "protocol version supported. The higher the protocol used, the\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5701 "more recent the version of Python needed to read the pickle\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5702 "produced.\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5703 "\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5704 "The file parameter must have a write() method that accepts a single\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5705 "string argument. It can thus be an open file object, a StringIO\n"
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5706 "object, or any other custom object that meets this interface.\n")
6740
1853b5bc0548 New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents: 6692
diff changeset
5707 },
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5708
38489
3fe3ccdf0155 Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents: 38431
diff changeset
5709 {"Unpickler", (PyCFunction)get_Unpickler, METH_O,
27584
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5710 PyDoc_STR("Unpickler(file) -- Create an unpickler.")},
65635c72135e The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents: 27580
diff changeset
5711
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5712 { NULL, NULL }
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5713 };
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5714
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5715 static int
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5716 init_stuff(PyObject *module_dict)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5717 {
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5718 PyObject *copyreg, *t, *r;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5719
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5720 #define INIT_STR(S) if (!( S ## _str=PyString_InternFromString(#S))) return -1;
5281
607fa32fc04a Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents: 4958
diff changeset
5721
29201
754fd34ad978 PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents: 28568
diff changeset
5722 if (PyType_Ready(&Unpicklertype) < 0)
754fd34ad978 PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents: 28568
diff changeset
5723 return -1;
754fd34ad978 PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents: 28568
diff changeset
5724 if (PyType_Ready(&Picklertype) < 0)
754fd34ad978 PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents: 28568
diff changeset
5725 return -1;
754fd34ad978 PyType_Ready(): Complain if the type is a base type, and gc'able, and
Tim Peters <tim.peters@gmail.com>
parents: 28568
diff changeset
5726
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5727 INIT_STR(__class__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5728 INIT_STR(__getinitargs__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5729 INIT_STR(__dict__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5730 INIT_STR(__getstate__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5731 INIT_STR(__setstate__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5732 INIT_STR(__name__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5733 INIT_STR(__main__);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5734 INIT_STR(__reduce__);
27961
ac10729f0932 Use __reduce_ex__.
Guido van Rossum <guido@python.org>
parents: 27944
diff changeset
5735 INIT_STR(__reduce_ex__);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5736 INIT_STR(write);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5737 INIT_STR(append);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5738 INIT_STR(read);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5739 INIT_STR(readline);
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5740 INIT_STR(copyreg);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5741 INIT_STR(dispatch_table);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5742
47189
f419b2e96a98 Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents: 47111
diff changeset
5743 if (!( copyreg = PyImport_ImportModule("copy_reg")))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5744 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5745
27573
674f3eecffc5 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents: 27566
diff changeset
5746 /* This is special because we want to use a different
674f3eecffc5 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents: 27566
diff changeset
5747 one in restricted mode. */
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5748 dispatch_table = PyObject_GetAttr(copyreg, dispatch_table_str);
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5749 if (!dispatch_table) return -1;
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5750
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5751 extension_registry = PyObject_GetAttrString(copyreg,
27665
d5eb12bccd1e Rename the extension registry variables to have leading underscores --
Guido van Rossum <guido@python.org>
parents: 27663
diff changeset
5752 "_extension_registry");
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5753 if (!extension_registry) return -1;
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5754
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5755 inverted_registry = PyObject_GetAttrString(copyreg,
27665
d5eb12bccd1e Rename the extension registry variables to have leading underscores --
Guido van Rossum <guido@python.org>
parents: 27663
diff changeset
5756 "_inverted_registry");
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5757 if (!inverted_registry) return -1;
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5758
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5759 extension_cache = PyObject_GetAttrString(copyreg,
27665
d5eb12bccd1e Rename the extension registry variables to have leading underscores --
Guido van Rossum <guido@python.org>
parents: 27663
diff changeset
5760 "_extension_cache");
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5761 if (!extension_cache) return -1;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5762
46865
b40827eb4b80 Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46337
diff changeset
5763 Py_DECREF(copyreg);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5764
27684
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
5765 if (!(empty_tuple = PyTuple_New(0)))
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
5766 return -1;
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
5767
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
5768 two_tuple = PyTuple_New(2);
96fd004a58b0 cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents: 27667
diff changeset
5769 if (two_tuple == NULL)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5770 return -1;
27686
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
5771 /* We use this temp container with no regard to refcounts, or to
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
5772 * keeping containees alive. Exempt from GC, because we don't
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
5773 * want anything looking at two_tuple() by magic.
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
5774 */
3599f6593fe9 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
Tim Peters <tim.peters@gmail.com>
parents: 27684
diff changeset
5775 PyObject_GC_UnTrack(two_tuple);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5776
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5777 /* Ugh */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5778 if (!( t=PyImport_ImportModule("__builtin__"))) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5779 if (PyDict_SetItemString(module_dict, "__builtins__", t) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5780 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5781
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5782 if (!( t=PyDict_New())) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5783 if (!( r=PyRun_String(
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5784 "def __str__(self):\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5785 " return self.args and ('%s' % self.args[0]) or '(what)'\n",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5786 Py_file_input,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5787 module_dict, t) )) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5788 Py_DECREF(r);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5789
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5790 PickleError = PyErr_NewException("cPickle.PickleError", NULL, t);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5791 if (!PickleError)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5792 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5793
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5794 Py_DECREF(t);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5795
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5796 PicklingError = PyErr_NewException("cPickle.PicklingError",
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5797 PickleError, NULL);
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5798 if (!PicklingError)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5799 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5800
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5801 if (!( t=PyDict_New())) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5802 if (!( r=PyRun_String(
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5803 "def __str__(self):\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5804 " a=self.args\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5805 " a=a and type(a[0]) or '(what)'\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5806 " return 'Cannot pickle %s objects' % a\n"
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5807 , Py_file_input,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5808 module_dict, t) )) return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5809 Py_DECREF(r);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5810
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5811 if (!( UnpickleableError = PyErr_NewException(
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5812 "cPickle.UnpickleableError", PicklingError, t)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5813 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5814
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5815 Py_DECREF(t);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5816
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5817 if (!( UnpicklingError = PyErr_NewException("cPickle.UnpicklingError",
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5818 PickleError, NULL)))
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5819 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5820
25290
f5ec08d45859 Make BadPickleGet a class. Fixes #609164.
Martin v. Löwis <martin@v.loewis.de>
parents: 24808
diff changeset
5821 if (!( BadPickleGet = PyErr_NewException("cPickle.BadPickleGet",
f5ec08d45859 Make BadPickleGet a class. Fixes #609164.
Martin v. Löwis <martin@v.loewis.de>
parents: 24808
diff changeset
5822 UnpicklingError, NULL)))
f5ec08d45859 Make BadPickleGet a class. Fixes #609164.
Martin v. Löwis <martin@v.loewis.de>
parents: 24808
diff changeset
5823 return -1;
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5824
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5825 if (PyDict_SetItemString(module_dict, "PickleError",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5826 PickleError) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5827 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5828
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5829 if (PyDict_SetItemString(module_dict, "PicklingError",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5830 PicklingError) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5831 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5832
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5833 if (PyDict_SetItemString(module_dict, "UnpicklingError",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5834 UnpicklingError) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5835 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5836
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5837 if (PyDict_SetItemString(module_dict, "UnpickleableError",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5838 UnpickleableError) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5839 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5840
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5841 if (PyDict_SetItemString(module_dict, "BadPickleGet",
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5842 BadPickleGet) < 0)
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5843 return -1;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5844
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5845 PycString_IMPORT;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5846
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5847 return 0;
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5848 }
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5849
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24302
diff changeset
5850 #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24302
diff changeset
5851 #define PyMODINIT_FUNC void
10097
f5f1b5e9814a Jim Fulton: this fixes seg faults with bad pickles like "c".
Guido van Rossum <guido@python.org>
parents: 9948
diff changeset
5852 #endif
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 24302
diff changeset
5853 PyMODINIT_FUNC
27578
2f227ff11f5e Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents: 27577
diff changeset
5854 initcPickle(void)
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5855 {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5856 PyObject *m, *d, *di, *v, *k;
36501
7fdc639bc5b4 Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents: 36324
diff changeset
5857 Py_ssize_t i;
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5858 char *rev = "1.71"; /* XXX when does this change? */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5859 PyObject *format_version;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5860 PyObject *compatible_formats;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5861
47111
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5862 /* XXX: Should mention that the pickle module will include the C
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5863 XXX: optimized implementation automatically. */
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5864 if (PyErr_WarnPy3k("the cPickle module has been removed in "
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5865 "Python 3.0", 2) < 0)
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5866 return;
ab80bbfa6f0c Added Python 3.0 warning to cPickle.
Alexandre Vassalotti <alexandre@peadrop.com>
parents: 46865
diff changeset
5867
44350
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
5868 Py_TYPE(&Picklertype) = &PyType_Type;
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
5869 Py_TYPE(&Unpicklertype) = &PyType_Type;
26384b8180c7 #1629: Renamed Py_Size, Py_Type and Py_Refcnt to Py_SIZE, Py_TYPE and Py_REFCNT. Macros for b/w compatibility are available.
Christian Heimes <christian@cheimes.de>
parents: 43472
diff changeset
5870 Py_TYPE(&PdataType) = &PyType_Type;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5871
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5872 /* Initialize some pieces. We need to do this before module creation,
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5873 * so we're forced to use a temporary dictionary. :(
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5874 */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5875 di = PyDict_New();
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5876 if (!di) return;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5877 if (init_stuff(di) < 0) return;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5878
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5879 /* Create the module and add the functions */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5880 m = Py_InitModule4("cPickle", cPickle_methods,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5881 cPickle_module_documentation,
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5882 (PyObject*)NULL,PYTHON_API_VERSION);
36324
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35999
diff changeset
5883 if (m == NULL)
1af7f719ed28 Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents: 35999
diff changeset
5884 return;
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5885
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5886 /* Add some symbolic constants to the module */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5887 d = PyModule_GetDict(m);
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5888 v = PyString_FromString(rev);
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5889 PyDict_SetItemString(d, "__version__", v);
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5890 Py_XDECREF(v);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5891
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5892 /* Copy data from di. Waaa. */
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5893 for (i=0; PyDict_Next(di, &i, &k, &v); ) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5894 if (PyObject_SetItem(d, k, v) < 0) {
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5895 Py_DECREF(di);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5896 return;
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5897 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5898 }
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5899 Py_DECREF(di);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5900
27864
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
5901 i = PyModule_AddIntConstant(m, "HIGHEST_PROTOCOL", HIGHEST_PROTOCOL);
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
5902 if (i < 0)
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
5903 return;
b4eb34372bdb Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents: 27832
diff changeset
5904
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5905 /* These are purely informational; no code uses them. */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5906 /* File format version we write. */
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47294
diff changeset
5907 format_version = PyString_FromString("2.0");
27662
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5908 /* Format versions we can read. */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5909 compatible_formats = Py_BuildValue("[sssss]",
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5910 "1.0", /* Original protocol 0 */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5911 "1.1", /* Protocol 0 + INST */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5912 "1.2", /* Original protocol 1 */
3a528aa222b6 Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents: 27656
diff changeset
5913 "1.3", /* Protocol 1 + BINFLOAT */
27663
df363d1b3842 Typo repair.
Tim Peters <tim.peters@gmail.com>
parents: 27662
diff changeset
5914 "2.0"); /* Original protocol 2 */
22732
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5915 PyDict_SetItemString(d, "format_version", format_version);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5916 PyDict_SetItemString(d, "compatible_formats", compatible_formats);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5917 Py_XDECREF(format_version);
00154a0fde61 Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents: 22725
diff changeset
5918 Py_XDECREF(compatible_formats);
4907
fd3626511dad cPickle, version 0.1.
Guido van Rossum <guido@python.org>
parents:
diff changeset
5919 }