Bug Summary

File:Python/marshal.c
Location:line 596, column 14
Description:The result of the '<<' expression is undefined

Annotated Source Code

1
2/* Write Python objects to files and read them back.
3 This is intended for writing and reading compiled Python code only;
4 a true persistent storage facility would be much harder, since
5 it would have to take circular links and sharing into account. */
6
7#define PY_SSIZE_T_CLEAN
8
9#include "Python.h"
10#include "longintrepr.h"
11#include "code.h"
12#include "marshal.h"
13
14#define ABS(x)((x) < 0 ? -(x) : (x)) ((x) < 0 ? -(x) : (x))
15
16/* High water mark to determine when the marshalled object is dangerously deep
17 * and risks coring the interpreter. When the object stack gets this deep,
18 * raise an exception instead of continuing.
19 * On Windows debug builds, reduce this value.
20 */
21#if defined(MS_WINDOWS) && defined(_DEBUG)
22#define MAX_MARSHAL_STACK_DEPTH2000 1500
23#else
24#define MAX_MARSHAL_STACK_DEPTH2000 2000
25#endif
26
27#define TYPE_NULL'0' '0'
28#define TYPE_NONE'N' 'N'
29#define TYPE_FALSE'F' 'F'
30#define TYPE_TRUE'T' 'T'
31#define TYPE_STOPITER'S' 'S'
32#define TYPE_ELLIPSIS'.' '.'
33#define TYPE_INT'i' 'i'
34#define TYPE_INT64'I' 'I'
35#define TYPE_FLOAT'f' 'f'
36#define TYPE_BINARY_FLOAT'g' 'g'
37#define TYPE_COMPLEX'x' 'x'
38#define TYPE_BINARY_COMPLEX'y' 'y'
39#define TYPE_LONG'l' 'l'
40#define TYPE_STRING's' 's'
41#define TYPE_TUPLE'(' '('
42#define TYPE_LIST'[' '['
43#define TYPE_DICT'{' '{'
44#define TYPE_CODE'c' 'c'
45#define TYPE_UNICODE'u' 'u'
46#define TYPE_UNKNOWN'?' '?'
47#define TYPE_SET'<' '<'
48#define TYPE_FROZENSET'>' '>'
49
50#define WFERR_OK0 0
51#define WFERR_UNMARSHALLABLE1 1
52#define WFERR_NESTEDTOODEEP2 2
53#define WFERR_NOMEMORY3 3
54
55typedef struct {
56 FILE *fp;
57 int error; /* see WFERR_* values */
58 int depth;
59 /* If fp == NULL, the following are valid: */
60 PyObject *str;
61 char *ptr;
62 char *end;
63 PyObject *strings; /* dict on marshal, list on unmarshal */
64 int version;
65} WFILE;
66
67#define w_byte(c, p)if (((p)->fp)) putc((c), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = (c); else w_more(c, p)
if (((p)->fp)) putc((c), (p)->fp); \
68 else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \
69 else w_more(c, p)
70
71static void
72w_more(int c, WFILE *p)
73{
74 Py_ssize_t size, newsize;
75 if (p->str == NULL((void *)0))
76 return; /* An error already occurred */
77 size = PyBytes_Size(p->str);
78 newsize = size + size + 1024;
79 if (newsize > 32*1024*1024) {
80 newsize = size + (size >> 3); /* 12.5% overallocation */
81 }
82 if (_PyBytes_Resize(&p->str, newsize) != 0) {
83 p->ptr = p->end = NULL((void *)0);
84 }
85 else {
86 p->ptr = PyBytes_AS_STRING((PyBytesObject *)p->str)((__builtin_expect(!(((((((PyObject*)((PyBytesObject *)p->
str))->ob_type))->tp_flags & ((1L<<27))) != 0
)), 0) ? __assert_rtn(__func__, "Python/marshal.c", 86, "PyBytes_Check((PyBytesObject *)p->str)"
) : (void)0), (((PyBytesObject *)((PyBytesObject *)p->str)
)->ob_sval))
+ size;
87 p->end =
88 PyBytes_AS_STRING((PyBytesObject *)p->str)((__builtin_expect(!(((((((PyObject*)((PyBytesObject *)p->
str))->ob_type))->tp_flags & ((1L<<27))) != 0
)), 0) ? __assert_rtn(__func__, "Python/marshal.c", 88, "PyBytes_Check((PyBytesObject *)p->str)"
) : (void)0), (((PyBytesObject *)((PyBytesObject *)p->str)
)->ob_sval))
+ newsize;
89 *p->ptr++ = Py_SAFE_DOWNCAST(c, int, char)((__builtin_expect(!((int)(char)(c) == (c)), 0) ? __assert_rtn
(__func__, "Python/marshal.c", 89, "(int)(char)(c) == (c)") :
(void)0), (char)(c))
;
90 }
91}
92
93static void
94w_string(char *s, int n, WFILE *p)
95{
96 if (p->fp != NULL((void *)0)) {
97 fwrite(s, 1, n, p->fp);
98 }
99 else {
100 while (--n >= 0) {
101 w_byte(*s, p)if (((p)->fp)) putc((*s), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = (*s); else w_more(*s, p)
;
102 s++;
103 }
104 }
105}
106
107static void
108w_short(int x, WFILE *p)
109{
110 w_byte((char)( x & 0xff), p)if (((p)->fp)) putc(((char)( x & 0xff)), (p)->fp); else
if ((p)->ptr != (p)->end) *(p)->ptr++ = ((char)( x &
0xff)); else w_more((char)( x & 0xff), p)
;
111 w_byte((char)((x>> 8) & 0xff), p)if (((p)->fp)) putc(((char)((x>> 8) & 0xff)), (p
)->fp); else if ((p)->ptr != (p)->end) *(p)->ptr++
= ((char)((x>> 8) & 0xff)); else w_more((char)((x>>
8) & 0xff), p)
;
112}
113
114static void
115w_long(long x, WFILE *p)
116{
117 w_byte((char)( x & 0xff), p)if (((p)->fp)) putc(((char)( x & 0xff)), (p)->fp); else
if ((p)->ptr != (p)->end) *(p)->ptr++ = ((char)( x &
0xff)); else w_more((char)( x & 0xff), p)
;
118 w_byte((char)((x>> 8) & 0xff), p)if (((p)->fp)) putc(((char)((x>> 8) & 0xff)), (p
)->fp); else if ((p)->ptr != (p)->end) *(p)->ptr++
= ((char)((x>> 8) & 0xff)); else w_more((char)((x>>
8) & 0xff), p)
;
119 w_byte((char)((x>>16) & 0xff), p)if (((p)->fp)) putc(((char)((x>>16) & 0xff)), (p
)->fp); else if ((p)->ptr != (p)->end) *(p)->ptr++
= ((char)((x>>16) & 0xff)); else w_more((char)((x>>
16) & 0xff), p)
;
120 w_byte((char)((x>>24) & 0xff), p)if (((p)->fp)) putc(((char)((x>>24) & 0xff)), (p
)->fp); else if ((p)->ptr != (p)->end) *(p)->ptr++
= ((char)((x>>24) & 0xff)); else w_more((char)((x>>
24) & 0xff), p)
;
121}
122
123#if SIZEOF_LONG8 > 4
124static void
125w_long64(long x, WFILE *p)
126{
127 w_long(x, p);
128 w_long(x>>32, p);
129}
130#endif
131
132/* We assume that Python longs are stored internally in base some power of
133 2**15; for the sake of portability we'll always read and write them in base
134 exactly 2**15. */
135
136#define PyLong_MARSHAL_SHIFT15 15
137#define PyLong_MARSHAL_BASE((short)1 << 15) ((short)1 << PyLong_MARSHAL_SHIFT15)
138#define PyLong_MARSHAL_MASK(((short)1 << 15) - 1) (PyLong_MARSHAL_BASE((short)1 << 15) - 1)
139#if PyLong_SHIFT30 % PyLong_MARSHAL_SHIFT15 != 0
140#error "PyLong_SHIFT must be a multiple of PyLong_MARSHAL_SHIFT"
141#endif
142#define PyLong_MARSHAL_RATIO(30 / 15) (PyLong_SHIFT30 / PyLong_MARSHAL_SHIFT15)
143
144static void
145w_PyLong(const PyLongObject *ob, WFILE *p)
146{
147 Py_ssize_t i, j, n, l;
148 digit d;
149
150 w_byte(TYPE_LONG, p)if (((p)->fp)) putc(('l'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('l'); else w_more('l', p)
;
151 if (Py_SIZE(ob)(((PyVarObject*)(ob))->ob_size) == 0) {
152 w_long((long)0, p);
153 return;
154 }
155
156 /* set l to number of base PyLong_MARSHAL_BASE digits */
157 n = ABS(Py_SIZE(ob))(((((PyVarObject*)(ob))->ob_size)) < 0 ? -((((PyVarObject
*)(ob))->ob_size)) : ((((PyVarObject*)(ob))->ob_size)))
;
158 l = (n-1) * PyLong_MARSHAL_RATIO(30 / 15);
159 d = ob->ob_digit[n-1];
160 assert(d != 0)(__builtin_expect(!(d != 0), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 160, "d != 0") : (void)0)
; /* a PyLong is always normalized */
161 do {
162 d >>= PyLong_MARSHAL_SHIFT15;
163 l++;
164 } while (d != 0);
165 w_long((long)(Py_SIZE(ob)(((PyVarObject*)(ob))->ob_size) > 0 ? l : -l), p);
166
167 for (i=0; i < n-1; i++) {
168 d = ob->ob_digit[i];
169 for (j=0; j < PyLong_MARSHAL_RATIO(30 / 15); j++) {
170 w_short(d & PyLong_MARSHAL_MASK(((short)1 << 15) - 1), p);
171 d >>= PyLong_MARSHAL_SHIFT15;
172 }
173 assert (d == 0)(__builtin_expect(!(d == 0), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 173, "d == 0") : (void)0)
;
174 }
175 d = ob->ob_digit[n-1];
176 do {
177 w_short(d & PyLong_MARSHAL_MASK(((short)1 << 15) - 1), p);
178 d >>= PyLong_MARSHAL_SHIFT15;
179 } while (d != 0);
180}
181
182static void
183w_object(PyObject *v, WFILE *p)
184{
185 Py_ssize_t i, n;
186
187 p->depth++;
188
189 if (p->depth > MAX_MARSHAL_STACK_DEPTH2000) {
190 p->error = WFERR_NESTEDTOODEEP2;
191 }
192 else if (v == NULL((void *)0)) {
193 w_byte(TYPE_NULL, p)if (((p)->fp)) putc(('0'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('0'); else w_more('0', p)
;
194 }
195 else if (v == Py_None(&_Py_NoneStruct)) {
196 w_byte(TYPE_NONE, p)if (((p)->fp)) putc(('N'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('N'); else w_more('N', p)
;
197 }
198 else if (v == PyExc_StopIteration) {
199 w_byte(TYPE_STOPITER, p)if (((p)->fp)) putc(('S'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('S'); else w_more('S', p)
;
200 }
201 else if (v == Py_Ellipsis(&_Py_EllipsisObject)) {
202 w_byte(TYPE_ELLIPSIS, p)if (((p)->fp)) putc(('.'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('.'); else w_more('.', p)
;
203 }
204 else if (v == Py_False((PyObject *) &_Py_FalseStruct)) {
205 w_byte(TYPE_FALSE, p)if (((p)->fp)) putc(('F'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('F'); else w_more('F', p)
;
206 }
207 else if (v == Py_True((PyObject *) &_Py_TrueStruct)) {
208 w_byte(TYPE_TRUE, p)if (((p)->fp)) putc(('T'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('T'); else w_more('T', p)
;
209 }
210 else if (PyLong_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyLong_Type)) {
211 long x = PyLong_AsLong(v);
212 if ((x == -1) && PyErr_Occurred()) {
213 PyLongObject *ob = (PyLongObject *)v;
214 PyErr_Clear();
215 w_PyLong(ob, p);
216 }
217 else {
218#if SIZEOF_LONG8 > 4
219 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31)((x) >> (31));
220 if (y && y != -1) {
221 w_byte(TYPE_INT64, p)if (((p)->fp)) putc(('I'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('I'); else w_more('I', p)
;
222 w_long64(x, p);
223 }
224 else
225#endif
226 {
227 w_byte(TYPE_INT, p)if (((p)->fp)) putc(('i'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('i'); else w_more('i', p)
;
228 w_long(x, p);
229 }
230 }
231 }
232 else if (PyFloat_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyFloat_Type)) {
233 if (p->version > 1) {
234 unsigned char buf[8];
235 if (_PyFloat_Pack8(PyFloat_AsDouble(v),
236 buf, 1) < 0) {
237 p->error = WFERR_UNMARSHALLABLE1;
238 return;
239 }
240 w_byte(TYPE_BINARY_FLOAT, p)if (((p)->fp)) putc(('g'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('g'); else w_more('g', p)
;
241 w_string((char*)buf, 8, p);
242 }
243 else {
244 char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v)(((PyFloatObject *)(v))->ob_fval),
245 'g', 17, 0, NULL((void *)0));
246 if (!buf) {
247 p->error = WFERR_NOMEMORY3;
248 return;
249 }
250 n = strlen(buf);
251 w_byte(TYPE_FLOAT, p)if (((p)->fp)) putc(('f'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('f'); else w_more('f', p)
;
252 w_byte((int)n, p)if (((p)->fp)) putc(((int)n), (p)->fp); else if ((p)->
ptr != (p)->end) *(p)->ptr++ = ((int)n); else w_more((int
)n, p)
;
253 w_string(buf, (int)n, p);
254 PyMem_Free(buf);
255 }
256 }
257 else if (PyComplex_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyComplex_Type)) {
258 if (p->version > 1) {
259 unsigned char buf[8];
260 if (_PyFloat_Pack8(PyComplex_RealAsDouble(v),
261 buf, 1) < 0) {
262 p->error = WFERR_UNMARSHALLABLE1;
263 return;
264 }
265 w_byte(TYPE_BINARY_COMPLEX, p)if (((p)->fp)) putc(('y'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('y'); else w_more('y', p)
;
266 w_string((char*)buf, 8, p);
267 if (_PyFloat_Pack8(PyComplex_ImagAsDouble(v),
268 buf, 1) < 0) {
269 p->error = WFERR_UNMARSHALLABLE1;
270 return;
271 }
272 w_string((char*)buf, 8, p);
273 }
274 else {
275 char *buf;
276 w_byte(TYPE_COMPLEX, p)if (((p)->fp)) putc(('x'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('x'); else w_more('x', p)
;
277 buf = PyOS_double_to_string(PyComplex_RealAsDouble(v),
278 'g', 17, 0, NULL((void *)0));
279 if (!buf) {
280 p->error = WFERR_NOMEMORY3;
281 return;
282 }
283 n = strlen(buf);
284 w_byte((int)n, p)if (((p)->fp)) putc(((int)n), (p)->fp); else if ((p)->
ptr != (p)->end) *(p)->ptr++ = ((int)n); else w_more((int
)n, p)
;
285 w_string(buf, (int)n, p);
286 PyMem_Free(buf);
287 buf = PyOS_double_to_string(PyComplex_ImagAsDouble(v),
288 'g', 17, 0, NULL((void *)0));
289 if (!buf) {
290 p->error = WFERR_NOMEMORY3;
291 return;
292 }
293 n = strlen(buf);
294 w_byte((int)n, p)if (((p)->fp)) putc(((int)n), (p)->fp); else if ((p)->
ptr != (p)->end) *(p)->ptr++ = ((int)n); else w_more((int
)n, p)
;
295 w_string(buf, (int)n, p);
296 PyMem_Free(buf);
297 }
298 }
299 else if (PyBytes_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyBytes_Type)) {
300 w_byte(TYPE_STRING, p)if (((p)->fp)) putc(('s'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('s'); else w_more('s', p)
;
301 n = PyBytes_GET_SIZE(v)((__builtin_expect(!(((((((PyObject*)(v))->ob_type))->tp_flags
& ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 301, "PyBytes_Check(v)") : (void)0),(((PyVarObject*)(v))->
ob_size))
;
302 if (n > INT_MAX2147483647) {
303 /* huge strings are not supported */
304 p->depth--;
305 p->error = WFERR_UNMARSHALLABLE1;
306 return;
307 }
308 w_long((long)n, p);
309 w_string(PyBytes_AS_STRING(v)((__builtin_expect(!(((((((PyObject*)(v))->ob_type))->tp_flags
& ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 309, "PyBytes_Check(v)") : (void)0), (((PyBytesObject *)(v)
)->ob_sval))
, (int)n, p);
310 }
311 else if (PyUnicode_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyUnicode_Type)) {
312 PyObject *utf8;
313 utf8 = PyUnicode_EncodeUTF8PyUnicodeUCS2_EncodeUTF8(PyUnicode_AS_UNICODE(v)((__builtin_expect(!(((((((PyObject*)(v))->ob_type))->tp_flags
& ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 313, "PyUnicode_Check(v)") : (void)0),(((PyUnicodeObject *)
(v))->str))
,
314 PyUnicode_GET_SIZE(v)((__builtin_expect(!(((((((PyObject*)(v))->ob_type))->tp_flags
& ((1L<<28))) != 0)), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 314, "PyUnicode_Check(v)") : (void)0),(((PyUnicodeObject *)
(v))->length))
,
315 "surrogatepass");
316 if (utf8 == NULL((void *)0)) {
317 p->depth--;
318 p->error = WFERR_UNMARSHALLABLE1;
319 return;
320 }
321 w_byte(TYPE_UNICODE, p)if (((p)->fp)) putc(('u'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('u'); else w_more('u', p)
;
322 n = PyBytes_GET_SIZE(utf8)((__builtin_expect(!(((((((PyObject*)(utf8))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 322, "PyBytes_Check(utf8)") : (void)0),
(((PyVarObject*)(utf8))->ob_size))
;
323 if (n > INT_MAX2147483647) {
324 p->depth--;
325 p->error = WFERR_UNMARSHALLABLE1;
326 return;
327 }
328 w_long((long)n, p);
329 w_string(PyBytes_AS_STRING(utf8)((__builtin_expect(!(((((((PyObject*)(utf8))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 329, "PyBytes_Check(utf8)") : (void)0),
(((PyBytesObject *)(utf8))->ob_sval))
, (int)n, p);
330 Py_DECREF(utf8)do { if (_Py_RefTotal-- , --((PyObject*)(utf8))->ob_refcnt
!= 0) { if (((PyObject*)utf8)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 330, (PyObject *)(utf8)); } else _Py_Dealloc
((PyObject *)(utf8)); } while (0)
;
331 }
332 else if (PyTuple_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyTuple_Type)) {
333 w_byte(TYPE_TUPLE, p)if (((p)->fp)) putc(('('), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('('); else w_more('(', p)
;
334 n = PyTuple_Size(v);
335 w_long((long)n, p);
336 for (i = 0; i < n; i++) {
337 w_object(PyTuple_GET_ITEM(v, i)(((PyTupleObject *)(v))->ob_item[i]), p);
338 }
339 }
340 else if (PyList_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyList_Type)) {
341 w_byte(TYPE_LIST, p)if (((p)->fp)) putc(('['), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('['); else w_more('[', p)
;
342 n = PyList_GET_SIZE(v)(((PyVarObject*)(v))->ob_size);
343 w_long((long)n, p);
344 for (i = 0; i < n; i++) {
345 w_object(PyList_GET_ITEM(v, i)(((PyListObject *)(v))->ob_item[i]), p);
346 }
347 }
348 else if (PyDict_CheckExact(v)((((PyObject*)(v))->ob_type) == &PyDict_Type)) {
349 Py_ssize_t pos;
350 PyObject *key, *value;
351 w_byte(TYPE_DICT, p)if (((p)->fp)) putc(('{'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('{'); else w_more('{', p)
;
352 /* This one is NULL object terminated! */
353 pos = 0;
354 while (PyDict_Next(v, &pos, &key, &value)) {
355 w_object(key, p);
356 w_object(value, p);
357 }
358 w_object((PyObject *)NULL((void *)0), p);
359 }
360 else if (PyAnySet_CheckExact(v)((((PyObject*)(v))->ob_type) == &PySet_Type || (((PyObject
*)(v))->ob_type) == &PyFrozenSet_Type)
) {
361 PyObject *value, *it;
362
363 if (PyObject_TypeCheck(v, &PySet_Type)((((PyObject*)(v))->ob_type) == (&PySet_Type) || PyType_IsSubtype
((((PyObject*)(v))->ob_type), (&PySet_Type)))
)
364 w_byte(TYPE_SET, p)if (((p)->fp)) putc(('<'), (p)->fp); else if ((p)->
ptr != (p)->end) *(p)->ptr++ = ('<'); else w_more('<'
, p)
;
365 else
366 w_byte(TYPE_FROZENSET, p)if (((p)->fp)) putc(('>'), (p)->fp); else if ((p)->
ptr != (p)->end) *(p)->ptr++ = ('>'); else w_more('>'
, p)
;
367 n = PyObject_Size(v);
368 if (n == -1) {
369 p->depth--;
370 p->error = WFERR_UNMARSHALLABLE1;
371 return;
372 }
373 w_long((long)n, p);
374 it = PyObject_GetIter(v);
375 if (it == NULL((void *)0)) {
376 p->depth--;
377 p->error = WFERR_UNMARSHALLABLE1;
378 return;
379 }
380 while ((value = PyIter_Next(it)) != NULL((void *)0)) {
381 w_object(value, p);
382 Py_DECREF(value)do { if (_Py_RefTotal-- , --((PyObject*)(value))->ob_refcnt
!= 0) { if (((PyObject*)value)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 382, (PyObject *)(value)); } else _Py_Dealloc
((PyObject *)(value)); } while (0)
;
383 }
384 Py_DECREF(it)do { if (_Py_RefTotal-- , --((PyObject*)(it))->ob_refcnt !=
0) { if (((PyObject*)it)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 384, (PyObject *)(it)); } else _Py_Dealloc
((PyObject *)(it)); } while (0)
;
385 if (PyErr_Occurred()) {
386 p->depth--;
387 p->error = WFERR_UNMARSHALLABLE1;
388 return;
389 }
390 }
391 else if (PyCode_Check(v)((((PyObject*)(v))->ob_type) == &PyCode_Type)) {
392 PyCodeObject *co = (PyCodeObject *)v;
393 w_byte(TYPE_CODE, p)if (((p)->fp)) putc(('c'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('c'); else w_more('c', p)
;
394 w_long(co->co_argcount, p);
395 w_long(co->co_kwonlyargcount, p);
396 w_long(co->co_nlocals, p);
397 w_long(co->co_stacksize, p);
398 w_long(co->co_flags, p);
399 w_object(co->co_code, p);
400 w_object(co->co_consts, p);
401 w_object(co->co_names, p);
402 w_object(co->co_varnames, p);
403 w_object(co->co_freevars, p);
404 w_object(co->co_cellvars, p);
405 w_object(co->co_filename, p);
406 w_object(co->co_name, p);
407 w_long(co->co_firstlineno, p);
408 w_object(co->co_lnotab, p);
409 }
410 else if (PyObject_CheckBuffer(v)(((v)->ob_type->tp_as_buffer != ((void *)0)) &&
((v)->ob_type->tp_as_buffer->bf_getbuffer != ((void
*)0)))
) {
411 /* Write unknown buffer-style objects as a string */
412 char *s;
413 PyBufferProcs *pb = v->ob_type->tp_as_buffer;
414 Py_buffer view;
415 if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE0) != 0) {
416 w_byte(TYPE_UNKNOWN, p)if (((p)->fp)) putc(('?'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('?'); else w_more('?', p)
;
417 p->error = WFERR_UNMARSHALLABLE1;
418 }
419 w_byte(TYPE_STRING, p)if (((p)->fp)) putc(('s'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('s'); else w_more('s', p)
;
420 n = view.len;
421 s = view.buf;
422 if (n > INT_MAX2147483647) {
423 p->depth--;
424 p->error = WFERR_UNMARSHALLABLE1;
425 return;
426 }
427 w_long((long)n, p);
428 w_string(s, (int)n, p);
429 if (pb->bf_releasebuffer != NULL((void *)0))
430 (*pb->bf_releasebuffer)(v, &view);
431 }
432 else {
433 w_byte(TYPE_UNKNOWN, p)if (((p)->fp)) putc(('?'), (p)->fp); else if ((p)->ptr
!= (p)->end) *(p)->ptr++ = ('?'); else w_more('?', p)
;
434 p->error = WFERR_UNMARSHALLABLE1;
435 }
436 p->depth--;
437}
438
439/* version currently has no effect for writing longs. */
440void
441PyMarshal_WriteLongToFile(long x, FILE *fp, int version)
442{
443 WFILE wf;
444 wf.fp = fp;
445 wf.error = WFERR_OK0;
446 wf.depth = 0;
447 wf.strings = NULL((void *)0);
448 wf.version = version;
449 w_long(x, &wf);
450}
451
452void
453PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version)
454{
455 WFILE wf;
456 wf.fp = fp;
457 wf.error = WFERR_OK0;
458 wf.depth = 0;
459 wf.strings = (version > 0) ? PyDict_New() : NULL((void *)0);
460 wf.version = version;
461 w_object(x, &wf);
462 Py_XDECREF(wf.strings)do { if ((wf.strings) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(wf.strings))->ob_refcnt != 0) { if (((
PyObject*)wf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 462, (PyObject *)(wf.strings)); } else _Py_Dealloc
((PyObject *)(wf.strings)); } while (0); } while (0)
;
463}
464
465typedef WFILE RFILE; /* Same struct with different invariants */
466
467#define rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr++ : EOF(-1))
468
469#define r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
((p)->fp ? getc((p)->fp) : rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
)
470
471static int
472r_string(char *s, int n, RFILE *p)
473{
474 if (p->fp != NULL((void *)0))
475 /* The result fits into int because it must be <=n. */
476 return (int)fread(s, 1, n, p->fp);
477 if (p->end - p->ptr < n)
478 n = (int)(p->end - p->ptr);
479 memcpy(s, p->ptr, n)((__builtin_object_size (s, 0) != (size_t) -1) ? __builtin___memcpy_chk
(s, p->ptr, n, __builtin_object_size (s, 0)) : __inline_memcpy_chk
(s, p->ptr, n))
;
480 p->ptr += n;
481 return n;
482}
483
484static int
485r_short(RFILE *p)
486{
487 register short x;
488 x = r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
;
489 x |= r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
<< 8;
490 /* Sign-extension, in case short greater than 16 bits */
491 x |= -(x & 0x8000);
492 return x;
493}
494
495static long
496r_long(RFILE *p)
497{
498 register long x;
499 register FILE *fp = p->fp;
500 if (fp) {
501 x = getc(fp);
502 x |= (long)getc(fp) << 8;
503 x |= (long)getc(fp) << 16;
504 x |= (long)getc(fp) << 24;
505 }
506 else {
507 x = rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
;
508 x |= (long)rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
<< 8;
509 x |= (long)rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
<< 16;
510 x |= (long)rs_byte(p)(((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr
++ : (-1))
<< 24;
511 }
512#if SIZEOF_LONG8 > 4
513 /* Sign extension for 64-bit machines */
514 x |= -(x & 0x80000000L);
515#endif
516 return x;
517}
518
519/* r_long64 deals with the TYPE_INT64 code. On a machine with
520 sizeof(long) > 4, it returns a Python int object, else a Python long
521 object. Note that w_long64 writes out TYPE_INT if 32 bits is enough,
522 so there's no inefficiency here in returning a PyLong on 32-bit boxes
523 for everything written via TYPE_INT64 (i.e., if an int is written via
524 TYPE_INT64, it *needs* more than 32 bits).
525*/
526static PyObject *
527r_long64(RFILE *p)
528{
529 long lo4 = r_long(p);
530 long hi4 = r_long(p);
531#if SIZEOF_LONG8 > 4
532 long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL);
533 return PyLong_FromLong(x);
534#else
535 unsigned char buf[8];
536 int one = 1;
537 int is_little_endian = (int)*(char*)&one;
538 if (is_little_endian) {
539 memcpy(buf, &lo4, 4)((__builtin_object_size (buf, 0) != (size_t) -1) ? __builtin___memcpy_chk
(buf, &lo4, 4, __builtin_object_size (buf, 0)) : __inline_memcpy_chk
(buf, &lo4, 4))
;
540 memcpy(buf+4, &hi4, 4)((__builtin_object_size (buf+4, 0) != (size_t) -1) ? __builtin___memcpy_chk
(buf+4, &hi4, 4, __builtin_object_size (buf+4, 0)) : __inline_memcpy_chk
(buf+4, &hi4, 4))
;
541 }
542 else {
543 memcpy(buf, &hi4, 4)((__builtin_object_size (buf, 0) != (size_t) -1) ? __builtin___memcpy_chk
(buf, &hi4, 4, __builtin_object_size (buf, 0)) : __inline_memcpy_chk
(buf, &hi4, 4))
;
544 memcpy(buf+4, &lo4, 4)((__builtin_object_size (buf+4, 0) != (size_t) -1) ? __builtin___memcpy_chk
(buf+4, &lo4, 4, __builtin_object_size (buf+4, 0)) : __inline_memcpy_chk
(buf+4, &lo4, 4))
;
545 }
546 return _PyLong_FromByteArray(buf, 8, is_little_endian, 1);
547#endif
548}
549
550static PyObject *
551r_PyLong(RFILE *p)
552{
553 PyLongObject *ob;
554 int size, i, j, md, shorts_in_top_digit;
555 long n;
556 digit d;
557
558 n = r_long(p);
559 if (n == 0)
1
Taking false branch
560 return (PyObject *)_PyLong_New(0);
561 if (n < -INT_MAX2147483647 || n > INT_MAX2147483647) {
2
Taking false branch
562 PyErr_SetString(PyExc_ValueError,
563 "bad marshal data (long size out of range)");
564 return NULL((void *)0);
565 }
566
567 size = 1 + (ABS(n)((n) < 0 ? -(n) : (n)) - 1) / PyLong_MARSHAL_RATIO(30 / 15);
568 shorts_in_top_digit = 1 + (ABS(n)((n) < 0 ? -(n) : (n)) - 1) % PyLong_MARSHAL_RATIO(30 / 15);
569 ob = _PyLong_New(size);
570 if (ob == NULL((void *)0))
3
Taking false branch
571 return NULL((void *)0);
572 Py_SIZE(ob)(((PyVarObject*)(ob))->ob_size) = n > 0 ? size : -size;
4
'?' condition is true
573
574 for (i = 0; i < size-1; i++) {
5
Loop condition is false. Execution continues on line 584
575 d = 0;
576 for (j=0; j < PyLong_MARSHAL_RATIO(30 / 15); j++) {
577 md = r_short(p);
578 if (md < 0 || md > PyLong_MARSHAL_BASE((short)1 << 15))
579 goto bad_digit;
580 d += (digit)md << j*PyLong_MARSHAL_SHIFT15;
581 }
582 ob->ob_digit[i] = d;
583 }
584 d = 0;
585 for (j=0; j < shorts_in_top_digit; j++) {
6
Loop condition is true. Entering loop body
9
Loop condition is true. Entering loop body
12
Loop condition is true. Entering loop body
15
Loop condition is true. Entering loop body
586 md = r_short(p);
587 if (md < 0 || md > PyLong_MARSHAL_BASE((short)1 << 15))
7
Taking false branch
10
Taking false branch
13
Taking false branch
16
Taking false branch
588 goto bad_digit;
589 /* topmost marshal digit should be nonzero */
590 if (md == 0 && j == shorts_in_top_digit - 1) {
8
Taking false branch
11
Taking false branch
14
Taking false branch
17
Taking false branch
591 Py_DECREF(ob)do { if (_Py_RefTotal-- , --((PyObject*)(ob))->ob_refcnt !=
0) { if (((PyObject*)ob)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 591, (PyObject *)(ob)); } else _Py_Dealloc
((PyObject *)(ob)); } while (0)
;
592 PyErr_SetString(PyExc_ValueError,
593 "bad marshal data (unnormalized long data)");
594 return NULL((void *)0);
595 }
596 d += (digit)md << j*PyLong_MARSHAL_SHIFT15;
18
The result of the '<<' expression is undefined
597 }
598 /* top digit should be nonzero, else the resulting PyLong won't be
599 normalized */
600 ob->ob_digit[size-1] = d;
601 return (PyObject *)ob;
602 bad_digit:
603 Py_DECREF(ob)do { if (_Py_RefTotal-- , --((PyObject*)(ob))->ob_refcnt !=
0) { if (((PyObject*)ob)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 603, (PyObject *)(ob)); } else _Py_Dealloc
((PyObject *)(ob)); } while (0)
;
604 PyErr_SetString(PyExc_ValueError,
605 "bad marshal data (digit out of range in long)");
606 return NULL((void *)0);
607}
608
609
610static PyObject *
611r_object(RFILE *p)
612{
613 /* NULL is a valid return value, it does not necessarily means that
614 an exception is set. */
615 PyObject *v, *v2;
616 long i, n;
617 int type = r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
;
618 PyObject *retval;
619
620 p->depth++;
621
622 if (p->depth > MAX_MARSHAL_STACK_DEPTH2000) {
623 p->depth--;
624 PyErr_SetString(PyExc_ValueError, "recursion limit exceeded");
625 return NULL((void *)0);
626 }
627
628 switch (type) {
629
630 case EOF(-1):
631 PyErr_SetString(PyExc_EOFError,
632 "EOF read where object expected");
633 retval = NULL((void *)0);
634 break;
635
636 case TYPE_NULL'0':
637 retval = NULL((void *)0);
638 break;
639
640 case TYPE_NONE'N':
641 Py_INCREF(Py_None)( _Py_RefTotal++ , ((PyObject*)((&_Py_NoneStruct)))->ob_refcnt
++)
;
642 retval = Py_None(&_Py_NoneStruct);
643 break;
644
645 case TYPE_STOPITER'S':
646 Py_INCREF(PyExc_StopIteration)( _Py_RefTotal++ , ((PyObject*)(PyExc_StopIteration))->ob_refcnt
++)
;
647 retval = PyExc_StopIteration;
648 break;
649
650 case TYPE_ELLIPSIS'.':
651 Py_INCREF(Py_Ellipsis)( _Py_RefTotal++ , ((PyObject*)((&_Py_EllipsisObject)))->
ob_refcnt++)
;
652 retval = Py_Ellipsis(&_Py_EllipsisObject);
653 break;
654
655 case TYPE_FALSE'F':
656 Py_INCREF(Py_False)( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_FalseStruct
)))->ob_refcnt++)
;
657 retval = Py_False((PyObject *) &_Py_FalseStruct);
658 break;
659
660 case TYPE_TRUE'T':
661 Py_INCREF(Py_True)( _Py_RefTotal++ , ((PyObject*)(((PyObject *) &_Py_TrueStruct
)))->ob_refcnt++)
;
662 retval = Py_True((PyObject *) &_Py_TrueStruct);
663 break;
664
665 case TYPE_INT'i':
666 retval = PyLong_FromLong(r_long(p));
667 break;
668
669 case TYPE_INT64'I':
670 retval = r_long64(p);
671 break;
672
673 case TYPE_LONG'l':
674 retval = r_PyLong(p);
675 break;
676
677 case TYPE_FLOAT'f':
678 {
679 char buf[256];
680 double dx;
681 retval = NULL((void *)0);
682 n = r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
;
683 if (n == EOF(-1) || r_string(buf, (int)n, p) != n) {
684 PyErr_SetString(PyExc_EOFError,
685 "EOF read where object expected");
686 break;
687 }
688 buf[n] = '\0';
689 dx = PyOS_string_to_double(buf, NULL((void *)0), NULL((void *)0));
690 if (dx == -1.0 && PyErr_Occurred())
691 break;
692 retval = PyFloat_FromDouble(dx);
693 break;
694 }
695
696 case TYPE_BINARY_FLOAT'g':
697 {
698 unsigned char buf[8];
699 double x;
700 if (r_string((char*)buf, 8, p) != 8) {
701 PyErr_SetString(PyExc_EOFError,
702 "EOF read where object expected");
703 retval = NULL((void *)0);
704 break;
705 }
706 x = _PyFloat_Unpack8(buf, 1);
707 if (x == -1.0 && PyErr_Occurred()) {
708 retval = NULL((void *)0);
709 break;
710 }
711 retval = PyFloat_FromDouble(x);
712 break;
713 }
714
715 case TYPE_COMPLEX'x':
716 {
717 char buf[256];
718 Py_complex c;
719 retval = NULL((void *)0);
720 n = r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
;
721 if (n == EOF(-1) || r_string(buf, (int)n, p) != n) {
722 PyErr_SetString(PyExc_EOFError,
723 "EOF read where object expected");
724 break;
725 }
726 buf[n] = '\0';
727 c.real = PyOS_string_to_double(buf, NULL((void *)0), NULL((void *)0));
728 if (c.real == -1.0 && PyErr_Occurred())
729 break;
730 n = r_byte(p)((p)->fp ? getc((p)->fp) : (((p)->ptr < (p)->end
) ? (unsigned char)*(p)->ptr++ : (-1)))
;
731 if (n == EOF(-1) || r_string(buf, (int)n, p) != n) {
732 PyErr_SetString(PyExc_EOFError,
733 "EOF read where object expected");
734 break;
735 }
736 buf[n] = '\0';
737 c.imag = PyOS_string_to_double(buf, NULL((void *)0), NULL((void *)0));
738 if (c.imag == -1.0 && PyErr_Occurred())
739 break;
740 retval = PyComplex_FromCComplex(c);
741 break;
742 }
743
744 case TYPE_BINARY_COMPLEX'y':
745 {
746 unsigned char buf[8];
747 Py_complex c;
748 if (r_string((char*)buf, 8, p) != 8) {
749 PyErr_SetString(PyExc_EOFError,
750 "EOF read where object expected");
751 retval = NULL((void *)0);
752 break;
753 }
754 c.real = _PyFloat_Unpack8(buf, 1);
755 if (c.real == -1.0 && PyErr_Occurred()) {
756 retval = NULL((void *)0);
757 break;
758 }
759 if (r_string((char*)buf, 8, p) != 8) {
760 PyErr_SetString(PyExc_EOFError,
761 "EOF read where object expected");
762 retval = NULL((void *)0);
763 break;
764 }
765 c.imag = _PyFloat_Unpack8(buf, 1);
766 if (c.imag == -1.0 && PyErr_Occurred()) {
767 retval = NULL((void *)0);
768 break;
769 }
770 retval = PyComplex_FromCComplex(c);
771 break;
772 }
773
774 case TYPE_STRING's':
775 n = r_long(p);
776 if (n < 0 || n > INT_MAX2147483647) {
777 PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)");
778 retval = NULL((void *)0);
779 break;
780 }
781 v = PyBytes_FromStringAndSize((char *)NULL((void *)0), n);
782 if (v == NULL((void *)0)) {
783 retval = NULL((void *)0);
784 break;
785 }
786 if (r_string(PyBytes_AS_STRING(v)((__builtin_expect(!(((((((PyObject*)(v))->ob_type))->tp_flags
& ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 786, "PyBytes_Check(v)") : (void)0), (((PyBytesObject *)(v)
)->ob_sval))
, (int)n, p) != n) {
787 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 787, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
788 PyErr_SetString(PyExc_EOFError,
789 "EOF read where object expected");
790 retval = NULL((void *)0);
791 break;
792 }
793 retval = v;
794 break;
795
796 case TYPE_UNICODE'u':
797 {
798 char *buffer;
799
800 n = r_long(p);
801 if (n < 0 || n > INT_MAX2147483647) {
802 PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)");
803 retval = NULL((void *)0);
804 break;
805 }
806 buffer = PyMem_NEW(char, n)( ((size_t)(n) > ((Py_ssize_t)(((size_t)-1)>>1)) / sizeof
(char)) ? ((void *)0) : ( (char *) _PyMem_DebugMalloc((n) * sizeof
(char)) ) )
;
807 if (buffer == NULL((void *)0)) {
808 retval = PyErr_NoMemory();
809 break;
810 }
811 if (r_string(buffer, (int)n, p) != n) {
812 PyMem_DEL_PyMem_DebugFree(buffer);
813 PyErr_SetString(PyExc_EOFError,
814 "EOF read where object expected");
815 retval = NULL((void *)0);
816 break;
817 }
818 v = PyUnicode_DecodeUTF8PyUnicodeUCS2_DecodeUTF8(buffer, n, "surrogatepass");
819 PyMem_DEL_PyMem_DebugFree(buffer);
820 retval = v;
821 break;
822 }
823
824 case TYPE_TUPLE'(':
825 n = r_long(p);
826 if (n < 0 || n > INT_MAX2147483647) {
827 PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)");
828 retval = NULL((void *)0);
829 break;
830 }
831 v = PyTuple_New((int)n);
832 if (v == NULL((void *)0)) {
833 retval = NULL((void *)0);
834 break;
835 }
836 for (i = 0; i < n; i++) {
837 v2 = r_object(p);
838 if ( v2 == NULL((void *)0) ) {
839 if (!PyErr_Occurred())
840 PyErr_SetString(PyExc_TypeError,
841 "NULL object in marshal data for tuple");
842 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 842, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
843 v = NULL((void *)0);
844 break;
845 }
846 PyTuple_SET_ITEM(v, (int)i, v2)(((PyTupleObject *)(v))->ob_item[(int)i] = v2);
847 }
848 retval = v;
849 break;
850
851 case TYPE_LIST'[':
852 n = r_long(p);
853 if (n < 0 || n > INT_MAX2147483647) {
854 PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)");
855 retval = NULL((void *)0);
856 break;
857 }
858 v = PyList_New((int)n);
859 if (v == NULL((void *)0)) {
860 retval = NULL((void *)0);
861 break;
862 }
863 for (i = 0; i < n; i++) {
864 v2 = r_object(p);
865 if ( v2 == NULL((void *)0) ) {
866 if (!PyErr_Occurred())
867 PyErr_SetString(PyExc_TypeError,
868 "NULL object in marshal data for list");
869 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 869, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
870 v = NULL((void *)0);
871 break;
872 }
873 PyList_SET_ITEM(v, (int)i, v2)(((PyListObject *)(v))->ob_item[(int)i] = (v2));
874 }
875 retval = v;
876 break;
877
878 case TYPE_DICT'{':
879 v = PyDict_New();
880 if (v == NULL((void *)0)) {
881 retval = NULL((void *)0);
882 break;
883 }
884 for (;;) {
885 PyObject *key, *val;
886 key = r_object(p);
887 if (key == NULL((void *)0))
888 break;
889 val = r_object(p);
890 if (val != NULL((void *)0))
891 PyDict_SetItem(v, key, val);
892 Py_DECREF(key)do { if (_Py_RefTotal-- , --((PyObject*)(key))->ob_refcnt !=
0) { if (((PyObject*)key)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 892, (PyObject *)(key)); } else _Py_Dealloc
((PyObject *)(key)); } while (0)
;
893 Py_XDECREF(val)do { if ((val) == ((void *)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(val))->ob_refcnt != 0) { if (((PyObject*
)val)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 893, (PyObject *)(val)); } else _Py_Dealloc((PyObject *)(val
)); } while (0); } while (0)
;
894 }
895 if (PyErr_Occurred()) {
896 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 896, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
897 v = NULL((void *)0);
898 }
899 retval = v;
900 break;
901
902 case TYPE_SET'<':
903 case TYPE_FROZENSET'>':
904 n = r_long(p);
905 if (n < 0 || n > INT_MAX2147483647) {
906 PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)");
907 retval = NULL((void *)0);
908 break;
909 }
910 v = (type == TYPE_SET'<') ? PySet_New(NULL((void *)0)) : PyFrozenSet_New(NULL((void *)0));
911 if (v == NULL((void *)0)) {
912 retval = NULL((void *)0);
913 break;
914 }
915 for (i = 0; i < n; i++) {
916 v2 = r_object(p);
917 if ( v2 == NULL((void *)0) ) {
918 if (!PyErr_Occurred())
919 PyErr_SetString(PyExc_TypeError,
920 "NULL object in marshal data for set");
921 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 921, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
922 v = NULL((void *)0);
923 break;
924 }
925 if (PySet_Add(v, v2) == -1) {
926 Py_DECREF(v)do { if (_Py_RefTotal-- , --((PyObject*)(v))->ob_refcnt !=
0) { if (((PyObject*)v)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 926, (PyObject *)(v)); } else _Py_Dealloc
((PyObject *)(v)); } while (0)
;
927 Py_DECREF(v2)do { if (_Py_RefTotal-- , --((PyObject*)(v2))->ob_refcnt !=
0) { if (((PyObject*)v2)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 927, (PyObject *)(v2)); } else _Py_Dealloc
((PyObject *)(v2)); } while (0)
;
928 v = NULL((void *)0);
929 break;
930 }
931 Py_DECREF(v2)do { if (_Py_RefTotal-- , --((PyObject*)(v2))->ob_refcnt !=
0) { if (((PyObject*)v2)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 931, (PyObject *)(v2)); } else _Py_Dealloc
((PyObject *)(v2)); } while (0)
;
932 }
933 retval = v;
934 break;
935
936 case TYPE_CODE'c':
937 {
938 int argcount;
939 int kwonlyargcount;
940 int nlocals;
941 int stacksize;
942 int flags;
943 PyObject *code = NULL((void *)0);
944 PyObject *consts = NULL((void *)0);
945 PyObject *names = NULL((void *)0);
946 PyObject *varnames = NULL((void *)0);
947 PyObject *freevars = NULL((void *)0);
948 PyObject *cellvars = NULL((void *)0);
949 PyObject *filename = NULL((void *)0);
950 PyObject *name = NULL((void *)0);
951 int firstlineno;
952 PyObject *lnotab = NULL((void *)0);
953
954 v = NULL((void *)0);
955
956 /* XXX ignore long->int overflows for now */
957 argcount = (int)r_long(p);
958 kwonlyargcount = (int)r_long(p);
959 nlocals = (int)r_long(p);
960 stacksize = (int)r_long(p);
961 flags = (int)r_long(p);
962 code = r_object(p);
963 if (code == NULL((void *)0))
964 goto code_error;
965 consts = r_object(p);
966 if (consts == NULL((void *)0))
967 goto code_error;
968 names = r_object(p);
969 if (names == NULL((void *)0))
970 goto code_error;
971 varnames = r_object(p);
972 if (varnames == NULL((void *)0))
973 goto code_error;
974 freevars = r_object(p);
975 if (freevars == NULL((void *)0))
976 goto code_error;
977 cellvars = r_object(p);
978 if (cellvars == NULL((void *)0))
979 goto code_error;
980 filename = r_object(p);
981 if (filename == NULL((void *)0))
982 goto code_error;
983 name = r_object(p);
984 if (name == NULL((void *)0))
985 goto code_error;
986 firstlineno = (int)r_long(p);
987 lnotab = r_object(p);
988 if (lnotab == NULL((void *)0))
989 goto code_error;
990
991 v = (PyObject *) PyCode_New(
992 argcount, kwonlyargcount,
993 nlocals, stacksize, flags,
994 code, consts, names, varnames,
995 freevars, cellvars, filename, name,
996 firstlineno, lnotab);
997
998 code_error:
999 Py_XDECREF(code)do { if ((code) == ((void *)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(code))->ob_refcnt != 0) { if (((PyObject
*)code)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 999, (PyObject *)(code)); } else _Py_Dealloc((PyObject *)(code
)); } while (0); } while (0)
;
1000 Py_XDECREF(consts)do { if ((consts) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(consts))->ob_refcnt != 0) { if (((PyObject
*)consts)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1000, (PyObject *)(consts)); } else _Py_Dealloc((PyObject *
)(consts)); } while (0); } while (0)
;
1001 Py_XDECREF(names)do { if ((names) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(names))->ob_refcnt != 0) { if (((PyObject
*)names)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1001, (PyObject *)(names)); } else _Py_Dealloc((PyObject *)
(names)); } while (0); } while (0)
;
1002 Py_XDECREF(varnames)do { if ((varnames) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(varnames))->ob_refcnt != 0) { if (((PyObject
*)varnames)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1002, (PyObject *)(varnames)); } else _Py_Dealloc((PyObject
*)(varnames)); } while (0); } while (0)
;
1003 Py_XDECREF(freevars)do { if ((freevars) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(freevars))->ob_refcnt != 0) { if (((PyObject
*)freevars)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1003, (PyObject *)(freevars)); } else _Py_Dealloc((PyObject
*)(freevars)); } while (0); } while (0)
;
1004 Py_XDECREF(cellvars)do { if ((cellvars) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(cellvars))->ob_refcnt != 0) { if (((PyObject
*)cellvars)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1004, (PyObject *)(cellvars)); } else _Py_Dealloc((PyObject
*)(cellvars)); } while (0); } while (0)
;
1005 Py_XDECREF(filename)do { if ((filename) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(filename))->ob_refcnt != 0) { if (((PyObject
*)filename)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1005, (PyObject *)(filename)); } else _Py_Dealloc((PyObject
*)(filename)); } while (0); } while (0)
;
1006 Py_XDECREF(name)do { if ((name) == ((void *)0)) ; else do { if (_Py_RefTotal--
, --((PyObject*)(name))->ob_refcnt != 0) { if (((PyObject
*)name)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1006, (PyObject *)(name)); } else _Py_Dealloc((PyObject *)(
name)); } while (0); } while (0)
;
1007 Py_XDECREF(lnotab)do { if ((lnotab) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(lnotab))->ob_refcnt != 0) { if (((PyObject
*)lnotab)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1007, (PyObject *)(lnotab)); } else _Py_Dealloc((PyObject *
)(lnotab)); } while (0); } while (0)
;
1008 }
1009 retval = v;
1010 break;
1011
1012 default:
1013 /* Bogus data got written, which isn't ideal.
1014 This will let you keep working and recover. */
1015 PyErr_SetString(PyExc_ValueError, "bad marshal data (unknown type code)");
1016 retval = NULL((void *)0);
1017 break;
1018
1019 }
1020 p->depth--;
1021 return retval;
1022}
1023
1024static PyObject *
1025read_object(RFILE *p)
1026{
1027 PyObject *v;
1028 if (PyErr_Occurred()) {
1029 fprintf(stderr__stderrp, "XXX readobject called with exception set\n");
1030 return NULL((void *)0);
1031 }
1032 v = r_object(p);
1033 if (v == NULL((void *)0) && !PyErr_Occurred())
1034 PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for object");
1035 return v;
1036}
1037
1038int
1039PyMarshal_ReadShortFromFile(FILE *fp)
1040{
1041 RFILE rf;
1042 assert(fp)(__builtin_expect(!(fp), 0) ? __assert_rtn(__func__, "Python/marshal.c"
, 1042, "fp") : (void)0)
;
1043 rf.fp = fp;
1044 rf.strings = NULL((void *)0);
1045 rf.end = rf.ptr = NULL((void *)0);
1046 return r_short(&rf);
1047}
1048
1049long
1050PyMarshal_ReadLongFromFile(FILE *fp)
1051{
1052 RFILE rf;
1053 rf.fp = fp;
1054 rf.strings = NULL((void *)0);
1055 rf.ptr = rf.end = NULL((void *)0);
1056 return r_long(&rf);
1057}
1058
1059#ifdef HAVE_FSTAT
1060/* Return size of file in bytes; < 0 if unknown. */
1061static off_t
1062getfilesize(FILE *fp)
1063{
1064 struct stat st;
1065 if (fstat(fileno(fp), &st) != 0)
1066 return -1;
1067 else
1068 return st.st_size;
1069}
1070#endif
1071
1072/* If we can get the size of the file up-front, and it's reasonably small,
1073 * read it in one gulp and delegate to ...FromString() instead. Much quicker
1074 * than reading a byte at a time from file; speeds .pyc imports.
1075 * CAUTION: since this may read the entire remainder of the file, don't
1076 * call it unless you know you're done with the file.
1077 */
1078PyObject *
1079PyMarshal_ReadLastObjectFromFile(FILE *fp)
1080{
1081/* REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. */
1082#define REASONABLE_FILE_LIMIT (1L << 18)
1083#ifdef HAVE_FSTAT
1084 off_t filesize;
1085 filesize = getfilesize(fp);
1086 if (filesize > 0 && filesize <= REASONABLE_FILE_LIMIT) {
1087 char* pBuf = (char *)PyMem_MALLOC_PyMem_DebugMalloc(filesize);
1088 if (pBuf != NULL((void *)0)) {
1089 PyObject* v;
1090 size_t n;
1091 /* filesize must fit into an int, because it
1092 is smaller than REASONABLE_FILE_LIMIT */
1093 n = fread(pBuf, 1, (int)filesize, fp);
1094 v = PyMarshal_ReadObjectFromString(pBuf, n);
1095 PyMem_FREE_PyMem_DebugFree(pBuf);
1096 return v;
1097 }
1098
1099 }
1100#endif
1101 /* We don't have fstat, or we do but the file is larger than
1102 * REASONABLE_FILE_LIMIT or malloc failed -- read a byte at a time.
1103 */
1104 return PyMarshal_ReadObjectFromFile(fp);
1105
1106#undef REASONABLE_FILE_LIMIT
1107}
1108
1109PyObject *
1110PyMarshal_ReadObjectFromFile(FILE *fp)
1111{
1112 RFILE rf;
1113 PyObject *result;
1114 rf.fp = fp;
1115 rf.strings = PyList_New(0);
1116 rf.depth = 0;
1117 rf.ptr = rf.end = NULL((void *)0);
1118 result = r_object(&rf);
1119 Py_DECREF(rf.strings)do { if (_Py_RefTotal-- , --((PyObject*)(rf.strings))->ob_refcnt
!= 0) { if (((PyObject*)rf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1119, (PyObject *)(rf.strings)); } else _Py_Dealloc
((PyObject *)(rf.strings)); } while (0)
;
1120 return result;
1121}
1122
1123PyObject *
1124PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len)
1125{
1126 RFILE rf;
1127 PyObject *result;
1128 rf.fp = NULL((void *)0);
1129 rf.ptr = str;
1130 rf.end = str + len;
1131 rf.strings = PyList_New(0);
1132 rf.depth = 0;
1133 result = r_object(&rf);
1134 Py_DECREF(rf.strings)do { if (_Py_RefTotal-- , --((PyObject*)(rf.strings))->ob_refcnt
!= 0) { if (((PyObject*)rf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1134, (PyObject *)(rf.strings)); } else _Py_Dealloc
((PyObject *)(rf.strings)); } while (0)
;
1135 return result;
1136}
1137
1138PyObject *
1139PyMarshal_WriteObjectToString(PyObject *x, int version)
1140{
1141 WFILE wf;
1142 PyObject *res = NULL((void *)0);
1143
1144 wf.fp = NULL((void *)0);
1145 wf.str = PyBytes_FromStringAndSize((char *)NULL((void *)0), 50);
1146 if (wf.str == NULL((void *)0))
1147 return NULL((void *)0);
1148 wf.ptr = PyBytes_AS_STRING((PyBytesObject *)wf.str)((__builtin_expect(!(((((((PyObject*)((PyBytesObject *)wf.str
))->ob_type))->tp_flags & ((1L<<27))) != 0)),
0) ? __assert_rtn(__func__, "Python/marshal.c", 1148, "PyBytes_Check((PyBytesObject *)wf.str)"
) : (void)0), (((PyBytesObject *)((PyBytesObject *)wf.str))->
ob_sval))
;
1149 wf.end = wf.ptr + PyBytes_Size(wf.str);
1150 wf.error = WFERR_OK0;
1151 wf.depth = 0;
1152 wf.version = version;
1153 wf.strings = (version > 0) ? PyDict_New() : NULL((void *)0);
1154 w_object(x, &wf);
1155 Py_XDECREF(wf.strings)do { if ((wf.strings) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(wf.strings))->ob_refcnt != 0) { if (((
PyObject*)wf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1155, (PyObject *)(wf.strings)); } else _Py_Dealloc
((PyObject *)(wf.strings)); } while (0); } while (0)
;
1156 if (wf.str != NULL((void *)0)) {
1157 char *base = PyBytes_AS_STRING((PyBytesObject *)wf.str)((__builtin_expect(!(((((((PyObject*)((PyBytesObject *)wf.str
))->ob_type))->tp_flags & ((1L<<27))) != 0)),
0) ? __assert_rtn(__func__, "Python/marshal.c", 1157, "PyBytes_Check((PyBytesObject *)wf.str)"
) : (void)0), (((PyBytesObject *)((PyBytesObject *)wf.str))->
ob_sval))
;
1158 if (wf.ptr - base > PY_SSIZE_T_MAX((Py_ssize_t)(((size_t)-1)>>1))) {
1159 Py_DECREF(wf.str)do { if (_Py_RefTotal-- , --((PyObject*)(wf.str))->ob_refcnt
!= 0) { if (((PyObject*)wf.str)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1159, (PyObject *)(wf.str)); } else _Py_Dealloc
((PyObject *)(wf.str)); } while (0)
;
1160 PyErr_SetString(PyExc_OverflowError,
1161 "too much marshal data for a string");
1162 return NULL((void *)0);
1163 }
1164 if (_PyBytes_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base)) < 0)
1165 return NULL((void *)0);
1166 }
1167 if (wf.error != WFERR_OK0) {
1168 Py_XDECREF(wf.str)do { if ((wf.str) == ((void *)0)) ; else do { if (_Py_RefTotal
-- , --((PyObject*)(wf.str))->ob_refcnt != 0) { if (((PyObject
*)wf.str)->ob_refcnt < 0) _Py_NegativeRefcount("Python/marshal.c"
, 1168, (PyObject *)(wf.str)); } else _Py_Dealloc((PyObject *
)(wf.str)); } while (0); } while (0)
;
1169 if (wf.error == WFERR_NOMEMORY3)
1170 PyErr_NoMemory();
1171 else
1172 PyErr_SetString(PyExc_ValueError,
1173 (wf.error==WFERR_UNMARSHALLABLE1)?"unmarshallable object"
1174 :"object too deeply nested to marshal");
1175 return NULL((void *)0);
1176 }
1177 if (wf.str != NULL((void *)0)) {
1178 /* XXX Quick hack -- need to do this differently */
1179 res = PyBytes_FromObject(wf.str);
1180 Py_DECREF(wf.str)do { if (_Py_RefTotal-- , --((PyObject*)(wf.str))->ob_refcnt
!= 0) { if (((PyObject*)wf.str)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1180, (PyObject *)(wf.str)); } else _Py_Dealloc
((PyObject *)(wf.str)); } while (0)
;
1181 }
1182 return res;
1183}
1184
1185/* And an interface for Python programs... */
1186
1187static PyObject *
1188marshal_dump(PyObject *self, PyObject *args)
1189{
1190 /* XXX Quick hack -- need to do this differently */
1191 PyObject *x;
1192 PyObject *f;
1193 int version = Py_MARSHAL_VERSION2;
1194 PyObject *s;
1195 PyObject *res;
1196 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "OO|i:dump", &x, &f, &version))
1197 return NULL((void *)0);
1198 s = PyMarshal_WriteObjectToString(x, version);
1199 if (s == NULL((void *)0))
1200 return NULL((void *)0);
1201 res = PyObject_CallMethod_PyObject_CallMethod_SizeT(f, "write", "O", s);
1202 Py_DECREF(s)do { if (_Py_RefTotal-- , --((PyObject*)(s))->ob_refcnt !=
0) { if (((PyObject*)s)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1202, (PyObject *)(s)); } else _Py_Dealloc
((PyObject *)(s)); } while (0)
;
1203 return res;
1204}
1205
1206PyDoc_STRVAR(dump_doc,static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1207"dump(value, file[, version])\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1208\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1209Write the value on the open file. The value must be a supported type.\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1210The file must be an open file object such as sys.stdout or returned by\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1211open() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1212\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1213If the value has (or contains an object that has) an unsupported type, a\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1214ValueError exception is raised — but garbage data will also be written\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1215to the file. The object will not be properly read back by load()\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1216\n\static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use."
1217The version argument indicates the data format that dump should use.")static char dump_doc[] = "dump(value, file[, version])\n\nWrite the value on the open file. The value must be a supported type.\nThe file must be an open file object such as sys.stdout or returned by\nopen() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\nIf the value has (or contains an object that has) an unsupported type, a\nValueError exception is raised — but garbage data will also be written\nto the file. The object will not be properly read back by load()\n\nThe version argument indicates the data format that dump should use.";
1218
1219static PyObject *
1220marshal_load(PyObject *self, PyObject *f)
1221{
1222 /* XXX Quick hack -- need to do this differently */
1223 PyObject *data, *result;
1224 RFILE rf;
1225 data = PyObject_CallMethod_PyObject_CallMethod_SizeT(f, "read", "");
1226 if (data == NULL((void *)0))
1227 return NULL((void *)0);
1228 rf.fp = NULL((void *)0);
1229 if (PyBytes_Check(data)((((((PyObject*)(data))->ob_type))->tp_flags & ((1L
<<27))) != 0)
) {
1230 rf.ptr = PyBytes_AS_STRING(data)((__builtin_expect(!(((((((PyObject*)(data))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 1230, "PyBytes_Check(data)") : (void)0)
, (((PyBytesObject *)(data))->ob_sval))
;
1231 rf.end = rf.ptr + PyBytes_GET_SIZE(data)((__builtin_expect(!(((((((PyObject*)(data))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 1231, "PyBytes_Check(data)") : (void)0)
,(((PyVarObject*)(data))->ob_size))
;
1232 }
1233 else if (PyBytes_Check(data)((((((PyObject*)(data))->ob_type))->tp_flags & ((1L
<<27))) != 0)
) {
1234 rf.ptr = PyBytes_AS_STRING(data)((__builtin_expect(!(((((((PyObject*)(data))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 1234, "PyBytes_Check(data)") : (void)0)
, (((PyBytesObject *)(data))->ob_sval))
;
1235 rf.end = rf.ptr + PyBytes_GET_SIZE(data)((__builtin_expect(!(((((((PyObject*)(data))->ob_type))->
tp_flags & ((1L<<27))) != 0)), 0) ? __assert_rtn(__func__
, "Python/marshal.c", 1235, "PyBytes_Check(data)") : (void)0)
,(((PyVarObject*)(data))->ob_size))
;
1236 }
1237 else {
1238 PyErr_Format(PyExc_TypeError,
1239 "f.read() returned neither string "
1240 "nor bytes but %.100s",
1241 data->ob_type->tp_name);
1242 Py_DECREF(data)do { if (_Py_RefTotal-- , --((PyObject*)(data))->ob_refcnt
!= 0) { if (((PyObject*)data)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1242, (PyObject *)(data)); } else _Py_Dealloc
((PyObject *)(data)); } while (0)
;
1243 return NULL((void *)0);
1244 }
1245 rf.strings = PyList_New(0);
1246 rf.depth = 0;
1247 result = read_object(&rf);
1248 Py_DECREF(rf.strings)do { if (_Py_RefTotal-- , --((PyObject*)(rf.strings))->ob_refcnt
!= 0) { if (((PyObject*)rf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1248, (PyObject *)(rf.strings)); } else _Py_Dealloc
((PyObject *)(rf.strings)); } while (0)
;
1249 Py_DECREF(data)do { if (_Py_RefTotal-- , --((PyObject*)(data))->ob_refcnt
!= 0) { if (((PyObject*)data)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1249, (PyObject *)(data)); } else _Py_Dealloc
((PyObject *)(data)); } while (0)
;
1250 return result;
1251}
1252
1253PyDoc_STRVAR(load_doc,static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1254"load(file)\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1255\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1256Read one value from the open file and return it. If no valid value is\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1257read (e.g. because the data has a different Python version’s\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1258incompatible marshal format), raise EOFError, ValueError or TypeError.\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1259The file must be an open file object opened in binary mode ('rb' or\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1260'r+b').\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1261\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1262Note: If an object containing an unsupported type was marshalled with\n\static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type."
1263dump(), load() will substitute None for the unmarshallable type.")static char load_doc[] = "load(file)\n\nRead one value from the open file and return it. If no valid value is\nread (e.g. because the data has a different Python version’s\nincompatible marshal format), raise EOFError, ValueError or TypeError.\nThe file must be an open file object opened in binary mode ('rb' or\n'r+b').\n\nNote: If an object containing an unsupported type was marshalled with\ndump(), load() will substitute None for the unmarshallable type.";
1264
1265
1266static PyObject *
1267marshal_dumps(PyObject *self, PyObject *args)
1268{
1269 PyObject *x;
1270 int version = Py_MARSHAL_VERSION2;
1271 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "O|i:dumps", &x, &version))
1272 return NULL((void *)0);
1273 return PyMarshal_WriteObjectToString(x, version);
1274}
1275
1276PyDoc_STRVAR(dumps_doc,static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1277"dumps(value[, version])\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1278\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1279Return the string that would be written to a file by dump(value, file).\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1280The value must be a supported type. Raise a ValueError exception if\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1281value has (or contains an object that has) an unsupported type.\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1282\n\static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use."
1283The version argument indicates the data format that dumps should use.")static char dumps_doc[] = "dumps(value[, version])\n\nReturn the string that would be written to a file by dump(value, file).\nThe value must be a supported type. Raise a ValueError exception if\nvalue has (or contains an object that has) an unsupported type.\n\nThe version argument indicates the data format that dumps should use.";
1284
1285
1286static PyObject *
1287marshal_loads(PyObject *self, PyObject *args)
1288{
1289 RFILE rf;
1290 Py_buffer p;
1291 char *s;
1292 Py_ssize_t n;
1293 PyObject* result;
1294 if (!PyArg_ParseTuple_PyArg_ParseTuple_SizeT(args, "s*:loads", &p))
1295 return NULL((void *)0);
1296 s = p.buf;
1297 n = p.len;
1298 rf.fp = NULL((void *)0);
1299 rf.ptr = s;
1300 rf.end = s + n;
1301 rf.strings = PyList_New(0);
1302 rf.depth = 0;
1303 result = read_object(&rf);
1304 Py_DECREF(rf.strings)do { if (_Py_RefTotal-- , --((PyObject*)(rf.strings))->ob_refcnt
!= 0) { if (((PyObject*)rf.strings)->ob_refcnt < 0) _Py_NegativeRefcount
("Python/marshal.c", 1304, (PyObject *)(rf.strings)); } else _Py_Dealloc
((PyObject *)(rf.strings)); } while (0)
;
1305 PyBuffer_Release(&p);
1306 return result;
1307}
1308
1309PyDoc_STRVAR(loads_doc,static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored."
1310"loads(string)\n\static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored."
1311\n\static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored."
1312Convert the string to a value. If no valid value is found, raise\n\static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored."
1313EOFError, ValueError or TypeError. Extra characters in the string are\n\static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored."
1314ignored.")static char loads_doc[] = "loads(string)\n\nConvert the string to a value. If no valid value is found, raise\nEOFError, ValueError or TypeError. Extra characters in the string are\nignored.";
1315
1316static PyMethodDef marshal_methods[] = {
1317 {"dump", marshal_dump, METH_VARARGS0x0001, dump_doc},
1318 {"load", marshal_load, METH_O0x0008, load_doc},
1319 {"dumps", marshal_dumps, METH_VARARGS0x0001, dumps_doc},
1320 {"loads", marshal_loads, METH_VARARGS0x0001, loads_doc},
1321 {NULL((void *)0), NULL((void *)0)} /* sentinel */
1322};
1323
1324
1325PyDoc_STRVAR(module_doc,static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1326"This module contains functions that can read and write Python values in\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1327a binary format. The format is specific to Python, but independent of\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1328machine architecture issues.\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1329\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1330Not all Python object types are supported; in general, only objects\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1331whose value is independent from a particular invocation of Python can be\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1332written and read by this module. The following types are supported:\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1333None, integers, floating point numbers, strings, bytes, bytearrays,\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1334tuples, lists, sets, dictionaries, and code objects, where it\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1335should be understood that tuples, lists and dictionaries are only\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1336supported as long as the values contained therein are themselves\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1337supported; and recursive lists and dictionaries should not be written\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1338(they will cause infinite loops).\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1339\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1340Variables:\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1341\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1342version -- indicates the format that the module uses. Version 0 is the\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1343 historical format, version 1 shares interned strings and version 2\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1344 uses a binary format for floating point numbers.\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1345\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1346Functions:\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1347\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1348dump() -- write value to a file\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1349load() -- read value from a file\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1350dumps() -- write value to a string\n\static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string"
1351loads() -- read value from a string")static char module_doc[] = "This module contains functions that can read and write Python values in\na binary format. The format is specific to Python, but independent of\nmachine architecture issues.\n\nNot all Python object types are supported; in general, only objects\nwhose value is independent from a particular invocation of Python can be\nwritten and read by this module. The following types are supported:\nNone, integers, floating point numbers, strings, bytes, bytearrays,\ntuples, lists, sets, dictionaries, and code objects, where it\nshould be understood that tuples, lists and dictionaries are only\nsupported as long as the values contained therein are themselves\nsupported; and recursive lists and dictionaries should not be written\n(they will cause infinite loops).\n\nVariables:\n\nversion -- indicates the format that the module uses. Version 0 is the\n historical format, version 1 shares interned strings and version 2\n uses a binary format for floating point numbers.\n\nFunctions:\n\ndump() -- write value to a file\nload() -- read value from a file\ndumps() -- write value to a string\nloads() -- read value from a string";
1352
1353
1354
1355static struct PyModuleDef marshalmodule = {
1356 PyModuleDef_HEAD_INIT{ { 0, 0, 1, ((void *)0) }, ((void *)0), 0, ((void *)0), },
1357 "marshal",
1358 module_doc,
1359 0,
1360 marshal_methods,
1361 NULL((void *)0),
1362 NULL((void *)0),
1363 NULL((void *)0),
1364 NULL((void *)0)
1365};
1366
1367PyMODINIT_FUNCPyObject*
1368PyMarshal_Init(void)
1369{
1370 PyObject *mod = PyModule_Create(&marshalmodule)PyModule_Create2TraceRefs(&marshalmodule, 1013);
1371 if (mod == NULL((void *)0))
1372 return NULL((void *)0);
1373 PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION2);
1374 return mod;
1375}