Mercurial > cpython-lru_cache-weakref
annotate Python/marshal.c @ 58689:514b56efd89a 3.1
Merged revisions 77962 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
................
r77962 | r.david.murray | 2010-02-04 11:41:57 -0500 (Thu, 04 Feb 2010) | 17 lines
Merged revisions 77943,77959-77960 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77943 | r.david.murray | 2010-02-03 08:36:23 -0500 (Wed, 03 Feb 2010) | 2 lines
Explicitly mention the default value for formatdate's usegmt parameter.
........
r77959 | nick.coghlan | 2010-02-04 07:43:58 -0500 (Thu, 04 Feb 2010) | 1 line
Issue 6760: Clarify args handling for subprocess.Popen. Patch by Chris Rebert
........
r77960 | r.david.murray | 2010-02-04 11:33:31 -0500 (Thu, 04 Feb 2010) | 2 lines
Add Chris Rebert to ACKS for issue 6760 Popen doc improvements.
........
................
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 04 Feb 2010 16:44:31 +0000 |
| parents | 08e59076d86b |
| children | f197407bdba2 0f9e8d3ecac3 |
| 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 | |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
14 #define ABS(x) ((x) < 0 ? -(x) : (x)) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
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. |
|
43007
5fde5d6964d7
[Oops, I forgot half of the patch.]
Guido van Rossum <guido@python.org>
parents:
42665
diff
changeset
|
19 * On Windows debug builds, reduce this value. |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
20 */ |
|
43007
5fde5d6964d7
[Oops, I forgot half of the patch.]
Guido van Rossum <guido@python.org>
parents:
42665
diff
changeset
|
21 #if defined(MS_WINDOWS) && defined(_DEBUG) |
|
5fde5d6964d7
[Oops, I forgot half of the patch.]
Guido van Rossum <guido@python.org>
parents:
42665
diff
changeset
|
22 #define MAX_MARSHAL_STACK_DEPTH 1500 |
|
5fde5d6964d7
[Oops, I forgot half of the patch.]
Guido van Rossum <guido@python.org>
parents:
42665
diff
changeset
|
23 #else |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
24 #define MAX_MARSHAL_STACK_DEPTH 2000 |
|
43007
5fde5d6964d7
[Oops, I forgot half of the patch.]
Guido van Rossum <guido@python.org>
parents:
42665
diff
changeset
|
25 #endif |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
26 |
| 35008 | 27 #define TYPE_NULL '0' |
| 28 #define TYPE_NONE 'N' | |
| 29 #define TYPE_FALSE 'F' | |
| 30 #define TYPE_TRUE 'T' | |
| 31 #define TYPE_STOPITER 'S' | |
| 32 #define TYPE_ELLIPSIS '.' | |
| 33 #define TYPE_INT 'i' | |
| 34 #define TYPE_INT64 'I' | |
| 35 #define TYPE_FLOAT 'f' | |
| 36 #define TYPE_BINARY_FLOAT 'g' | |
| 37 #define TYPE_COMPLEX 'x' | |
| 38 #define TYPE_BINARY_COMPLEX 'y' | |
| 39 #define TYPE_LONG 'l' | |
| 40 #define TYPE_STRING 's' | |
| 41 #define TYPE_TUPLE '(' | |
| 42 #define TYPE_LIST '[' | |
| 43 #define TYPE_DICT '{' | |
| 44 #define TYPE_CODE 'c' | |
| 45 #define TYPE_UNICODE 'u' | |
| 46 #define TYPE_UNKNOWN '?' | |
| 47 #define TYPE_SET '<' | |
| 48 #define TYPE_FROZENSET '>' | |
| 267 | 49 |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
50 #define WFERR_OK 0 |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
51 #define WFERR_UNMARSHALLABLE 1 |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
52 #define WFERR_NESTEDTOODEEP 2 |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
53 #define WFERR_NOMEMORY 3 |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
54 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
55 typedef struct { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 FILE *fp; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
57 int error; /* see WFERR_* values */ |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
58 int depth; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
59 /* 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
|
60 PyObject *str; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
61 char *ptr; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
62 char *end; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
63 PyObject *strings; /* dict on marshal, list on unmarshal */ |
| 35008 | 64 int version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
65 } WFILE; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
66 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
67 #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
|
68 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
|
69 else w_more(c, p) |
| 267 | 70 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
71 static void |
|
13672
bfc5b2a8c11f
-- changed w_more to take an integer instead of a char
Fredrik Lundh <fredrik@pythonware.com>
parents:
13658
diff
changeset
|
72 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
|
73 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
74 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
|
75 if (p->str == NULL) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
76 return; /* An error already occurred */ |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
77 size = PyBytes_Size(p->str); |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45082
diff
changeset
|
78 newsize = size + size + 1024; |
|
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45082
diff
changeset
|
79 if (newsize > 32*1024*1024) { |
|
48321
f6726f32ef70
Merged revisions 64119,64147,64150,64165,64219-64221,64229-64230,64233,64235,64253,64278,64280,64301,64303,64320,64328,64338-64339 via svnmerge from
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents:
47580
diff
changeset
|
80 newsize = size + (size >> 3); /* 12.5% overallocation */ |
|
47067
960ade856078
Merged revisions 62998-63003,63005-63006,63009-63012,63014-63017,63019-63020,63022-63024,63026-63029,63031-63041,63043-63045,63047-63054,63056-63062 via svnmerge from
Alexandre Vassalotti <alexandre@peadrop.com>
parents:
45082
diff
changeset
|
81 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
82 if (_PyBytes_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
|
83 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
|
84 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
85 else { |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
86 p->ptr = PyBytes_AS_STRING((PyBytesObject *)p->str) + size; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
87 p->end = |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
88 PyBytes_AS_STRING((PyBytesObject *)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
|
89 *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
|
90 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
91 } |
|
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 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
94 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
|
95 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
96 if (p->fp != NULL) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
97 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
|
98 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
99 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
100 while (--n >= 0) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
101 w_byte(*s, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
102 s++; |
|
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 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
105 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
106 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
107 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
108 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
|
109 { |
|
24434
9ef82377669d
Fix SF 588452: debug build crashes on marshal.dumps([128] * 1000).
Thomas Heller <theller@ctypes.org>
parents:
23851
diff
changeset
|
110 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
|
111 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
|
112 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
113 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
114 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
115 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
|
116 { |
|
24435
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
117 w_byte((char)( x & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
118 w_byte((char)((x>> 8) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
119 w_byte((char)((x>>16) & 0xff), p); |
|
7dc3f4077e59
Whitespace normalization.
Thomas Heller <theller@ctypes.org>
parents:
24434
diff
changeset
|
120 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
|
121 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
122 |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
123 #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
|
124 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
125 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
|
126 { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
127 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
|
128 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
|
129 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
130 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
131 |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
132 /* We assume that Python longs are stored internally in base some power of |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
133 2**15; for the sake of portability we'll always read and write them in base |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
134 exactly 2**15. */ |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
135 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
136 #define PyLong_MARSHAL_SHIFT 15 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
137 #define PyLong_MARSHAL_BASE ((short)1 << PyLong_MARSHAL_SHIFT) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
138 #define PyLong_MARSHAL_MASK (PyLong_MARSHAL_BASE - 1) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
139 #if PyLong_SHIFT % PyLong_MARSHAL_SHIFT != 0 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
140 #error "PyLong_SHIFT must be a multiple of PyLong_MARSHAL_SHIFT" |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
141 #endif |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
142 #define PyLong_MARSHAL_RATIO (PyLong_SHIFT / PyLong_MARSHAL_SHIFT) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
143 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
144 static void |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
145 w_PyLong(const PyLongObject *ob, WFILE *p) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
146 { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
147 Py_ssize_t i, j, n, l; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
148 digit d; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
149 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
150 w_byte(TYPE_LONG, p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
151 if (Py_SIZE(ob) == 0) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
152 w_long((long)0, p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
153 return; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
154 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
155 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
156 /* set l to number of base PyLong_MARSHAL_BASE digits */ |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
157 n = ABS(Py_SIZE(ob)); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
158 l = (n-1) * PyLong_MARSHAL_RATIO; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
159 d = ob->ob_digit[n-1]; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
160 assert(d != 0); /* a PyLong is always normalized */ |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
161 do { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
162 d >>= PyLong_MARSHAL_SHIFT; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
163 l++; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
164 } while (d != 0); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
165 w_long((long)(Py_SIZE(ob) > 0 ? l : -l), p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
166 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
167 for (i=0; i < n-1; i++) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
168 d = ob->ob_digit[i]; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
169 for (j=0; j < PyLong_MARSHAL_RATIO; j++) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
170 w_short(d & PyLong_MARSHAL_MASK, p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
171 d >>= PyLong_MARSHAL_SHIFT; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
172 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
173 assert (d == 0); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
174 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
175 d = ob->ob_digit[n-1]; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
176 do { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
177 w_short(d & PyLong_MARSHAL_MASK, p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
178 d >>= PyLong_MARSHAL_SHIFT; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
179 } while (d != 0); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
180 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
181 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
182 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
183 w_object(PyObject *v, WFILE *p) |
| 267 | 184 { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
185 Py_ssize_t i, n; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
186 |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
187 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
|
188 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
189 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
190 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
|
191 } |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
192 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
|
193 w_byte(TYPE_NULL, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
194 } |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
195 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
|
196 w_byte(TYPE_NONE, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
197 } |
|
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
|
198 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
|
199 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
|
200 } |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
201 else if (v == Py_Ellipsis) { |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
202 w_byte(TYPE_ELLIPSIS, p); |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
203 } |
|
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
|
204 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
|
205 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
|
206 } |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
207 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
|
208 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
|
209 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
210 else if (PyLong_CheckExact(v)) { |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
211 long x = PyLong_AsLong(v); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
212 if ((x == -1) && PyErr_Occurred()) { |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
213 PyLongObject *ob = (PyLongObject *)v; |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
214 PyErr_Clear(); |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
215 w_PyLong(ob, p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
216 } |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
217 else { |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
218 #if SIZEOF_LONG > 4 |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
219 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
220 if (y && y != -1) { |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
221 w_byte(TYPE_INT64, p); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
222 w_long64(x, p); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
223 } |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
224 else |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
225 #endif |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
226 { |
|
40626
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
227 w_byte(TYPE_INT, p); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
228 w_long(x, p); |
|
4aee3f672f77
Merged the int/long unification branch, by very crude means (sorry Thomas!).
Guido van Rossum <guido@python.org>
parents:
40527
diff
changeset
|
229 } |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
230 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
231 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
232 else if (PyFloat_CheckExact(v)) { |
| 35008 | 233 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
|
234 unsigned char buf[8]; |
| 35008 | 235 if (_PyFloat_Pack8(PyFloat_AsDouble(v), |
| 236 buf, 1) < 0) { | |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
237 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 238 return; |
| 239 } | |
| 240 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
|
241 w_string((char*)buf, 8, p); |
| 35008 | 242 } |
| 243 else { | |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
244 char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v), |
|
53192
973f4d7aa87c
Make sure that marshal and pickle continue to output 17
Mark Dickinson <dickinsm@gmail.com>
parents:
53187
diff
changeset
|
245 'g', 17, 0, NULL); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
246 if (!buf) { |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
247 p->error = WFERR_NOMEMORY; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
248 return; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
249 } |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
250 n = strlen(buf); |
| 35008 | 251 w_byte(TYPE_FLOAT, p); |
|
36522
2791676b3825
Move cast to suppress warning.
Martin v. Löwis <martin@v.loewis.de>
parents:
36501
diff
changeset
|
252 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
|
253 w_string(buf, (int)n, p); |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
254 PyMem_Free(buf); |
| 35008 | 255 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
256 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
257 #ifndef WITHOUT_COMPLEX |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
258 else if (PyComplex_CheckExact(v)) { |
| 35008 | 259 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
|
260 unsigned char buf[8]; |
| 35008 | 261 if (_PyFloat_Pack8(PyComplex_RealAsDouble(v), |
| 262 buf, 1) < 0) { | |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
263 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 264 return; |
| 265 } | |
| 266 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
|
267 w_string((char*)buf, 8, p); |
| 35008 | 268 if (_PyFloat_Pack8(PyComplex_ImagAsDouble(v), |
| 269 buf, 1) < 0) { | |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
270 p->error = WFERR_UNMARSHALLABLE; |
| 35008 | 271 return; |
| 272 } | |
|
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
|
273 w_string((char*)buf, 8, p); |
| 35008 | 274 } |
| 275 else { | |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
276 char *buf; |
| 35008 | 277 w_byte(TYPE_COMPLEX, p); |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
278 buf = PyOS_double_to_string(PyComplex_RealAsDouble(v), |
|
53192
973f4d7aa87c
Make sure that marshal and pickle continue to output 17
Mark Dickinson <dickinsm@gmail.com>
parents:
53187
diff
changeset
|
279 'g', 17, 0, NULL); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
280 if (!buf) { |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
281 p->error = WFERR_NOMEMORY; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
282 return; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
283 } |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
284 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
|
285 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
|
286 w_string(buf, (int)n, p); |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
287 PyMem_Free(buf); |
|
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
288 buf = PyOS_double_to_string(PyComplex_ImagAsDouble(v), |
|
53192
973f4d7aa87c
Make sure that marshal and pickle continue to output 17
Mark Dickinson <dickinsm@gmail.com>
parents:
53187
diff
changeset
|
289 'g', 17, 0, NULL); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
290 if (!buf) { |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
291 p->error = WFERR_NOMEMORY; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
292 return; |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
293 } |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
294 n = strlen(buf); |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
295 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
|
296 w_string(buf, (int)n, p); |
|
53187
b653eab13b73
The other half of Issue #1580: use short float repr where possible.
Eric Smith <eric@trueblade.com>
parents:
52215
diff
changeset
|
297 PyMem_Free(buf); |
| 35008 | 298 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
299 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
300 #endif |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
301 else if (PyBytes_CheckExact(v)) { |
|
43777
0d462d789b18
Merging the py3k-pep3137 branch back into the py3k branch.
Guido van Rossum <guido@python.org>
parents:
43734
diff
changeset
|
302 w_byte(TYPE_STRING, p); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
303 n = PyBytes_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
|
304 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
|
305 /* 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
|
306 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
307 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
|
308 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
309 } |
|
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
|
310 w_long((long)n, p); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
311 w_string(PyBytes_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
|
312 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
313 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
|
314 PyObject *utf8; |
|
53681
52a77ef069cd
Issue #3672: Reject surrogates in utf-8 codec; add surrogates error
Martin v. Löwis <martin@v.loewis.de>
parents:
53300
diff
changeset
|
315 utf8 = PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(v), |
|
52a77ef069cd
Issue #3672: Reject surrogates in utf-8 codec; add surrogates error
Martin v. Löwis <martin@v.loewis.de>
parents:
53300
diff
changeset
|
316 PyUnicode_GET_SIZE(v), |
|
53965
fbcdae3e0ca1
Rename the surrogates error handler to surrogatepass.
Martin v. Löwis <martin@v.loewis.de>
parents:
53707
diff
changeset
|
317 "surrogatepass"); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
318 if (utf8 == NULL) { |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
319 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
320 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
|
321 return; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
322 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
323 w_byte(TYPE_UNICODE, p); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
324 n = PyBytes_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
|
325 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
|
326 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
327 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
|
328 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
329 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
330 w_long((long)n, p); |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
331 w_string(PyBytes_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
|
332 Py_DECREF(utf8); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
333 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
341 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
342 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
|
343 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
|
344 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
|
345 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
|
346 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
|
347 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
|
348 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
349 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
350 else if (PyDict_CheckExact(v)) { |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
351 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
|
352 PyObject *key, *value; |
|
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_DICT, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
354 /* This one is NULL object terminated! */ |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
355 pos = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
356 while (PyDict_Next(v, &pos, &key, &value)) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
357 w_object(key, p); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
358 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
|
359 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
360 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
|
361 } |
|
43815
85cf334b32c3
Merged revisions 58886-58929 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43777
diff
changeset
|
362 else if (PyAnySet_CheckExact(v)) { |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
363 PyObject *value, *it; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
364 |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
365 if (PyObject_TypeCheck(v, &PySet_Type)) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
366 w_byte(TYPE_SET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
367 else |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
368 w_byte(TYPE_FROZENSET, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
369 n = PyObject_Size(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
370 if (n == -1) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
371 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
372 p->error = WFERR_UNMARSHALLABLE; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
373 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
374 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
375 w_long((long)n, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
376 it = PyObject_GetIter(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
377 if (it == NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
378 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
379 p->error = WFERR_UNMARSHALLABLE; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
380 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
381 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
382 while ((value = PyIter_Next(it)) != NULL) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
383 w_object(value, p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
384 Py_DECREF(value); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
385 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
386 Py_DECREF(it); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
387 if (PyErr_Occurred()) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
388 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
389 p->error = WFERR_UNMARSHALLABLE; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
390 return; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
391 } |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
392 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
393 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
|
394 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
|
395 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
|
396 w_long(co->co_argcount, p); |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
397 w_long(co->co_kwonlyargcount, p); |
|
23851
d6ae544acd24
Fix SF bug # 561858 Assertion with very long lists
Neal Norwitz <nnorwitz@gmail.com>
parents:
22785
diff
changeset
|
398 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
|
399 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
|
400 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
|
401 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
|
402 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
|
403 w_object(co->co_names, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
404 w_object(co->co_varnames, p); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
405 w_object(co->co_freevars, p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 } |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
412 else if (PyObject_CheckBuffer(v)) { |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
413 /* 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
|
414 char *s; |
|
20947
c555f1e7c4be
Use PyObject_CheckReadBuffer().
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
20552
diff
changeset
|
415 PyBufferProcs *pb = v->ob_type->tp_as_buffer; |
|
43423
0476a2cc5658
Change PyBuffer to Py_buffer to be consistent with other non-object structures like Py_complex. Add some more functionality to the memoryview object.
Travis E. Oliphant <oliphant@enthought.com>
parents:
43007
diff
changeset
|
416 Py_buffer view; |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
417 if ((*pb->bf_getbuffer)(v, &view, PyBUF_SIMPLE) != 0) { |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
418 w_byte(TYPE_UNKNOWN, p); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
419 p->error = WFERR_UNMARSHALLABLE; |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
420 } |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
421 w_byte(TYPE_STRING, p); |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
422 n = view.len; |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
423 s = view.buf; |
|
36866
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
424 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
|
425 p->depth--; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
426 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
|
427 return; |
|
9eb24f92a784
Change int to Py_ssize_t in several places.
Martin v. Löwis <martin@v.loewis.de>
parents:
36792
diff
changeset
|
428 } |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
429 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
|
430 w_string(s, (int)n, p); |
|
42665
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
431 if (pb->bf_releasebuffer != NULL) |
|
85c22b4d4455
Merged in py3k-buffer branch to main line. All objects now use the buffer protocol in PEP 3118.
Travis E. Oliphant <oliphant@enthought.com>
parents:
42404
diff
changeset
|
432 (*pb->bf_releasebuffer)(v, &view); |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
433 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
434 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
435 w_byte(TYPE_UNKNOWN, p); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
436 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
|
437 } |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
438 p->depth--; |
| 267 | 439 } |
| 440 | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
441 /* version currently has no effect for writing longs. */ |
| 267 | 442 void |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
443 PyMarshal_WriteLongToFile(long x, FILE *fp, int version) |
| 267 | 444 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
445 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
446 wf.fp = fp; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
447 wf.error = WFERR_OK; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
448 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
449 wf.strings = NULL; |
| 35008 | 450 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
451 w_long(x, &wf); |
| 267 | 452 } |
| 453 | |
| 454 void | |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
455 PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp, int version) |
| 267 | 456 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
457 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
458 wf.fp = fp; |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
459 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
|
460 wf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
461 wf.strings = (version > 0) ? PyDict_New() : NULL; |
| 35008 | 462 wf.version = version; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
463 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
|
464 Py_XDECREF(wf.strings); |
| 267 | 465 } |
| 466 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
467 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
|
468 |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
469 #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
|
470 |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
471 #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) |
| 267 | 472 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
473 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
474 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
|
475 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
476 if (p->fp != NULL) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
477 /* 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
|
478 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
|
479 if (p->end - p->ptr < n) |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
480 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
|
481 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
|
482 p->ptr += n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
483 return n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
484 } |
|
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 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
487 r_short(RFILE *p) |
| 267 | 488 { |
| 489 register short x; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
490 x = r_byte(p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
491 x |= r_byte(p) << 8; |
| 14678 | 492 /* Sign-extension, in case short greater than 16 bits */ |
| 493 x |= -(x & 0x8000); | |
| 267 | 494 return x; |
| 495 } | |
| 496 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
497 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
498 r_long(RFILE *p) |
| 267 | 499 { |
| 500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 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
|
506 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
|
507 } |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
508 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
|
509 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
|
510 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
|
511 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
|
512 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
|
513 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
514 #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
|
515 /* Sign extension for 64-bit machines */ |
| 14678 | 516 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
|
517 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
518 return x; |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
519 } |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
520 |
|
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
|
521 /* 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 */ |
|
7e628f60245e
marshal.c r_long64: When reading a TYPE_INT64 value on a box with 32-bit
Tim Peters <tim.peters@gmail.com>
parents:
19343
diff
changeset
|
528 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
529 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
|
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 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
|
532 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
|
533 #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
|
534 long x = (hi4 << 32) | (lo4 & 0xFFFFFFFFL); |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43815
diff
changeset
|
535 return PyLong_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
|
536 #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
|
537 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
|
538 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
|
539 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
|
540 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
|
541 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
|
542 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
|
543 } |
|
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 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
|
545 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
|
546 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
|
547 } |
|
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 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
|
549 #endif |
| 267 | 550 } |
| 551 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
552 static PyObject * |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
553 r_PyLong(RFILE *p) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
554 { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
555 PyLongObject *ob; |
|
56297
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
556 int size, i, j, md, shorts_in_top_digit; |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
557 long n; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
558 digit d; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
559 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
560 n = r_long(p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
561 if (n == 0) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
562 return (PyObject *)_PyLong_New(0); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
563 if (n < -INT_MAX || n > INT_MAX) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
564 PyErr_SetString(PyExc_ValueError, |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
565 "bad marshal data (long size out of range)"); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
566 return NULL; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
567 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
568 |
|
56297
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
569 size = 1 + (ABS(n) - 1) / PyLong_MARSHAL_RATIO; |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
570 shorts_in_top_digit = 1 + (ABS(n) - 1) % PyLong_MARSHAL_RATIO; |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
571 ob = _PyLong_New(size); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
572 if (ob == NULL) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
573 return NULL; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
574 Py_SIZE(ob) = n > 0 ? size : -size; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
575 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
576 for (i = 0; i < size-1; i++) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
577 d = 0; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
578 for (j=0; j < PyLong_MARSHAL_RATIO; j++) { |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
579 md = r_short(p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
580 if (md < 0 || md > PyLong_MARSHAL_BASE) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
581 goto bad_digit; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
582 d += (digit)md << j*PyLong_MARSHAL_SHIFT; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
583 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
584 ob->ob_digit[i] = d; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
585 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
586 d = 0; |
|
56297
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
587 for (j=0; j < shorts_in_top_digit; j++) { |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
588 md = r_short(p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
589 if (md < 0 || md > PyLong_MARSHAL_BASE) |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
590 goto bad_digit; |
|
56297
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
591 /* topmost marshal digit should be nonzero */ |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
592 if (md == 0 && j == shorts_in_top_digit - 1) { |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
593 Py_DECREF(ob); |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
594 PyErr_SetString(PyExc_ValueError, |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
595 "bad marshal data (unnormalized long data)"); |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
596 return NULL; |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
597 } |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
598 d += (digit)md << j*PyLong_MARSHAL_SHIFT; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
599 } |
|
56297
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
600 /* top digit should be nonzero, else the resulting PyLong won't be |
|
08e59076d86b
Merged revisions 75145 via svnmerge from
Mark Dickinson <dickinsm@gmail.com>
parents:
54035
diff
changeset
|
601 normalized */ |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
602 ob->ob_digit[size-1] = d; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
603 return (PyObject *)ob; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
604 bad_digit: |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
605 Py_DECREF(ob); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
606 PyErr_SetString(PyExc_ValueError, |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
607 "bad marshal data (digit out of range in long)"); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
608 return NULL; |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
609 } |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
610 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
611 |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
612 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
613 r_object(RFILE *p) |
| 267 | 614 { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
615 /* 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
|
616 an exception is set. */ |
|
45071
f380d991390e
Merged revisions 60441-60474 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45044
diff
changeset
|
617 PyObject *v, *v2; |
| 267 | 618 long i, n; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
619 int type = r_byte(p); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
620 PyObject *retval; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
621 |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
622 p->depth++; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
623 |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
624 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
625 p->depth--; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
626 PyErr_SetString(PyExc_ValueError, "recursion limit exceeded"); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
627 return NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
628 } |
|
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
|
629 |
| 267 | 630 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
|
631 |
| 267 | 632 case EOF: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
633 PyErr_SetString(PyExc_EOFError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
634 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
635 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
636 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
|
637 |
| 267 | 638 case TYPE_NULL: |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
639 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
640 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
|
641 |
| 267 | 642 case TYPE_NONE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
643 Py_INCREF(Py_None); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
644 retval = Py_None; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
645 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
|
646 |
|
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
|
647 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
|
648 Py_INCREF(PyExc_StopIteration); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
649 retval = PyExc_StopIteration; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
650 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
|
651 |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
652 case TYPE_ELLIPSIS: |
|
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_Ellipsis); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
654 retval = Py_Ellipsis; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
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 |
|
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
|
657 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
|
658 Py_INCREF(Py_False); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
659 retval = Py_False; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
660 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
|
661 |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
22705
diff
changeset
|
662 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
|
663 Py_INCREF(Py_True); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
664 retval = Py_True; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
665 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
|
666 |
| 267 | 667 case TYPE_INT: |
|
44099
f324631462a2
Cleanup: Replaced most PyInt_ aliases with PyLong_ and disabled the aliases in intobject.h
Christian Heimes <christian@cheimes.de>
parents:
43815
diff
changeset
|
668 retval = PyLong_FromLong(r_long(p)); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
669 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
|
670 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
671 case TYPE_INT64: |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
672 retval = r_long64(p); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
673 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
|
674 |
| 267 | 675 case TYPE_LONG: |
|
52215
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
676 retval = r_PyLong(p); |
|
bb5de24a343f
Issue #4258: Make it possible to use 30-bit digits for PyLongs:
Mark Dickinson <dickinsm@gmail.com>
parents:
52171
diff
changeset
|
677 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
|
678 |
| 267 | 679 case TYPE_FLOAT: |
| 680 { | |
| 681 char buf[256]; | |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
682 double dx; |
|
53707
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
683 retval = NULL; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
684 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
685 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
|
686 PyErr_SetString(PyExc_EOFError, |
| 267 | 687 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
688 break; |
| 267 | 689 } |
| 690 buf[n] = '\0'; | |
|
53707
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
691 dx = PyOS_string_to_double(buf, NULL, NULL); |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
692 if (dx == -1.0 && PyErr_Occurred()) |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
693 break; |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
694 retval = PyFloat_FromDouble(dx); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
695 break; |
| 267 | 696 } |
|
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
|
697 |
| 35008 | 698 case TYPE_BINARY_FLOAT: |
| 699 { | |
|
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
|
700 unsigned char buf[8]; |
| 35008 | 701 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
|
702 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 703 PyErr_SetString(PyExc_EOFError, |
| 704 "EOF read where object expected"); | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
705 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
706 break; |
| 35008 | 707 } |
| 708 x = _PyFloat_Unpack8(buf, 1); | |
| 709 if (x == -1.0 && PyErr_Occurred()) { | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
710 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
711 break; |
| 35008 | 712 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
713 retval = PyFloat_FromDouble(x); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
714 break; |
| 35008 | 715 } |
| 716 | |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
717 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
718 case TYPE_COMPLEX: |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
719 { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
720 char buf[256]; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3731
diff
changeset
|
721 Py_complex c; |
|
53707
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
722 retval = NULL; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
723 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
724 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
|
725 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
726 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
727 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
728 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
729 buf[n] = '\0'; |
|
53707
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
730 c.real = PyOS_string_to_double(buf, NULL, NULL); |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
731 if (c.real == -1.0 && PyErr_Occurred()) |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
732 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
733 n = r_byte(p); |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
734 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
|
735 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
736 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
737 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
738 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
739 buf[n] = '\0'; |
|
53707
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
740 c.imag = PyOS_string_to_double(buf, NULL, NULL); |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
741 if (c.imag == -1.0 && PyErr_Occurred()) |
|
13a82a710f19
Issue #5914: Add new C-API function PyOS_string_to_double, to complement
Mark Dickinson <dickinsm@gmail.com>
parents:
53681
diff
changeset
|
742 break; |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
743 retval = PyComplex_FromCComplex(c); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
744 break; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
745 } |
| 35008 | 746 |
| 747 case TYPE_BINARY_COMPLEX: | |
| 748 { | |
|
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
|
749 unsigned char buf[8]; |
| 35008 | 750 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
|
751 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 752 PyErr_SetString(PyExc_EOFError, |
| 753 "EOF read where object expected"); | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
754 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
755 break; |
| 35008 | 756 } |
| 757 c.real = _PyFloat_Unpack8(buf, 1); | |
| 758 if (c.real == -1.0 && PyErr_Occurred()) { | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
759 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
760 break; |
| 35008 | 761 } |
|
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
|
762 if (r_string((char*)buf, 8, p) != 8) { |
| 35008 | 763 PyErr_SetString(PyExc_EOFError, |
| 764 "EOF read where object expected"); | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
765 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
766 break; |
| 35008 | 767 } |
| 768 c.imag = _PyFloat_Unpack8(buf, 1); | |
| 769 if (c.imag == -1.0 && PyErr_Occurred()) { | |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
770 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
771 break; |
| 35008 | 772 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
773 retval = PyComplex_FromCComplex(c); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
774 break; |
| 35008 | 775 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
776 #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
|
777 |
| 267 | 778 case TYPE_STRING: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
779 n = r_long(p); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
780 if (n < 0 || n > INT_MAX) { |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
781 PyErr_SetString(PyExc_ValueError, "bad marshal data (string size out of range)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
782 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
783 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
784 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
785 v = PyBytes_FromStringAndSize((char *)NULL, n); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
786 if (v == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
787 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
788 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
789 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
790 if (r_string(PyBytes_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
|
791 Py_DECREF(v); |
|
8e9682fd57f8
Fix a couple of crashing-on-malformed data marshal bugs.
Michael W. Hudson <mwh@python.net>
parents:
35008
diff
changeset
|
792 PyErr_SetString(PyExc_EOFError, |
| 267 | 793 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
794 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
795 break; |
| 267 | 796 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
797 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
798 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
|
799 |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
800 case TYPE_UNICODE: |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
801 { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
802 char *buffer; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
803 |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
804 n = r_long(p); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
805 if (n < 0 || n > INT_MAX) { |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
806 PyErr_SetString(PyExc_ValueError, "bad marshal data (unicode size out of range)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
807 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
808 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
809 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
810 buffer = PyMem_NEW(char, n); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
811 if (buffer == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
812 retval = PyErr_NoMemory(); |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
813 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
814 } |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
815 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
|
816 PyMem_DEL(buffer); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
817 PyErr_SetString(PyExc_EOFError, |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
818 "EOF read where object expected"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
819 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
820 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
821 } |
|
53965
fbcdae3e0ca1
Rename the surrogates error handler to surrogatepass.
Martin v. Löwis <martin@v.loewis.de>
parents:
53707
diff
changeset
|
822 v = PyUnicode_DecodeUTF8(buffer, n, "surrogatepass"); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
823 PyMem_DEL(buffer); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
824 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
825 break; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
826 } |
|
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
|
827 |
| 267 | 828 case TYPE_TUPLE: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
829 n = r_long(p); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
830 if (n < 0 || n > INT_MAX) { |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
831 PyErr_SetString(PyExc_ValueError, "bad marshal data (tuple size out of range)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
832 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
833 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
834 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
835 v = PyTuple_New((int)n); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
836 if (v == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
837 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
838 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
839 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
840 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
|
841 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
|
842 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
843 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
844 PyErr_SetString(PyExc_TypeError, |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
845 "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
|
846 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
|
847 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
848 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
849 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
850 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
|
851 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
852 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
853 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
|
854 |
| 267 | 855 case TYPE_LIST: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
856 n = r_long(p); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
857 if (n < 0 || n > INT_MAX) { |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
858 PyErr_SetString(PyExc_ValueError, "bad marshal data (list size out of range)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
859 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
860 break; |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
861 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
862 v = PyList_New((int)n); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
863 if (v == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
864 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
865 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
866 } |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
867 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
|
868 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
|
869 if ( v2 == NULL ) { |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
870 if (!PyErr_Occurred()) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
871 PyErr_SetString(PyExc_TypeError, |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
872 "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
|
873 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
|
874 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
875 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
876 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
877 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
|
878 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
879 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
880 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
|
881 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
882 case TYPE_DICT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
883 v = PyDict_New(); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
884 if (v == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
885 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
886 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
887 } |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
888 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
889 PyObject *key, *val; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
890 key = r_object(p); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
891 if (key == NULL) |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
892 break; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
893 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
|
894 if (val != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
895 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
|
896 Py_DECREF(key); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
897 Py_XDECREF(val); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
898 } |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
899 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
900 Py_DECREF(v); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
901 v = NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
902 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
903 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
904 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
|
905 |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
906 case TYPE_SET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
907 case TYPE_FROZENSET: |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
908 n = r_long(p); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
909 if (n < 0 || n > INT_MAX) { |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
910 PyErr_SetString(PyExc_ValueError, "bad marshal data (set size out of range)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
911 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
912 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
913 } |
|
45044
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
914 v = (type == TYPE_SET) ? PySet_New(NULL) : PyFrozenSet_New(NULL); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
915 if (v == NULL) { |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
916 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
917 break; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
918 } |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
919 for (i = 0; i < n; i++) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
920 v2 = r_object(p); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
921 if ( v2 == NULL ) { |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
922 if (!PyErr_Occurred()) |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
923 PyErr_SetString(PyExc_TypeError, |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
924 "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
|
925 Py_DECREF(v); |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
926 v = NULL; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
927 break; |
|
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
928 } |
|
45044
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
929 if (PySet_Add(v, v2) == -1) { |
|
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
930 Py_DECREF(v); |
|
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
931 Py_DECREF(v2); |
|
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
932 v = NULL; |
|
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
933 break; |
|
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
934 } |
|
45082
d7540031b959
Merged revisions 60475-60479,60481-60488 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
45071
diff
changeset
|
935 Py_DECREF(v2); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
936 } |
|
45044
c3b38a85989f
Merged revisions 60383-60407 via svnmerge from
Christian Heimes <christian@cheimes.de>
parents:
44351
diff
changeset
|
937 retval = v; |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
938 break; |
|
34394
b480abaf1f6f
SF 1098985: set objects cannot be marshalled
Raymond Hettinger <python@rcn.com>
parents:
34205
diff
changeset
|
939 |
| 267 | 940 case TYPE_CODE: |
|
41715
f60c877d52c8
Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41653
diff
changeset
|
941 { |
| 35008 | 942 int argcount; |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
943 int kwonlyargcount; |
| 35008 | 944 int nlocals; |
| 945 int stacksize; | |
| 946 int flags; | |
| 947 PyObject *code = NULL; | |
| 948 PyObject *consts = NULL; | |
| 949 PyObject *names = NULL; | |
| 950 PyObject *varnames = NULL; | |
| 951 PyObject *freevars = NULL; | |
| 952 PyObject *cellvars = NULL; | |
| 953 PyObject *filename = NULL; | |
| 954 PyObject *name = NULL; | |
| 955 int firstlineno; | |
| 956 PyObject *lnotab = NULL; | |
| 957 | |
| 958 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
|
959 |
|
41715
f60c877d52c8
Merged revisions 55270-55324 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41653
diff
changeset
|
960 /* XXX ignore long->int overflows for now */ |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
961 argcount = (int)r_long(p); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
962 kwonlyargcount = (int)r_long(p); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
963 nlocals = (int)r_long(p); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
964 stacksize = (int)r_long(p); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
965 flags = (int)r_long(p); |
| 35008 | 966 code = r_object(p); |
| 967 if (code == NULL) | |
| 968 goto code_error; | |
| 969 consts = r_object(p); | |
| 970 if (consts == NULL) | |
| 971 goto code_error; | |
| 972 names = r_object(p); | |
| 973 if (names == NULL) | |
| 974 goto code_error; | |
| 975 varnames = r_object(p); | |
| 976 if (varnames == NULL) | |
| 977 goto code_error; | |
| 978 freevars = r_object(p); | |
| 979 if (freevars == NULL) | |
| 980 goto code_error; | |
| 981 cellvars = r_object(p); | |
| 982 if (cellvars == NULL) | |
| 983 goto code_error; | |
| 984 filename = r_object(p); | |
| 985 if (filename == NULL) | |
| 986 goto code_error; | |
| 987 name = r_object(p); | |
| 988 if (name == NULL) | |
| 989 goto code_error; | |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
990 firstlineno = (int)r_long(p); |
| 35008 | 991 lnotab = r_object(p); |
| 992 if (lnotab == NULL) | |
| 993 goto code_error; | |
| 994 | |
| 995 v = (PyObject *) PyCode_New( | |
|
40215
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
996 argcount, kwonlyargcount, |
|
1cce0526d9b0
Jiwon Seo's PEP 3102 implementation.
Guido van Rossum <guido@python.org>
parents:
39610
diff
changeset
|
997 nlocals, stacksize, flags, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
998 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
|
999 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
|
1000 firstlineno, lnotab); |
| 35008 | 1001 |
| 1002 code_error: | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1003 Py_XDECREF(code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1004 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1005 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1006 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1007 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
1008 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1009 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1010 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
|
1011 Py_XDECREF(lnotab); |
| 267 | 1012 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1013 retval = v; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1014 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
|
1015 |
| 267 | 1016 default: |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1017 /* 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
|
1018 This will let you keep working and recover. */ |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
1019 PyErr_SetString(PyExc_ValueError, "bad marshal data (unknown type code)"); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1020 retval = NULL; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1021 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
|
1022 |
| 267 | 1023 } |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1024 p->depth--; |
|
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1025 return retval; |
| 267 | 1026 } |
| 1027 | |
|
32343
54b257e55f99
Make private function static
Neal Norwitz <nnorwitz@gmail.com>
parents:
32305
diff
changeset
|
1028 static PyObject * |
|
31824
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1029 read_object(RFILE *p) |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1030 { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1031 PyObject *v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1032 if (PyErr_Occurred()) { |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1033 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
|
1034 return NULL; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1035 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1036 v = r_object(p); |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1037 if (v == NULL && !PyErr_Occurred()) |
|
52171
4e927faf30ea
Merged revisions 70378 via svnmerge from
Nick Coghlan <ncoghlan@gmail.com>
parents:
49057
diff
changeset
|
1038 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
|
1039 return v; |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1040 } |
|
331de8b9d1ed
Marshal clean-up (SF patch #873224)
Armin Rigo <arigo@tunes.org>
parents:
30311
diff
changeset
|
1041 |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1042 int |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1043 PyMarshal_ReadShortFromFile(FILE *fp) |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1044 { |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1045 RFILE rf; |
|
36783
965bb4a54096
Fix gcc (4.0.x) warning about use of uninitialized variables.
Thomas Wouters <thomas@python.org>
parents:
36522
diff
changeset
|
1046 assert(fp); |
|
20552
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1047 rf.fp = fp; |
|
36784
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1048 rf.strings = NULL; |
|
d853bc06847e
Fix incompatible assignment warning from previous checkin.
Thomas Wouters <thomas@python.org>
parents:
36783
diff
changeset
|
1049 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
|
1050 return r_short(&rf); |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1051 } |
|
65dd6157f999
SF patch #470393 (Jim Ahlstrom): Add missing marshal function
Guido van Rossum <guido@python.org>
parents:
19605
diff
changeset
|
1052 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1053 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1054 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
|
1055 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1056 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1057 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1058 rf.strings = NULL; |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43423
diff
changeset
|
1059 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
|
1060 return r_long(&rf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1061 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1062 |
|
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
|
1063 #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
|
1064 /* 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
|
1065 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
|
1066 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
|
1067 { |
|
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
|
1068 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
|
1069 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
|
1070 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
|
1071 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
|
1072 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
|
1073 } |
|
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
|
1074 #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
|
1075 |
|
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
|
1076 /* 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
|
1077 * 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
|
1078 * 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
|
1079 * 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
|
1080 * 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
|
1081 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1082 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
|
1083 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
|
1084 { |
|
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
|
1085 /* 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
|
1086 * 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
|
1087 */ |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1088 #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
|
1089 #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
|
1090 #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
|
1091 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
|
1092 #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
|
1093 #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
|
1094 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
|
1095 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
|
1096 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
|
1097 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
|
1098 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
|
1099 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
|
1100 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
|
1101 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
|
1102 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
|
1103 PyObject* v; |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1104 size_t n; |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1105 /* 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
|
1106 is smaller than REASONABLE_FILE_LIMIT */ |
|
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 } |
|
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
|
1113 |
|
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
|
1114 } |
|
a36a4932e399
Variant of SF patch 103252: Startup optimize: read *.pyc as string, not with getc().
Tim Peters <tim.peters@gmail.com>
parents:
15408
diff
changeset
|
1115 #endif |
|
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
|
1116 /* 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
|
1117 * 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
|
1118 */ |
|
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 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
|
1120 |
|
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
|
1121 #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
|
1122 #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
|
1123 } |
|
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 |
|
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
|
1125 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
|
1126 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
|
1127 { |
|
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
|
1128 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1129 PyObject *result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1130 rf.fp = fp; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1131 rf.strings = PyList_New(0); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1132 rf.depth = 0; |
|
43734
3e5edf19d5f0
Merged revisions 58221-58741 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
43423
diff
changeset
|
1133 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
|
1134 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1135 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1136 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1137 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1138 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1139 PyObject * |
|
36501
7fdc639bc5b4
Merge ssize_t branch.
Martin v. Löwis <martin@v.loewis.de>
parents:
36324
diff
changeset
|
1140 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
|
1141 { |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1142 RFILE rf; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1143 PyObject *result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1144 rf.fp = NULL; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1145 rf.ptr = str; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1146 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
|
1147 rf.strings = PyList_New(0); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1148 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1149 result = r_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1150 Py_DECREF(rf.strings); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1151 return result; |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1152 } |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
1153 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1154 PyObject * |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1155 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
|
1156 { |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1157 WFILE wf; |
|
41653
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1158 PyObject *res = NULL; |
|
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1159 |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1160 wf.fp = NULL; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1161 wf.str = PyBytes_FromStringAndSize((char *)NULL, 50); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1162 if (wf.str == NULL) |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1163 return NULL; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1164 wf.ptr = PyBytes_AS_STRING((PyBytesObject *)wf.str); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1165 wf.end = wf.ptr + PyBytes_Size(wf.str); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1166 wf.error = WFERR_OK; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
1167 wf.depth = 0; |
| 35008 | 1168 wf.version = version; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1169 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
|
1170 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
|
1171 Py_XDECREF(wf.strings); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1172 if (wf.str != NULL) { |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1173 char *base = PyBytes_AS_STRING((PyBytesObject *)wf.str); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1174 if (wf.ptr - base > PY_SSIZE_T_MAX) { |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1175 Py_DECREF(wf.str); |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1176 PyErr_SetString(PyExc_OverflowError, |
|
41595
2c54763c4504
More coding by random modification.
Guido van Rossum <guido@python.org>
parents:
41587
diff
changeset
|
1177 "too much marshal data for a string"); |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1178 return NULL; |
|
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1179 } |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1180 if (_PyBytes_Resize(&wf.str, (Py_ssize_t)(wf.ptr - base)) < 0) |
|
41653
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1181 return NULL; |
|
40450
cc992d75d5b3
Four months of trunk changes (including a few releases...)
Thomas Wouters <thomas@python.org>
parents:
40215
diff
changeset
|
1182 } |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1183 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
|
1184 Py_XDECREF(wf.str); |
|
53300
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1185 if (wf.error == WFERR_NOMEMORY) |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1186 PyErr_NoMemory(); |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1187 else |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1188 PyErr_SetString(PyExc_ValueError, |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1189 (wf.error==WFERR_UNMARSHALLABLE)?"unmarshallable object" |
|
ed3f51f2abfb
Added handling of PyOS_double_to_string out-of-memory errors. Closes issue 5775.
Eric Smith <eric@trueblade.com>
parents:
53192
diff
changeset
|
1190 :"object too deeply nested to marshal"); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1191 return NULL; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1192 } |
|
41653
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1193 if (wf.str != NULL) { |
|
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1194 /* XXX Quick hack -- need to do this differently */ |
|
49057
8ffec372040e
fixes deferred/release blocker issue #3797: Fixed the dbm, marshal, mmap,
Gregory P. Smith <greg@mad-scientist.com>
parents:
48683
diff
changeset
|
1195 res = PyBytes_FromObject(wf.str); |
|
41653
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1196 Py_DECREF(wf.str); |
|
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1197 } |
|
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1198 return res; |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1199 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
1200 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
1201 /* And an interface for Python programs... */ |
| 267 | 1202 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1203 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1204 marshal_dump(PyObject *self, PyObject *args) |
| 267 | 1205 { |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1206 /* XXX Quick hack -- need to do this differently */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1207 PyObject *x; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1208 PyObject *f; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1209 int version = Py_MARSHAL_VERSION; |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1210 PyObject *s; |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1211 PyObject *res; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1212 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
|
1213 return NULL; |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1214 s = PyMarshal_WriteObjectToString(x, version); |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1215 if (s == NULL) |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
1216 return NULL; |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1217 res = PyObject_CallMethod(f, "write", "O", s); |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1218 Py_DECREF(s); |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1219 return res; |
| 267 | 1220 } |
| 1221 | |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1222 PyDoc_STRVAR(dump_doc, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1223 "dump(value, file[, version])\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1224 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1225 Write the value on the open file. The value must be a supported type.\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1226 The file must be an open file object such as sys.stdout or returned by\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1227 open() or os.popen(). It must be opened in binary mode ('wb' or 'w+b').\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1228 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1229 If the value has (or contains an object that has) an unsupported type, a\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1230 ValueError exception is raised — but garbage data will also be written\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1231 to the file. The object will not be properly read back by load()\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1232 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1233 The version argument indicates the data format that dump should use."); |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1234 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1235 static PyObject * |
|
38669
19fd6141940d
Partially merge trunk into p3yk. The removal of Mac/Tools is confusing svn
Thomas Wouters <thomas@python.org>
parents:
36866
diff
changeset
|
1236 marshal_load(PyObject *self, PyObject *f) |
| 267 | 1237 { |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1238 /* XXX Quick hack -- need to do this differently */ |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1239 PyObject *data, *result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1240 RFILE rf; |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1241 data = PyObject_CallMethod(f, "read", ""); |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1242 if (data == NULL) |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1243 return NULL; |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1244 rf.fp = NULL; |
|
47301
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1245 if (PyBytes_Check(data)) { |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1246 rf.ptr = PyBytes_AS_STRING(data); |
|
23ab586c427a
Renamed PyString to PyBytes
Christian Heimes <christian@cheimes.de>
parents:
47300
diff
changeset
|
1247 rf.end = rf.ptr + PyBytes_GET_SIZE(data); |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1248 } |
|
49057
8ffec372040e
fixes deferred/release blocker issue #3797: Fixed the dbm, marshal, mmap,
Gregory P. Smith <greg@mad-scientist.com>
parents:
48683
diff
changeset
|
1249 else if (PyBytes_Check(data)) { |
|
8ffec372040e
fixes deferred/release blocker issue #3797: Fixed the dbm, marshal, mmap,
Gregory P. Smith <greg@mad-scientist.com>
parents:
48683
diff
changeset
|
1250 rf.ptr = PyBytes_AS_STRING(data); |
|
8ffec372040e
fixes deferred/release blocker issue #3797: Fixed the dbm, marshal, mmap,
Gregory P. Smith <greg@mad-scientist.com>
parents:
48683
diff
changeset
|
1251 rf.end = rf.ptr + PyBytes_GET_SIZE(data); |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1252 } |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1253 else { |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1254 PyErr_Format(PyExc_TypeError, |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1255 "f.read() returned neither string " |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1256 "nor bytes but %.100s", |
|
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1257 data->ob_type->tp_name); |
|
41653
52533370f1ad
Make test_marshal pass. Not my best work. :-(
Guido van Rossum <guido@python.org>
parents:
41595
diff
changeset
|
1258 Py_DECREF(data); |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1259 return NULL; |
| 267 | 1260 } |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1261 rf.strings = PyList_New(0); |
|
42404
0c300b29200c
Add a missing "rf.depth = 0;" to marshal_load().
Guido van Rossum <guido@python.org>
parents:
42334
diff
changeset
|
1262 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1263 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1264 Py_DECREF(rf.strings); |
|
42071
825041fc8e2c
Rip out the file object's implementation.
Guido van Rossum <guido@python.org>
parents:
41824
diff
changeset
|
1265 Py_DECREF(data); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1266 return result; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1267 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1268 |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1269 PyDoc_STRVAR(load_doc, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1270 "load(file)\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1271 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1272 Read one value from the open file and return it. If no valid value is\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1273 read (e.g. because the data has a different Python version’s\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1274 incompatible marshal format), raise EOFError, ValueError or TypeError.\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1275 The file must be an open file object opened in binary mode ('rb' or\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1276 'r+b').\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1277 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1278 Note: If an object containing an unsupported type was marshalled with\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1279 dump(), load() will substitute None for the unmarshallable type."); |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1280 |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1281 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1282 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1283 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
|
1284 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1285 PyObject *x; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1286 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
|
1287 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
|
1288 return NULL; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1289 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
|
1290 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1291 |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1292 PyDoc_STRVAR(dumps_doc, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1293 "dumps(value[, version])\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1294 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1295 Return the string that would be written to a file by dump(value, file).\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1296 The value must be a supported type. Raise a ValueError exception if\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1297 value has (or contains an object that has) an unsupported type.\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1298 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1299 The version argument indicates the data format that dumps should use."); |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1300 |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1301 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1302 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1303 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
|
1304 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1305 RFILE rf; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48370
diff
changeset
|
1306 Py_buffer p; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1307 char *s; |
|
36792
688795873ff1
Make Py_ssize_t clean.
Thomas Wouters <thomas@python.org>
parents:
36784
diff
changeset
|
1308 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
|
1309 PyObject* result; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48370
diff
changeset
|
1310 if (!PyArg_ParseTuple(args, "s*:loads", &p)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1311 return NULL; |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48370
diff
changeset
|
1312 s = p.buf; |
|
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48370
diff
changeset
|
1313 n = p.len; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1314 rf.fp = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1315 rf.ptr = s; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
1316 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
|
1317 rf.strings = PyList_New(0); |
|
41824
24b60622b944
Merged revisions 55407-55513 via svnmerge from
Guido van Rossum <guido@python.org>
parents:
41715
diff
changeset
|
1318 rf.depth = 0; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1319 result = read_object(&rf); |
|
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1320 Py_DECREF(rf.strings); |
|
48683
cd3b0b7fd8e1
Merged revisions 65654 via svnmerge from
Martin v. Löwis <martin@v.loewis.de>
parents:
48370
diff
changeset
|
1321 PyBuffer_Release(&p); |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1322 return result; |
| 267 | 1323 } |
| 1324 | |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1325 PyDoc_STRVAR(loads_doc, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1326 "loads(string)\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1327 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1328 Convert the string to a value. If no valid value is found, raise\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1329 EOFError, ValueError or TypeError. Extra characters in the string are\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1330 ignored."); |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1331 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
1332 static PyMethodDef marshal_methods[] = { |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1333 {"dump", marshal_dump, METH_VARARGS, dump_doc}, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1334 {"load", marshal_load, METH_O, load_doc}, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1335 {"dumps", marshal_dumps, METH_VARARGS, dumps_doc}, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1336 {"loads", marshal_loads, METH_VARARGS, loads_doc}, |
| 267 | 1337 {NULL, NULL} /* sentinel */ |
| 1338 }; | |
| 1339 | |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1340 |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1341 PyDoc_STRVAR(module_doc, |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1342 "This module contains functions that can read and write Python values in\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1343 a binary format. The format is specific to Python, but independent of\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1344 machine architecture issues.\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1345 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1346 Not all Python object types are supported; in general, only objects\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1347 whose value is independent from a particular invocation of Python can be\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1348 written and read by this module. The following types are supported:\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1349 None, integers, floating point numbers, strings, bytes, bytearrays,\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1350 tuples, lists, sets, dictionaries, and code objects, where it\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1351 should be understood that tuples, lists and dictionaries are only\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1352 supported as long as the values contained therein are themselves\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1353 supported; and recursive lists and dictionaries should not be written\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1354 (they will cause infinite loops).\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1355 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1356 Variables:\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1357 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1358 version -- indicates the format that the module uses. Version 0 is the\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1359 historical format, version 1 shares interned strings and version 2\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1360 uses a binary format for floating point numbers.\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1361 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1362 Functions:\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1363 \n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1364 dump() -- write value to a file\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1365 load() -- read value from a file\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1366 dumps() -- write value to a string\n\ |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1367 loads() -- read value from a string"); |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1368 |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1369 |
|
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1370 |
|
48370
bfaf14295794
Rename a variable to be more in line with the name of the module.
Brett Cannon <bcannon@gmail.com>
parents:
48321
diff
changeset
|
1371 static struct PyModuleDef marshalmodule = { |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1372 PyModuleDef_HEAD_INIT, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1373 "marshal", |
|
54035
19e959626109
Merged revisions 72597 via svnmerge from
R. David Murray <rdmurray@bitdance.com>
parents:
53965
diff
changeset
|
1374 module_doc, |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1375 0, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1376 marshal_methods, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1377 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1378 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1379 NULL, |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1380 NULL |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1381 }; |
|
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1382 |
|
30311
f003e48f562d
Bug #794140: cygwin builds do not embed
Jason Tishler <jason@tishler.net>
parents:
24435
diff
changeset
|
1383 PyMODINIT_FUNC |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
1384 PyMarshal_Init(void) |
| 267 | 1385 { |
|
48370
bfaf14295794
Rename a variable to be more in line with the name of the module.
Brett Cannon <bcannon@gmail.com>
parents:
48321
diff
changeset
|
1386 PyObject *mod = PyModule_Create(&marshalmodule); |
|
36324
1af7f719ed28
Check return result from Py_InitModule*(). This API can fail.
Neal Norwitz <nnorwitz@gmail.com>
parents:
35877
diff
changeset
|
1387 if (mod == NULL) |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1388 return NULL; |
|
32422
3df36e2e5ddc
Patch #923098: Share interned strings in marshal.
Martin v. Löwis <martin@v.loewis.de>
parents:
32343
diff
changeset
|
1389 PyModule_AddIntConstant(mod, "version", Py_MARSHAL_VERSION); |
|
47580
94f64f11fdd0
Implement PEP 3121: new module initialization and finalization API.
Martin v. Löwis <martin@v.loewis.de>
parents:
47343
diff
changeset
|
1390 return mod; |
| 267 | 1391 } |
