Mercurial > cpython-lru_cache-weakref
annotate Python/marshal.c @ 57303:4aa4c19dfaed legacy-trunk
#1757126: fix typo with the cyrillic_asian alias
| author | Philip Jenvey <pjenvey@underboss.org> |
|---|---|
| date | Tue, 17 Nov 2009 02:42:26 +0000 |
| parents | 4cbc3fe93671 |
| children | 86f699766016 |
| 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 |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
47 #define WFERR_OK 0 |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
48 #define WFERR_UNMARSHALLABLE 1 |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
49 #define WFERR_NESTEDTOODEEP 2 |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
50 #define WFERR_NOMEMORY 3 |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
51 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 typedef struct { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 FILE *fp; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
54 int error; /* see WFERR_* values */ |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
55 int depth; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 /* 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
|
57 PyObject *str; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
58 char *ptr; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
59 char *end; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
60 PyObject *strings; /* dict on marshal, list on unmarshal */ |
| 35008 | 61 int version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
62 } WFILE; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
63 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
64 #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
|
65 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
|
66 else w_more(c, p) |
| 267 | 67 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
68 static void |
|
13672
bfc5b2a8c11f
-- changed w_more to take an integer instead of a char
Fredrik Lundh <fredrik@pythonware.com>
parents:
13658
diff
changeset
|
69 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
|
70 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
71 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
|
72 if (p->str == NULL) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 if (newsize > 32*1024*1024) { |
|
47730
4650eefb5838
Issue 3116: fix quadratic behavior in marshal.dumps().
Raymond Hettinger <python@rcn.com>
parents:
47527
diff
changeset
|
77 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
|
78 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
79 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
|
80 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
|
81 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
82 else { |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 *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
|
87 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
88 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
89 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
90 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
91 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
|
92 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
93 if (p->fp != NULL) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
94 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
|
95 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
96 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
97 while (--n >= 0) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
98 w_byte(*s, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
99 s++; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
100 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
101 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
102 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
103 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
104 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
105 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
|
106 { |
|
24434
9ef82377669d
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
Thomas Heller <theller@ctypes.org>
parents:
23851
diff
changeset
|
107 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
|
108 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
|
109 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
110 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
111 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
112 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
|
113 { |
|
24435
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
114 w_byte((char)( x & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
115 w_byte((char)((x>> 8) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
116 w_byte((char)((x>>16) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
117 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
|
118 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
119 |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
120 #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
|
121 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
122 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
|
123 { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
124 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
|
125 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
|
126 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
127 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
128 |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
129 /* 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
|
130 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
|
131 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
|
132 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
133 #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
|
134 #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
|
135 #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
|
136 #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
|
137 #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
|
138 #endif |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
139 #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
|
140 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
141 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
|
142 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
|
143 { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
144 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
|
145 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
|
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 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
|
148 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
|
149 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
|
150 return; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
151 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
152 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
153 /* 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
|
154 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
|
155 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
|
156 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
|
157 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
|
158 do { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
159 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
|
160 l++; |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
161 } 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
|
162 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
|
163 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
170 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
|
171 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
172 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
|
173 do { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
174 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
|
175 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
|
176 } 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
|
177 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
178 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
179 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
180 w_object(PyObject *v, WFILE *p) |
| 267 | 181 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
182 Py_ssize_t i, n; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
183 |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
184 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
|
185 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
186 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
187 p->error = WFERR_NESTEDTOODEEP; |
|
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
|
188 } |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
189 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
|
190 w_byte(TYPE_NULL, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
191 } |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
192 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
|
193 w_byte(TYPE_NONE, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
194 } |
|
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
|
195 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
|
196 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
|
197 } |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
198 else if (v == Py_Ellipsis) { |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
199 w_byte(TYPE_ELLIPSIS, p); |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
200 } |
|
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
|
201 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
|
202 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
|
203 } |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
204 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
|
205 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
|
206 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
207 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
|
208 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
|
209 #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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
215 else |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
216 #endif |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
217 { |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
218 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
|
219 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
|
220 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
221 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
222 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
|
223 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
|
224 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
|
225 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
226 else if (PyFloat_CheckExact(v)) { |
| 35008 | 227 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
|
228 unsigned char buf[8]; |
| 35008 | 229 if (_PyFloat_Pack8(PyFloat_AsDouble(v), |
| 230 buf, 1) < 0) { | |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
231 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 232 return; |
| 233 } | |
| 234 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
|
235 w_string((char*)buf, 8, p); |
| 35008 | 236 } |
| 237 else { | |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
238 char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v), |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
239 'g', 17, 0, NULL); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
240 if (!buf) { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
241 p->error = WFERR_NOMEMORY; |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
242 return; |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
243 } |
|
36522
2791676b3825
Move cast to suppress warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
244 n = strlen(buf); |
| 35008 | 245 w_byte(TYPE_FLOAT, p); |
|
36522
2791676b3825
Move cast to suppress warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
246 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
|
247 w_string(buf, (int)n, p); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
248 PyMem_Free(buf); |
| 35008 | 249 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
250 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
251 #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
|
252 else if (PyComplex_CheckExact(v)) { |
| 35008 | 253 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
|
254 unsigned char buf[8]; |
| 35008 | 255 if (_PyFloat_Pack8(PyComplex_RealAsDouble(v), |
| 256 buf, 1) < 0) { | |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
257 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 258 return; |
| 259 } | |
| 260 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
|
261 w_string((char*)buf, 8, p); |
| 35008 | 262 if (_PyFloat_Pack8(PyComplex_ImagAsDouble(v), |
| 263 buf, 1) < 0) { | |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
264 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 265 return; |
| 266 } | |
|
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
|
267 w_string((char*)buf, 8, p); |
| 35008 | 268 } |
| 269 else { | |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
270 char *buf; |
| 35008 | 271 w_byte(TYPE_COMPLEX, p); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
272 buf = PyOS_double_to_string(PyComplex_RealAsDouble(v), |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
273 'g', 17, 0, NULL); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
274 if (!buf) { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
275 p->error = WFERR_NOMEMORY; |
|
39448
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
276 return; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
277 } |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
278 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
|
279 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
|
280 w_string(buf, (int)n, p); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
281 PyMem_Free(buf); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
282 buf = PyOS_double_to_string(PyComplex_ImagAsDouble(v), |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
283 'g', 17, 0, NULL); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
284 if (!buf) { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
285 p->error = WFERR_NOMEMORY; |
|
39448
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
286 return; |
|
2179d9f14278
This code is actually not used unless WITHOUT_COMPLEX is defined.
Neal Norwitz <nnorwitz@gmail.com>
parents:
38490
diff
changeset
|
287 } |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
288 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
|
289 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
|
290 w_string(buf, (int)n, p); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
291 PyMem_Free(buf); |
| 35008 | 292 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
293 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
294 #endif |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
295 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
|
296 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
|
297 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
|
298 if (o) { |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
299 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
|
300 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
|
301 w_long(w, p); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
302 goto exit; |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
303 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
304 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
|
305 int ok; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
306 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
|
307 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
|
308 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
|
309 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
|
310 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
|
311 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
312 p->error = WFERR_UNMARSHALLABLE; |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
313 return; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
314 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
315 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
|
316 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
317 } |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
318 else { |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
319 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
|
320 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
321 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
|
322 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
|
323 /* 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
|
324 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
325 p->error = WFERR_UNMARSHALLABLE; |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
326 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
327 } |
|
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
|
328 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
|
329 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
|
330 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
331 #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
|
332 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
|
333 PyObject *utf8; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
334 utf8 = PyUnicode_AsUTF8String(v); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
335 if (utf8 == NULL) { |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
336 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
337 p->error = WFERR_UNMARSHALLABLE; |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
338 return; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
339 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
340 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
|
341 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
|
342 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
|
343 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
344 p->error = WFERR_UNMARSHALLABLE; |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
345 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
346 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
347 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
|
348 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
|
349 Py_DECREF(utf8); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
350 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
351 #endif |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
359 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
360 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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 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
|
366 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
367 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
368 else if (PyDict_CheckExact(v)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
369 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
|
370 PyObject *key, *value; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
371 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
|
372 /* This one is NULL object terminated! */ |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
373 pos = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
374 while (PyDict_Next(v, &pos, &key, &value)) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
375 w_object(key, p); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
376 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
|
377 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
378 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
|
379 } |
|
43781
da58cf9bcb01
Fix marshal's incorrect handling of subclasses of builtin types (backport candidate).
Raymond Hettinger <python@rcn.com>
parents:
43536
diff
changeset
|
380 else if (PyAnySet_CheckExact(v)) { |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
381 PyObject *value, *it; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
382 |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
383 if (PyObject_TypeCheck(v, &PySet_Type)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
384 w_byte(TYPE_SET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
385 else |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
386 w_byte(TYPE_FROZENSET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
387 n = PyObject_Size(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
388 if (n == -1) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
389 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
390 p->error = WFERR_UNMARSHALLABLE; |
|
34394
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 w_long((long)n, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
394 it = PyObject_GetIter(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
395 if (it == NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
396 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
397 p->error = WFERR_UNMARSHALLABLE; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
398 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
399 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
400 while ((value = PyIter_Next(it)) != NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
401 w_object(value, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
402 Py_DECREF(value); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
403 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
404 Py_DECREF(it); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
405 if (PyErr_Occurred()) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
406 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
407 p->error = WFERR_UNMARSHALLABLE; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
408 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
409 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
410 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
411 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
|
412 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
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 w_object(co->co_names, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
421 w_object(co->co_varnames, p); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
422 w_object(co->co_freevars, p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 } |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20552
diff
changeset
|
429 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
|
430 /* 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
|
431 char *s; |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20552
diff
changeset
|
432 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
|
433 w_byte(TYPE_STRING, p); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
434 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
|
435 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
|
436 p->depth--; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
437 p->error = WFERR_UNMARSHALLABLE; |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
438 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
439 } |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
440 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
|
441 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
|
442 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
443 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
444 w_byte(TYPE_UNKNOWN, p); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
445 p->error = WFERR_UNMARSHALLABLE; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
446 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
447 exit: |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
448 p->depth--; |
| 267 | 449 } |
| 450 | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
451 /* version currently has no effect for writing longs. */ |
| 267 | 452 void |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
453 PyMarshal_WriteLongToFile(long x, FILE *fp, int version) |
| 267 | 454 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
455 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
456 wf.fp = fp; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
457 wf.error = WFERR_OK; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
458 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
459 wf.strings = NULL; |
| 35008 | 460 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
461 w_long(x, &wf); |
| 267 | 462 } |
| 463 | |
| 464 void | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
465 PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) |
| 267 | 466 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
467 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
468 wf.fp = fp; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
469 wf.error = WFERR_OK; |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
470 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
471 wf.strings = (version > 0) ? PyDict_New() : NULL; |
| 35008 | 472 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
473 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
|
474 Py_XDECREF(wf.strings); |
| 267 | 475 } |
| 476 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
477 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
|
478 |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
479 #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
|
480 |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
481 #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) |
| 267 | 482 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
483 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
484 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
|
485 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
486 if (p->fp != NULL) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
487 /* 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
|
488 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
|
489 if (p->end - p->ptr < n) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
490 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
|
491 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
|
492 p->ptr += n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
493 return n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
494 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
495 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
496 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
497 r_short(RFILE *p) |
| 267 | 498 { |
| 499 register short x; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
500 x = r_byte(p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
501 x |= r_byte(p) << 8; |
| 14678 | 502 /* Sign-extension, in case short greater than 16 bits */ |
| 503 x |= -(x & 0x8000); | |
| 267 | 504 return x; |
| 505 } | |
| 506 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
507 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
508 r_long(RFILE *p) |
| 267 | 509 { |
| 510 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
|
511 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
|
512 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
|
513 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
|
514 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
|
515 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
|
516 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
|
517 } |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
524 #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
|
525 /* Sign extension for 64-bit machines */ |
| 14678 | 526 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
|
527 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
528 return x; |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
529 } |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
530 |
|
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
|
531 /* 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
|
532 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
|
533 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
|
534 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
|
535 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
|
536 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
|
537 */ |
|
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 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
539 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
|
540 { |
|
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
|
541 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
|
542 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
|
543 #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
|
544 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
|
545 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
|
546 #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
|
547 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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 } |
|
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
|
554 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
|
555 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
|
556 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
|
557 } |
|
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
|
558 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
|
559 #endif |
| 267 | 560 } |
| 561 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
562 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
|
563 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
|
564 { |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
565 PyLongObject *ob; |
|
56292
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
566 int size, i, j, md, shorts_in_top_digit; |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
567 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
|
568 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
|
569 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
570 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
|
571 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
|
572 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
|
573 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
|
574 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
|
575 "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
|
576 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
|
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 |
|
56292
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
579 size = 1 + (ABS(n) - 1) / PyLong_MARSHAL_RATIO; |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
580 shorts_in_top_digit = 1 + (ABS(n) - 1) % PyLong_MARSHAL_RATIO; |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
581 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
|
582 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
|
583 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
|
584 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
|
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 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
|
587 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
|
588 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
594 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
|
595 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
596 d = 0; |
|
56292
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
597 for (j=0; j < shorts_in_top_digit; j++) { |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
598 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
|
599 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
|
600 goto bad_digit; |
|
56292
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
601 /* topmost marshal digit should be nonzero */ |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
602 if (md == 0 && j == shorts_in_top_digit - 1) { |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
603 Py_DECREF(ob); |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
604 PyErr_SetString(PyExc_ValueError, |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
605 "bad marshal data (unnormalized long data)"); |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
606 return NULL; |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
607 } |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
608 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
|
609 } |
|
56292
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
610 /* top digit should be nonzero, else the resulting PyLong won't be |
|
91f9df5367c1
Issue #7019: Unmarshalling of bad long data could produce unnormalized
Mark Dickinson <dickinsm@gmail.com>
parents:
54037
diff
changeset
|
611 normalized */ |
|
52233
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
612 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
|
613 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
|
614 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
|
615 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
|
616 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
|
617 "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
|
618 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
|
619 } |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
620 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
621 |
|
9b358eae532a
Issue #4258: Use 30-bit digits for Python longs, on 64-bit platforms.
Mark Dickinson <dickinsm@gmail.com>
parents:
52169
diff
changeset
|
622 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
623 r_object(RFILE *p) |
| 267 | 624 { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
625 /* 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
|
626 an exception is set. */ |
|
45054
53b90f31efd6
Removed unused var
Christian Heimes <christian@cheimes.de>
parents:
45039
diff
changeset
|
627 PyObject *v, *v2; |
| 267 | 628 long i, n; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
629 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
|
630 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
|
631 |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
632 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
|
633 |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
634 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
|
635 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
|
636 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
|
637 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
|
638 } |
|
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 |
| 267 | 640 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
|
641 |
| 267 | 642 case EOF: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
643 PyErr_SetString(PyExc_EOFError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
644 "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
|
645 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
|
646 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
|
647 |
| 267 | 648 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
|
649 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
|
650 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
|
651 |
| 267 | 652 case TYPE_NONE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
653 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
|
654 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
|
655 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
|
656 |
|
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
|
657 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
|
658 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
|
659 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
|
660 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
|
661 |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
662 case TYPE_ELLIPSIS: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
663 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
|
664 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
|
665 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
|
666 |
|
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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
672 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
|
673 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
|
674 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
|
675 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
|
676 |
| 267 | 677 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
|
678 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
|
679 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
|
680 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 |
| 267 | 685 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
|
686 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
|
687 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
|
688 |
| 267 | 689 case TYPE_FLOAT: |
| 690 { | |
| 691 char buf[256]; | |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
692 double dx; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
693 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
694 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
|
695 PyErr_SetString(PyExc_EOFError, |
| 267 | 696 "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
|
697 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
|
698 break; |
| 267 | 699 } |
| 700 buf[n] = '\0'; | |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
701 dx = PyOS_string_to_double(buf, NULL, NULL); |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
702 if (dx == -1.0 && PyErr_Occurred()) { |
|
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
703 retval = NULL; |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
704 break; |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
705 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
706 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
|
707 break; |
| 267 | 708 } |
|
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
|
709 |
| 35008 | 710 case TYPE_BINARY_FLOAT: |
| 711 { | |
|
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
|
712 unsigned char buf[8]; |
| 35008 | 713 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
|
714 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 715 PyErr_SetString(PyExc_EOFError, |
| 716 "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
|
717 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
|
718 break; |
| 35008 | 719 } |
| 720 x = _PyFloat_Unpack8(buf, 1); | |
| 721 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
|
722 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
|
723 break; |
| 35008 | 724 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
725 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
|
726 break; |
| 35008 | 727 } |
| 728 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
729 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
730 case TYPE_COMPLEX: |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
731 { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
732 char buf[256]; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3731
diff
changeset
|
733 Py_complex c; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
734 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
735 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
|
736 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
737 "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
|
738 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
|
739 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
740 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
741 buf[n] = '\0'; |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
742 c.real = PyOS_string_to_double(buf, NULL, NULL); |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
743 if (c.real == -1.0 && PyErr_Occurred()) { |
|
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
744 retval = NULL; |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
745 break; |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
746 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
747 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
748 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
|
749 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
750 "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
|
751 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
|
752 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
753 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
754 buf[n] = '\0'; |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
755 c.imag = PyOS_string_to_double(buf, NULL, NULL); |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
756 if (c.imag == -1.0 && PyErr_Occurred()) { |
|
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
757 retval = NULL; |
|
56877
140d88d1b179
Removed PyOS_ascii_atof from marshal.c, as mentioned in issue 7117. Also brings it more in line with py3k.
Eric Smith <eric@trueblade.com>
parents:
56604
diff
changeset
|
758 break; |
|
57010
4cbc3fe93671
Set retval on PyOS_string_to_double failure.
Mark Dickinson <dickinsm@gmail.com>
parents:
56877
diff
changeset
|
759 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
760 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
|
761 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
762 } |
| 35008 | 763 |
| 764 case TYPE_BINARY_COMPLEX: | |
| 765 { | |
|
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
|
766 unsigned char buf[8]; |
| 35008 | 767 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
|
768 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 769 PyErr_SetString(PyExc_EOFError, |
| 770 "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
|
771 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
|
772 break; |
| 35008 | 773 } |
| 774 c.real = _PyFloat_Unpack8(buf, 1); | |
| 775 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
|
776 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
|
777 break; |
| 35008 | 778 } |
|
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
|
779 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 780 PyErr_SetString(PyExc_EOFError, |
| 781 "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
|
782 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
|
783 break; |
| 35008 | 784 } |
| 785 c.imag = _PyFloat_Unpack8(buf, 1); | |
| 786 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
|
787 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
|
788 break; |
| 35008 | 789 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
790 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
|
791 break; |
| 35008 | 792 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
793 #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
|
794 |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
795 case TYPE_INTERNED: |
| 267 | 796 case TYPE_STRING: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
797 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
|
798 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
|
799 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
|
800 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
|
801 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
802 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
803 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
|
804 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
|
805 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
|
806 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
807 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
808 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
|
809 Py_DECREF(v); |
|
8e9682fd57f8
Fix a couple of crashing-on-malformed data marshal bugs.
Michael W. Hudson <mwh@python.net>
parents:
35008
diff
changeset
|
810 PyErr_SetString(PyExc_EOFError, |
| 267 | 811 "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
|
812 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
|
813 break; |
| 267 | 814 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
815 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
|
816 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
|
817 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
|
818 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
|
819 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
820 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
821 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
822 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
|
823 break; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
824 |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
825 case TYPE_STRINGREF: |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
826 n = r_long(p); |
| 35071 | 827 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
|
828 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
|
829 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
|
830 break; |
| 35071 | 831 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
832 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
|
833 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
|
834 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
|
835 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
|
836 |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
837 #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
|
838 case TYPE_UNICODE: |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
839 { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
840 char *buffer; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
841 |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
842 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
|
843 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
|
844 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
|
845 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
|
846 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
847 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
848 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
|
849 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
|
850 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
|
851 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
852 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
853 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
|
854 PyMem_DEL(buffer); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
855 PyErr_SetString(PyExc_EOFError, |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
856 "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
|
857 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
|
858 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
859 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
860 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
|
861 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
|
862 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
|
863 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
864 } |
|
19343
7257e87e0720
Patch #445762: Support --disable-unicode
Martin v. Löwis <martin@v.loewis.de>
parents:
18148
diff
changeset
|
865 #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
|
866 |
| 267 | 867 case TYPE_TUPLE: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
868 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
|
869 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
|
870 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
|
871 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
|
872 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
873 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
874 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
|
875 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
|
876 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
|
877 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
878 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
879 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
|
880 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
|
881 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
882 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
883 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
|
884 "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
|
885 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
|
886 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
887 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
888 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
889 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
|
890 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
891 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
|
892 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
|
893 |
| 267 | 894 case TYPE_LIST: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
895 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
|
896 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
|
897 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
|
898 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
|
899 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
900 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
901 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
|
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 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
906 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
|
907 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
|
908 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
909 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
910 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
|
911 "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
|
912 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
|
913 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
914 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
915 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
916 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
|
917 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
918 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
|
919 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
|
920 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
921 case TYPE_DICT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
922 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
|
923 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
|
924 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
|
925 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
926 } |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
927 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
928 PyObject *key, *val; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
929 key = r_object(p); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
930 if (key == NULL) |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
931 break; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
932 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
|
933 if (val != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
934 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
|
935 Py_DECREF(key); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
936 Py_XDECREF(val); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
937 } |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
938 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
939 Py_DECREF(v); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
940 v = NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
941 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
942 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
|
943 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
|
944 |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
945 case TYPE_SET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
946 case TYPE_FROZENSET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
947 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
|
948 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
|
949 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
|
950 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
|
951 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
952 } |
|
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
|
953 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
|
954 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
|
955 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
|
956 break; |
|
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
957 } |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
958 for (i = 0; i < n; i++) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
959 v2 = r_object(p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
960 if ( v2 == NULL ) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
961 if (!PyErr_Occurred()) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
962 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
|
963 "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
|
964 Py_DECREF(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
965 v = NULL; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
966 break; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
967 } |
|
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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 } |
| 45081 | 974 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
|
975 } |
|
45039
7a6a80e84a8a
Removed unnecessary conditional (spotted by Neal Norwitz).
Raymond Hettinger <python@rcn.com>
parents:
45036
diff
changeset
|
976 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
|
977 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
978 |
| 267 | 979 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
|
980 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
|
981 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
|
982 "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
|
983 "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
|
984 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
|
985 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
|
986 } |
|
10bf4bed5096
fix for part of bug #453523: disable unmarshalling of code objects in
Michael W. Hudson <mwh@python.net>
parents:
19547
diff
changeset
|
987 else { |
| 35008 | 988 int argcount; |
| 989 int nlocals; | |
| 990 int stacksize; | |
| 991 int flags; | |
| 992 PyObject *code = NULL; | |
| 993 PyObject *consts = NULL; | |
| 994 PyObject *names = NULL; | |
| 995 PyObject *varnames = NULL; | |
| 996 PyObject *freevars = NULL; | |
| 997 PyObject *cellvars = NULL; | |
| 998 PyObject *filename = NULL; | |
| 999 PyObject *name = NULL; | |
| 1000 int firstlineno; | |
| 1001 PyObject *lnotab = NULL; | |
| 1002 | |
| 1003 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
|
1004 |
|
39995
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1005 /* 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
|
1006 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
|
1007 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
|
1008 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
|
1009 flags = (int)r_long(p); |
| 35008 | 1010 code = r_object(p); |
| 1011 if (code == NULL) | |
| 1012 goto code_error; | |
| 1013 consts = r_object(p); | |
| 1014 if (consts == NULL) | |
| 1015 goto code_error; | |
| 1016 names = r_object(p); | |
| 1017 if (names == NULL) | |
| 1018 goto code_error; | |
| 1019 varnames = r_object(p); | |
| 1020 if (varnames == NULL) | |
| 1021 goto code_error; | |
| 1022 freevars = r_object(p); | |
| 1023 if (freevars == NULL) | |
| 1024 goto code_error; | |
| 1025 cellvars = r_object(p); | |
| 1026 if (cellvars == NULL) | |
| 1027 goto code_error; | |
| 1028 filename = r_object(p); | |
| 1029 if (filename == NULL) | |
| 1030 goto code_error; | |
| 1031 name = r_object(p); | |
| 1032 if (name == NULL) | |
| 1033 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
|
1034 firstlineno = (int)r_long(p); |
| 35008 | 1035 lnotab = r_object(p); |
| 1036 if (lnotab == NULL) | |
| 1037 goto code_error; | |
| 1038 | |
| 1039 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
|
1040 argcount, nlocals, stacksize, flags, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
1041 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
|
1042 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
|
1043 firstlineno, lnotab); |
| 35008 | 1044 |
| 1045 code_error: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1046 Py_XDECREF(code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1047 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1048 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1049 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1050 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1051 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1052 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1053 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
|
1054 Py_XDECREF(lnotab); |
| 267 | 1055 |
| 1056 } | |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1057 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
|
1058 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
|
1059 |
| 267 | 1060 default: |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1061 /* 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
|
1062 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
|
1063 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
|
1064 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
|
1065 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
|
1066 |
| 267 | 1067 } |
|
41741
6f1293ab3ac4
Fix bug in marshal where bad data would cause a segfault due to
Neal Norwitz <nnorwitz@gmail.com>
parents:
39995
diff
changeset
|
1068 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
|
1069 return retval; |
| 267 | 1070 } |
| 1071 | |
|
32343
54b257e55f99
Make private function static
Neal Norwitz <nnorwitz@gmail.com>
parents:
32305
diff
changeset
|
1072 static PyObject * |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1073 read_object(RFILE *p) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1074 { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1075 PyObject *v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1076 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1077 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
|
1078 return NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1079 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1080 v = r_object(p); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1081 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
|
1082 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
|
1083 return v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1084 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1085 |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1086 int |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1087 PyMarshal_ReadShortFromFile(FILE *fp) |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1088 { |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1089 RFILE rf; |
|
36783
965bb4a54096
Fix gcc (4.0.x) warning about use of uninitialized variables.
Thomas Wouters <thomas@python.org>
parents:
36522
diff
changeset
|
1090 assert(fp); |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1091 rf.fp = fp; |
|
36784
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1092 rf.strings = NULL; |
|
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1093 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
|
1094 return r_short(&rf); |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1095 } |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1096 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1097 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1098 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
|
1099 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1100 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1101 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1102 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
|
1103 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
|
1104 return r_long(&rf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1105 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1106 |
|
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
|
1107 #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
|
1108 /* 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
|
1109 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
|
1110 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
|
1111 { |
|
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 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
|
1113 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
|
1114 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
|
1115 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
|
1116 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
|
1117 } |
|
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 #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
|
1119 |
|
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
|
1120 /* 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
|
1121 * 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
|
1122 * 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
|
1123 * 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
|
1124 * 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
|
1125 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1126 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
|
1127 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
|
1128 { |
|
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
|
1129 /* 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
|
1130 * 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
|
1131 */ |
|
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 #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
|
1133 #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
|
1134 #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
|
1135 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
|
1136 #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
|
1137 #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
|
1138 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
|
1139 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
|
1140 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
|
1141 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
|
1142 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
|
1143 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
|
1144 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
|
1145 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
|
1146 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
|
1147 PyObject* v; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1148 size_t n; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1149 /* 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
|
1150 is smaller than REASONABLE_FILE_LIMIT */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1151 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
|
1152 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
|
1153 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
|
1154 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
|
1155 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
|
1156 } |
|
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
|
1157 |
|
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
|
1158 } |
|
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
|
1159 #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
|
1160 /* 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
|
1161 * 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
|
1162 */ |
|
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
|
1163 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
|
1164 |
|
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
|
1165 #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
|
1166 #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
|
1167 } |
|
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
|
1168 |
|
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
|
1169 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
|
1170 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
|
1171 { |
|
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
|
1172 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1173 PyObject *result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1174 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1175 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
|
1176 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
|
1177 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
|
1178 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1179 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1180 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1181 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1182 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1183 PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1184 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
|
1185 { |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1186 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1187 PyObject *result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1188 rf.fp = NULL; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1189 rf.ptr = str; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1190 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
|
1191 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
|
1192 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1193 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1194 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1195 return result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1196 } |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1197 |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1198 static void |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1199 set_error(int error) |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1200 { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1201 switch (error) { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1202 case WFERR_NOMEMORY: |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1203 PyErr_NoMemory(); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1204 break; |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1205 case WFERR_UNMARSHALLABLE: |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1206 PyErr_SetString(PyExc_ValueError, "unmarshallable object"); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1207 break; |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1208 case WFERR_NESTEDTOODEEP: |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1209 default: |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1210 PyErr_SetString(PyExc_ValueError, |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1211 "object too deeply nested to marshal"); |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1212 break; |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1213 } |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1214 } |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1215 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1216 PyObject * |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1217 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
|
1218 { |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1219 WFILE wf; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1220 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
|
1221 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
|
1222 if (wf.str == NULL) |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1223 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
|
1224 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
|
1225 wf.end = wf.ptr + PyString_Size(wf.str); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1226 wf.error = WFERR_OK; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1227 wf.depth = 0; |
| 35008 | 1228 wf.version = version; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1229 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
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 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
|
1236 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
|
1237 "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
|
1238 return NULL; |
|
6ba402b60041
Forward-port of r52136,52138: a review of overflow-detecting code.
Armin Rigo <arigo@tunes.org>
parents:
39448
diff
changeset
|
1239 } |
|
47527
52294af4b663
This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents:
47294
diff
changeset
|
1240 _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
|
1241 } |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1242 if (wf.error != WFERR_OK) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1243 Py_XDECREF(wf.str); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1244 set_error(wf.error); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1245 return NULL; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1246 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1247 return wf.str; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1248 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1249 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
1250 /* And an interface for Python programs... */ |
| 267 | 1251 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1252 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1253 marshal_dump(PyObject *self, PyObject *args) |
| 267 | 1254 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1255 WFILE wf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1256 PyObject *x; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1257 PyObject *f; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1258 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
|
1259 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
|
1260 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1261 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1262 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1263 "marshal.dump() 2nd arg must be file"); |
| 267 | 1264 return NULL; |
| 1265 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1266 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
|
1267 wf.str = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1268 wf.ptr = wf.end = NULL; |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1269 wf.error = WFERR_OK; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1270 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1271 wf.strings = (version > 0) ? PyDict_New() : 0; |
|
35877
40f3d79b2125
version was not initialized properly
Neal Norwitz <nnorwitz@gmail.com>
parents:
35766
diff
changeset
|
1272 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1273 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
|
1274 Py_XDECREF(wf.strings); |
|
56604
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1275 if (wf.error != WFERR_OK) { |
|
d1666cc7bc74
Removed calls to PyFloat_AsReprString.
Eric Smith <eric@trueblade.com>
parents:
56292
diff
changeset
|
1276 set_error(wf.error); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1277 return NULL; |
|
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1278 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1279 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1280 return Py_None; |
| 267 | 1281 } |
| 1282 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1283 PyDoc_STRVAR(dump_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1284 "dump(value, file[, version])\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1285 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1286 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
|
1287 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
|
1288 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
|
1289 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1290 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
|
1291 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
|
1292 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
|
1293 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1294 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
|
1295 dump should use."); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1296 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1297 static PyObject * |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
36866
diff
changeset
|
1298 marshal_load(PyObject *self, PyObject *f) |
| 267 | 1299 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1300 RFILE rf; |
|
38490
a5298f371be7
Convert more modules to METH_VARARGS.
Georg Brandl <georg@python.org>
parents:
36866
diff
changeset
|
1301 PyObject *result; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1302 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1303 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1304 "marshal.load() arg must be file"); |
| 267 | 1305 return NULL; |
| 1306 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1307 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
|
1308 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
|
1309 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1310 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1311 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1312 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1313 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1314 |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1315 PyDoc_STRVAR(load_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1316 "load(file)\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1317 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1318 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
|
1319 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
|
1320 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
|
1321 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
|
1322 'r+b').\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1323 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1324 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
|
1325 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
|
1326 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1327 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1328 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1329 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
|
1330 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1331 PyObject *x; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1332 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
|
1333 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
|
1334 return NULL; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1335 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
|
1336 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1337 |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1338 PyDoc_STRVAR(dumps_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1339 "dumps(value[, version])\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1340 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1341 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
|
1342 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
|
1343 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
|
1344 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1345 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
|
1346 dumps should use."); |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1347 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1348 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1349 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1350 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
|
1351 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1352 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1353 char *s; |
|
36792
688795873ff1
Make Py_ssize_t clean.
Thomas Wouters <thomas@python.org>
parents:
36784
diff
changeset
|
1354 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
|
1355 PyObject* result; |
|
35070
1332f2e705b2
Remove extraneous format character from PyArg_ParseTuple call in
Michael W. Hudson <mwh@python.net>
parents:
35010
diff
changeset
|
1356 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
|
1357 return NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1358 rf.fp = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1359 rf.ptr = s; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1360 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
|
1361 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
|
1362 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1363 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1364 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1365 return result; |
| 267 | 1366 } |
| 1367 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1368 PyDoc_STRVAR(loads_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1369 "loads(string)\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1370 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1371 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
|
1372 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
|
1373 ignored."); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1374 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1375 static PyMethodDef marshal_methods[] = { |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1376 {"dump", marshal_dump, METH_VARARGS, dump_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1377 {"load", marshal_load, METH_O, load_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1378 {"dumps", marshal_dumps, METH_VARARGS, dumps_doc}, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1379 {"loads", marshal_loads, METH_VARARGS, loads_doc}, |
| 267 | 1380 {NULL, NULL} /* sentinel */ |
| 1381 }; | |
| 1382 | |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1383 PyDoc_STRVAR(marshal_doc, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1384 "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
|
1385 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
|
1386 machine architecture issues.\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1387 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1388 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
|
1389 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
|
1390 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
|
1391 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
|
1392 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
|
1393 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
|
1394 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
|
1395 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
|
1396 (they will cause infinite loops).\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1397 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1398 Variables:\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1399 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1400 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
|
1401 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
|
1402 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
|
1403 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
|
1404 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1405 Functions:\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1406 \n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1407 dump() -- write value to a file\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1408 load() -- read value from a file\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1409 dumps() -- write value to a string\n\ |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1410 loads() -- read value from a string"); |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1411 |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1412 |
|
30311
f003e48f562d
Bug #794140: cygwin builds do not embed
Jason Tishler <jason@tishler.net>
parents:
24435
diff
changeset
|
1413 PyMODINIT_FUNC |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1414 PyMarshal_Init(void) |
| 267 | 1415 { |
|
54033
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1416 PyObject *mod = Py_InitModule3("marshal", marshal_methods, |
|
6419828ef65a
Issue 5994: add docstrings to marshal.
R. David Murray <rdmurray@bitdance.com>
parents:
52233
diff
changeset
|
1417 marshal_doc); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35877
diff
changeset
|
1418 if (mod == NULL) |
|
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35877
diff
changeset
|
1419 return; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1420 PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION); |
| 267 | 1421 } |
