Mercurial > cpython-lru_cache-weakref
annotate Python/marshal.c @ 55822:6758bf2002da legacy-trunk
#5101: add back tests to test_funcattrs that were lost during unittest conversion, and make some PEP8 cleanups.
| author | Georg Brandl <georg@python.org> |
|---|---|
| date | Fri, 04 Sep 2009 11:19:34 +0000 |
| parents | bbb911f7c0c2 |
| children | 91f9df5367c1 |
| rev | line source |
|---|---|
| 267 | 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 | |
|
36792
688795873ff1
Make Py_ssize_t clean.
Thomas Wouters <thomas@python.org>
parents:
36784
diff
changeset
|
7 #define PY_SSIZE_T_CLEAN |
|
688795873ff1
Make Py_ssize_t clean.
Thomas Wouters <thomas@python.org>
parents:
36784
diff
changeset
|
8 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
9 #include "Python.h" |
| 267 | 10 #include "longintrepr.h" |
|
35742
1c4d192f1568
Merge ast-branch to head
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
35346
diff
changeset
|
11 #include "code.h" |
| 267 | 12 #include "marshal.h" |
| 13 | |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
14 #define ABS(x) ((x) < 0 ? -(x) : (x)) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
15 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
16 /* High water mark to determine when the marshalled object is dangerously deep |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
17 * and risks coring the interpreter. When the object stack gets this deep, |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
18 * raise an exception instead of continuing. |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
19 */ |
|
41748
6f0dba807734
Last try for tweaking the max stack depth. 5000 was the original value,
Neal Norwitz <nnorwitz@gmail.com>
parents:
41747
diff
changeset
|
20 #define MAX_MARSHAL_STACK_DEPTH 2000 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
21 |
| 35008 | 22 #define TYPE_NULL '0' |
| 23 #define TYPE_NONE 'N' | |
| 24 #define TYPE_FALSE 'F' | |
| 25 #define TYPE_TRUE 'T' | |
| 26 #define TYPE_STOPITER 'S' | |
| 27 #define TYPE_ELLIPSIS '.' | |
| 28 #define TYPE_INT 'i' | |
| 29 #define TYPE_INT64 'I' | |
| 30 #define TYPE_FLOAT 'f' | |
| 31 #define TYPE_BINARY_FLOAT 'g' | |
| 32 #define TYPE_COMPLEX 'x' | |
| 33 #define TYPE_BINARY_COMPLEX 'y' | |
| 34 #define TYPE_LONG 'l' | |
| 35 #define TYPE_STRING 's' | |
| 36 #define TYPE_INTERNED 't' | |
| 37 #define TYPE_STRINGREF 'R' | |
| 38 #define TYPE_TUPLE '(' | |
| 39 #define TYPE_LIST '[' | |
| 40 #define TYPE_DICT '{' | |
| 41 #define TYPE_CODE 'c' | |
| 42 #define TYPE_UNICODE 'u' | |
| 43 #define TYPE_UNKNOWN '?' | |
| 44 #define TYPE_SET '<' | |
| 45 #define TYPE_FROZENSET '>' | |
| 267 | 46 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
47 typedef struct { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
48 FILE *fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
49 int error; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
50 int depth; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
51 /* If fp == NULL, the following are valid: */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
52 PyObject *str; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 char *ptr; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
54 char *end; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
55 PyObject *strings; /* dict on marshal, list on unmarshal */ |
| 35008 | 56 int version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
57 } WFILE; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
58 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
59 #define w_byte(c, p) if (((p)->fp)) putc((c), (p)->fp); \ |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
60 else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \ |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
61 else w_more(c, p) |
| 267 | 62 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
63 static void |
|
13672
bfc5b2a8c11f
-- changed w_more to take an integer instead of a char
Fredrik Lundh <fredrik@pythonware.com>
parents:
13658
diff
changeset
|
64 w_more(int c, WFILE *p) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
65 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
66 Py_ssize_t size, newsize; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
67 if (p->str == NULL) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
68 return; /* An error already occurred */ |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
69 size = PyString_Size(p->str); |
|
46880
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
45081
diff
changeset
|
70 newsize = size + size + 1024; |
|
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
45081
diff
changeset
|
71 if (newsize > 32*1024*1024) { |
|
47730
4650eefb5838
Issue 3116: fix quadratic behavior in marshal.dumps().
Raymond Hettinger <python@rcn.com>
parents:
47527
diff
changeset
|
72 newsize = size + (size >> 3); /* 12.5% overallocation */ |
|
46880
4fb6c0c169ff
#1792: Improve performance of marshal.dumps() on large objects by increasing
Andrew M. Kuchling <amk@amk.ca>
parents:
45081
diff
changeset
|
73 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
74 if (_PyString_Resize(&p->str, newsize) != 0) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
75 p->ptr = p->end = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
76 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
77 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
78 p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
79 p->end = |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
80 PyString_AS_STRING((PyStringObject *)p->str) + newsize; |
|
13674
c90d94d287d7
Included assert.h in Python.h -- it's absurd that this basic tool of
Tim Peters <tim.peters@gmail.com>
parents:
13672
diff
changeset
|
81 *p->ptr++ = Py_SAFE_DOWNCAST(c, int, char); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
82 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
83 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
84 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
85 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
86 w_string(char *s, int n, WFILE *p) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
87 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
88 if (p->fp != NULL) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
89 fwrite(s, 1, n, p->fp); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
90 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
91 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
92 while (--n >= 0) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
93 w_byte(*s, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
94 s++; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
95 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
96 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
97 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
98 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
99 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
100 w_short(int x, WFILE *p) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
101 { |
|
24434
9ef82377669d
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
Thomas Heller <theller@ctypes.org>
parents:
23851
diff
changeset
|
102 w_byte((char)( x & 0xff), p); |
|
9ef82377669d
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
Thomas Heller <theller@ctypes.org>
parents:
23851
diff
changeset
|
103 w_byte((char)((x>> 8) & 0xff), p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
104 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
105 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
106 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
107 w_long(long x, WFILE *p) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
108 { |
|
24435
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
109 w_byte((char)( x & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
110 w_byte((char)((x>> 8) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
111 w_byte((char)((x>>16) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
112 w_byte((char)((x>>24) & 0xff), p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
113 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
114 |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
115 #if SIZEOF_LONG > 4 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
116 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
117 w_long64(long x, WFILE *p) |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
118 { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
119 w_long(x, p); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
120 w_long(x>>32, p); |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
121 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
122 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
123 |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
124 /* We assume that Python longs are stored internally in base some power of |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
125 2**15; for the sake of portability we'll always read and write them in base |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
126 exactly 2**15. */ |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
127 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
128 #define PyLong_MARSHAL_SHIFT 15 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
129 #define PyLong_MARSHAL_BASE ((short)1 << PyLong_MARSHAL_SHIFT) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
130 #define PyLong_MARSHAL_MASK (PyLong_MARSHAL_BASE - 1) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
131 #if PyLong_SHIFT % PyLong_MARSHAL_SHIFT != 0 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
132 #error "PyLong_SHIFT must be a multiple of PyLong_MARSHAL_SHIFT" |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
133 #endif |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
134 #define PyLong_MARSHAL_RATIO (PyLong_SHIFT / PyLong_MARSHAL_SHIFT) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
135 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
136 static void |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
137 w_PyLong(const PyLongObject *ob, WFILE *p) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
138 { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
139 Py_ssize_t i, j, n, l; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
140 digit d; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
141 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
142 w_byte(TYPE_LONG, p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
143 if (Py_SIZE(ob) == 0) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
144 w_long((long)0, p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
145 return; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
146 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
147 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
148 /* set l to number of base PyLong_MARSHAL_BASE digits */ |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
149 n = ABS(Py_SIZE(ob)); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
150 l = (n-1) * PyLong_MARSHAL_RATIO; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
151 d = ob->ob_digit[n-1]; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
152 assert(d != 0); /* a PyLong is always normalized */ |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
153 do { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
154 d >>= PyLong_MARSHAL_SHIFT; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
155 l++; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
156 } while (d != 0); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
157 w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
158 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
159 for (i=0; i < n-1; i++) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
160 d = ob->ob_digit[i]; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
161 for (j=0; j < PyLong_MARSHAL_RATIO; j++) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
162 w_short(d & PyLong_MARSHAL_MASK, p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
163 d >>= PyLong_MARSHAL_SHIFT; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
164 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
165 assert (d == 0); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
166 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
167 d = ob->ob_digit[n-1]; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
168 do { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
169 w_short(d & PyLong_MARSHAL_MASK, p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
170 d >>= PyLong_MARSHAL_SHIFT; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
171 } while (d != 0); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
172 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
173 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
174 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
175 w_object(PyObject *v, WFILE *p) |
| 267 | 176 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
177 Py_ssize_t i, n; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
178 |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
179 p->depth++; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
180 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
181 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
182 p->error = 2; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
183 } |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
184 else if (v == NULL) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
185 w_byte(TYPE_NULL, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
186 } |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
187 else if (v == Py_None) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
188 w_byte(TYPE_NONE, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
189 } |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
190 else if (v == PyExc_StopIteration) { |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
191 w_byte(TYPE_STOPITER, p); |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
192 } |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
193 else if (v == Py_Ellipsis) { |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
194 w_byte(TYPE_ELLIPSIS, p); |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
195 } |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
196 else if (v == Py_False) { |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
197 w_byte(TYPE_FALSE, p); |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
198 } |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
199 else if (v == Py_True) { |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
200 w_byte(TYPE_TRUE, p); |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
201 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
202 else if (PyInt_CheckExact(v)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
203 long x = PyInt_AS_LONG((PyIntObject *)v); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
204 #if SIZEOF_LONG > 4 |
|
17368
bb75d93f6a31
test_pickle works on sizeof(long)==8 boxes again.
Tim Peters <tim.peters@gmail.com>
parents:
16311
diff
changeset
|
205 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31); |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
206 if (y && y != -1) { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
207 w_byte(TYPE_INT64, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
208 w_long64(x, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
209 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
210 else |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
211 #endif |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
212 { |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
213 w_byte(TYPE_INT, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
214 w_long(x, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
215 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
216 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
217 else if (PyLong_CheckExact(v)) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
218 PyLongObject *ob = (PyLongObject *)v; |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
219 w_PyLong(ob, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
220 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
221 else if (PyFloat_CheckExact(v)) { |
| 35008 | 222 if (p->version > 1) { |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
223 unsigned char buf[8]; |
| 35008 | 224 if (_PyFloat_Pack8(PyFloat_AsDouble(v), |
| 225 buf, 1) < 0) { | |
| 226 p->error = 1; | |
| 227 return; | |
| 228 } | |
| 229 w_byte(TYPE_BINARY_FLOAT, p); | |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
230 w_string((char*)buf, 8, p); |
| 35008 | 231 } |
| 232 else { | |
| 233 char buf[256]; /* Plenty to format any double */ | |
| 234 PyFloat_AsReprString(buf, (PyFloatObject *)v); | |
|
36522
2791676b3825
Move cast to suppress warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
235 n = strlen(buf); |
| 35008 | 236 w_byte(TYPE_FLOAT, p); |
|
36522
2791676b3825
Move cast to suppress warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
237 w_byte((int)n, p); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
238 w_string(buf, (int)n, p); |
| 35008 | 239 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
240 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
241 #ifndef WITHOUT_COMPLEX |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
242 else if (PyComplex_CheckExact(v)) { |
| 35008 | 243 if (p->version > 1) { |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
244 unsigned char buf[8]; |
| 35008 | 245 if (_PyFloat_Pack8(PyComplex_RealAsDouble(v), |
| 246 buf, 1) < 0) { | |
| 247 p->error = 1; | |
| 248 return; | |
| 249 } | |
| 250 w_byte(TYPE_BINARY_COMPLEX, p); | |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
251 w_string((char*)buf, 8, p); |
| 35008 | 252 if (_PyFloat_Pack8(PyComplex_ImagAsDouble(v), |
| 253 buf, 1) < 0) { | |
| 254 p->error = 1; | |
| 255 return; | |
| 256 } | |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
257 w_string((char*)buf, 8, p); |
| 35008 | 258 } |
| 259 else { | |
| 260 char buf[256]; /* Plenty to format any double */ | |
| 261 PyFloatObject *temp; | |
| 262 w_byte(TYPE_COMPLEX, p); | |
| 263 temp = (PyFloatObject*)PyFloat_FromDouble( | |
| 264 PyComplex_RealAsDouble(v)); | |
|
39448
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
265 if (!temp) { |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
266 p->error = 1; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
267 return; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
268 } |
| 35008 | 269 PyFloat_AsReprString(buf, temp); |
| 270 Py_DECREF(temp); | |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
271 n = strlen(buf); |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
272 w_byte((int)n, p); |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
273 w_string(buf, (int)n, p); |
| 35008 | 274 temp = (PyFloatObject*)PyFloat_FromDouble( |
| 275 PyComplex_ImagAsDouble(v)); | |
|
39448
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
276 if (!temp) { |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
277 p->error = 1; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
278 return; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
279 } |
| 35008 | 280 PyFloat_AsReprString(buf, temp); |
| 281 Py_DECREF(temp); | |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
282 n = strlen(buf); |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
283 w_byte((int)n, p); |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
284 w_string(buf, (int)n, p); |
| 35008 | 285 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
286 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
287 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
288 else if (PyString_CheckExact(v)) { |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
289 if (p->strings && PyString_CHECK_INTERNED(v)) { |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
290 PyObject *o = PyDict_GetItem(p->strings, v); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
291 if (o) { |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
292 long w = PyInt_AsLong(o); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
293 w_byte(TYPE_STRINGREF, p); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
294 w_long(w, p); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
295 goto exit; |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
296 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
297 else { |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
298 int ok; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
299 o = PyInt_FromSsize_t(PyDict_Size(p->strings)); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
300 ok = o && |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
301 PyDict_SetItem(p->strings, v, o) >= 0; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
302 Py_XDECREF(o); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
303 if (!ok) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
304 p->depth--; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
305 p->error = 1; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
306 return; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
307 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
308 w_byte(TYPE_INTERNED, p); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
309 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
310 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
311 else { |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
312 w_byte(TYPE_STRING, p); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
313 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
314 n = PyString_GET_SIZE(v); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
315 if (n > INT_MAX) { |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
316 /* huge strings are not supported */ |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
317 p->depth--; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
318 p->error = 1; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
319 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
320 } |
|
2368
663aa059e29f
hope to fix DEC Alpha gcc problems by declaring ints instead of longs
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
321 w_long((long)n, p); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
322 w_string(PyString_AS_STRING(v), (int)n, p); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
323 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
324 #ifdef Py_USING_UNICODE |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
325 else if (PyUnicode_CheckExact(v)) { |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
326 PyObject *utf8; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
327 utf8 = PyUnicode_AsUTF8String(v); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
328 if (utf8 == NULL) { |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
329 p->depth--; |
|
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
330 p->error = 1; |
|
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
331 return; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
332 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
333 w_byte(TYPE_UNICODE, p); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
334 n = PyString_GET_SIZE(utf8); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
335 if (n > INT_MAX) { |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
336 p->depth--; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
337 p->error = 1; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
338 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
339 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
340 w_long((long)n, p); |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
341 w_string(PyString_AS_STRING(utf8), (int)n, p); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
342 Py_DECREF(utf8); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
343 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
344 #endif |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
345 else if (PyTuple_CheckExact(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
346 w_byte(TYPE_TUPLE, p); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
347 n = PyTuple_Size(v); |
|
2368
663aa059e29f
hope to fix DEC Alpha gcc problems by declaring ints instead of longs
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
348 w_long((long)n, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
349 for (i = 0; i < n; i++) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
350 w_object(PyTuple_GET_ITEM(v, i), p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
351 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
352 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
353 else if (PyList_CheckExact(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
354 w_byte(TYPE_LIST, p); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
355 n = PyList_GET_SIZE(v); |
|
2368
663aa059e29f
hope to fix DEC Alpha gcc problems by declaring ints instead of longs
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
356 w_long((long)n, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
357 for (i = 0; i < n; i++) { |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
358 w_object(PyList_GET_ITEM(v, i), p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
359 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
360 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
361 else if (PyDict_CheckExact(v)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
362 Py_ssize_t pos; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
363 PyObject *key, *value; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
364 w_byte(TYPE_DICT, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
365 /* This one is NULL object terminated! */ |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
366 pos = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
367 while (PyDict_Next(v, &pos, &key, &value)) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
368 w_object(key, p); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
369 w_object(value, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
370 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
371 w_object((PyObject *)NULL, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
372 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
373 else if (PyAnySet_CheckExact(v)) { |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
374 PyObject *value, *it; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
375 |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
376 if (PyObject_TypeCheck(v, &PySet_Type)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
377 w_byte(TYPE_SET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
378 else |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
379 w_byte(TYPE_FROZENSET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
380 n = PyObject_Size(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
381 if (n == -1) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
382 p->depth--; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
383 p->error = 1; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
384 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
385 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
386 w_long((long)n, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
387 it = PyObject_GetIter(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
388 if (it == NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
389 p->depth--; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
390 p->error = 1; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
391 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
392 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
393 while ((value = PyIter_Next(it)) != NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
394 w_object(value, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
395 Py_DECREF(value); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
396 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
397 Py_DECREF(it); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
398 if (PyErr_Occurred()) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
399 p->depth--; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
400 p->error = 1; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
401 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
402 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
403 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
404 else if (PyCode_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
405 PyCodeObject *co = (PyCodeObject *)v; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
406 w_byte(TYPE_CODE, p); |
|
23851
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
407 w_long(co->co_argcount, p); |
|
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
408 w_long(co->co_nlocals, p); |
|
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
409 w_long(co->co_stacksize, p); |
|
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
410 w_long(co->co_flags, p); |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
411 w_object(co->co_code, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
412 w_object(co->co_consts, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
413 w_object(co->co_names, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
414 w_object(co->co_varnames, p); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
415 w_object(co->co_freevars, p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
416 w_object(co->co_cellvars, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
417 w_object(co->co_filename, p); |
|
1257
1cabc2b6c970
* Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents:
1191
diff
changeset
|
418 w_object(co->co_name, p); |
|
23851
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
419 w_long(co->co_firstlineno, p); |
|
5042
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
420 w_object(co->co_lnotab, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
421 } |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20552
diff
changeset
|
422 else if (PyObject_CheckReadBuffer(v)) { |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
423 /* Write unknown buffer-style objects as a string */ |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
424 char *s; |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20552
diff
changeset
|
425 PyBufferProcs *pb = v->ob_type->tp_as_buffer; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
426 w_byte(TYPE_STRING, p); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
427 n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
428 if (n > INT_MAX) { |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
429 p->depth--; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
430 p->error = 1; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
431 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
432 } |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
433 w_long((long)n, p); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
434 w_string(s, (int)n, p); |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
435 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
436 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
437 w_byte(TYPE_UNKNOWN, p); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
438 p->error = 1; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
439 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
440 exit: |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
441 p->depth--; |
| 267 | 442 } |
| 443 | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
444 /* version currently has no effect for writing longs. */ |
| 267 | 445 void |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
446 PyMarshal_WriteLongToFile(long x, FILE *fp, int version) |
| 267 | 447 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
448 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
449 wf.fp = fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
450 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
451 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
452 wf.strings = NULL; |
| 35008 | 453 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
454 w_long(x, &wf); |
| 267 | 455 } |
| 456 | |
| 457 void | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
458 PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) |
| 267 | 459 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
460 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
461 wf.fp = fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
462 wf.error = 0; |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
463 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
464 wf.strings = (version > 0) ? PyDict_New() : NULL; |
| 35008 | 465 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
466 w_object(x, &wf); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
467 Py_XDECREF(wf.strings); |
| 267 | 468 } |
| 469 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
470 typedef WFILE RFILE; /* Same struct with different invariants */ |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
471 |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
472 #define rs_byte(p) (((p)->ptr < (p)->end) ? (unsigned char)*(p)->ptr++ : EOF) |
|
2503
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
473 |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
474 #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) |
| 267 | 475 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
476 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
477 r_string(char *s, int n, RFILE *p) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
478 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
479 if (p->fp != NULL) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
480 /* The result fits into int because it must be <=n. */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
481 return (int)fread(s, 1, n, p->fp); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
482 if (p->end - p->ptr < n) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
483 n = (int)(p->end - p->ptr); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
484 memcpy(s, p->ptr, n); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
485 p->ptr += n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
486 return n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
487 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
488 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
489 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
490 r_short(RFILE *p) |
| 267 | 491 { |
| 492 register short x; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
493 x = r_byte(p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
494 x |= r_byte(p) << 8; |
| 14678 | 495 /* Sign-extension, in case short greater than 16 bits */ |
| 496 x |= -(x & 0x8000); | |
| 267 | 497 return x; |
| 498 } | |
| 499 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
500 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
501 r_long(RFILE *p) |
| 267 | 502 { |
| 503 register long x; | |
|
2503
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
504 register FILE *fp = p->fp; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
505 if (fp) { |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
506 x = getc(fp); |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
507 x |= (long)getc(fp) << 8; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
508 x |= (long)getc(fp) << 16; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
509 x |= (long)getc(fp) << 24; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
510 } |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
511 else { |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
512 x = rs_byte(p); |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
513 x |= (long)rs_byte(p) << 8; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
514 x |= (long)rs_byte(p) << 16; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
515 x |= (long)rs_byte(p) << 24; |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
516 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
517 #if SIZEOF_LONG > 4 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
518 /* Sign extension for 64-bit machines */ |
| 14678 | 519 x |= -(x & 0x80000000L); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
520 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
521 return x; |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
522 } |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
523 |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
524 /* r_long64 deals with the TYPE_INT64 code. On a machine with |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
525 sizeof(long) > 4, it returns a Python int object, else a Python long |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
526 object. Note that w_long64 writes out TYPE_INT if 32 bits is enough, |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
527 so there's no inefficiency here in returning a PyLong on 32-bit boxes |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
528 for everything written via TYPE_INT64 (i.e., if an int is written via |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
529 TYPE_INT64, it *needs* more than 32 bits). |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
530 */ |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
531 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
532 r_long64(RFILE *p) |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
533 { |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
534 long lo4 = r_long(p); |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
535 long hi4 = r_long(p); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
536 #if SIZEOF_LONG > 4 |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
537 long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL); |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
538 return PyInt_FromLong(x); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
539 #else |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
540 unsigned char buf[8]; |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
541 int one = 1; |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
542 int is_little_endian = (int)*(char*)&one; |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
543 if (is_little_endian) { |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
544 memcpy(buf, &lo4, 4); |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
545 memcpy(buf+4, &hi4, 4); |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
546 } |
|
19547
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
547 else { |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
548 memcpy(buf, &hi4, 4); |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
549 memcpy(buf+4, &lo4, 4); |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
550 } |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
551 return _PyLong_FromByteArray(buf, 8, is_little_endian, 1); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
552 #endif |
| 267 | 553 } |
| 554 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
555 static PyObject * |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
556 r_PyLong(RFILE *p) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
557 { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
558 PyLongObject *ob; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
559 int size, i, j, md; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
560 long n; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
561 digit d; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
562 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
563 n = r_long(p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
564 if (n == 0) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
565 return (PyObject *)_PyLong_New(0); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
566 if (n < -INT_MAX || n > INT_MAX) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
567 PyErr_SetString(PyExc_ValueError, |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
568 "bad marshal data (long size out of range)"); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
569 return NULL; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
570 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
571 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
572 size = 1 + (ABS(n)-1) / PyLong_MARSHAL_RATIO; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
573 ob = _PyLong_New(size); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
574 if (ob == NULL) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
575 return NULL; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
576 Py_SIZE(ob) = n > 0 ? size : -size; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
577 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
578 for (i = 0; i < size-1; i++) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
579 d = 0; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
580 for (j=0; j < PyLong_MARSHAL_RATIO; j++) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
581 md = r_short(p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
582 if (md < 0 || md > PyLong_MARSHAL_BASE) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
583 goto bad_digit; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
584 d += (digit)md << j*PyLong_MARSHAL_SHIFT; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
585 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
586 ob->ob_digit[i] = d; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
587 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
588 d = 0; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
589 for (j=0; j < (ABS(n)-1)%PyLong_MARSHAL_RATIO + 1; j++) { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
590 md = r_short(p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
591 if (md < 0 || md > PyLong_MARSHAL_BASE) |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
592 goto bad_digit; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
593 d += (digit)md << j*PyLong_MARSHAL_SHIFT; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
594 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
595 ob->ob_digit[size-1] = d; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
596 return (PyObject *)ob; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
597 bad_digit: |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
598 Py_DECREF(ob); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
599 PyErr_SetString(PyExc_ValueError, |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
600 "bad marshal data (digit out of range in long)"); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
601 return NULL; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
602 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
603 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
604 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
605 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
606 r_object(RFILE *p) |
| 267 | 607 { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
608 /* NULL is a valid return value, it does not necessarily means that |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
609 an exception is set. */ |
|
45054
53b90f31efd6
Removed unused var
Christian Heimes <christian@cheimes.de>
parents:
45039
diff
changeset
|
610 PyObject *v, *v2; |
| 267 | 611 long i, n; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
612 int type = r_byte(p); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
613 PyObject *retval; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
614 |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
615 p->depth++; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
616 |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
617 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
618 p->depth--; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
619 PyErr_SetString(PyExc_ValueError, "recursion limit exceeded"); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
620 return NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
621 } |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
622 |
| 267 | 623 switch (type) { |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
624 |
| 267 | 625 case EOF: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
626 PyErr_SetString(PyExc_EOFError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
627 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
628 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
629 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
630 |
| 267 | 631 case TYPE_NULL: |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
632 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
633 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
634 |
| 267 | 635 case TYPE_NONE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
636 Py_INCREF(Py_None); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
637 retval = Py_None; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
638 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
639 |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
640 case TYPE_STOPITER: |
|
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
641 Py_INCREF(PyExc_StopIteration); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
642 retval = PyExc_StopIteration; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
643 break; |
|
18148
7bc473b2c654
Merging the gen-branch into the main line, at Guido's direction. Yay!
Tim Peters <tim.peters@gmail.com>
parents:
17707
diff
changeset
|
644 |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
645 case TYPE_ELLIPSIS: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
646 Py_INCREF(Py_Ellipsis); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
647 retval = Py_Ellipsis; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
648 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
649 |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
650 case TYPE_FALSE: |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
651 Py_INCREF(Py_False); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
652 retval = Py_False; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
653 break; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
654 |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
655 case TYPE_TRUE: |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
656 Py_INCREF(Py_True); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
657 retval = Py_True; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
658 break; |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
659 |
| 267 | 660 case TYPE_INT: |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
661 retval = PyInt_FromLong(r_long(p)); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
662 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
663 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
664 case TYPE_INT64: |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
665 retval = r_long64(p); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
666 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
667 |
| 267 | 668 case TYPE_LONG: |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
669 retval = r_PyLong(p); |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
670 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
671 |
| 267 | 672 case TYPE_FLOAT: |
| 673 { | |
| 674 char buf[256]; | |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
675 double dx; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
676 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
677 if (n == EOF || r_string(buf, (int)n, p) != n) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
678 PyErr_SetString(PyExc_EOFError, |
| 267 | 679 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
680 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
681 break; |
| 267 | 682 } |
| 683 buf[n] = '\0'; | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
684 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
685 PyFPE_START_PROTECT("atof", break) |
|
32305
13656d58d450
Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents:
31824
diff
changeset
|
686 dx = PyOS_ascii_atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
687 PyFPE_END_PROTECT(dx) |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
688 retval = PyFloat_FromDouble(dx); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
689 break; |
| 267 | 690 } |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
691 |
| 35008 | 692 case TYPE_BINARY_FLOAT: |
| 693 { | |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
694 unsigned char buf[8]; |
| 35008 | 695 double x; |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
696 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 697 PyErr_SetString(PyExc_EOFError, |
| 698 "EOF read where object expected"); | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
699 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
700 break; |
| 35008 | 701 } |
| 702 x = _PyFloat_Unpack8(buf, 1); | |
| 703 if (x == -1.0 && PyErr_Occurred()) { | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
704 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
705 break; |
| 35008 | 706 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
707 retval = PyFloat_FromDouble(x); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
708 break; |
| 35008 | 709 } |
| 710 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
711 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
712 case TYPE_COMPLEX: |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
713 { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
714 char buf[256]; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3731
diff
changeset
|
715 Py_complex c; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
716 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
717 if (n == EOF || r_string(buf, (int)n, p) != n) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
718 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
719 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
720 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
721 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
722 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
723 buf[n] = '\0'; |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
724 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
725 PyFPE_START_PROTECT("atof", break;) |
|
32305
13656d58d450
Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents:
31824
diff
changeset
|
726 c.real = PyOS_ascii_atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
727 PyFPE_END_PROTECT(c) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
728 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
729 if (n == EOF || r_string(buf, (int)n, p) != n) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
730 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
731 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
732 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
733 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
734 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
735 buf[n] = '\0'; |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
736 PyFPE_START_PROTECT("atof", break) |
|
32305
13656d58d450
Patch #774665: Make Python LC_NUMERIC agnostic.
Martin v. Löwis <martin@v.loewis.de>
parents:
31824
diff
changeset
|
737 c.imag = PyOS_ascii_atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
738 PyFPE_END_PROTECT(c) |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
739 retval = PyComplex_FromCComplex(c); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
740 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
741 } |
| 35008 | 742 |
| 743 case TYPE_BINARY_COMPLEX: | |
| 744 { | |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
745 unsigned char buf[8]; |
| 35008 | 746 Py_complex c; |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
747 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 748 PyErr_SetString(PyExc_EOFError, |
| 749 "EOF read where object expected"); | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
750 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
751 break; |
| 35008 | 752 } |
| 753 c.real = _PyFloat_Unpack8(buf, 1); | |
| 754 if (c.real == -1.0 && PyErr_Occurred()) { | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
755 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
756 break; |
| 35008 | 757 } |
|
35126
70681267a74a
Fix signedness of various char variables to stop causing a warning under gcc 4.
Brett Cannon <bcannon@gmail.com>
parents:
35071
diff
changeset
|
758 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 759 PyErr_SetString(PyExc_EOFError, |
| 760 "EOF read where object expected"); | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
761 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
762 break; |
| 35008 | 763 } |
| 764 c.imag = _PyFloat_Unpack8(buf, 1); | |
| 765 if (c.imag == -1.0 && PyErr_Occurred()) { | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
766 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
767 break; |
| 35008 | 768 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
769 retval = PyComplex_FromCComplex(c); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
770 break; |
| 35008 | 771 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
772 #endif |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
773 |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
774 case TYPE_INTERNED: |
| 267 | 775 case TYPE_STRING: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
776 n = r_long(p); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
777 if (n < 0 || n > INT_MAX) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
778 PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
779 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
780 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
781 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
782 v = PyString_FromStringAndSize((char *)NULL, n); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
783 if (v == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
784 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
785 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
786 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
787 if (r_string(PyString_AS_STRING(v), (int)n, p) != n) { |
|
35010
8e9682fd57f8
Fix a couple of crashing-on-malformed data marshal bugs.
Michael W. Hudson <mwh@python.net>
parents:
35008
diff
changeset
|
788 Py_DECREF(v); |
|
8e9682fd57f8
Fix a couple of crashing-on-malformed data marshal bugs.
Michael W. Hudson <mwh@python.net>
parents:
35008
diff
changeset
|
789 PyErr_SetString(PyExc_EOFError, |
| 267 | 790 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
791 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
792 break; |
| 267 | 793 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
794 if (type == TYPE_INTERNED) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
795 PyString_InternInPlace(&v); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
796 if (PyList_Append(p->strings, v) < 0) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
797 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
798 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
799 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
800 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
801 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
802 break; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
803 |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
804 case TYPE_STRINGREF: |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
805 n = r_long(p); |
| 35071 | 806 if (n < 0 || n >= PyList_GET_SIZE(p->strings)) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
807 PyErr_SetString(PyExc_ValueError, "bad marshal data (string ref out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
808 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
809 break; |
| 35071 | 810 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
811 v = PyList_GET_ITEM(p->strings, n); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
812 Py_INCREF(v); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
813 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
814 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
815 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
816 #ifdef Py_USING_UNICODE |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
817 case TYPE_UNICODE: |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
818 { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
819 char *buffer; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
820 |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
821 n = r_long(p); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
822 if (n < 0 || n > INT_MAX) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
823 PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
824 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
825 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
826 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
827 buffer = PyMem_NEW(char, n); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
828 if (buffer == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
829 retval = PyErr_NoMemory(); |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
830 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
831 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
832 if (r_string(buffer, (int)n, p) != n) { |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
833 PyMem_DEL(buffer); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
834 PyErr_SetString(PyExc_EOFError, |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
835 "EOF read where object expected"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
836 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
837 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
838 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
839 v = PyUnicode_DecodeUTF8(buffer, n, NULL); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
840 PyMem_DEL(buffer); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
841 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
842 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
843 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
844 #endif |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
845 |
| 267 | 846 case TYPE_TUPLE: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
847 n = r_long(p); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
848 if (n < 0 || n > INT_MAX) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
849 PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
850 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
851 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
852 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
853 v = PyTuple_New((int)n); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
854 if (v == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
855 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
856 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
857 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
858 for (i = 0; i < n; i++) { |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
859 v2 = r_object(p); |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
860 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
861 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
862 PyErr_SetString(PyExc_TypeError, |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
863 "NULL object in marshal data for tuple"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
864 Py_DECREF(v); |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
865 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
866 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
867 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
868 PyTuple_SET_ITEM(v, (int)i, v2); |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
869 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
870 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
871 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
872 |
| 267 | 873 case TYPE_LIST: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
874 n = r_long(p); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
875 if (n < 0 || n > INT_MAX) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
876 PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
877 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
878 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
879 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
880 v = PyList_New((int)n); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
881 if (v == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
882 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
883 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
884 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
885 for (i = 0; i < n; i++) { |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
886 v2 = r_object(p); |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
887 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
888 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
889 PyErr_SetString(PyExc_TypeError, |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
890 "NULL object in marshal data for list"); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
891 Py_DECREF(v); |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
892 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
893 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
894 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
895 PyList_SET_ITEM(v, (int)i, v2); |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
896 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
897 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
898 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
899 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
900 case TYPE_DICT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
901 v = PyDict_New(); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
902 if (v == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
903 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
904 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
905 } |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
906 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
907 PyObject *key, *val; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
908 key = r_object(p); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
909 if (key == NULL) |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
910 break; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
911 val = r_object(p); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
912 if (val != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
913 PyDict_SetItem(v, key, val); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
914 Py_DECREF(key); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
915 Py_XDECREF(val); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
916 } |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
917 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
918 Py_DECREF(v); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
919 v = NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
920 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
921 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
922 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
923 |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
924 case TYPE_SET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
925 case TYPE_FROZENSET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
926 n = r_long(p); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
927 if (n < 0 || n > INT_MAX) { |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
928 PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
929 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
930 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
931 } |
|
45036
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
932 v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
933 if (v == NULL) { |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
934 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
935 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
936 } |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
937 for (i = 0; i < n; i++) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
938 v2 = r_object(p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
939 if ( v2 == NULL ) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
940 if (!PyErr_Occurred()) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
941 PyErr_SetString(PyExc_TypeError, |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
942 "NULL object in marshal data for set"); |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
943 Py_DECREF(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
944 v = NULL; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
945 break; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
946 } |
|
45036
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
947 if (PySet_Add(v, v2) == -1) { |
|
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
948 Py_DECREF(v); |
|
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
949 Py_DECREF(v2); |
|
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
950 v = NULL; |
|
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
951 break; |
|
1e583eb71b3f
Let marshal built-up sets and frozensets one element at a time (without creating an intermediate tuple).
Raymond Hettinger <python@rcn.com>
parents:
44964
diff
changeset
|
952 } |
| 45081 | 953 Py_DECREF(v2); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
954 } |
|
45039
7a6a80e84a8a
Removed unnecessary conditional (spotted by Neal Norwitz).
Raymond Hettinger <python@rcn.com>
parents:
45036
diff
changeset
|
955 retval = v; |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
956 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
957 |
| 267 | 958 case TYPE_CODE: |
|
19605
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
959 if (PyEval_GetRestricted()) { |
|
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
960 PyErr_SetString(PyExc_RuntimeError, |
|
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
961 "cannot unmarshal code objects in " |
|
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
962 "restricted execution mode"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
963 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
964 break; |
|
19605
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
965 } |
|
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
966 else { |
| 35008 | 967 int argcount; |
| 968 int nlocals; | |
| 969 int stacksize; | |
| 970 int flags; | |
| 971 PyObject *code = NULL; | |
| 972 PyObject *consts = NULL; | |
| 973 PyObject *names = NULL; | |
| 974 PyObject *varnames = NULL; | |
| 975 PyObject *freevars = NULL; | |
| 976 PyObject *cellvars = NULL; | |
| 977 PyObject *filename = NULL; | |
| 978 PyObject *name = NULL; | |
| 979 int firstlineno; | |
| 980 PyObject *lnotab = NULL; | |
| 981 | |
| 982 v = NULL; | |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
983 |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
984 /* XXX ignore long->int overflows for now */ |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
985 argcount = (int)r_long(p); |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
986 nlocals = (int)r_long(p); |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
987 stacksize = (int)r_long(p); |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
988 flags = (int)r_long(p); |
| 35008 | 989 code = r_object(p); |
| 990 if (code == NULL) | |
| 991 goto code_error; | |
| 992 consts = r_object(p); | |
| 993 if (consts == NULL) | |
| 994 goto code_error; | |
| 995 names = r_object(p); | |
| 996 if (names == NULL) | |
| 997 goto code_error; | |
| 998 varnames = r_object(p); | |
| 999 if (varnames == NULL) | |
| 1000 goto code_error; | |
| 1001 freevars = r_object(p); | |
| 1002 if (freevars == NULL) | |
| 1003 goto code_error; | |
| 1004 cellvars = r_object(p); | |
| 1005 if (cellvars == NULL) | |
| 1006 goto code_error; | |
| 1007 filename = r_object(p); | |
| 1008 if (filename == NULL) | |
| 1009 goto code_error; | |
| 1010 name = r_object(p); | |
| 1011 if (name == NULL) | |
| 1012 goto code_error; | |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1013 firstlineno = (int)r_long(p); |
| 35008 | 1014 lnotab = r_object(p); |
| 1015 if (lnotab == NULL) | |
| 1016 goto code_error; | |
| 1017 | |
| 1018 v = (PyObject *) PyCode_New( | |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1019 argcount, nlocals, stacksize, flags, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
1020 code, consts, names, varnames, |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1021 freevars, cellvars, filename, name, |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1022 firstlineno, lnotab); |
| 35008 | 1023 |
| 1024 code_error: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1025 Py_XDECREF(code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1026 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1027 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1028 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1029 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1030 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1031 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1032 Py_XDECREF(name); |
|
5905
c2423843a26f
Plugged a leak. (The same as the one plugged in compile.c -- forgot
Guido van Rossum <guido@python.org>
parents:
5608
diff
changeset
|
1033 Py_XDECREF(lnotab); |
| 267 | 1034 |
| 1035 } | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1036 retval = v; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1037 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1038 |
| 267 | 1039 default: |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1040 /* Bogus data got written, which isn't ideal. |
|
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1041 This will let you keep working and recover. */ |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
1042 PyErr_SetString(PyExc_ValueError, "bad marshal data (unknown type code)"); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1043 retval = NULL; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1044 break; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1045 |
| 267 | 1046 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1047 p->depth--; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1048 return retval; |
| 267 | 1049 } |
| 1050 | |
|
32343
54b257e55f99
Make private function static
Neal Norwitz <nnorwitz@gmail.com>
parents:
32305
diff
changeset
|
1051 static PyObject * |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1052 read_object(RFILE *p) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1053 { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1054 PyObject *v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1055 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1056 fprintf(stderr, "XXX readobject called with exception set\n"); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1057 return NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1058 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1059 v = r_object(p); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1060 if (v == NULL && !PyErr_Occurred()) |
|
52169
beaf00c98b71
Make marshalling errors a little more informative as to what went wrong
Nick Coghlan <ncoghlan@gmail.com>
parents:
47730
diff
changeset
|
1061 PyErr_SetString(PyExc_TypeError, "NULL object in marshal data for object"); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1062 return v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1063 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1064 |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1065 int |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1066 PyMarshal_ReadShortFromFile(FILE *fp) |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1067 { |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1068 RFILE rf; |
|
36783
965bb4a54096
Fix gcc (4.0.x) warning about use of uninitialized variables.
Thomas Wouters <thomas@python.org>
parents:
36522
diff
changeset
|
1069 assert(fp); |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1070 rf.fp = fp; |
|
36784
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1071 rf.strings = NULL; |
|
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1072 rf.end = rf.ptr = NULL; |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1073 return r_short(&rf); |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1074 } |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1075 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1076 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1077 PyMarshal_ReadLongFromFile(FILE *fp) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1078 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1079 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1080 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1081 rf.strings = NULL; |
|
43536
cda0b625275a
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
Neal Norwitz <nnorwitz@gmail.com>
parents:
41748
diff
changeset
|
1082 rf.ptr = rf.end = NULL; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1083 return r_long(&rf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1084 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1085 |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1086 #ifdef HAVE_FSTAT |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1087 /* Return size of file in bytes; < 0 if unknown. */ |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1088 static off_t |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1089 getfilesize(FILE *fp) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1090 { |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1091 struct stat st; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1092 if (fstat(fileno(fp), &st) != 0) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1093 return -1; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1094 else |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1095 return st.st_size; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1096 } |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1097 #endif |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1098 |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1099 /* If we can get the size of the file up-front, and it's reasonably small, |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1100 * read it in one gulp and delegate to ...FromString() instead. Much quicker |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1101 * than reading a byte at a time from file; speeds .pyc imports. |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1102 * CAUTION: since this may read the entire remainder of the file, don't |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1103 * call it unless you know you're done with the file. |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1104 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1105 PyObject * |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1106 PyMarshal_ReadLastObjectFromFile(FILE *fp) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1107 { |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1108 /* 75% of 2.1's .pyc files can exploit SMALL_FILE_LIMIT. |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1109 * REASONABLE_FILE_LIMIT is by defn something big enough for Tkinter.pyc. |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1110 */ |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1111 #define SMALL_FILE_LIMIT (1L << 14) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1112 #define REASONABLE_FILE_LIMIT (1L << 18) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1113 #ifdef HAVE_FSTAT |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1114 off_t filesize; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1115 #endif |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1116 #ifdef HAVE_FSTAT |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1117 filesize = getfilesize(fp); |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1118 if (filesize > 0) { |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1119 char buf[SMALL_FILE_LIMIT]; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1120 char* pBuf = NULL; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1121 if (filesize <= SMALL_FILE_LIMIT) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1122 pBuf = buf; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1123 else if (filesize <= REASONABLE_FILE_LIMIT) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1124 pBuf = (char *)PyMem_MALLOC(filesize); |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1125 if (pBuf != NULL) { |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1126 PyObject* v; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1127 size_t n; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1128 /* filesize must fit into an int, because it |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1129 is smaller than REASONABLE_FILE_LIMIT */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1130 n = fread(pBuf, 1, (int)filesize, fp); |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1131 v = PyMarshal_ReadObjectFromString(pBuf, n); |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1132 if (pBuf != buf) |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1133 PyMem_FREE(pBuf); |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1134 return v; |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1135 } |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1136 |
|
15979
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1137 } |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1138 #endif |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1139 /* We don't have fstat, or we do but the file is larger than |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1140 * REASONABLE_FILE_LIMIT or malloc failed -- read a byte at a time. |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1141 */ |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1142 return PyMarshal_ReadObjectFromFile(fp); |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1143 |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1144 #undef SMALL_FILE_LIMIT |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1145 #undef REASONABLE_FILE_LIMIT |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1146 } |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1147 |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1148 PyObject * |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1149 PyMarshal_ReadObjectFromFile(FILE *fp) |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1150 { |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1151 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1152 PyObject *result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1153 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1154 rf.strings = PyList_New(0); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1155 rf.depth = 0; |
|
43536
cda0b625275a
Fix Coverity 185-186: If the passed in FILE is NULL, uninitialized memory
Neal Norwitz <nnorwitz@gmail.com>
parents:
41748
diff
changeset
|
1156 rf.ptr = rf.end = NULL; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1157 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1158 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1159 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1160 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1161 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1162 PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1163 PyMarshal_ReadObjectFromString(char *str, Py_ssize_t len) |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1164 { |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1165 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1166 PyObject *result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1167 rf.fp = NULL; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1168 rf.ptr = str; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1169 rf.end = str + len; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1170 rf.strings = PyList_New(0); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1171 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1172 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1173 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1174 return result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1175 } |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1176 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1177 PyObject * |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1178 PyMarshal_WriteObjectToString(PyObject *x, int version) |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1179 { |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1180 WFILE wf; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1181 wf.fp = NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1182 wf.str = PyString_FromStringAndSize((char *)NULL, 50); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1183 if (wf.str == NULL) |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1184 return NULL; |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1185 wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str); |
|
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1186 wf.end = wf.ptr + PyString_Size(wf.str); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1187 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1188 wf.depth = 0; |
| 35008 | 1189 wf.version = version; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1190 wf.strings = (version > 0) ? PyDict_New() : NULL; |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1191 w_object(x, &wf); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1192 Py_XDECREF(wf.strings); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1193 if (wf.str != NULL) { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1194 char *base = PyString_AS_STRING((PyStringObject *)wf.str); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1195 if (wf.ptr - base > PY_SSIZE_T_MAX) { |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1196 Py_DECREF(wf.str); |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1197 PyErr_SetString(PyExc_OverflowError, |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1198 "too much marshall data for a string"); |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1199 return NULL; |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1200 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1201 _PyString_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base)); |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1202 } |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1203 if (wf.error) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1204 Py_XDECREF(wf.str); |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1205 PyErr_SetString(PyExc_ValueError, |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1206 (wf.error==1)?"unmarshallable object" |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1207 :"object too deeply nested to marshal"); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1208 return NULL; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1209 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1210 return wf.str; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1211 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1212 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
1213 /* And an interface for Python programs... */ |
| 267 | 1214 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1215 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1216 marshal_dump(PyObject *self, PyObject *args) |
| 267 | 1217 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1218 WFILE wf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1219 PyObject *x; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1220 PyObject *f; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1221 int version = Py_MARSHAL_VERSION; |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1222 if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1223 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1224 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1225 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1226 "marshal.dump() 2nd arg must be file"); |
| 267 | 1227 return NULL; |
| 1228 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1229 wf.fp = PyFile_AsFile(f); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1230 wf.str = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1231 wf.ptr = wf.end = NULL; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1232 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1233 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1234 wf.strings = (version > 0) ? PyDict_New() : 0; |
|
35877
40f3d79b2125
version was not initialized properly
Neal Norwitz <nnorwitz@gmail.com>
parents:
35766
diff
changeset
|
1235 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1236 w_object(x, &wf); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1237 Py_XDECREF(wf.strings); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1238 if (wf.error) { |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
1239 PyErr_SetString(PyExc_ValueError, |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1240 (wf.error==1)?"unmarshallable object" |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1241 :"object too deeply nested to marshal"); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1242 return NULL; |
|
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1243 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1244 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1245 return Py_None; |
| 267 | 1246 } |
| 1247 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1248 PyDoc_STRVAR(dump_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1249 "dump(value, file[, version])\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1250 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1251 Write the value on the open file. The value must be a supported type.\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1252 The file must be an open file object such as sys.stdout or returned by\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1253 open() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1254 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1255 If the value has (or contains an object that has) an unsupported type, a\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1256 ValueError exception is raised — but garbage data will also be written\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1257 to the file. The object will not be properly read back by load()\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1258 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1259 New in version 2.4: The version argument indicates the data format that\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1260 dump should use."); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1261 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1262 static PyObject * |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
36866
diff
changeset
|
1263 marshal_load(PyObject *self, PyObject *f) |
| 267 | 1264 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1265 RFILE rf; |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
36866
diff
changeset
|
1266 PyObject *result; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1267 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1268 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1269 "marshal.load() arg must be file"); |
| 267 | 1270 return NULL; |
| 1271 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1272 rf.fp = PyFile_AsFile(f); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1273 rf.strings = PyList_New(0); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1274 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1275 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1276 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1277 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1278 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1279 |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1280 PyDoc_STRVAR(load_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1281 "load(file)\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1282 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1283 Read one value from the open file and return it. If no valid value is\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1284 read (e.g. because the data has a different Python version’s\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1285 incompatible marshal format), raise EOFError, ValueError or TypeError.\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1286 The file must be an open file object opened in binary mode ('rb' or\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1287 'r+b').\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1288 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1289 Note: If an object containing an unsupported type was marshalled with\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1290 dump(), load() will substitute None for the unmarshallable type."); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1291 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1292 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1293 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1294 marshal_dumps(PyObject *self, PyObject *args) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1295 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1296 PyObject *x; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1297 int version = Py_MARSHAL_VERSION; |
|
34205
ea340006c1f3
Back-ported: marshal.dumps() with the new optional argument 'version' just
Armin Rigo <arigo@tunes.org>
parents:
32422
diff
changeset
|
1298 if (!PyArg_ParseTuple(args, "O|i:dumps", &x, &version)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1299 return NULL; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1300 return PyMarshal_WriteObjectToString(x, version); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1301 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1302 |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1303 PyDoc_STRVAR(dumps_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1304 "dumps(value[, version])\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1305 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1306 Return the string that would be written to a file by dump(value, file).\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1307 The value must be a supported type. Raise a ValueError exception if\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1308 value has (or contains an object that has) an unsupported type.\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1309 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1310 New in version 2.4: The version argument indicates the data format that\n\ |
|
54037
bbb911f7c0c2
Move news item to correct section, remove spurious 'see below'
R. David Murray <rdmurray@bitdance.com>
parents:
54033
diff
changeset
|
1311 dumps should use."); |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1312 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1313 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1314 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1315 marshal_loads(PyObject *self, PyObject *args) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1316 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1317 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1318 char *s; |
|
36792
688795873ff1
Make Py_ssize_t clean.
Thomas Wouters <thomas@python.org>
parents:
36784
diff
changeset
|
1319 Py_ssize_t n; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1320 PyObject* result; |
|
35070
1332f2e705b2
Remove extraneous format character from PyArg_ParseTuple call in
Michael W. Hudson <mwh@python.net>
parents:
35010
diff
changeset
|
1321 if (!PyArg_ParseTuple(args, "s#:loads", &s, &n)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1322 return NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1323 rf.fp = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1324 rf.ptr = s; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1325 rf.end = s + n; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1326 rf.strings = PyList_New(0); |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1327 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1328 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1329 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1330 return result; |
| 267 | 1331 } |
| 1332 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1333 PyDoc_STRVAR(loads_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1334 "loads(string)\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1335 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1336 Convert the string to a value. If no valid value is found, raise\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1337 EOFError, ValueError or TypeError. Extra characters in the string are\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1338 ignored."); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1339 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1340 static PyMethodDef marshal_methods[] = { |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1341 {"dump", marshal_dump, METH_VARARGS, dump_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1342 {"load", marshal_load, METH_O, load_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1343 {"dumps", marshal_dumps, METH_VARARGS, dumps_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1344 {"loads", marshal_loads, METH_VARARGS, loads_doc}, |
| 267 | 1345 {NULL, NULL} /* sentinel */ |
| 1346 }; | |
| 1347 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1348 PyDoc_STRVAR(marshal_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1349 "This module contains functions that can read and write Python values in\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1350 a binary format. The format is specific to Python, but independent of\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1351 machine architecture issues.\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1352 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1353 Not all Python object types are supported; in general, only objects\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1354 whose value is independent from a particular invocation of Python can be\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1355 written and read by this module. The following types are supported:\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1356 None, integers, long integers, floating point numbers, strings, Unicode\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1357 objects, tuples, lists, sets, dictionaries, and code objects, where it\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1358 should be understood that tuples, lists and dictionaries are only\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1359 supported as long as the values contained therein are themselves\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1360 supported; and recursive lists and dictionaries should not be written\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1361 (they will cause infinite loops).\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1362 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1363 Variables:\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1364 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1365 version -- indicates the format that the module uses. Version 0 is the\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1366 historical format, version 1 (added in Python 2.4) shares interned\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1367 strings and version 2 (added in Python 2.5) uses a binary format for\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1368 floating point numbers. (New in version 2.4)\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1369 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1370 Functions:\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1371 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1372 dump() -- write value to a file\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1373 load() -- read value from a file\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1374 dumps() -- write value to a string\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1375 loads() -- read value from a string"); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1376 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1377 |
|
30311
f003e48f562d
Bug #794140: cygwin builds do not embed
Jason Tishler <jason@tishler.net>
parents:
24435
diff
changeset
|
1378 PyMODINIT_FUNC |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1379 PyMarshal_Init(void) |
| 267 | 1380 { |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1381 PyObject *mod = Py_InitModule3("marshal", marshal_methods, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1382 marshal_doc); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35877
diff
changeset
|
1383 if (mod == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35877
diff
changeset
|
1384 return; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1385 PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION); |
| 267 | 1386 } |
