Mercurial > cpython-lru_cache-weakref
annotate Modules/cPickle.c @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 0c7ead034a03 |
| children | e38335d4df91 |
| rev | line source |
|---|---|
| 4907 | 1 #include "Python.h" |
| 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 | 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 | 105 static char MARKv = MARK; |
| 106 | |
| 10946 | 107 static PyObject *PickleError; |
| 4907 | 108 static PyObject *PicklingError; |
| 10946 | 109 static PyObject *UnpickleableError; |
| 4907 | 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 | 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, |
|
57439
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
135 *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 | 356 } Picklerobject; |
| 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 | 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 | 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 | 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 | 446 if (nbyteswritten != (size_t)n) { |
| 447 PyErr_SetFromErrno(PyExc_IOError); | |
| 448 return -1; | |
| 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 | 452 } |
| 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 | 525 } |
| 526 | |
| 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 | 572 } |
| 573 | |
| 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 | 629 } |
| 630 | |
| 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 | 645 } |
| 646 | |
| 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; |
|
55430
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
666 |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
667 if (PyString_GET_SIZE(str) != n) { |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
668 PyErr_SetNone(PyExc_EOFError); |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
669 return -1; |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
670 } |
|
868b4e639b5a
Merged revisions 74189 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
54344
diff
changeset
|
671 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
672 return n; |
| 4907 | 673 } |
| 674 | |
| 675 | |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
676 static Py_ssize_t |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
677 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
|
678 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
679 PyObject *str; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
680 Py_ssize_t str_size; |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
681 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
682 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
|
683 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
684 } |
|
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 ((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
|
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 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
|
690 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
|
691 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
692 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
|
693 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
694 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
695 return str_size; |
| 4907 | 696 } |
| 697 | |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
698 /* 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
|
699 * 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
|
700 * 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
|
701 */ |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
702 static char * |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
34126
diff
changeset
|
703 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
|
704 { |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
705 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
|
706 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
|
707 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
|
708 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
|
709 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
|
710 return r; |
| 4907 | 711 } |
| 712 | |
| 713 | |
| 714 static int | |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
715 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
|
716 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
717 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
|
718 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
|
719 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
|
720 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
|
721 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
722 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
|
723 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
|
724 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
725 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
726 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
727 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
|
728 return -1; |
|
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 (!( 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
|
731 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
|
732 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
733 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
734 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
|
735 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
736 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
|
737 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
|
738 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
|
739 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
|
740 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
741 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
|
742 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
|
743 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
|
744 return 0; |
|
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 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
|
748 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
|
749 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
|
750 len = 2; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
751 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
752 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
753 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
|
754 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
|
755 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
|
756 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
|
757 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
|
758 len = 5; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
759 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
760 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
761 |
|
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
|
762 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
|
763 return -1; |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
764 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
765 return 0; |
| 4907 | 766 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
767 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
768 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
769 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
770 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
|
771 { |
|
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
|
772 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
|
773 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
774 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
775 return put2(self, ob); |
| 4907 | 776 } |
| 777 | |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
778 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
779 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
780 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
|
781 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
782 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
|
783 int p; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
784 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
|
785 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
|
786 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
|
787 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
788 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
|
789 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
790 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
791 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
|
792 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
793 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
794 /* 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
|
795 /* 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
|
796 * 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
|
797 * 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
|
798 * 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
|
799 */ |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
800 p++; |
|
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
801 |
|
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
802 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
|
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 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
805 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
|
806 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
807 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
808 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
|
809 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
810 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
811 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
|
812 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
|
813 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
|
814 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
|
815 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
816 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
|
817 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
818 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
819 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
|
820 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
|
821 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
|
822 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
|
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 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
|
825 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
|
826 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
|
827 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
|
828 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
829 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
830 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 len = 5; |
|
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 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
840 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
|
841 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
|
842 len = 2; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
843 } |
|
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 |
|
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
|
846 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
|
847 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
848 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
849 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
850 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
851 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
852 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
|
853 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
|
854 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
|
855 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
856 return res; |
| 4907 | 857 } |
| 858 | |
|
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
|
859 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
860 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
|
861 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
862 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
|
863 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
|
864 *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
|
865 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
866 module = PyObject_GetAttrString(global, "__module__"); |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
867 if (module) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
868 return module; |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
869 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
870 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
871 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
872 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
|
873 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
874 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
|
875 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
876 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
877 i = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
878 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
|
879 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
880 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
|
881 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
882 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
|
883 if (!global_name_attr) { |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
884 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
885 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
886 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
887 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
|
888 continue; |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
891 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
|
892 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
|
893 continue; |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
896 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
|
897 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
898 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
899 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
900 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
901 /* 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
|
902 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
|
903 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
|
904 */ |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
905 if (!j) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
906 j=1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
907 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
|
908 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
909 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
910 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
|
911 return name; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
912 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
913 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
914 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
915 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
|
916 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
|
917 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
918 /* 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
|
919 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
|
920 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
|
921 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
|
922 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
|
923 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
|
924 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
|
925 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
926 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
927 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
928 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
|
929 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
|
930 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
931 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
|
932 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
|
933 PyErr_Format(PyExc_ValueError, |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
934 "fast mode: can't pickle cyclic objects " |
|
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
935 "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
|
936 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
|
937 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
|
938 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
939 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
940 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
|
941 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
|
942 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
|
943 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
944 } |
|
26561
12bc4a3e45af
A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents:
25290
diff
changeset
|
945 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
|
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 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
|
948 } |
|
03624d7484fa
Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20385
diff
changeset
|
949 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
950 int |
|
20443
03624d7484fa
Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20385
diff
changeset
|
951 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
|
952 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
953 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
|
954 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
|
955 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
|
956 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
957 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
|
958 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
|
959 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
960 } |
|
26561
12bc4a3e45af
A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents:
25290
diff
changeset
|
961 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
|
962 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
963 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
|
964 } |
|
03624d7484fa
Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20385
diff
changeset
|
965 |
|
03624d7484fa
Better fix for core dumps on recursive objects in fast mode.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20385
diff
changeset
|
966 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
967 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
|
968 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
969 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
|
970 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
|
971 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
972 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
973 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
974 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
975 |
|
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
|
976 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
977 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
|
978 { |
|
35999
9541369b0dca
Add const to several API functions that take char *.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
34126
diff
changeset
|
979 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
|
980 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
|
981 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
|
982 |
|
27599
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
983 if (self->proto >= 2) { |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
984 char opcode = l ? NEWTRUE : NEWFALSE; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
985 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
|
986 return -1; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
987 } |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
988 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
|
989 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
|
990 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
|
991 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
992 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
993 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
994 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
|
995 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
996 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
|
997 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
|
998 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
|
999 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1000 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
|
1001 #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
|
1002 || l > 0x7fffffffL |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1003 || 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
|
1004 #endif |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1005 ) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1006 /* 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
|
1007 * 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
|
1008 */ |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1009 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
|
1010 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
|
1011 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
|
1012 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1013 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1014 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1015 /* 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
|
1016 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
|
1017 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
|
1018 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
|
1019 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
|
1020 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1021 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
|
1022 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
|
1023 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
|
1024 len = 2; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1025 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1026 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1027 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
|
1028 len = 3; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1029 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1030 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1031 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1032 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
|
1033 len = 5; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1034 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1035 |
|
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
|
1036 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
|
1037 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1038 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1039 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1040 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1041 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1042 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1043 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1044 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1045 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
|
1046 { |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1047 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
|
1048 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
|
1049 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
|
1050 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1051 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
|
1052 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1053 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
|
1054 /* 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
|
1055 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
|
1056 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
|
1057 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
|
1058 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
|
1059 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
|
1060 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
|
1061 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1062 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
|
1063 /* 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
|
1064 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
|
1065 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
|
1066 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
|
1067 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
|
1068 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
|
1069 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
|
1070 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1071 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
|
1072 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
|
1073 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
|
1074 /* 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
|
1075 * 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
|
1076 * 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
|
1077 * 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
|
1078 * 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
|
1079 * 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
|
1080 * 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
|
1081 * 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
|
1082 * 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
|
1083 * 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
|
1084 * 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
|
1085 * 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
|
1086 * 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
|
1087 */ |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1088 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
|
1089 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
|
1090 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
|
1091 "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
|
1092 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
|
1093 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1094 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
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 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
|
1100 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
|
1101 /* 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
|
1102 * 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
|
1103 * bits. |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1104 */ |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1105 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
|
1106 (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
|
1107 --nbytes; |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1108 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1114 else { |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1115 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
|
1116 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
|
1117 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
|
1118 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
|
1119 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
|
1120 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1121 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
|
1122 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1123 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
|
1124 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
|
1125 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
|
1126 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
|
1127 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
|
1128 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
|
1129 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1130 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
1131 /* 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
|
1132 * (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
|
1133 */ |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1134 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
|
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 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1137 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
|
1138 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1139 |
|
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
|
1140 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
|
1141 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1142 |
|
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
|
1143 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
|
1144 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
|
1145 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
|
1146 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1147 |
|
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
|
1148 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
|
1149 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1150 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1151 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1152 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1153 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1154 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
|
1155 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1156 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1157 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1158 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1159 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1160 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
|
1161 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1162 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
|
1163 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1164 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
|
1165 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
|
1166 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
|
1167 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
|
1168 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
|
1169 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
|
1170 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1171 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1172 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1173 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
|
1174 c_str[0] = FLOAT; |
|
38055
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37756
diff
changeset
|
1175 PyOS_ascii_formatd(c_str + 1, sizeof(c_str) - 2, "%.17g", x); |
|
fcc61835c6ac
Bug #1473625: stop cPickle making float dumps locale dependent in protocol 0.
Georg Brandl <georg@python.org>
parents:
37756
diff
changeset
|
1176 /* 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
|
1177 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
|
1178 |
|
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
|
1179 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
|
1180 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1181 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1182 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1183 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1184 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1185 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1186 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1187 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1188 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
|
1189 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1190 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
|
1191 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
|
1192 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1193 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
|
1194 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1195 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1196 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
|
1197 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
|
1198 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1199 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
|
1200 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1201 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
|
1202 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1203 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1204 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
|
1205 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
|
1206 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
|
1207 |
|
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
|
1208 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
|
1209 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1210 |
|
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
|
1211 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
|
1212 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1213 |
|
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
|
1214 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
|
1215 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1216 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1217 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
|
1218 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1219 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1220 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1221 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
|
1222 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1223 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
|
1224 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1225 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1226 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
|
1227 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
|
1228 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
|
1229 len = 2; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1230 } |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 len = 5; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1236 } |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1237 else |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1238 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
|
1239 |
|
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
|
1240 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
|
1241 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1242 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1243 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
|
1244 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
|
1245 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
|
1246 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1247 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
|
1248 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
|
1249 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
|
1250 (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
|
1251 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
|
1252 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1253 } |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1256 if (doput) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1257 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
|
1258 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1259 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1260 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1261 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1262 err: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1263 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
|
1264 return -1; |
| 4907 | 1265 } |
| 1266 | |
| 1267 | |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
1268 #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
|
1269 /* 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
|
1270 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
|
1271 static PyObject * |
|
50290
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1272 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
|
1273 { |
|
50290
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1274 PyObject *repr; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1275 char *p; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1276 char *q; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1277 |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1278 static const char *hexdigit = "0123456789abcdef"; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1279 #ifdef Py_UNICODE_WIDE |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1280 const Py_ssize_t expandsize = 10; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1281 #else |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1282 const Py_ssize_t expandsize = 6; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1283 #endif |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1284 |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1285 if (size > PY_SSIZE_T_MAX / expandsize) |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1286 return PyErr_NoMemory(); |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1287 |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1288 repr = PyString_FromStringAndSize(NULL, expandsize * size); |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1289 if (repr == NULL) |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1290 return NULL; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1291 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
|
1292 return repr; |
|
50290
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1293 |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1294 p = q = PyString_AS_STRING(repr); |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1295 while (size-- > 0) { |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1296 Py_UNICODE ch = *s++; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1297 #ifdef Py_UNICODE_WIDE |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1298 /* Map 32-bit characters to '\Uxxxxxxxx' */ |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1299 if (ch >= 0x10000) { |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1300 *p++ = '\\'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1301 *p++ = 'U'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1302 *p++ = hexdigit[(ch >> 28) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1303 *p++ = hexdigit[(ch >> 24) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1304 *p++ = hexdigit[(ch >> 20) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1305 *p++ = hexdigit[(ch >> 16) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1306 *p++ = hexdigit[(ch >> 12) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1307 *p++ = hexdigit[(ch >> 8) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1308 *p++ = hexdigit[(ch >> 4) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1309 *p++ = hexdigit[ch & 15]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1310 } |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1311 else |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1312 #else |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1313 /* Map UTF-16 surrogate pairs to '\U00xxxxxx' */ |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1314 if (ch >= 0xD800 && ch < 0xDC00) { |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1315 Py_UNICODE ch2; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1316 Py_UCS4 ucs; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1317 |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1318 ch2 = *s++; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1319 size--; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1320 if (ch2 >= 0xDC00 && ch2 <= 0xDFFF) { |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1321 ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1322 *p++ = '\\'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1323 *p++ = 'U'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1324 *p++ = hexdigit[(ucs >> 28) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1325 *p++ = hexdigit[(ucs >> 24) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1326 *p++ = hexdigit[(ucs >> 20) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1327 *p++ = hexdigit[(ucs >> 16) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1328 *p++ = hexdigit[(ucs >> 12) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1329 *p++ = hexdigit[(ucs >> 8) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1330 *p++ = hexdigit[(ucs >> 4) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1331 *p++ = hexdigit[ucs & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1332 continue; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1333 } |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1334 /* 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
|
1335 s--; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1336 size++; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1337 } |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1338 #endif |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1339 /* Map 16-bit characters to '\uxxxx' */ |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1340 if (ch >= 256 || ch == '\\' || ch == '\n') { |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1341 *p++ = '\\'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1342 *p++ = 'u'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1343 *p++ = hexdigit[(ch >> 12) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1344 *p++ = hexdigit[(ch >> 8) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1345 *p++ = hexdigit[(ch >> 4) & 0xf]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1346 *p++ = hexdigit[ch & 15]; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1347 } |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1348 /* Copy everything else as-is */ |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1349 else |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1350 *p++ = (char) ch; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1351 } |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1352 *p = '\0'; |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1353 _PyString_Resize(&repr, p - q); |
|
d27024755593
Merged revisions 67934-67935 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
49609
diff
changeset
|
1354 return repr; |
|
15607
59bfbbe581c2
Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents:
15011
diff
changeset
|
1355 } |
|
59bfbbe581c2
Minimal fix for the complaints about pickling Unicode objects. (SF
Guido van Rossum <guido@python.org>
parents:
15011
diff
changeset
|
1356 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1357 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1358 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
|
1359 { |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1360 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
|
1361 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
|
1362 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1363 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
|
1364 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1365 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1366 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
|
1367 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
|
1368 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
|
1369 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1370 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
|
1371 PyUnicode_AS_UNICODE(args), PyUnicode_GET_SIZE(args)); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1372 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
|
1373 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1374 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1375 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
|
1376 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
|
1377 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
|
1378 |
|
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
|
1379 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
|
1380 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1381 |
|
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
|
1382 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
|
1383 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1384 |
|
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
|
1385 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
|
1386 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1387 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1388 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
|
1389 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1390 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1391 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1392 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
|
1393 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1394 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
|
1395 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1396 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1397 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
|
1398 goto err; |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39348
diff
changeset
|
1399 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
|
1400 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
|
1401 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1402 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
|
1403 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
|
1404 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
|
1405 len = 5; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1406 |
|
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
|
1407 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
|
1408 goto err; |
|
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 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
|
1411 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
|
1412 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1413 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
|
1414 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1415 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1416 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
|
1417 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
|
1418 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1419 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1420 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1421 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
|
1422 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1423 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1424 if (doput) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1425 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
|
1426 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1427 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1428 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1429 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1430 err: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1431 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
|
1432 return -1; |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1433 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
1434 #endif |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
1435 |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1436 /* 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
|
1437 static int |
| 27687 | 1438 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
|
1439 { |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1440 int i; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1441 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
|
1442 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1443 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
|
1444 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1445 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
|
1446 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
|
1447 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1448 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
|
1449 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1450 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
|
1451 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1452 } |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1453 res = 0; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1454 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1455 finally: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1456 return res; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1457 } |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1458 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1459 /* 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
|
1460 * used across protocols to minimize the space needed to pickle them. |
| 27687 | 1461 * 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
|
1462 * (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
|
1463 * 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
|
1464 */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1465 static int |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1466 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
|
1467 { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1468 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
|
1469 int len, i; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1470 int res = -1; |
|
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 static char tuple = TUPLE; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1473 static char pop = POP; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1474 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
|
1475 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
|
1476 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1477 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
|
1478 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1479 |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1480 if (len == 0) { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1481 char c_str[2]; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1482 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1483 if (self->proto) { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1484 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
|
1485 len = 1; |
|
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 else { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1488 c_str[0] = MARK; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1489 c_str[1] = TUPLE; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1490 len = 2; |
|
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 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
|
1493 res = 0; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1494 /* 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
|
1495 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1496 } |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1497 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1498 /* A non-empty tuple. */ |
|
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 /* 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
|
1501 * 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
|
1502 * 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
|
1503 * 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
|
1504 */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1505 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
|
1506 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
|
1507 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1508 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1509 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
|
1510 /* Use TUPLE{1,2,3} opcodes. */ |
| 27687 | 1511 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
|
1512 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
|
1513 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
|
1514 /* pop the len elements */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1515 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
|
1516 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
|
1517 goto finally; |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1518 /* 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
|
1519 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
|
1520 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1521 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1522 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1523 } |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1524 /* Not recursive. */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1525 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
|
1526 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1527 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
|
1528 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1529 |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1530 /* 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
|
1531 * 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
|
1532 */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1533 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
|
1534 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1535 |
| 27687 | 1536 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
|
1537 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1538 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1539 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
|
1540 /* 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
|
1541 if (self->bin) { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1542 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
|
1543 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1544 } |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1545 else { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1546 /* 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
|
1547 * the MARK too. |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1548 */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1549 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
|
1550 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
|
1551 goto finally; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1552 } |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1553 /* fetch from memo */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1554 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
|
1555 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
|
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 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1558 |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1559 /* Not recursive. */ |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1560 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
|
1561 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1562 |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1563 memoize: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
1564 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
|
1565 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
|
1566 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1567 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1568 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
|
1569 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1570 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1571 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1572 /* 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
|
1573 * MARK item item ... item APPENDS |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1574 * 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
|
1575 * 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
|
1576 * Returns 0 on success, <0 on error. |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1577 */ |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1578 static int |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1579 batch_list(Picklerobject *self, PyObject *iter) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1580 { |
|
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
|
1581 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
|
1582 PyObject *firstitem = NULL; |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1583 int i, n; |
|
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 static char append = APPEND; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1586 static char appends = APPENDS; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1587 |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1588 assert(iter != NULL); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1589 |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1590 if (self->proto == 0) { |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1591 /* 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
|
1592 for (;;) { |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1593 obj = PyIter_Next(iter); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1594 if (obj == NULL) { |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1595 if (PyErr_Occurred()) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1596 return -1; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1597 break; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1598 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1599 i = save(self, obj, 0); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1600 Py_DECREF(obj); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1601 if (i < 0) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1602 return -1; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1603 if (self->write_func(self, &append, 1) < 0) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1604 return -1; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1605 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1606 return 0; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1607 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1608 |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1609 /* proto > 0: write in batches of BATCHSIZE. */ |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1610 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
|
1611 /* 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
|
1612 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
|
1613 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
|
1614 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
|
1615 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
|
1616 |
|
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 /* 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
|
1618 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
|
1619 } |
|
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 |
|
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 /* 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
|
1622 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
|
1623 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
|
1624 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
|
1625 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
|
1626 |
|
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 /* 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
|
1628 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
|
1629 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
|
1630 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
|
1631 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
|
1632 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
|
1633 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
|
1634 } |
|
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 |
|
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 /* 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
|
1637 |
|
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 /* 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
|
1639 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
|
1640 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
|
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 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
|
1643 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
|
1644 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
|
1645 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
|
1646 |
|
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 /* 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
|
1648 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
|
1649 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
|
1650 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
|
1651 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
|
1652 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
|
1653 |
|
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
|
1654 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
|
1655 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
|
1656 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1657 obj = PyIter_Next(iter); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1658 if (obj == NULL) { |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1659 if (PyErr_Occurred()) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1660 goto BatchFailed; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1661 break; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1662 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1663 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1664 |
|
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
|
1665 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
|
1666 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
|
1667 |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1668 } while (n == BATCHSIZE); |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1669 return 0; |
|
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 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
|
1672 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
|
1673 Py_XDECREF(obj); |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1674 return -1; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1675 } |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1676 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1677 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1678 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
|
1679 { |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1680 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
|
1681 char s[3]; |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1682 int len; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1683 PyObject *iter; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1684 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1685 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
|
1686 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1687 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1688 /* 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
|
1689 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
|
1690 s[0] = EMPTY_LIST; |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1691 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
|
1692 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1693 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1694 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
|
1695 s[1] = LIST; |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1696 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
|
1697 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1698 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1699 if (self->write_func(self, s, len) < 0) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1700 goto finally; |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1701 |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1702 /* 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
|
1703 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
|
1704 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1705 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1706 /* Memoize. */ |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1707 if (len == 0) { |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1708 if (put(self, args) >= 0) |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1709 res = 0; |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1710 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
|
1711 } |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1712 if (put2(self, args) < 0) |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1713 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
|
1714 |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1715 /* Materialize the list elements. */ |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1716 iter = PyObject_GetIter(args); |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1717 if (iter == NULL) |
|
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1718 goto finally; |
|
47856
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1719 |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1720 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
|
1721 { |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1722 res = batch_list(self, iter); |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1723 Py_LeaveRecursiveCall(); |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1724 } |
|
27822
19ac12ac8041
Implemented list batching in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27688
diff
changeset
|
1725 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
|
1726 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1727 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1728 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
|
1729 res = -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1730 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1731 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1732 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1733 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1734 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1735 /* 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
|
1736 * 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
|
1737 * 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
|
1738 * 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
|
1739 * 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
|
1740 * |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1741 * 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
|
1742 * 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
|
1743 * 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
|
1744 * 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
|
1745 */ |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1746 static int |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1747 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
|
1748 { |
|
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
|
1749 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
|
1750 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
|
1751 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
|
1752 |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1753 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
|
1754 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
|
1755 |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1756 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
|
1757 |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1758 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
|
1759 /* 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
|
1760 for (;;) { |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1761 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
|
1762 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
|
1763 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
|
1764 return -1; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1765 break; |
|
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 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
|
1768 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
|
1769 "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
|
1770 return -1; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1771 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1772 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
|
1773 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
|
1774 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
|
1775 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
|
1776 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
|
1777 return -1; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1778 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
|
1779 return -1; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1780 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1781 return 0; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1782 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1783 |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1784 /* 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
|
1785 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
|
1786 /* 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
|
1787 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
|
1788 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
|
1789 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
|
1790 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
|
1791 |
|
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 /* 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
|
1793 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
|
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 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
|
1796 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
|
1797 "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
|
1798 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
|
1799 } |
|
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 |
|
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 /* 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
|
1802 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
|
1803 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
|
1804 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
|
1805 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
|
1806 |
|
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 /* 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
|
1808 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
|
1809 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
|
1810 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
|
1811 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
|
1812 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
|
1813 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
|
1814 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
|
1815 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
|
1816 } |
|
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 |
|
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 /* 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
|
1819 |
|
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 /* 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
|
1821 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
|
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 |
|
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 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
|
1825 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
|
1826 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
|
1827 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
|
1828 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
|
1829 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
|
1830 |
|
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 /* 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
|
1832 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
|
1833 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
|
1834 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
|
1835 "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
|
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 } |
|
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 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
|
1839 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
|
1840 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
|
1841 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
|
1842 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
|
1843 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
|
1844 |
|
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
|
1845 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
|
1846 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
|
1847 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1848 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
|
1849 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
|
1850 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
|
1851 goto BatchFailed; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1852 break; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1853 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1854 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1855 |
|
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
|
1856 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
|
1857 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
|
1858 |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1859 } 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
|
1860 return 0; |
|
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 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
|
1863 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
|
1864 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
|
1865 return -1; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1866 } |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1867 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1868 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1869 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
|
1870 { |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1871 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
|
1872 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
|
1873 int len; |
|
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1874 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
|
1875 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1876 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
|
1877 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1878 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1879 /* 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
|
1880 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
|
1881 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
|
1882 len = 1; |
|
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 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1885 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
|
1886 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
|
1887 len = 2; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1888 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1889 |
|
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
|
1890 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
|
1891 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1892 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1893 /* 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
|
1894 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
|
1895 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1896 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1897 if (len == 0) { |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1898 if (put(self, args) >= 0) |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1899 res = 0; |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1900 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
|
1901 } |
|
27832
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1902 if (put2(self, args) < 0) |
|
7f171f9db8af
Minor cleanup of new batch-list/dict code.
Tim Peters <tim.peters@gmail.com>
parents:
27825
diff
changeset
|
1903 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
|
1904 |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1905 /* 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
|
1906 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
|
1907 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
|
1908 goto finally; |
|
47856
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1909 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
|
1910 { |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1911 res = batch_dict(self, iter); |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1912 Py_LeaveRecursiveCall(); |
|
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
1913 } |
|
27825
011f734258db
Implemented batching for dicts in cPickle. This is after two failed
Tim Peters <tim.peters@gmail.com>
parents:
27822
diff
changeset
|
1914 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
|
1915 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1916 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1917 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
|
1918 res = -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1919 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1920 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1921 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1922 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
1923 |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
1924 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1925 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
|
1926 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1927 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
|
1928 *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
|
1929 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
|
1930 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
|
1931 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1932 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
|
1933 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1934 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
|
1935 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1936 |
|
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
|
1937 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
|
1938 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1939 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1940 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
|
1941 goto finally; |
|
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 (self->bin) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1944 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
|
1945 goto finally; |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1948 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
|
1949 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
|
1950 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
|
1951 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1952 if (!( class_args = |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1953 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
|
1954 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1955 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1956 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
|
1957 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1958 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1959 for (i = 0; i < len; i++) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1960 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
|
1961 goto finally; |
|
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 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
|
1964 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
|
1965 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1966 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1967 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1968 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
|
1969 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1970 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1971 else { |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
1972 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
1973 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
1974 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
1975 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
|
1976 } |
|
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 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
|
1979 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
|
1980 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
|
1981 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1982 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1983 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
1984 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
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1987 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1988 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
|
1989 (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
|
1990 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1991 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1992 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
|
1993 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
|
1994 |
|
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
|
1995 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
|
1996 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
1997 |
|
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
|
1998 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
|
1999 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2000 |
|
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
|
2001 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
|
2002 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2003 |
|
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
|
2004 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
|
2005 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2006 |
|
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
|
2007 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
|
2008 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2009 } |
|
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
|
2010 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
|
2011 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2012 } |
|
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 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
|
2015 state = PyObject_Call(getstate_func, empty_tuple, NULL); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2016 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
|
2017 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2018 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2019 else { |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2020 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2021 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2022 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2023 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
|
2024 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2025 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
|
2026 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2027 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2028 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2029 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
|
2030 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2031 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2032 } |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2035 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
|
2036 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
|
2037 goto finally; |
|
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 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2040 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
|
2041 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2042 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2043 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2044 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
|
2045 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2046 |
|
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
|
2047 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
|
2048 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2049 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2050 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2051 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2052 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2053 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
|
2054 res = -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2055 |
|
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(module); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2057 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
|
2058 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
|
2059 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
|
2060 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
|
2061 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
|
2062 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2063 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2064 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2065 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2066 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2067 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2068 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
|
2069 { |
|
24209
a546593968d6
remove decl of unused variable
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24208
diff
changeset
|
2070 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
|
2071 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
|
2072 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
|
2073 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2074 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
|
2075 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2076 if (name) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2077 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
|
2078 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
|
2079 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2080 else { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2081 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
|
2082 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2083 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2084 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2085 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
|
2086 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2087 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2088 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
|
2089 (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
|
2090 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2091 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2092 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
|
2093 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
|
2094 |
|
26790
89c9c6c405ef
Add an XXX comment about relative imports.
Guido van Rossum <guido@python.org>
parents:
26561
diff
changeset
|
2095 /* 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
|
2096 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
|
2097 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
|
2098 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
|
2099 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
|
2100 "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
|
2101 "failed", |
|
a6962f52f239
save_global(): Trying to resolve module.name can fail for two
Tim Peters <tim.peters@gmail.com>
parents:
27903
diff
changeset
|
2102 "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
|
2103 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2104 } |
|
24208
efabc1511dc2
Do more robust test of whether global objects are accessible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24014
diff
changeset
|
2105 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
|
2106 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
|
2107 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
|
2108 "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
|
2109 "failed", |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2110 "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
|
2111 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2112 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2113 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
|
2114 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
|
2115 cPickle_ErrFormat(PicklingError, |
|
27684
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2116 "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
|
2117 "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
|
2118 "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
|
2119 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2120 } |
|
24208
efabc1511dc2
Do more robust test of whether global objects are accessible.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
24014
diff
changeset
|
2121 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
|
2122 |
|
27684
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2123 if (self->proto >= 2) { |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2124 /* 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
|
2125 * 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
|
2126 */ |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2127 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
|
2128 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
|
2129 char c_str[5]; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2130 int n; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2131 |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2132 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
|
2133 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
|
2134 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
|
2135 if (py_code == NULL) |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2136 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
|
2137 |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2138 /* 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
|
2139 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
|
2140 cPickle_ErrFormat(PicklingError, "Can't pickle %s: " |
| 27688 | 2141 "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
|
2142 "OO", args, py_code); |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2143 goto finally; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2144 } |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2145 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
|
2146 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
|
2147 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
|
2148 "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
|
2149 "Ol", args, code); |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2150 goto finally; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2151 } |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2152 |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2153 /* Generate an EXT opcode. */ |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2154 if (code <= 0xff) { |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2155 c_str[0] = EXT1; |
|
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; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2157 n = 2; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2158 } |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2159 else if (code <= 0xffff) { |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2160 c_str[0] = EXT2; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2161 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
|
2162 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
|
2163 n = 3; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2164 } |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2165 else { |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2166 c_str[0] = EXT4; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2167 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
|
2168 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
|
2169 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
|
2170 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
|
2171 n = 5; |
|
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 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
|
2175 res = 0; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2176 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
|
2177 } |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2178 |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
2179 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
|
2180 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
|
2181 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2182 |
|
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
|
2183 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
|
2184 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2185 |
|
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
|
2186 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
|
2187 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2188 |
|
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
|
2189 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
|
2190 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2191 |
|
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
|
2192 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
|
2193 goto finally; |
|
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 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
|
2196 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2197 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2198 res = 0; |
|
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 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2201 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
|
2202 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
|
2203 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
|
2204 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2205 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2206 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2207 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2208 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2209 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
|
2210 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2211 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
|
2212 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
|
2213 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2214 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
|
2215 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2216 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
|
2217 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
|
2218 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
|
2219 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
|
2220 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
|
2221 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2222 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
|
2223 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2224 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
|
2225 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
|
2226 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
|
2227 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
|
2228 "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
|
2229 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2230 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2231 |
|
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
|
2232 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
|
2233 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2234 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2235 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
|
2236 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2237 |
|
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
|
2238 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
|
2239 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
|
2240 (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
|
2241 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
|
2242 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2243 |
|
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
|
2244 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
|
2245 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2246 |
|
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 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2249 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2250 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
|
2251 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
|
2252 res = -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2253 else |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2254 res = 1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2255 } |
|
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 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2258 } |
|
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 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2261 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2262 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2263 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
|
2264 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2265 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2266 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2267 |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2268 /* 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
|
2269 * 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
|
2270 */ |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
2271 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
|
2272 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
|
2273 { |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2274 PyObject *callable; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2275 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
|
2276 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
|
2277 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
|
2278 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
|
2279 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
|
2280 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2281 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
|
2282 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2283 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
|
2284 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
|
2285 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
|
2286 |
|
49609
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49148
diff
changeset
|
2287 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
|
2288 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
|
2289 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
|
2290 "%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
|
2291 "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
|
2292 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
|
2293 } |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49148
diff
changeset
|
2294 |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2295 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
|
2296 &callable, |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2297 &argtup, |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2298 &state, |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2299 &listitems, |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2300 &dictitems)) |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2301 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2302 |
|
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
|
2303 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
|
2304 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
|
2305 "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
|
2306 "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
|
2307 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
|
2308 } |
|
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
|
2309 |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2310 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
|
2311 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
|
2312 |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2313 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
|
2314 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
|
2315 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
|
2316 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
|
2317 "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
|
2318 "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
|
2319 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
|
2320 } |
|
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49148
diff
changeset
|
2321 |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2322 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
|
2323 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
|
2324 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
|
2325 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
|
2326 "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
|
2327 "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
|
2328 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
|
2329 } |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2330 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2331 /* 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
|
2332 * 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
|
2333 */ |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2334 if (use_newobj) { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2335 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
|
2336 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2337 if (temp == NULL) { |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2338 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2339 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2340 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2341 return -1; |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2342 use_newobj = 0; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2343 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2344 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2345 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
|
2346 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
|
2347 "__newobj__") == 0; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2348 Py_DECREF(temp); |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2349 } |
|
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 if (use_newobj) { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2352 PyObject *cls; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2353 PyObject *newargtup; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2354 int n, i; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2355 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2356 /* Sanity checks. */ |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2357 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
|
2358 if (n < 1) { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2359 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
|
2360 "is empty"); |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2361 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2362 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2363 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2364 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
|
2365 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
|
2366 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
|
2367 "__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
|
2368 return -1; |
|
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 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2371 /* 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
|
2372 if (ob != NULL) { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2373 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
|
2374 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2375 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
|
2376 if (ob_dot_class == NULL) { |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2377 if (PyErr_ExceptionMatches( |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2378 PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2379 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2380 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2381 return -1; |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2382 } |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2383 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
|
2384 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
|
2385 if (i) { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2386 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
|
2387 "__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
|
2388 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2389 } |
|
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 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2392 /* 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
|
2393 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
|
2394 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2395 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2396 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
|
2397 if (newargtup == NULL) |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2398 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2399 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
|
2400 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
|
2401 Py_INCREF(temp); |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2402 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
|
2403 } |
| 43472 | 2404 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
|
2405 Py_DECREF(newargtup); |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2406 if (i < 0) |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2407 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2408 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2409 /* Add NEWOBJ opcode. */ |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2410 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
|
2411 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2412 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2413 else { |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2414 /* Not using NEWOBJ. */ |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2415 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
|
2416 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
|
2417 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
|
2418 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2419 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2420 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2421 /* Memoize. */ |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2422 /* 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
|
2423 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
|
2424 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
|
2425 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
|
2426 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2427 } |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2428 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
|
2429 return -1; |
|
27899
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 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2432 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2433 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
|
2434 return -1; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2435 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2436 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
|
2437 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
|
2438 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2439 if (state) { |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2440 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
|
2441 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
|
2442 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2443 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2444 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2445 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2446 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2447 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2448 static int |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
2449 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
|
2450 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2451 PyTypeObject *type; |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2452 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
|
2453 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
|
2454 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
|
2455 |
|
47856
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
2456 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
|
2457 return -1; |
|
24532
82c48653861b
Add recursion counter for pickling. Fixes #576084.
Martin v. Löwis <martin@v.loewis.de>
parents:
24471
diff
changeset
|
2458 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2459 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
|
2460 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
|
2461 res = tmp; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2462 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2463 } |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2466 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
|
2467 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
|
2468 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2469 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2470 |
|
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
|
2471 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
|
2472 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2473 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
|
2474 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
|
2475 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
|
2476 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
|
2477 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
|
2478 } |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22732
diff
changeset
|
2479 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2480 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
|
2481 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
|
2482 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
|
2483 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2484 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2485 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2486 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2487 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
|
2488 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
|
2489 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
|
2490 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2491 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2492 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2493 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2494 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
|
2495 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
|
2496 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
|
2497 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2498 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2499 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2500 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2501 case 't': |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
2502 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
|
2503 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
|
2504 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2505 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2506 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2507 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2508 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
|
2509 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
|
2510 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
|
2511 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2512 } |
|
47803
8b6c2856dbe5
Issue 3164. Small fix to don't repeat a comparation
Facundo Batista <facundobatista@gmail.com>
parents:
47587
diff
changeset
|
2513 break; |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2514 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
2515 #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
|
2516 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
|
2517 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
|
2518 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
|
2519 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2520 } |
|
47803
8b6c2856dbe5
Issue 3164. Small fix to don't repeat a comparation
Facundo Batista <facundobatista@gmail.com>
parents:
47587
diff
changeset
|
2521 break; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
2522 #endif |
|
22732
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 |
|
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
|
2525 if (Py_REFCNT(args) > 1) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2526 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
|
2527 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2528 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2529 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
|
2530 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
|
2531 goto finally; |
|
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 res = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2534 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2535 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2536 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2537 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2538 switch (type->tp_name[0]) { |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2539 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
|
2540 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
|
2541 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
|
2542 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2543 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2544 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2545 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
2546 #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
|
2547 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
|
2548 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
|
2549 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
|
2550 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2551 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2552 break; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
2553 #endif |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
2554 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2555 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
|
2556 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
|
2557 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
|
2558 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2559 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2560 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
|
2561 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
|
2562 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2563 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2564 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2565 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2566 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
|
2567 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
|
2568 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
|
2569 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2570 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2571 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2572 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2573 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
|
2574 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
|
2575 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
|
2576 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2577 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2578 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2579 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2580 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
|
2581 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
|
2582 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
|
2583 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2584 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2585 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2586 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2587 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
|
2588 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
|
2589 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
|
2590 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2591 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2592 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2593 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2594 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
|
2595 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
|
2596 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
|
2597 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
|
2598 /* fall back to reduce */ |
|
c6753db9c6af
made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents:
30683
diff
changeset
|
2599 PyErr_Clear(); |
|
c6753db9c6af
made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents:
30683
diff
changeset
|
2600 break; |
|
c6753db9c6af
made cPickle fall back to the copy_reg/reduce protocol,
Christian Tismer <tismer@stackless.com>
parents:
30683
diff
changeset
|
2601 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2602 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2603 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2604 break; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2605 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2606 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
|
2607 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
|
2608 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
|
2609 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2610 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2611 } |
|
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 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
|
2614 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
|
2615 res = tmp; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2616 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2617 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2618 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2619 |
|
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
|
2620 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
|
2621 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
|
2622 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
|
2623 } |
|
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
|
2624 |
| 27961 | 2625 /* 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
|
2626 * copy_reg.dispatch_table, the object's __reduce_ex__ method, |
| 27961 | 2627 * 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
|
2628 */ |
|
27876
8789e9822aa4
save(): Reformat tail end just for clarity.
Tim Peters <tim.peters@gmail.com>
parents:
27869
diff
changeset
|
2629 __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
|
2630 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
|
2631 Py_INCREF(__reduce__); |
| 27961 | 2632 Py_INCREF(args); |
| 2633 ARG_TUP(self, args); | |
| 2634 if (self->arg) { | |
| 2635 t = PyObject_Call(__reduce__, self->arg, NULL); | |
| 2636 FREE_ARG_TUP(self); | |
| 2637 } | |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2638 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2639 else { |
| 27961 | 2640 /* Check for a __reduce_ex__ method. */ |
| 2641 __reduce__ = PyObject_GetAttr(args, __reduce_ex___str); | |
| 2642 if (__reduce__ != NULL) { | |
| 2643 t = PyInt_FromLong(self->proto); | |
| 2644 if (t != NULL) { | |
| 2645 ARG_TUP(self, t); | |
| 2646 t = NULL; | |
| 2647 if (self->arg) { | |
| 2648 t = PyObject_Call(__reduce__, | |
| 2649 self->arg, NULL); | |
| 2650 FREE_ARG_TUP(self); | |
| 2651 } | |
| 2652 } | |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2653 } |
| 27961 | 2654 else { |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2655 if (PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2656 PyErr_Clear(); |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2657 else |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
2658 goto finally; |
| 27961 | 2659 /* Check for a __reduce__ method. */ |
| 2660 __reduce__ = PyObject_GetAttr(args, __reduce___str); | |
| 2661 if (__reduce__ != NULL) { | |
| 2662 t = PyObject_Call(__reduce__, | |
| 2663 empty_tuple, NULL); | |
| 2664 } | |
| 2665 else { | |
| 2666 PyErr_SetObject(UnpickleableError, args); | |
| 2667 goto finally; | |
| 2668 } | |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2669 } |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2670 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2671 |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2672 if (t == NULL) |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2673 goto finally; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2674 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2675 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
|
2676 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
|
2677 goto finally; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2678 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2679 |
|
49609
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49148
diff
changeset
|
2680 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
|
2681 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
|
2682 "%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
|
2683 "O", __reduce__); |
|
27899
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2684 goto finally; |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2685 } |
|
d0f4f3cd4fe4
cPickle produces NEWOBJ appropriately now. It still doesn't know
Tim Peters <tim.peters@gmail.com>
parents:
27882
diff
changeset
|
2686 |
|
49609
b3df58f76e49
Issue #4176: Pickle would crash the interpreter when a __reduce__ function
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
49148
diff
changeset
|
2687 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
|
2688 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2689 finally: |
|
47856
e14739c58401
Fix #2702, with a correct accounting of recursion.
Facundo Batista <facundobatista@gmail.com>
parents:
47828
diff
changeset
|
2690 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
|
2691 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
|
2692 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
|
2693 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
|
2694 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2695 return res; |
| 4907 | 2696 } |
| 2697 | |
| 2698 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2699 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2700 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
|
2701 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2702 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
|
2703 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2704 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
|
2705 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
|
2706 |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2707 bytes[0] = PROTO; |
|
27593
57bdf4bac435
dump(): Added asserts that self->proto is sane.
Tim Peters <tim.peters@gmail.com>
parents:
27592
diff
changeset
|
2708 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
|
2709 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
|
2710 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
|
2711 return -1; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2712 } |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2713 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2714 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
|
2715 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2716 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2717 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
|
2718 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2719 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
2720 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
|
2721 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2722 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2723 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2724 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2725 |
| 4907 | 2726 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2727 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
|
2728 { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2729 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
|
2730 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
|
2731 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
|
2732 return Py_None; |
|
9522
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2733 } |
|
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2734 |
|
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2735 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2736 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
|
2737 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2738 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
|
2739 long ik; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2740 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
|
2741 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
|
2742 Pdata *data; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2743 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2744 /* Can be called by Python code or C code */ |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2745 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
|
2746 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2747 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2748 /* 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
|
2749 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
|
2750 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
|
2751 "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
|
2752 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2753 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2754 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2755 /* 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
|
2756 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
|
2757 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2758 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
|
2759 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
|
2760 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2761 /* 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
|
2762 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
|
2763 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
|
2764 lm++; |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2765 have_get = malloc(lm); |
|
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2766 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
|
2767 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
|
2768 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2769 /* Scan for gets. */ |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2770 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
|
2771 k = data->data[i]; |
|
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2772 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2773 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
|
2774 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
|
2775 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2776 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
|
2777 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
|
2778 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
|
2779 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
|
2780 "Invalid get data"); |
|
39143
0e0a97ced8e9
Fix memory leaks spotted by Klocwork #37.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39135
diff
changeset
|
2781 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
|
2782 } |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2783 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
|
2784 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
|
2785 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2786 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2787 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
|
2788 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
|
2789 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
|
2790 ) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2791 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
|
2792 "Unexpected data in internal list"); |
|
39143
0e0a97ced8e9
Fix memory leaks spotted by Klocwork #37.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39135
diff
changeset
|
2793 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
|
2794 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2795 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2796 else { /* put */ |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2797 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
|
2798 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
|
2799 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
|
2800 "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
|
2801 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2802 } |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2803 have_get[ik] = 1; |
|
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2804 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
|
2805 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2806 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2807 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2808 /* 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
|
2809 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
|
2810 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
|
2811 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
|
2812 |
|
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2813 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
|
2814 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
|
2815 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
2816 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
|
2817 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
|
2818 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
|
2819 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
|
2820 while (--ssize >= 0) |
|
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2821 *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
|
2822 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2823 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2824 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2825 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
|
2826 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
|
2827 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
|
2828 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
|
2829 *s++ = BINGET; |
|
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 & 0xff); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2831 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2832 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2833 *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
|
2834 *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
|
2835 *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
|
2836 *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
|
2837 *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
|
2838 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2839 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2840 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2841 else { /* put */ |
|
27600
313e944a2c88
Minor cleanup, mostly adding horizontal whitespace, and breaking apart
Tim Peters <tim.peters@gmail.com>
parents:
27599
diff
changeset
|
2842 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
|
2843 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2844 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
|
2845 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
|
2846 *s++ = BINPUT; |
|
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 & 0xff); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2848 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2849 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2850 *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
|
2851 *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
|
2852 *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
|
2853 *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
|
2854 *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
|
2855 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2856 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2857 } |
|
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 if (clear) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2861 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
|
2862 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
|
2863 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2864 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2865 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
|
2866 return r; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2867 err: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2868 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
|
2869 return NULL; |
|
9522
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2870 } |
|
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2871 |
|
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
2872 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2873 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
|
2874 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2875 PyObject *ob; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2876 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
|
2877 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2878 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
|
2879 return 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 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
|
2882 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2883 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2884 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
|
2885 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2886 /* 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
|
2887 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
|
2888 return (PyObject*)self; |
| 4907 | 2889 } |
| 2890 | |
| 2891 | |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2892 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
|
2893 { |
|
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 {"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
|
2895 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
|
2896 "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
|
2897 {"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
|
2898 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
|
2899 {"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
|
2900 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
|
2901 {NULL, NULL} /* sentinel */ |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2902 }; |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2903 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2904 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
2905 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
|
2906 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
|
2907 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2908 Picklerobject *self; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2909 |
|
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
|
2910 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
|
2911 proto = HIGHEST_PROTOCOL; |
|
b4eb34372bdb
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27832
diff
changeset
|
2912 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
|
2913 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
|
2914 "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
|
2915 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
|
2916 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
|
2917 } |
|
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 |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
2919 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
|
2920 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
|
2921 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
|
2922 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
|
2923 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
|
2924 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
|
2925 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
|
2926 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
|
2927 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
|
2928 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
|
2929 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
|
2930 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
|
2931 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
|
2932 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
|
2933 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
|
2934 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
|
2935 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
|
2936 |
|
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
|
2937 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
|
2938 if (file) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2939 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
|
2940 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
|
2941 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
|
2942 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
|
2943 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
|
2944 } |
|
65635c72135e
The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents:
27580
diff
changeset
|
2945 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
|
2946 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2947 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
|
2948 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2949 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2950 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
|
2951 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
|
2952 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
|
2953 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
|
2954 "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
|
2955 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2956 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2957 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
|
2958 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2959 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
|
2960 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
|
2961 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2962 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
|
2963 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
|
2964 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2965 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2966 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
|
2967 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2968 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
|
2969 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
|
2970 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
|
2971 PyErr_Clear(); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
2972 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
|
2973 "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
|
2974 "attribute"); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2975 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2976 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2977 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2978 |
|
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
|
2979 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
|
2980 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
|
2981 PyErr_NoMemory(); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2982 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2983 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2984 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2985 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2986 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
|
2987 /* Restricted execution, get private tables */ |
|
57439
b51fda754f5a
Merged revisions 76499 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
55430
diff
changeset
|
2988 PyObject *m = PyImport_ImportModule("copy_reg"); |
|
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 |
|
3a528aa222b6
Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents:
27656
diff
changeset
|
2990 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
|
2991 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
|
2992 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
|
2993 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
|
2994 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
|
2995 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
|
2996 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
2997 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
|
2998 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
|
2999 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
|
3000 } |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3001 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
|
3002 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3003 return self; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3004 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3005 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
|
3006 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
|
3007 return NULL; |
| 4907 | 3008 } |
| 3009 | |
| 3010 | |
| 3011 static PyObject * | |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
3012 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
|
3013 { |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
3014 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
|
3015 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
|
3016 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
|
3017 |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
3018 /* XXX |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
3019 * 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
|
3020 * 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
|
3021 * 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
|
3022 * 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
|
3023 * 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
|
3024 */ |
|
65635c72135e
The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents:
27580
diff
changeset
|
3025 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
|
3026 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
|
3027 proto = 0; |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
3028 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
|
3029 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
|
3030 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3031 } |
|
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
|
3032 return (PyObject *)newPicklerobject(file, proto); |
| 4907 | 3033 } |
| 3034 | |
| 3035 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3036 static void |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3037 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
|
3038 { |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3039 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
|
3040 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
|
3041 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
|
3042 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
|
3043 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
|
3044 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
|
3045 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
|
3046 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
|
3047 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
|
3048 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
|
3049 Py_TYPE(self)->tp_free((PyObject *)self); |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3050 } |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3051 |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3052 static int |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3053 Pickler_traverse(Picklerobject *self, visitproc visit, void *arg) |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3054 { |
|
37756
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->write); |
|
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->memo); |
|
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->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
|
3058 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
|
3059 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
|
3060 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
|
3061 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
|
3062 Py_VISIT(self->dispatch_table); |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3063 return 0; |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3064 } |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3065 |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3066 static int |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3067 Pickler_clear(Picklerobject *self) |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3068 { |
|
37748
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->write); |
|
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->memo); |
|
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->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
|
3072 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
|
3073 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
|
3074 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
|
3075 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
|
3076 Py_CLEAR(self->dispatch_table); |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3077 return 0; |
| 4907 | 3078 } |
| 3079 | |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3080 static PyObject * |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3081 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
|
3082 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3083 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
|
3084 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
|
3085 else |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3086 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
|
3087 return p->pers_func; |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3088 } |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3089 |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3090 static int |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3091 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
|
3092 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3093 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
|
3094 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
|
3095 "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
|
3096 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3097 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3098 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
|
3099 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
|
3100 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
|
3101 return 0; |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3102 } |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3103 |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3104 static int |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3105 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
|
3106 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3107 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
|
3108 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
|
3109 "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
|
3110 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3111 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3112 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
|
3113 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
|
3114 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
|
3115 return 0; |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3116 } |
| 4907 | 3117 |
| 3118 static PyObject * | |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3119 Pickler_get_memo(Picklerobject *p) |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3120 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3121 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
|
3122 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
|
3123 else |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3124 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
|
3125 return p->memo; |
| 4907 | 3126 } |
| 3127 | |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3128 static int |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3129 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
|
3130 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3131 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
|
3132 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
|
3133 "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
|
3134 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3135 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3136 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
|
3137 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
|
3138 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3139 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3140 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
|
3141 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
|
3142 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
|
3143 return 0; |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3144 } |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3145 |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3146 static PyObject * |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3147 Pickler_get_error(Picklerobject *p) |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3148 { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3149 /* 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
|
3150 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
|
3151 return PicklingError; |
| 4907 | 3152 } |
| 3153 | |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3154 static PyMemberDef Pickler_members[] = { |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3155 {"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
|
3156 {"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
|
3157 {NULL} |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3158 }; |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3159 |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3160 static PyGetSetDef Pickler_getsets[] = { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3161 {"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
|
3162 (setter)Pickler_set_pers_func}, |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3163 {"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
|
3164 {"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
|
3165 {"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
|
3166 {NULL} |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3167 }; |
| 4907 | 3168 |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23332
diff
changeset
|
3169 PyDoc_STRVAR(Picklertype__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23332
diff
changeset
|
3170 "Objects that know how to pickle objects\n"); |
| 4907 | 3171 |
| 6774 | 3172 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
|
3173 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
|
3174 "cPickle.Pickler", /*tp_name*/ |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3175 sizeof(Picklerobject), /*tp_basicsize*/ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3176 0, |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3177 (destructor)Pickler_dealloc, /* tp_dealloc */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3178 0, /* tp_print */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3179 0, /* tp_getattr */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3180 0, /* tp_setattr */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3181 0, /* tp_compare */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3182 0, /* tp_repr */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3183 0, /* tp_as_number */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3184 0, /* tp_as_sequence */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3185 0, /* tp_as_mapping */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3186 0, /* tp_hash */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3187 0, /* tp_call */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3188 0, /* tp_str */ |
|
27104
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
26790
diff
changeset
|
3189 PyObject_GenericGetAttr, /* tp_getattro */ |
|
2443c557cbc3
Patch #661760: Cygwin auto-import module patch
Jason Tishler <jason@tishler.net>
parents:
26790
diff
changeset
|
3190 PyObject_GenericSetAttr, /* tp_setattro */ |
|
20385
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3191 0, /* tp_as_buffer */ |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3192 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
|
3193 Picklertype__doc__, /* tp_doc */ |
|
28567
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3194 (traverseproc)Pickler_traverse, /* tp_traverse */ |
|
bc8923fdd83b
Make Picklers collectable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28335
diff
changeset
|
3195 (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
|
3196 0, /* tp_richcompare */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3197 0, /* tp_weaklistoffset */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3198 0, /* tp_iter */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3199 0, /* tp_iternext */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3200 Pickler_methods, /* tp_methods */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3201 Pickler_members, /* tp_members */ |
|
be58eee69a94
Progress on SF bug #466175 and general cleanup.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19543
diff
changeset
|
3202 Pickler_getsets, /* tp_getset */ |
| 6774 | 3203 }; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3204 |
| 4907 | 3205 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3206 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
|
3207 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3208 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
|
3209 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3210 if (fc) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3211 if (fc==Py_None) { |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
3212 PyErr_SetString(UnpicklingError, "Global and instance " |
|
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
3213 "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
|
3214 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3215 } |
|
38314
1fdf29a88f0e
Replace PyObject_CallFunction calls with only object args
Georg Brandl <georg@python.org>
parents:
38055
diff
changeset
|
3216 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
|
3217 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
|
3218 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3219 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3220 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
|
3221 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
|
3222 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3223 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3224 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
|
3225 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
|
3226 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
|
3227 if (!module) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3228 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3229 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
|
3230 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
|
3231 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3232 else |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3233 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
|
3234 return global; |
| 4907 | 3235 } |
| 3236 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3237 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3238 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
|
3239 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3240 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
|
3241 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
|
3242 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3243 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3244 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3245 return self->marks[--self->num_marks]; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3246 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3247 |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
3248 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3249 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3250 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
|
3251 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3252 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
|
3253 return 0; |
| 4907 | 3254 } |
| 3255 | |
|
10097
f5f1b5e9814a
Jim Fulton: this fixes seg faults with bad pickles like "c".
Guido van Rossum <guido@python.org>
parents:
9948
diff
changeset
|
3256 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3257 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
|
3258 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3259 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
|
3260 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
|
3261 } |
| 4907 | 3262 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3263 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3264 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
|
3265 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3266 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
|
3267 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
|
3268 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
|
3269 long l; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3270 |
|
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
|
3271 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
|
3272 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
|
3273 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
|
3274 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3275 errno = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3276 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
|
3277 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3278 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
|
3279 /* 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
|
3280 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
|
3281 errno = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3282 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
|
3283 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
|
3284 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
|
3285 "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
|
3286 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3287 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3288 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3289 else { |
|
22851
ed03806d88cd
Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents:
22805
diff
changeset
|
3290 if (len == 3 && (l == 0 || l == 1)) { |
|
ed03806d88cd
Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents:
22805
diff
changeset
|
3291 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
|
3292 } |
|
ed03806d88cd
Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents:
22805
diff
changeset
|
3293 else { |
|
ed03806d88cd
Implement an idea by Paul Rubin:
Guido van Rossum <guido@python.org>
parents:
22805
diff
changeset
|
3294 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
|
3295 } |
|
22732
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 |
|
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 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
|
3300 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3301 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3302 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3303 free(s); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3304 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3305 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3306 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3307 |
|
27599
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
3308 static int |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
3309 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
|
3310 { |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
3311 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
|
3312 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
|
3313 return 0; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
3314 } |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
3315 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3316 /* 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
|
3317 * 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
|
3318 * 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
|
3319 * 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
|
3320 */ |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
3321 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
|
3322 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
|
3323 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3324 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
|
3325 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3326 long l; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3327 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3328 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
|
3329 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
|
3330 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
|
3331 } |
|
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
|
3332 #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
|
3333 /* 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
|
3334 * 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
|
3335 * 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
|
3336 */ |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3337 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
|
3338 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
|
3339 #endif |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3340 return l; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3341 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3342 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3343 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3344 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3345 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
|
3346 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3347 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
|
3348 long l; |
|
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 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
|
3351 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3352 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
|
3353 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3354 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3355 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
|
3356 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3357 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3358 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3359 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3360 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3361 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
|
3362 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3363 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3364 |
|
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
|
3365 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
|
3366 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3367 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3368 return load_binintx(self, s, 4); |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3369 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
3370 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3371 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3372 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3373 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
|
3374 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3375 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3376 |
|
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
|
3377 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
|
3378 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3379 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3380 return load_binintx(self, s, 1); |
| 4907 | 3381 } |
| 3382 | |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
3383 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3384 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3385 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
|
3386 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3387 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3388 |
|
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
|
3389 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
|
3390 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3391 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3392 return load_binintx(self, s, 2); |
| 4907 | 3393 } |
| 3394 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3395 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3396 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
|
3397 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3398 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
|
3399 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
|
3400 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
|
3401 |
|
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
|
3402 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
|
3403 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
|
3404 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
|
3405 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3406 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
|
3407 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3408 |
|
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 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
|
3411 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3412 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3413 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3414 free(s); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3415 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3416 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
|
3417 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3418 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3419 /* '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
|
3420 * 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
|
3421 */ |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3422 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
|
3423 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
|
3424 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
3425 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
|
3426 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
|
3427 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
|
3428 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
|
3429 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3430 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
|
3431 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
|
3432 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
|
3433 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3434 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
|
3435 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
|
3436 /* 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
|
3437 * this. |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3438 */ |
|
27656
ba3eaff49b7a
load_counted_long(): Changed a ValueError to an UnpicklingError, just
Tim Peters <tim.peters@gmail.com>
parents:
27643
diff
changeset
|
3439 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
|
3440 "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
|
3441 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
|
3442 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3443 |
|
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 (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
|
3445 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
|
3446 else { |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3447 /* Read the raw little-endian bytes & convert. */ |
| 27594 | 3448 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
|
3449 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
|
3450 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
|
3451 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
|
3452 } |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
3453 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
|
3454 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
|
3455 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
|
3456 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
|
3457 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3458 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3459 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3460 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
|
3461 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3462 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
|
3463 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
|
3464 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
|
3465 double d; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3466 |
|
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
|
3467 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
|
3468 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
|
3469 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
|
3470 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3471 errno = 0; |
|
32305
13656d58d450
Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents:
31592
diff
changeset
|
3472 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
|
3473 |
|
51020
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50522
diff
changeset
|
3474 if ((errno == ERANGE && !(fabs(d) <= 1.0)) || |
|
0139648526d9
Merged revisions 68903,68906 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
50522
diff
changeset
|
3475 (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
|
3476 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
|
3477 "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
|
3478 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3479 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3480 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3481 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
|
3482 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3483 |
|
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 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
|
3486 return 0; |
|
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 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3489 free(s); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3490 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3491 return res; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3492 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3493 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3494 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3495 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
|
3496 { |
|
28335
70003b0cb837
New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents:
28334
diff
changeset
|
3497 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
|
3498 double x; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3499 char *p; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3500 |
|
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
|
3501 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
|
3502 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3503 |
|
28335
70003b0cb837
New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents:
28334
diff
changeset
|
3504 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
|
3505 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
|
3506 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
|
3507 |
|
70003b0cb837
New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
Tim Peters <tim.peters@gmail.com>
parents:
28334
diff
changeset
|
3508 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
|
3509 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
|
3510 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
|
3511 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3512 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
|
3513 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3514 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3515 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3516 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3517 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
|
3518 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3519 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
|
3520 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
|
3521 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
|
3522 |
|
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
|
3523 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
|
3524 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
|
3525 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
|
3526 |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3527 |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3528 /* Strip outermost quotes */ |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3529 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
|
3530 len--; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3531 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
|
3532 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
|
3533 p = s + 1 ; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3534 len -= 2; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3535 } 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
|
3536 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
|
3537 p = s + 1 ; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3538 len -= 2; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3539 } else |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3540 goto insecure; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3541 /********************************************/ |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3542 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3543 str = PyString_DecodeEscape(p, len, NULL, 0, NULL); |
|
39348
7d6b97158180
Prevent memory leak on error.
Neal Norwitz <nnorwitz@gmail.com>
parents:
39143
diff
changeset
|
3544 free(s); |
|
24808
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3545 if (str) { |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3546 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
|
3547 res = 0; |
|
ab63af3ec349
Patch #505705: Remove eval in pickle and cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
24796
diff
changeset
|
3548 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3549 return res; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3550 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3551 insecure: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3552 free(s); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3553 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
|
3554 return -1; |
| 4907 | 3555 } |
| 3556 | |
| 3557 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3558 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3559 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
|
3560 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3561 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
|
3562 long l; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3563 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3564 |
|
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
|
3565 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
|
3566 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3567 l = calc_binint(s, 4); |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3568 if (l < 0) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3569 /* 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
|
3570 * this. |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3571 */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3572 PyErr_SetString(UnpicklingError, |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3573 "BINSTRING pickle has negative byte count"); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3574 return -1; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3575 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3576 |
|
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
|
3577 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
|
3578 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3579 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3580 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
|
3581 return -1; |
|
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 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
|
3584 return 0; |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3587 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3588 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3589 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
|
3590 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3591 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
|
3592 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
|
3593 char *s; |
|
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, 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
|
3596 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3597 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3598 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
|
3599 |
|
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
|
3600 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
|
3601 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3602 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
|
3603 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3604 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
|
3605 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
|
3606 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3607 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3608 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3609 #ifdef Py_USING_UNICODE |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3610 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3611 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
|
3612 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3613 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
|
3614 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
|
3615 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3616 |
|
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
|
3617 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
|
3618 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
|
3619 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3620 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
|
3621 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3622 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3623 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
|
3624 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3625 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3626 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3627 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
|
3628 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3629 #endif |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3630 |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3631 |
|
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3632 #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
|
3633 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3634 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
|
3635 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3636 PyObject *unicode; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3637 long l; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3638 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3639 |
|
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
|
3640 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
|
3641 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3642 l = calc_binint(s, 4); |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3643 if (l < 0) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3644 /* 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
|
3645 * this. |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3646 */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3647 PyErr_SetString(UnpicklingError, |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3648 "BINUNICODE pickle has negative byte count"); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3649 return -1; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47527
diff
changeset
|
3650 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3651 |
|
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
|
3652 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
|
3653 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3654 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3655 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
|
3656 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3657 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3658 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
|
3659 return 0; |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3660 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
3661 #endif |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3662 |
|
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3663 |
|
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
3664 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3665 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
|
3666 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3667 PyObject *tup; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3668 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3669 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3670 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
|
3671 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
|
3672 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
|
3673 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3674 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3675 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3676 static int |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3677 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
|
3678 { |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3679 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
|
3680 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3681 if (tup == NULL) |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3682 return -1; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3683 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3684 while (--len >= 0) { |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3685 PyObject *element; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3686 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3687 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
|
3688 if (element == NULL) |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3689 return -1; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
3690 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
|
3691 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3692 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
|
3693 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3694 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3695 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3696 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3697 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
|
3698 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3699 PyObject *list; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3700 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3701 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
|
3702 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
|
3703 return 0; |
| 4907 | 3704 } |
| 3705 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3706 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3707 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
|
3708 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3709 PyObject *dict; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3710 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3711 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
|
3712 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
|
3713 return 0; |
| 4907 | 3714 } |
| 3715 | |
| 3716 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3717 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3718 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
|
3719 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3720 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
|
3721 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3722 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3723 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
|
3724 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
|
3725 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
|
3726 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3727 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3728 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3729 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3730 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
|
3731 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3732 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
|
3733 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
|
3734 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3735 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
|
3736 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
|
3737 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3738 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
|
3739 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3740 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
|
3741 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
|
3742 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
|
3743 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
|
3744 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
|
3745 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3746 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3747 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3748 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
|
3749 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
|
3750 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3751 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3752 |
| 4907 | 3753 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3754 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
|
3755 { |
|
27573
674f3eecffc5
Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents:
27566
diff
changeset
|
3756 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
|
3757 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3758 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
|
3759 int l; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3760 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3761 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
|
3762 if (!( l )) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3763 PyObject *__getinitargs__; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3764 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3765 __getinitargs__ = PyObject_GetAttr(cls, |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
3766 __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
|
3767 if (!__getinitargs__) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3768 /* 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
|
3769 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
|
3770 PyObject *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 PyErr_Clear(); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3773 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
|
3774 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3775 return inst; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3776 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3777 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
|
3778 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3779 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3780 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
|
3781 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
|
3782 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3783 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3784 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
|
3785 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3786 err: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3787 { |
|
38949
56bf56f5c821
Fix bug #1512695: cPickle.loads could crash if it was interrupted with
Neal Norwitz <nnorwitz@gmail.com>
parents:
38489
diff
changeset
|
3788 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
|
3789 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3790 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
|
3791 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
|
3792 /* 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
|
3793 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
|
3794 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
|
3795 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
|
3796 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
|
3797 v=r; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3798 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3799 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
|
3800 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3801 return NULL; |
| 4907 | 3802 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
3803 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3804 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3805 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3806 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
|
3807 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3808 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
|
3809 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3810 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3811 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
|
3812 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
|
3813 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
|
3814 if (class) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3815 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
|
3816 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
|
3817 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3818 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
|
3819 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3820 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
|
3821 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
|
3822 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3823 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3824 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3825 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3826 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3827 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
|
3828 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3829 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
|
3830 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
|
3831 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3832 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3833 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
|
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) 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
|
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 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
|
3838 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
|
3839 |
|
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
|
3840 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
|
3841 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
|
3842 if ((class_name = PyString_FromStringAndSize(s, len - 1))) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3843 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
|
3844 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
|
3845 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
|
3846 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3847 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3848 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
|
3849 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3850 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
|
3851 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3852 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
|
3853 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
|
3854 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
|
3855 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3856 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
|
3857 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3858 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
|
3859 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3860 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
|
3861 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3862 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3863 |
|
27869
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3864 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
|
3865 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
|
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 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
|
3868 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
|
3869 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
|
3870 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
|
3871 |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3872 /* 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
|
3873 * 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
|
3874 */ |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3875 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
|
3876 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
|
3877 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
|
3878 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
|
3879 "tuple."); |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3880 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 } |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3882 |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3883 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
|
3884 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
|
3885 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
|
3886 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
|
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 "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
|
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 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
|
3892 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
|
3893 "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
|
3894 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 |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3897 /* 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
|
3898 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
|
3899 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
|
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 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
|
3902 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
|
3903 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
|
3904 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
|
3905 |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3906 Fail: |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
3907 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
|
3908 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
|
3909 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
|
3910 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3911 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3912 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3913 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
|
3914 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3915 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
|
3916 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3917 char *s; |
|
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) 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
|
3920 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
|
3921 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
|
3922 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
|
3923 |
|
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
|
3924 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
|
3925 if (len < 2) { |
|
12bc4a3e45af
A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents:
25290
diff
changeset
|
3926 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
|
3927 return bad_readline(); |
|
12bc4a3e45af
A patch from Kevin Jacobs, plugging several leaks discovered when
Tim Peters <tim.peters@gmail.com>
parents:
25290
diff
changeset
|
3928 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3929 if ((class_name = PyString_FromStringAndSize(s, len - 1))) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3930 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
|
3931 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
|
3932 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
|
3933 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3934 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3935 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
|
3936 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3937 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
|
3938 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
|
3939 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3940 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3941 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3942 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
3943 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3944 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
|
3945 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3946 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
|
3947 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3948 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3949 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3950 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
|
3951 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
|
3952 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
|
3953 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
3954 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
|
3955 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
|
3956 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3957 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
|
3958 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
|
3959 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
|
3960 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3961 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3962 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3963 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3964 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
|
3965 if (self->arg) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3966 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
|
3967 NULL); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3968 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
|
3969 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3970 } |
|
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 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
|
3973 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3974 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
|
3975 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3976 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3977 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3978 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
|
3979 "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
|
3980 "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
|
3981 return -1; |
|
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 } |
|
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 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
3986 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
|
3987 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3988 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
|
3989 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3990 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
|
3991 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
|
3992 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
|
3993 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3994 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
|
3995 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
|
3996 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
|
3997 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3998 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
3999 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4000 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4001 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
|
4002 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
|
4003 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
|
4004 NULL); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4005 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
|
4006 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4007 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
|
4008 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4009 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4010 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
|
4011 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4012 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4013 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4014 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
|
4015 "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
|
4016 "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
|
4017 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4018 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4019 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4020 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4021 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4022 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4023 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
|
4024 { |
|
54344
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4025 int len = self->stack->length; |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4026 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4027 /* 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
|
4028 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
|
4029 pop the right one. We do this by looking at the top of the |
|
54344
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4030 mark stack first, and only signalling a stack underflow if |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4031 the object stack is empty and the mark stack doesn't match |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4032 our expectations. |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4033 */ |
|
54344
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4034 if (self->num_marks > 0 && self->marks[self->num_marks - 1] == len) { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4035 self->num_marks--; |
|
58188
afe6dde80abb
Merged revisions 77352-77354 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
57439
diff
changeset
|
4036 } else if (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
|
4037 len--; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4038 Py_DECREF(self->stack->data[len]); |
|
54344
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4039 self->stack->length = len; |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4040 } else { |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4041 return stackUnderflow(); |
|
d3daad0e7f6f
Merged revisions 72930 via svnmerge from
Collin Winter <collinw@gmail.com>
parents:
51020
diff
changeset
|
4042 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4043 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4044 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4045 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4046 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4047 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4048 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
|
4049 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4050 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4051 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4052 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
|
4053 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4054 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4055 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
|
4056 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4057 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4058 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4059 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4060 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4061 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4062 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
|
4063 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4064 PyObject *last; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4065 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4066 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4067 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
|
4068 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
|
4069 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
|
4070 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
|
4071 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4072 } |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4075 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4076 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
|
4077 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4078 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
|
4079 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4080 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4081 int rc; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4082 |
|
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
|
4083 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
|
4084 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
|
4085 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
4086 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
|
4087 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4088 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
|
4089 if (! value) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4090 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
|
4091 rc = -1; |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4092 } |
|
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4093 else { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4094 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
|
4095 rc = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4096 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4097 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4098 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
|
4099 return rc; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4100 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4101 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4102 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4103 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4104 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
|
4105 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4106 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
|
4107 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
|
4108 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4109 int rc; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4110 |
|
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
|
4111 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
|
4112 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4113 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
|
4114 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
|
4115 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4116 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
|
4117 if (! value) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4118 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
|
4119 rc = -1; |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4120 } |
|
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4121 else { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4122 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
|
4123 rc = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4124 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4125 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4126 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
|
4127 return rc; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4128 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4129 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4130 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4131 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4132 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
|
4133 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4134 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
|
4135 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
|
4136 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4137 long key; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4138 int rc; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4139 |
|
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
|
4140 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
|
4141 |
|
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[0]; |
|
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; |
|
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[1]; |
|
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 << 8; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4146 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
|
4147 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
|
4148 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
|
4149 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
|
4150 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4151 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
|
4152 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4153 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
|
4154 if (! value) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4155 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
|
4156 rc = -1; |
|
27882
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4157 } |
|
46659675d7f7
Minor assorted cleanups; no semantic changes.
Tim Peters <tim.peters@gmail.com>
parents:
27879
diff
changeset
|
4158 else { |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4159 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
|
4160 rc = 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4161 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4162 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4163 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
|
4164 return rc; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4165 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4166 |
|
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
|
4167 /* 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
|
4168 * 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
|
4169 */ |
|
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 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
|
4171 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
|
4172 { |
|
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 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
|
4174 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
|
4175 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
|
4176 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
|
4177 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
|
4178 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
|
4179 |
|
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 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
|
4181 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
|
4182 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
|
4183 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
|
4184 /* 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
|
4185 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
|
4186 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
|
4187 } |
|
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 |
|
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 /* 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
|
4190 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
|
4191 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
|
4192 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
|
4193 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
|
4194 /* 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
|
4195 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
|
4196 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
|
4197 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
|
4198 } |
|
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 |
|
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 /* 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
|
4201 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
|
4202 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
|
4203 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
|
4204 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
|
4205 "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
|
4206 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
|
4207 } |
|
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
|
4208 /* Since the extension registry is manipulable via Python code, |
| 27667 | 4209 * 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
|
4210 */ |
|
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 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
|
4212 !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
|
4213 !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
|
4214 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
|
4215 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
|
4216 "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
|
4217 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
|
4218 } |
|
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 /* 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
|
4220 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
|
4221 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
|
4222 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
|
4223 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
|
4224 } |
|
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 /* 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
|
4226 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
|
4227 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
|
4228 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
|
4229 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
|
4230 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
|
4231 } |
|
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
|
4232 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
|
4233 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
|
4234 } |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4235 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4236 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4237 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
|
4238 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4239 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
|
4240 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
|
4241 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4242 |
|
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
|
4243 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
|
4244 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
|
4245 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
|
4246 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
|
4247 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
|
4248 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
|
4249 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
|
4250 return l; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4251 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4252 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4253 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4254 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4255 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
|
4256 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4257 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
|
4258 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
|
4259 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4260 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4261 |
|
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
|
4262 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
|
4263 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
|
4264 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4265 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
|
4266 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4267 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
|
4268 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
|
4269 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
|
4270 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
|
4271 return len; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4272 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4273 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4274 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4275 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4276 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
|
4277 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4278 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
|
4279 long key; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4280 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
|
4281 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4282 int len; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4283 |
|
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
|
4284 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
|
4285 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
|
4286 |
|
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[0]; |
|
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; |
|
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[1]; |
|
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 << 8; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4291 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
|
4292 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
|
4293 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
|
4294 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
|
4295 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4296 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
|
4297 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
|
4298 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
|
4299 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
|
4300 return len; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4301 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4302 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4303 |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
4304 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4305 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
|
4306 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4307 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
|
4308 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
|
4309 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4310 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
|
4311 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
|
4312 /* nothing to do */ |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4313 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
|
4314 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4315 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
|
4316 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4317 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
|
4318 PyObject *slice; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4319 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
|
4320 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4321 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
|
4322 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
|
4323 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
|
4324 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
|
4325 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
|
4326 return i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4327 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4328 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4329 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4330 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
|
4331 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4332 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4333 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
|
4334 PyObject *junk; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4335 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4336 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
|
4337 junk=0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4338 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
|
4339 if (self->arg) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4340 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
|
4341 NULL); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4342 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
|
4343 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4344 if (! junk) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4345 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
|
4346 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
|
4347 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
|
4348 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4349 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4350 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
|
4351 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4352 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
|
4353 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
|
4354 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4355 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4356 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4357 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4358 |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
4359 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4360 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4361 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
|
4362 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4363 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
|
4364 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4365 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4366 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4367 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4368 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
|
4369 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4370 return do_append(self, marker(self)); |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4371 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4372 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4373 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4374 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4375 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
|
4376 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4377 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
|
4378 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
|
4379 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4380 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
|
4381 && 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
|
4382 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4383 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
|
4384 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4385 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
|
4386 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
|
4387 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
|
4388 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
|
4389 r=-1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4390 break; |
|
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 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4393 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4394 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
|
4395 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4396 return r; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4397 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4398 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4399 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4400 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4401 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
|
4402 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4403 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
|
4404 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4405 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4406 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4407 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
|
4408 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4409 return do_setitems(self, marker(self)); |
| 4907 | 4410 } |
| 4411 | |
| 4412 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4413 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4414 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
|
4415 { |
|
27901
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4416 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
|
4417 PyObject *__setstate__; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4418 PyObject *d_key, *d_value; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
4419 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
|
4420 int res = -1; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4421 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4422 /* 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
|
4423 * 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
|
4424 */ |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4425 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
|
4426 return stackUnderflow(); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4427 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
|
4428 if (state == NULL) |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4429 return -1; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4430 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
|
4431 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4432 __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
|
4433 if (__setstate__ != NULL) { |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4434 PyObject *junk = NULL; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4435 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4436 /* 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
|
4437 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
|
4438 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
|
4439 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
|
4440 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
|
4441 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4442 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
|
4443 if (junk == NULL) |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4444 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
|
4445 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
|
4446 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4447 } |
|
29499
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
4448 if (!PyErr_ExceptionMatches(PyExc_AttributeError)) |
|
d0d4d696ab24
Remove many blanket try/except clauses.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
29201
diff
changeset
|
4449 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
|
4450 PyErr_Clear(); |
|
27901
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4451 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4452 /* 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
|
4453 * 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
|
4454 */ |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4455 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
|
4456 PyObject *temp = state; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4457 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
|
4458 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
|
4459 Py_INCREF(state); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4460 Py_INCREF(slotstate); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4461 Py_DECREF(temp); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4462 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4463 else |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4464 slotstate = NULL; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4465 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4466 /* 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
|
4467 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
|
4468 PyObject *dict; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4469 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
|
4470 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
|
4471 "dictionary"); |
|
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 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4474 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
|
4475 if (dict == NULL) |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4476 goto finally; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4477 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4478 i = 0; |
|
27901
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4479 while (PyDict_Next(state, &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
|
4480 if (PyObject_SetItem(dict, 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
|
4481 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
|
4482 } |
|
27901
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4483 Py_DECREF(dict); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4484 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4485 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4486 /* 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
|
4487 if (slotstate != NULL) { |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4488 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
|
4489 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
|
4490 "a dictionary"); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4491 goto finally; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4492 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4493 i = 0; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4494 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
|
4495 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
|
4496 goto finally; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4497 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4498 } |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4499 res = 0; |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4500 |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4501 finally: |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4502 Py_DECREF(state); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4503 Py_XDECREF(slotstate); |
|
55adf08a213a
cPickle.c, load_build(): Taught cPickle how to pick apart
Tim Peters <tim.peters@gmail.com>
parents:
27899
diff
changeset
|
4504 return res; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4505 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4506 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4507 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4508 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4509 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
|
4510 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4511 int s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4512 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4513 /* 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
|
4514 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
|
4515 mark stack. |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4518 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
|
4519 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
|
4520 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
|
4521 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
|
4522 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
|
4523 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
|
4524 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
|
4525 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
|
4526 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
|
4527 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
|
4528 PyErr_NoMemory(); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4529 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4530 } |
|
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 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
|
4532 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
|
4533 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4534 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4535 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
|
4536 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4537 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4538 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4539 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4540 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4541 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
|
4542 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4543 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
|
4544 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4545 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
|
4546 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
|
4547 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
|
4548 if (callable) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4549 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
|
4550 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
|
4551 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4552 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
|
4553 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4554 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
|
4555 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4556 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
|
4557 return 0; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4558 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
4559 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4560 /* 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
|
4561 * 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
|
4562 */ |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4563 static int |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4564 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
|
4565 { |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4566 int i; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4567 char *protobyte; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4568 |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4569 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
|
4570 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
|
4571 return -1; |
|
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 = 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
|
4574 /* 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
|
4575 * 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
|
4576 */ |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4577 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
|
4578 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
|
4579 return 0; |
|
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 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
|
4582 return -1; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4583 } |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4584 |
| 4907 | 4585 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4586 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
|
4587 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4588 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
|
4589 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4590 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4591 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
|
4592 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
|
4593 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4594 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
|
4595 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
|
4596 break; |
|
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 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
|
4599 case NONE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4600 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
|
4601 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4602 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4603 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4604 case BININT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4605 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
|
4606 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4607 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4608 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4609 case BININT1: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4610 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
|
4611 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4612 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4613 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4614 case BININT2: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4615 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
|
4616 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4617 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4618 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4619 case INT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4620 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
|
4621 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4622 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4623 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4624 case LONG: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4625 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
|
4626 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4627 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4628 |
|
27585
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4629 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
|
4630 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
|
4631 break; |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4632 continue; |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4633 |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4634 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
|
4635 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
|
4636 break; |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4637 continue; |
|
a05814184e8c
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Tim Peters <tim.peters@gmail.com>
parents:
27584
diff
changeset
|
4638 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4639 case FLOAT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4640 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
|
4641 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4642 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4643 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4644 case BINFLOAT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4645 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
|
4646 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4647 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4648 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4649 case BINSTRING: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4650 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
|
4651 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4652 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4653 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4654 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
|
4655 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
|
4656 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4657 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4658 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4659 case STRING: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4660 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
|
4661 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4662 continue; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
4663 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
4664 #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
|
4665 case UNICODE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4666 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
|
4667 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4668 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4669 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4670 case BINUNICODE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4671 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
|
4672 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4673 continue; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
4674 #endif |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
4675 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4676 case EMPTY_TUPLE: |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4677 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
|
4678 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4679 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4680 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4681 case TUPLE1: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4682 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
|
4683 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4684 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4685 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4686 case TUPLE2: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4687 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
|
4688 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4689 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4690 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4691 case TUPLE3: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
4692 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
|
4693 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4694 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4695 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4696 case TUPLE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4697 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
|
4698 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4699 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4700 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4701 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
|
4702 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
|
4703 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4704 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4705 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4706 case LIST: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4707 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
|
4708 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4709 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4710 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4711 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
|
4712 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
|
4713 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4714 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4715 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4716 case DICT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4717 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
|
4718 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4719 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4720 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4721 case OBJ: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4722 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
|
4723 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4724 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4725 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4726 case INST: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4727 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
|
4728 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4729 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4730 |
|
27869
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
4731 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
|
4732 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
|
4733 break; |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
4734 continue; |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
4735 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4736 case GLOBAL: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4737 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
|
4738 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4739 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4740 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4741 case APPEND: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4742 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
|
4743 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4744 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4745 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4746 case APPENDS: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4747 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
|
4748 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4749 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4750 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4751 case BUILD: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4752 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
|
4753 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4754 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4755 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4756 case DUP: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4757 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
|
4758 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4759 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4760 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4761 case BINGET: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4762 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
|
4763 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4764 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4765 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4766 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
|
4767 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
|
4768 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4769 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4770 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4771 case GET: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4772 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
|
4773 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4774 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4775 |
|
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
|
4776 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
|
4777 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
|
4778 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
|
4779 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
|
4780 |
|
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 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
|
4782 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
|
4783 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
|
4784 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
|
4785 |
|
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 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
|
4787 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
|
4788 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
|
4789 continue; |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4790 case MARK: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4791 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
|
4792 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4793 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4794 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4795 case BINPUT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4796 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
|
4797 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4798 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4799 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4800 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
|
4801 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
|
4802 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4803 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4804 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4805 case PUT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4806 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
|
4807 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4808 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4809 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4810 case POP: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4811 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
|
4812 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4813 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4814 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4815 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
|
4816 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
|
4817 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4818 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4819 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4820 case SETITEM: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4821 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
|
4822 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4823 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4824 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4825 case SETITEMS: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4826 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
|
4827 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4828 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4829 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4830 case STOP: |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4833 case PERSID: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4834 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
|
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 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4837 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4838 case BINPERSID: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4839 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
|
4840 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4841 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4842 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4843 case REDUCE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4844 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
|
4845 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4846 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4847 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4848 case PROTO: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4849 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
|
4850 break; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4851 continue; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
4852 |
|
27599
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4853 case NEWTRUE: |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4854 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
|
4855 break; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4856 continue; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4857 |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4858 case NEWFALSE: |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4859 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
|
4860 break; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4861 continue; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
4862 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4863 case '\0': |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4864 /* 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
|
4865 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
|
4866 break; |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4867 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4868 default: |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4869 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
|
4870 "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
|
4871 "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
|
4872 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4873 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4874 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4875 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4876 } |
|
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 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
|
4879 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
|
4880 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
|
4881 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4882 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4883 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4884 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4885 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
|
4886 return val; |
| 4907 | 4887 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
4888 |
| 4907 | 4889 |
|
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
|
4890 /* 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
|
4891 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
|
4892 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4893 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4894 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
|
4895 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4896 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4897 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4898 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
|
4899 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
|
4900 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4901 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4902 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4903 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4904 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
|
4905 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4906 int i; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4907 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4908 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4909 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
|
4910 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
|
4911 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
|
4912 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
|
4913 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
|
4914 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
|
4915 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4916 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4917 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
|
4918 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
|
4919 { |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
4920 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
|
4921 |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
4922 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
|
4923 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
|
4924 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
|
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 cls */ |
|
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_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
|
4931 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
|
4932 } |
|
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 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4935 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
|
4936 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4937 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4938 |
|
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
|
4939 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
|
4940 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
|
4941 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
|
4942 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
|
4943 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4944 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4945 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4946 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
|
4947 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4948 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4949 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
|
4950 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
|
4951 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
|
4952 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
|
4953 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4954 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4955 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
|
4956 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
|
4957 |
|
9522
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
4958 if (self->stack->length < 1) return stackUnderflow(); |
|
a1a8df73bfff
New version from Jim Fulton:
Guido van Rossum <guido@python.org>
parents:
8999
diff
changeset
|
4959 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
|
4960 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
|
4961 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4962 |
|
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
|
4963 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
|
4964 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
|
4965 { |
|
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
|
4966 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
|
4967 |
|
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 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
|
4969 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
|
4970 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
|
4971 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
|
4972 } |
|
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 |
|
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
|
4974 |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
4975 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
4976 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
|
4977 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4978 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
|
4979 char *s; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4980 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4981 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
|
4982 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
|
4983 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4984 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
|
4985 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
|
4986 break; |
|
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 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
|
4989 case NONE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4990 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
|
4991 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4992 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4993 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4994 case BININT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4995 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
|
4996 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4997 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4998 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
4999 case BININT1: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5000 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
|
5001 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5002 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5003 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5004 case BININT2: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5005 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
|
5006 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5007 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5008 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5009 case INT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5010 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
|
5011 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5012 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5013 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5014 case LONG: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5015 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
|
5016 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5017 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5018 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5019 case LONG1: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5020 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
|
5021 break; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5022 continue; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5023 |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5024 case LONG4: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5025 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
|
5026 break; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5027 continue; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5028 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5029 case FLOAT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5030 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
|
5031 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5032 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5033 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5034 case BINFLOAT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5035 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
|
5036 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5037 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5038 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5039 case BINSTRING: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5040 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
|
5041 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5042 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5043 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5044 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
|
5045 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
|
5046 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5047 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5048 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5049 case STRING: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5050 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
|
5051 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5052 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
|
5053 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
5054 #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
|
5055 case UNICODE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5056 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
|
5057 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5058 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5059 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5060 case BINUNICODE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5061 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
|
5062 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5063 continue; |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18933
diff
changeset
|
5064 #endif |
|
11982
a13294aef02e
Marc-Andre Lemburg: support pickling Unicode objects, both in text
Guido van Rossum <guido@python.org>
parents:
11882
diff
changeset
|
5065 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5066 case EMPTY_TUPLE: |
|
27615
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5067 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
|
5068 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5069 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5070 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5071 case TUPLE1: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5072 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
|
5073 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5074 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5075 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5076 case TUPLE2: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5077 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
|
5078 break; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5079 continue; |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5080 |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5081 case TUPLE3: |
|
45ad77a43d87
cPickle support for TUPLE[123]. Incidentally plugged several undetected
Tim Peters <tim.peters@gmail.com>
parents:
27601
diff
changeset
|
5082 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
|
5083 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5084 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5085 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5086 case TUPLE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5087 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
|
5088 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5089 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5090 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5091 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
|
5092 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
|
5093 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5094 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5095 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5096 case LIST: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5097 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
|
5098 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5099 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5100 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5101 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
|
5102 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
|
5103 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5104 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5105 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5106 case DICT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5107 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
|
5108 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5109 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5110 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5111 case OBJ: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5112 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
|
5113 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5114 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5115 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5116 case INST: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5117 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
|
5118 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5119 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5120 |
|
27869
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
5121 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
|
5122 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
|
5123 break; |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
5124 continue; |
|
870cf14add2a
Taught cPickle how to read pickles containing NEWOBJ. This won't get
Tim Peters <tim.peters@gmail.com>
parents:
27864
diff
changeset
|
5125 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5126 case GLOBAL: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5127 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
|
5128 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5129 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5130 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5131 case APPEND: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5132 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
|
5133 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5134 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5135 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5136 case APPENDS: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5137 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
|
5138 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5139 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5140 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5141 case BUILD: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5142 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
|
5143 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5144 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5145 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5146 case DUP: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5147 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
|
5148 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5149 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5150 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5151 case BINGET: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5152 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
|
5153 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5154 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5155 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5156 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
|
5157 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
|
5158 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5159 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5160 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5161 case GET: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5162 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
|
5163 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5164 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5165 |
|
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
|
5166 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
|
5167 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
|
5168 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
|
5169 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
|
5170 |
|
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 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
|
5172 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
|
5173 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
|
5174 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
|
5175 |
|
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 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
|
5177 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
|
5178 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
|
5179 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
|
5180 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5181 case MARK: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5182 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
|
5183 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5184 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5185 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5186 case BINPUT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5187 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
|
5188 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5189 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5190 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5191 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
|
5192 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
|
5193 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5194 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5195 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5196 case PUT: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5197 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
|
5198 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5199 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5200 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5201 case POP: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5202 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
|
5203 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5204 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5205 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5206 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
|
5207 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
|
5208 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5209 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5210 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5211 case SETITEM: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5212 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
|
5213 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5214 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5215 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5216 case SETITEMS: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5217 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
|
5218 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5219 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5220 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5221 case STOP: |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5224 case PERSID: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5225 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
|
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 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5228 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5229 case BINPERSID: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5230 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
|
5231 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5232 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5233 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5234 case REDUCE: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5235 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
|
5236 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5237 continue; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5238 |
|
27591
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5239 case PROTO: |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5240 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
|
5241 break; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5242 continue; |
|
d6b65e3855a2
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
Tim Peters <tim.peters@gmail.com>
parents:
27585
diff
changeset
|
5243 |
|
27599
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5244 case NEWTRUE: |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5245 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
|
5246 break; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5247 continue; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5248 |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5249 case NEWFALSE: |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5250 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
|
5251 break; |
|
d158d10ef4ae
Implemented proto 2 NEWTRUE and NEWFALSE in cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27596
diff
changeset
|
5252 continue; |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5253 default: |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5254 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
|
5255 "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
|
5256 "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
|
5257 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5258 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5259 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5260 break; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5261 } |
|
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 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
|
5264 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
|
5265 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
|
5266 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5267 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5268 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5269 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5270 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
|
5271 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
|
5272 } |
|
17062
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
5273 |
|
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
|
5274 |
| 4907 | 5275 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5276 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
|
5277 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5278 return load(self); |
| 4907 | 5279 } |
| 5280 | |
|
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
|
5281 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5282 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
|
5283 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5284 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
|
5285 } |
|
1853b5bc0548
New versions of cPickle and cStringIO, from Jim Fulton's cPickle 1.0b1
Guido van Rossum <guido@python.org>
parents:
6692
diff
changeset
|
5286 |
| 4907 | 5287 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5288 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
|
5289 {"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
|
5290 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
|
5291 }, |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5292 {"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
|
5293 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
|
5294 "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
|
5295 "\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
|
5296 "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
|
5297 "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
|
5298 "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
|
5299 "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
|
5300 }, |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5301 {NULL, NULL} /* sentinel */ |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5302 }; |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5303 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5304 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5305 static Unpicklerobject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5306 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
|
5307 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5308 Unpicklerobject *self; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5309 |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5310 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
|
5311 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5312 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5313 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
|
5314 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
|
5315 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
|
5316 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
|
5317 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
|
5318 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
|
5319 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
|
5320 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
|
5321 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
|
5322 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
|
5323 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
|
5324 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
|
5325 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5326 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
|
5327 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5328 |
|
39135
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38949
diff
changeset
|
5329 if (!self->stack) |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38949
diff
changeset
|
5330 goto err; |
|
12e973bdfeee
Fix more memory allocation issues found with failmalloc.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38949
diff
changeset
|
5331 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5332 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
|
5333 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
|
5334 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5335 /* 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
|
5336 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
|
5337 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
|
5338 if (self->fp == NULL) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5339 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
|
5340 "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
|
5341 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5342 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5343 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
|
5344 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
|
5345 } |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5346 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
|
5347 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
|
5348 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
|
5349 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
|
5350 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5351 else { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5352 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5353 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
|
5354 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
|
5355 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
|
5356 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5357 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
|
5358 (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
|
5359 PyErr_Clear(); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5360 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
|
5361 "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
|
5362 "'readline' attributes" ); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5363 goto err; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5364 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5365 } |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5366 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
|
5367 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5368 return self; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5369 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5370 err: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5371 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
|
5372 return NULL; |
| 4907 | 5373 } |
| 5374 | |
| 5375 | |
| 5376 static PyObject * | |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5377 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
|
5378 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5379 return (PyObject *)newUnpicklerobject(file); |
| 4907 | 5380 } |
| 5381 | |
| 5382 | |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5383 static void |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5384 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
|
5385 { |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5386 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
|
5387 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
|
5388 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
|
5389 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
|
5390 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
|
5391 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
|
5392 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
|
5393 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
|
5394 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
|
5395 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
|
5396 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5397 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
|
5398 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
|
5399 } |
|
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->buf_size) { |
|
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->buf); |
|
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 |
|
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
|
5405 Py_TYPE(self)->tp_free((PyObject *)self); |
| 4907 | 5406 } |
| 5407 | |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5408 static int |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5409 Unpickler_traverse(Unpicklerobject *self, visitproc visit, void *arg) |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5410 { |
|
37756
7b2e436a4a21
Use Py_VISIT in all tp_traverse methods, instead of traversing manually or
Thomas Wouters <thomas@python.org>
parents:
37748
diff
changeset
|
5411 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
|
5412 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
|
5413 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
|
5414 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
|
5415 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
|
5416 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
|
5417 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
|
5418 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
|
5419 Py_VISIT(self->find_class); |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5420 return 0; |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5421 } |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5422 |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5423 static int |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5424 Unpickler_clear(Unpicklerobject *self) |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5425 { |
|
37748
d1547426ab61
Use Py_CLEAR instead of in-place DECREF/XDECREF or custom macros, for
Thomas Wouters <thomas@python.org>
parents:
37555
diff
changeset
|
5426 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
|
5427 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
|
5428 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
|
5429 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
|
5430 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
|
5431 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
|
5432 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
|
5433 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
|
5434 Py_CLEAR(self->find_class); |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5435 return 0; |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5436 } |
| 4907 | 5437 |
| 5438 static PyObject * | |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5439 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
|
5440 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5441 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
|
5442 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
|
5443 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
|
5444 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5445 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5446 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5447 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
|
5448 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
|
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 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
|
5452 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
|
5453 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
|
5454 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5455 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5456 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5457 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
|
5458 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
|
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 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
|
5462 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
|
5463 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
|
5464 return NULL; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5465 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5466 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5467 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
|
5468 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
|
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 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
|
5472 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
|
5473 return UnpicklingError; |
|
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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5476 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
|
5477 } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5478 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5479 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5480 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5481 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
|
5482 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5483 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5484 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
|
5485 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
|
5486 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
|
5487 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
|
5488 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5489 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5490 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5491 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
|
5492 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
|
5493 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
|
5494 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
|
5495 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5496 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5497 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5498 if (! value) { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5499 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
|
5500 "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
|
5501 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5502 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5503 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5504 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
|
5505 if (!PyDict_Check(value)) { |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5506 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
|
5507 "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
|
5508 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5509 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5510 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
|
5511 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
|
5512 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
|
5513 return 0; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5514 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5515 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5516 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
|
5517 return -1; |
| 4907 | 5518 } |
| 5519 | |
|
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
|
5520 /* --------------------------------------------------------------------------- |
|
65635c72135e
The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents:
27580
diff
changeset
|
5521 * 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
|
5522 */ |
|
65635c72135e
The C pickle now knows how to deal with a proto= argument. Assorted
Tim Peters <tim.peters@gmail.com>
parents:
27580
diff
changeset
|
5523 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5524 /* dump(obj, file, protocol=0). */ |
| 4907 | 5525 static PyObject * |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5526 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
|
5527 { |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
5528 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
|
5529 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
|
5530 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
|
5531 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
|
5532 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5533 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
|
5534 &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
|
5535 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5536 |
|
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
|
5537 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
|
5538 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5539 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5540 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
|
5541 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5542 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5543 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
|
5544 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
|
5545 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5546 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5547 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
|
5548 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5549 return res; |
| 4907 | 5550 } |
| 5551 | |
| 5552 | |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5553 /* dumps(obj, protocol=0). */ |
| 4907 | 5554 static PyObject * |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5555 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
|
5556 { |
|
36675
dba6494735d0
Revert backwards-incompatible const changes.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
5557 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
|
5558 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
|
5559 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
|
5560 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
|
5561 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5562 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
|
5563 &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
|
5564 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5565 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5566 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
|
5567 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5568 |
|
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
|
5569 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
|
5570 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5571 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5572 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
|
5573 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5574 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5575 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
|
5576 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5577 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5578 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
|
5579 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
|
5580 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5581 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
|
5582 } |
|
33c8680b3b35
SF bug [ #233200 ] cPickle does not use Py_BEGIN_ALLOW_THREADS.
Tim Peters <tim.peters@gmail.com>
parents:
15607
diff
changeset
|
5583 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5584 |
|
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
|
5585 /* load(fileobj). */ |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5586 static PyObject * |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5587 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
|
5588 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5589 Unpicklerobject *unpickler = 0; |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5590 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
|
5591 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5592 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
|
5593 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5594 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5595 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
|
5596 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5597 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5598 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
|
5599 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5600 return res; |
| 4907 | 5601 } |
| 5602 | |
| 5603 | |
|
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
|
5604 /* loads(string) */ |
| 4907 | 5605 static PyObject * |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5606 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
|
5607 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5608 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
|
5609 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
|
5610 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5611 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
|
5612 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5613 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5614 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
|
5615 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5616 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5617 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
|
5618 goto finally; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5619 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5620 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
|
5621 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5622 finally: |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5623 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
|
5624 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
|
5625 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5626 return res; |
| 4907 | 5627 } |
| 5628 | |
| 5629 | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23332
diff
changeset
|
5630 PyDoc_STRVAR(Unpicklertype__doc__, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
23332
diff
changeset
|
5631 "Objects that know how to unpickle"); |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5632 |
| 6774 | 5633 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
|
5634 PyVarObject_HEAD_INIT(NULL, 0) |
|
28568
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5635 "cPickle.Unpickler", /*tp_name*/ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5636 sizeof(Unpicklerobject), /*tp_basicsize*/ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5637 0, |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5638 (destructor)Unpickler_dealloc, /* tp_dealloc */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5639 0, /* tp_print */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5640 (getattrfunc)Unpickler_getattr, /* tp_getattr */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5641 (setattrfunc)Unpickler_setattr, /* tp_setattr */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5642 0, /* tp_compare */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5643 0, /* tp_repr */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5644 0, /* tp_as_number */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5645 0, /* tp_as_sequence */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5646 0, /* tp_as_mapping */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5647 0, /* tp_hash */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5648 0, /* tp_call */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5649 0, /* tp_str */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5650 0, /* tp_getattro */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5651 0, /* tp_setattro */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5652 0, /* tp_as_buffer */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5653 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
|
5654 Unpicklertype__doc__, /* tp_doc */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5655 (traverseproc)Unpickler_traverse, /* tp_traverse */ |
|
d08d7b4be532
Make Unpickler objects colletable.
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
28567
diff
changeset
|
5656 (inquiry)Unpickler_clear, /* tp_clear */ |
| 6774 | 5657 }; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5658 |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5659 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
|
5660 {"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
|
5661 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
|
5662 "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
|
5663 "\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
|
5664 "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
|
5665 }, |
|
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 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5667 {"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
|
5668 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
|
5669 "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
|
5670 "\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
|
5671 "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
|
5672 }, |
|
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 |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5674 {"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
|
5675 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
|
5676 |
|
22706
14ebd7610902
Use symbolic METH_VARARGS/METH_OLDARGS instead of 1/0 for ml_flags
Neal Norwitz <nnorwitz@gmail.com>
parents:
22464
diff
changeset
|
5677 {"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
|
5678 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
|
5679 |
|
32829
cbd4ae74890d
Patch #995766: Keyword argument support in cPickle.
Martin v. Löwis <martin@v.loewis.de>
parents:
32305
diff
changeset
|
5680 {"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
|
5681 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
|
5682 "\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
|
5683 "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
|
5684 "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
|
5685 "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
|
5686 "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
|
5687 "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
|
5688 "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
|
5689 "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
|
5690 "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
|
5691 "\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
|
5692 "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
|
5693 "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
|
5694 "\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
|
5695 "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
|
5696 "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
|
5697 "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
|
5698 "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
|
5699 "\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 "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
|
5701 "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
|
5702 "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
|
5703 }, |
|
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
|
5704 |
|
38489
3fe3ccdf0155
Make use of METH_O and METH_NOARGS where possible.
Georg Brandl <georg@python.org>
parents:
38431
diff
changeset
|
5705 {"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
|
5706 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
|
5707 |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5708 { NULL, NULL } |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5709 }; |
|
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5710 |
| 4907 | 5711 static int |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5712 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
|
5713 { |
|
46865
b40827eb4b80
Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46337
diff
changeset
|
5714 PyObject *copyreg, *t, *r; |
|
5281
607fa32fc04a
Jim Fulton's version 2.2.
Guido van Rossum <guido@python.org>
parents:
4958
diff
changeset
|
5715 |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
5716 #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
|
5717 |
|
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
|
5718 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
|
5719 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
|
5720 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
|
5721 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
|
5722 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5723 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
|
5724 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
|
5725 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
|
5726 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
|
5727 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
|
5728 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
|
5729 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
|
5730 INIT_STR(__reduce__); |
| 27961 | 5731 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
|
5732 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
|
5733 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
|
5734 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
|
5735 INIT_STR(readline); |
|
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(dispatch_table); |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5737 |
|
47189
f419b2e96a98
Revert copy_reg -> copyreg rename.
Georg Brandl <georg@python.org>
parents:
47111
diff
changeset
|
5738 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
|
5739 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5740 |
|
27573
674f3eecffc5
Removed all uses of the out-of-favor __safe_for_unpickling__ magic
Tim Peters <tim.peters@gmail.com>
parents:
27566
diff
changeset
|
5741 /* 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
|
5742 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
|
5743 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
|
5744 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
|
5745 |
|
46865
b40827eb4b80
Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46337
diff
changeset
|
5746 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
|
5747 "_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
|
5748 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
|
5749 |
|
46865
b40827eb4b80
Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46337
diff
changeset
|
5750 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
|
5751 "_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
|
5752 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
|
5753 |
|
46865
b40827eb4b80
Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46337
diff
changeset
|
5754 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
|
5755 "_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
|
5756 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
|
5757 |
|
46865
b40827eb4b80
Added module stub for copy_reg renaming in 3.0.
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
46337
diff
changeset
|
5758 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
|
5759 |
|
27684
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
5760 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
|
5761 return -1; |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
5762 |
|
96fd004a58b0
cPickle now generates proto 2 EXT[124] when appropriate.
Tim Peters <tim.peters@gmail.com>
parents:
27667
diff
changeset
|
5763 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
|
5764 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
|
5765 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
|
5766 /* 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
|
5767 * 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
|
5768 * 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
|
5769 */ |
|
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
|
5770 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
|
5771 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5772 /* Ugh */ |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5773 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
|
5774 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
|
5775 return -1; |
|
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 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
|
5778 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
|
5779 "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
|
5780 " 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
|
5781 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
|
5782 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
|
5783 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
|
5784 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5785 PickleError = PyErr_NewException("cPickle.PickleError", NULL, t); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5786 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
|
5787 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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5789 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
|
5790 |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5791 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
|
5792 PickleError, NULL); |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5793 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
|
5794 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5795 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5796 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
|
5797 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
|
5798 "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
|
5799 " 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
|
5800 " 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
|
5801 " 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
|
5802 , 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
|
5803 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
|
5804 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
|
5805 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5806 if (!( UnpickleableError = PyErr_NewException( |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5807 "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
|
5808 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 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5810 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
|
5811 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5812 if (!( UnpicklingError = PyErr_NewException("cPickle.UnpicklingError", |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5813 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
|
5814 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5815 |
|
25290
f5ec08d45859
Make BadPickleGet a class. Fixes #609164.
Martin v. Löwis <martin@v.loewis.de>
parents:
24808
diff
changeset
|
5816 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
|
5817 UnpicklingError, NULL))) |
|
f5ec08d45859
Make BadPickleGet a class. Fixes #609164.
Martin v. Löwis <martin@v.loewis.de>
parents:
24808
diff
changeset
|
5818 return -1; |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5819 |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5820 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
|
5821 PickleError) < 0) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5822 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5823 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5824 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
|
5825 PicklingError) < 0) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5826 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5827 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5828 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
|
5829 UnpicklingError) < 0) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5830 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5831 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5832 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
|
5833 UnpickleableError) < 0) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5834 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5835 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5836 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
|
5837 BadPickleGet) < 0) |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5838 return -1; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5839 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5840 PycString_IMPORT; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5841 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5842 return 0; |
| 4907 | 5843 } |
| 5844 | |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24302
diff
changeset
|
5845 #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
|
5846 #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
|
5847 #endif |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
24302
diff
changeset
|
5848 PyMODINIT_FUNC |
|
27578
2f227ff11f5e
Trimmed trailing whitespace.
Tim Peters <tim.peters@gmail.com>
parents:
27577
diff
changeset
|
5849 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
|
5850 { |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5851 PyObject *m, *d, *di, *v, *k; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
5852 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
|
5853 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
|
5854 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
|
5855 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
|
5856 |
|
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
|
5857 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
|
5858 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
|
5859 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
|
5860 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5861 /* 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
|
5862 * 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
|
5863 */ |
|
3a528aa222b6
Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents:
27656
diff
changeset
|
5864 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
|
5865 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
|
5866 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
|
5867 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5868 /* 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
|
5869 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
|
5870 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
|
5871 (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
|
5872 if (m == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35999
diff
changeset
|
5873 return; |
|
22732
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5874 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5875 /* 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
|
5876 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
|
5877 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
|
5878 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
|
5879 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
|
5880 |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5881 /* 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
|
5882 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
|
5883 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
|
5884 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
|
5885 return; |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5886 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5887 } |
|
00154a0fde61
Reindent. Break long lines. Move comments before the statements.
Martin v. Löwis <martin@v.loewis.de>
parents:
22725
diff
changeset
|
5888 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
|
5889 |
|
27864
b4eb34372bdb
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27832
diff
changeset
|
5890 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
|
5891 if (i < 0) |
|
b4eb34372bdb
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27832
diff
changeset
|
5892 return; |
|
b4eb34372bdb
Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle.
Tim Peters <tim.peters@gmail.com>
parents:
27832
diff
changeset
|
5893 |
|
27662
3a528aa222b6
Brought some module variables into synch with pickle.py's current values.
Tim Peters <tim.peters@gmail.com>
parents:
27656
diff
changeset
|
5894 /* 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
|
5895 /* 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
|
5896 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
|
5897 /* 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
|
5898 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
|
5899 "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
|
5900 "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
|
5901 "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
|
5902 "1.3", /* Protocol 1 + BINFLOAT */ |
| 27663 | 5903 "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
|
5904 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
|
5905 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
|
5906 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
|
5907 Py_XDECREF(compatible_formats); |
| 4907 | 5908 } |
