Mercurial > cpython-lru_cache-weakref
annotate Python/marshal.c @ 19283:b865cd5c1925 legacy-trunk
Added comments before recently added/assigned slots in the type object,
so the backward compatibility issues will be easier to understand. I only
added comments indicating additions and assignments back to Python 2.0.
| author | Fred Drake <fdrake@acm.org> |
|---|---|
| date | Wed, 15 Aug 2001 18:32:33 +0000 |
| parents | 7bc473b2c654 |
| children | 7257e87e0720 |
| 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 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
7 #include "Python.h" |
| 267 | 8 #include "longintrepr.h" |
| 9 #include "compile.h" | |
| 10 #include "marshal.h" | |
| 11 | |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
12 /* 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
|
13 * 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
|
14 * raise an exception instead of continuing. |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
15 */ |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
16 #define MAX_MARSHAL_STACK_DEPTH 5000 |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
17 |
| 267 | 18 #define TYPE_NULL '0' |
| 19 #define TYPE_NONE 'N' | |
|
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
|
20 #define TYPE_STOPITER 'S' |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
21 #define TYPE_ELLIPSIS '.' |
| 267 | 22 #define TYPE_INT 'i' |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
23 #define TYPE_INT64 'I' |
| 267 | 24 #define TYPE_FLOAT 'f' |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
25 #define TYPE_COMPLEX 'x' |
| 267 | 26 #define TYPE_LONG 'l' |
| 27 #define TYPE_STRING 's' | |
| 28 #define TYPE_TUPLE '(' | |
| 29 #define TYPE_LIST '[' | |
| 30 #define TYPE_DICT '{' | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
31 #define TYPE_CODE 'c' |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
32 #define TYPE_UNICODE 'u' |
| 267 | 33 #define TYPE_UNKNOWN '?' |
| 34 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
35 typedef struct { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
36 FILE *fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
37 int error; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
38 int depth; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
39 /* 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
|
40 PyObject *str; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
41 char *ptr; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
42 char *end; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
43 } WFILE; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
44 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
45 #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
|
46 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
|
47 else w_more(c, p) |
| 267 | 48 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
49 static void |
|
13672
bfc5b2a8c11f
-- changed w_more to take an integer instead of a char
Fredrik Lundh <fredrik@pythonware.com>
parents:
13658
diff
changeset
|
50 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
|
51 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
52 int size, newsize; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
53 if (p->str == NULL) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
54 return; /* An error already occurred */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
55 size = PyString_Size(p->str); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
56 newsize = size + 1024; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
57 if (_PyString_Resize(&p->str, newsize) != 0) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
58 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
|
59 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
60 else { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
61 p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
62 p->end = |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
63 PyString_AS_STRING((PyStringObject *)p->str) + newsize; |
|
13674
c90d94d287d7
Included assert.h in Python.h -- it's absurd that this basic tool of
Tim Peters <tim.peters@gmail.com>
parents:
13672
diff
changeset
|
64 *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
|
65 } |
|
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 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
68 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
69 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
|
70 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
71 if (p->fp != NULL) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
72 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
|
73 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
74 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
75 while (--n >= 0) { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
76 w_byte(*s, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
77 s++; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
78 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
79 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
80 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
81 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
82 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
83 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
|
84 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
85 w_byte( x & 0xff, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
86 w_byte((x>> 8) & 0xff, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
87 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
88 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
89 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
90 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
|
91 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
92 w_byte((int)( x & 0xff), p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
93 w_byte((int)((x>> 8) & 0xff), p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
94 w_byte((int)((x>>16) & 0xff), p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
95 w_byte((int)((x>>24) & 0xff), p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
96 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
97 |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
98 #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
|
99 static void |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
100 w_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
|
101 { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
102 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
|
103 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
|
104 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
105 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
106 |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
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_object(PyObject *v, WFILE *p) |
| 267 | 109 { |
|
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
|
110 int i, n; |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
111 PyBufferProcs *pb; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
112 |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
113 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
|
114 |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
115 if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
116 p->error = 2; |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
117 } |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
118 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
|
119 w_byte(TYPE_NULL, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
120 } |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
121 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
|
122 w_byte(TYPE_NONE, p); |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
123 } |
|
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
|
124 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
|
125 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
|
126 } |
|
7982
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
127 else if (v == Py_Ellipsis) { |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
128 w_byte(TYPE_ELLIPSIS, p); |
|
a909a2869ac5
Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents:
5905
diff
changeset
|
129 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
130 else if (PyInt_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
131 long x = PyInt_AS_LONG((PyIntObject *)v); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
132 #if SIZEOF_LONG > 4 |
|
17368
bb75d93f6a31
test_pickle works on sizeof(long)==8 boxes again.
Tim Peters <tim.peters@gmail.com>
parents:
16311
diff
changeset
|
133 long y = Py_ARITHMETIC_RIGHT_SHIFT(long, x, 31); |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
134 if (y && y != -1) { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
135 w_byte(TYPE_INT64, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
136 w_long64(x, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
137 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
138 else |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
139 #endif |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
140 { |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
141 w_byte(TYPE_INT, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
142 w_long(x, p); |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
143 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
144 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
145 else if (PyLong_Check(v)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
146 PyLongObject *ob = (PyLongObject *)v; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
147 w_byte(TYPE_LONG, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
148 n = ob->ob_size; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
149 w_long((long)n, p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
150 if (n < 0) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
151 n = -n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
152 for (i = 0; i < n; i++) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
153 w_short(ob->ob_digit[i], p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
154 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
155 else if (PyFloat_Check(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
156 char buf[256]; /* Plenty to format any double */ |
|
17707
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17368
diff
changeset
|
157 PyFloat_AsReprString(buf, (PyFloatObject *)v); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
158 n = strlen(buf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
159 w_byte(TYPE_FLOAT, p); |
|
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
|
160 w_byte(n, p); |
|
663aa059e29f
hope to fix DEC Alpha gcc problems by declaring ints instead of longs
Guido van Rossum <guido@python.org>
parents:
2062
diff
changeset
|
161 w_string(buf, n, p); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
162 } |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
163 #ifndef WITHOUT_COMPLEX |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
164 else if (PyComplex_Check(v)) { |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
165 char buf[256]; /* Plenty to format any double */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
166 PyFloatObject *temp; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
167 w_byte(TYPE_COMPLEX, p); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
168 temp = (PyFloatObject*)PyFloat_FromDouble( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
169 PyComplex_RealAsDouble(v)); |
|
17707
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17368
diff
changeset
|
170 PyFloat_AsReprString(buf, temp); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
171 Py_DECREF(temp); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
172 n = strlen(buf); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
173 w_byte(n, p); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
174 w_string(buf, n, p); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
175 temp = (PyFloatObject*)PyFloat_FromDouble( |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
176 PyComplex_ImagAsDouble(v)); |
|
17707
fe4c1034b480
SF bug #422177: Results from .pyc differs from .py
Tim Peters <tim.peters@gmail.com>
parents:
17368
diff
changeset
|
177 PyFloat_AsReprString(buf, temp); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
178 Py_DECREF(temp); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
179 n = strlen(buf); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
180 w_byte(n, p); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
181 w_string(buf, n, p); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
182 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
183 #endif |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
184 else if (PyString_Check(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
185 w_byte(TYPE_STRING, p); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
186 n = PyString_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
|
187 w_long((long)n, p); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
188 w_string(PyString_AS_STRING(v), n, p); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
189 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
190 else if (PyUnicode_Check(v)) { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
191 PyObject *utf8; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
192 utf8 = PyUnicode_AsUTF8String(v); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
193 if (utf8 == NULL) { |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
194 p->depth--; |
|
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
195 p->error = 1; |
|
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
196 return; |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
197 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
198 w_byte(TYPE_UNICODE, p); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
199 n = PyString_GET_SIZE(utf8); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
200 w_long((long)n, p); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
201 w_string(PyString_AS_STRING(utf8), n, p); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
202 Py_DECREF(utf8); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
203 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
204 else if (PyTuple_Check(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
211 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
212 else if (PyList_Check(v)) { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
219 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
220 else if (PyDict_Check(v)) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
221 int pos; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
222 PyObject *key, *value; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
223 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
|
224 /* This one is NULL object terminated! */ |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
225 pos = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
226 while (PyDict_Next(v, &pos, &key, &value)) { |
|
1288
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
227 w_object(key, p); |
|
9fed5726a36d
Several changes in one:
Guido van Rossum <guido@python.org>
parents:
1270
diff
changeset
|
228 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
|
229 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
230 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
|
231 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
232 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
|
233 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
|
234 w_byte(TYPE_CODE, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
235 w_short(co->co_argcount, p); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
236 w_short(co->co_nlocals, p); |
|
4995
267ed480ec1b
Marshal the new stacksize item in code objects.
Guido van Rossum <guido@python.org>
parents:
4656
diff
changeset
|
237 w_short(co->co_stacksize, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
238 w_short(co->co_flags, p); |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
239 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
|
240 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
|
241 w_object(co->co_names, p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
242 w_object(co->co_varnames, p); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
243 w_object(co->co_freevars, p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
244 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
|
245 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
|
246 w_object(co->co_name, p); |
|
5042
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
247 w_short(co->co_firstlineno, p); |
|
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
248 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
|
249 } |
|
9293
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
250 else if ((pb = v->ob_type->tp_as_buffer) != NULL && |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
251 pb->bf_getsegcount != NULL && |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
252 pb->bf_getreadbuffer != NULL && |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
253 (*pb->bf_getsegcount)(v, NULL) == 1) |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
254 { |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
255 /* 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
|
256 char *s; |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
257 w_byte(TYPE_STRING, p); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
258 n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
259 w_long((long)n, p); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
260 w_string(s, n, p); |
|
0a67db47e1d0
Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents:
8465
diff
changeset
|
261 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
262 else { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
263 w_byte(TYPE_UNKNOWN, p); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
264 p->error = 1; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
265 } |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
266 |
|
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
267 p->depth--; |
| 267 | 268 } |
| 269 | |
| 270 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
271 PyMarshal_WriteLongToFile(long x, FILE *fp) |
| 267 | 272 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
273 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
274 wf.fp = fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
275 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
276 wf.depth = 0; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
277 w_long(x, &wf); |
| 267 | 278 } |
| 279 | |
| 280 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
281 PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp) |
| 267 | 282 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
283 WFILE wf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
284 wf.fp = fp; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
285 wf.error = 0; |
|
13106
a6725acdf33b
Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents:
13070
diff
changeset
|
286 wf.depth = 0; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
287 w_object(x, &wf); |
| 267 | 288 } |
| 289 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
290 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
|
291 |
|
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
|
292 #define rs_byte(p) (((p)->ptr != (p)->end) ? (unsigned char)*(p)->ptr++ : EOF) |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
293 |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
294 #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) |
| 267 | 295 |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
296 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
297 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
|
298 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
299 if (p->fp != NULL) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
300 return fread(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
|
301 if (p->end - p->ptr < n) |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
302 n = p->end - p->ptr; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
303 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
|
304 p->ptr += n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
305 return n; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
306 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
307 |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
308 static int |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
309 r_short(RFILE *p) |
| 267 | 310 { |
| 311 register short x; | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
312 x = r_byte(p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
313 x |= r_byte(p) << 8; |
| 14678 | 314 /* Sign-extension, in case short greater than 16 bits */ |
| 315 x |= -(x & 0x8000); | |
| 267 | 316 return x; |
| 317 } | |
| 318 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
319 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
320 r_long(RFILE *p) |
| 267 | 321 { |
| 322 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
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 } |
|
4dd1af0ddef0
various tuple related optimizations; remove unused b/w compat code from ceval.c
Guido van Rossum <guido@python.org>
parents:
2368
diff
changeset
|
330 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
|
331 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
|
332 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
|
333 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
|
334 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
|
335 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
336 #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
|
337 /* Sign extension for 64-bit machines */ |
| 14678 | 338 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
|
339 #endif |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
340 return x; |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
341 } |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
342 |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
343 static long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
344 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
|
345 { |
|
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
346 register long x; |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
347 x = r_long(p); |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
348 #if SIZEOF_LONG > 4 |
| 14678 | 349 x = (x & 0xFFFFFFFFL) | (r_long(p) << 32); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
350 #else |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
351 if (r_long(p) != 0) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
352 PyObject *f = PySys_GetObject("stderr"); |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
353 if (f != NULL) |
|
5608
79e49cbce2ef
PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents:
5373
diff
changeset
|
354 (void) PyFile_WriteString( |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
355 "Warning: un-marshal 64-bit int in 32-bit mode\n", |
|
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
356 f); |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
357 } |
|
4656
186c2ad4abf3
Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents:
4592
diff
changeset
|
358 #endif |
| 267 | 359 return x; |
| 360 } | |
| 361 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
362 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
363 r_object(RFILE *p) |
| 267 | 364 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
365 PyObject *v, *v2; |
| 267 | 366 long i, n; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
367 int type = r_byte(p); |
|
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
|
368 |
| 267 | 369 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
|
370 |
| 267 | 371 case EOF: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
372 PyErr_SetString(PyExc_EOFError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
373 "EOF read where object expected"); |
| 267 | 374 return 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
|
375 |
| 267 | 376 case TYPE_NULL: |
| 377 return 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
|
378 |
| 267 | 379 case TYPE_NONE: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
380 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
381 return Py_None; |
|
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
|
382 |
|
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
|
383 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
|
384 Py_INCREF(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
|
385 return 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
|
386 |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
387 case TYPE_ELLIPSIS: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
388 Py_INCREF(Py_Ellipsis); |
|
4403
3b3f7c3f6da2
Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents:
4039
diff
changeset
|
389 return Py_Ellipsis; |
|
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
|
390 |
| 267 | 391 case TYPE_INT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
392 return PyInt_FromLong(r_long(p)); |
|
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
|
393 |
|
4592
3bf9e2beaf8c
Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents:
4503
diff
changeset
|
394 case TYPE_INT64: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
395 return PyInt_FromLong(r_long64(p)); |
|
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
|
396 |
| 267 | 397 case TYPE_LONG: |
| 398 { | |
| 399 int size; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
400 PyLongObject *ob; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
401 n = r_long(p); |
| 267 | 402 size = n<0 ? -n : n; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
403 ob = _PyLong_New(size); |
| 267 | 404 if (ob == NULL) |
| 405 return NULL; | |
| 406 ob->ob_size = n; | |
| 407 for (i = 0; i < size; i++) | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
408 ob->ob_digit[i] = r_short(p); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
409 return (PyObject *)ob; |
| 267 | 410 } |
|
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
|
411 |
| 267 | 412 case TYPE_FLOAT: |
| 413 { | |
| 414 char buf[256]; | |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
415 double dx; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
416 n = r_byte(p); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
417 if (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
|
418 PyErr_SetString(PyExc_EOFError, |
| 267 | 419 "EOF read where object expected"); |
| 420 return NULL; | |
| 421 } | |
| 422 buf[n] = '\0'; | |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
423 PyFPE_START_PROTECT("atof", return 0) |
|
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
424 dx = atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
425 PyFPE_END_PROTECT(dx) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
426 return PyFloat_FromDouble(dx); |
| 267 | 427 } |
|
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
|
428 |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
429 #ifndef WITHOUT_COMPLEX |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
430 case TYPE_COMPLEX: |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
431 { |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
432 char buf[256]; |
|
3766
516490c8192c
Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents:
3731
diff
changeset
|
433 Py_complex c; |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
434 n = r_byte(p); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
435 if (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
|
436 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
437 "EOF read where object expected"); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
438 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
439 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
440 buf[n] = '\0'; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
441 PyFPE_START_PROTECT("atof", return 0) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
442 c.real = atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
443 PyFPE_END_PROTECT(c) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
444 n = r_byte(p); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
445 if (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
|
446 PyErr_SetString(PyExc_EOFError, |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
447 "EOF read where object expected"); |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
448 return NULL; |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
449 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
450 buf[n] = '\0'; |
|
5119
bda01a374762
Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents:
5115
diff
changeset
|
451 PyFPE_START_PROTECT("atof", return 0) |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
452 c.imag = atof(buf); |
|
5197
74c12704a0bd
New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents:
5119
diff
changeset
|
453 PyFPE_END_PROTECT(c) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
454 return PyComplex_FromCComplex(c); |
|
3323
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
455 } |
|
6098aaa8ae7f
changes for complex numbers
Guido van Rossum <guido@python.org>
parents:
3234
diff
changeset
|
456 #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
|
457 |
| 267 | 458 case TYPE_STRING: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
459 n = r_long(p); |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
460 if (n < 0) { |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
461 PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
462 return NULL; |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
463 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
464 v = PyString_FromStringAndSize((char *)NULL, n); |
| 267 | 465 if (v != NULL) { |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
466 if (r_string(PyString_AS_STRING(v), (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
|
467 Py_DECREF(v); |
| 267 | 468 v = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
469 PyErr_SetString(PyExc_EOFError, |
| 267 | 470 "EOF read where object expected"); |
| 471 } | |
| 472 } | |
| 473 return v; | |
|
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
|
474 |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
475 case TYPE_UNICODE: |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
476 { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
477 char *buffer; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
478 |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
479 n = r_long(p); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
480 if (n < 0) { |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
481 PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
482 return NULL; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
483 } |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
484 buffer = PyMem_NEW(char, n); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
485 if (buffer == NULL) |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
486 return PyErr_NoMemory(); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
487 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
|
488 PyMem_DEL(buffer); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
489 PyErr_SetString(PyExc_EOFError, |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
490 "EOF read where object expected"); |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
491 return NULL; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
492 } |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
493 v = PyUnicode_DecodeUTF8(buffer, n, NULL); |
|
12576
1c7c2dd1beb1
Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents:
12135
diff
changeset
|
494 PyMem_DEL(buffer); |
|
11976
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
495 return v; |
|
513354d87a85
Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents:
9300
diff
changeset
|
496 } |
|
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
|
497 |
| 267 | 498 case TYPE_TUPLE: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
499 n = r_long(p); |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
500 if (n < 0) { |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
501 PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
502 return NULL; |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
503 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
504 v = PyTuple_New((int)n); |
| 267 | 505 if (v == NULL) |
| 506 return v; | |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
507 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
|
508 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
|
509 if ( v2 == NULL ) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
510 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
|
511 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
512 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
513 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
514 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
|
515 } |
| 267 | 516 return v; |
|
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
|
517 |
| 267 | 518 case TYPE_LIST: |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
519 n = r_long(p); |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
520 if (n < 0) { |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
521 PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
522 return NULL; |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
523 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
524 v = PyList_New((int)n); |
| 267 | 525 if (v == NULL) |
| 526 return v; | |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
527 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
|
528 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
|
529 if ( v2 == NULL ) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
530 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
|
531 v = NULL; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
532 break; |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
533 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
534 PyList_SetItem(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
|
535 } |
| 267 | 536 return v; |
|
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
|
537 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
538 case TYPE_DICT: |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
539 v = PyDict_New(); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
540 if (v == NULL) |
|
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
541 return NULL; |
|
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
542 for (;;) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
543 PyObject *key, *val; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
544 key = r_object(p); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
545 if (key == NULL) |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
546 break; /* XXX Assume TYPE_NULL, not an error */ |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
547 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
|
548 if (val != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
549 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
|
550 Py_DECREF(key); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
551 Py_XDECREF(val); |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
552 } |
|
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
553 return v; |
|
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
|
554 |
| 267 | 555 case TYPE_CODE: |
| 556 { | |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
557 int argcount = r_short(p); |
|
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
558 int nlocals = r_short(p); |
|
4995
267ed480ec1b
Marshal the new stacksize item in code objects.
Guido van Rossum <guido@python.org>
parents:
4656
diff
changeset
|
559 int stacksize = r_short(p); |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
560 int flags = r_short(p); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
561 PyObject *code = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
562 PyObject *consts = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
563 PyObject *names = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
564 PyObject *varnames = NULL; |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
565 PyObject *freevars = NULL; |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
566 PyObject *cellvars = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
567 PyObject *filename = NULL; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
568 PyObject *name = NULL; |
| 5115 | 569 int firstlineno = 0; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
570 PyObject *lnotab = 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
|
571 |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
572 code = r_object(p); |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
573 if (code) consts = r_object(p); |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
574 if (consts) names = r_object(p); |
|
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
575 if (names) varnames = r_object(p); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
576 if (varnames) freevars = r_object(p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
577 if (freevars) cellvars = r_object(p); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
578 if (cellvars) filename = r_object(p); |
|
3234
aafe7d634985
Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents:
3012
diff
changeset
|
579 if (filename) name = r_object(p); |
|
5042
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
580 if (name) { |
|
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
581 firstlineno = r_short(p); |
|
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
582 lnotab = r_object(p); |
|
9b7e0cf51990
Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents:
4995
diff
changeset
|
583 } |
|
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
|
584 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
585 if (!PyErr_Occurred()) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
586 v = (PyObject *) PyCode_New( |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
587 argcount, nlocals, stacksize, flags, |
|
2844
0261bf5b3819
keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents:
2503
diff
changeset
|
588 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
|
589 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
|
590 firstlineno, lnotab); |
| 267 | 591 } |
| 592 else | |
| 593 v = NULL; | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
594 Py_XDECREF(code); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
595 Py_XDECREF(consts); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
596 Py_XDECREF(names); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
597 Py_XDECREF(varnames); |
|
16257
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
598 Py_XDECREF(freevars); |
|
fd8c7203251f
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
15979
diff
changeset
|
599 Py_XDECREF(cellvars); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
600 Py_XDECREF(filename); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
601 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
|
602 Py_XDECREF(lnotab); |
| 267 | 603 |
| 604 } | |
| 605 return v; | |
|
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
|
606 |
| 267 | 607 default: |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
608 /* 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
|
609 This will let you keep working and recover. */ |
|
8465
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
610 PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
|
0e6fbbe3b63c
When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents:
8329
diff
changeset
|
611 return 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
|
612 |
| 267 | 613 } |
| 614 } | |
| 615 | |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
616 long |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
617 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
|
618 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
619 RFILE rf; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
620 rf.fp = fp; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
621 return r_long(&rf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
622 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
623 |
|
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
|
624 #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
|
625 /* 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
|
626 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
|
627 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
|
628 { |
|
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
|
629 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
|
630 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
|
631 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
|
632 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
|
633 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
|
634 } |
|
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
|
635 #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
|
636 |
|
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
|
637 /* 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
|
638 * 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
|
639 * 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
|
640 * 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
|
641 * 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
|
642 */ |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
643 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
|
644 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
|
645 { |
|
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
|
646 /* 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
|
647 * 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
|
648 */ |
|
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
|
649 #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
|
650 #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
|
651 #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
|
652 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
|
653 #endif |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
654 if (PyErr_Occurred()) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
655 fprintf(stderr, "XXX rd_object called with exception set\n"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
656 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
657 } |
|
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
|
658 #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
|
659 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
|
660 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
|
661 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
|
662 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
|
663 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
|
664 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
|
665 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
|
666 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
|
667 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
|
668 PyObject* 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
|
669 size_t n = fread(pBuf, 1, filesize, 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
|
670 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
|
671 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
|
672 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
|
673 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
|
674 } |
|
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
|
675 |
|
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
|
676 } |
|
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
|
677 #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
|
678 /* 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
|
679 * 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
|
680 */ |
|
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
|
681 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
|
682 |
|
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
|
683 #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
|
684 #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
|
685 } |
|
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
|
686 |
|
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
|
687 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
|
688 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
|
689 { |
|
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
|
690 RFILE rf; |
|
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
691 if (PyErr_Occurred()) { |
|
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
|
692 fprintf(stderr, "XXX rd_object called with exception set\n"); |
|
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
|
693 return NULL; |
|
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
|
694 } |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
695 rf.fp = fp; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
696 return r_object(&rf); |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
697 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
698 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
699 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
700 PyMarshal_ReadObjectFromString(char *str, int len) |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
701 { |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
702 RFILE rf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
703 if (PyErr_Occurred()) { |
|
2052
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
704 fprintf(stderr, "XXX rds_object called with exception set\n"); |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
705 return NULL; |
|
d7e91437f0a2
Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents:
1929
diff
changeset
|
706 } |
|
1270
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
707 rf.fp = NULL; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
708 rf.str = NULL; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
709 rf.ptr = str; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
710 rf.end = str + len; |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
711 return r_object(&rf); |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
712 } |
|
14369a5e6167
Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents:
1257
diff
changeset
|
713 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
714 PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
715 PyMarshal_WriteObjectToString(PyObject *x) /* wrs_object() */ |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
716 { |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
717 WFILE wf; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
718 wf.fp = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
719 wf.str = PyString_FromStringAndSize((char *)NULL, 50); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
720 if (wf.str == NULL) |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
721 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
722 wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
723 wf.end = wf.ptr + PyString_Size(wf.str); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
724 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
725 wf.depth = 0; |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
726 w_object(x, &wf); |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
727 if (wf.str != NULL) |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
728 _PyString_Resize(&wf.str, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
729 (int) (wf.ptr - |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
730 PyString_AS_STRING((PyStringObject *)wf.str))); |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
731 if (wf.error) { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
732 Py_XDECREF(wf.str); |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
733 PyErr_SetString(PyExc_ValueError, |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
734 (wf.error==1)?"unmarshallable object" |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
735 :"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
|
736 return NULL; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
737 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
738 return wf.str; |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
739 } |
|
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
740 |
|
279
9c924f9c3b16
Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents:
272
diff
changeset
|
741 /* And an interface for Python programs... */ |
| 267 | 742 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
743 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
744 marshal_dump(PyObject *self, PyObject *args) |
| 267 | 745 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
746 WFILE wf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
747 PyObject *x; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
748 PyObject *f; |
|
12135
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
749 if (!PyArg_ParseTuple(args, "OO:dump", &x, &f)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
750 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
751 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
752 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
753 "marshal.dump() 2nd arg must be file"); |
| 267 | 754 return NULL; |
| 755 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
756 wf.fp = PyFile_AsFile(f); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
757 wf.str = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
758 wf.ptr = wf.end = NULL; |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
759 wf.error = 0; |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
760 wf.depth = 0; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
761 w_object(x, &wf); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
762 if (wf.error) { |
|
16311
8c41f3861aad
It's unclear whether PyMarshal_XXX() are part of the public or private API.
Tim Peters <tim.peters@gmail.com>
parents:
16257
diff
changeset
|
763 PyErr_SetString(PyExc_ValueError, |
|
13070
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
764 (wf.error==1)?"unmarshallable object" |
|
7392e71f6cce
Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents:
12576
diff
changeset
|
765 :"object too deeply nested to marshal"); |
|
3731
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
766 return NULL; |
|
de1cb33219e3
Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents:
3620
diff
changeset
|
767 } |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
768 Py_INCREF(Py_None); |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
769 return Py_None; |
| 267 | 770 } |
| 771 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
772 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
773 marshal_load(PyObject *self, PyObject *args) |
| 267 | 774 { |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
775 RFILE rf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
776 PyObject *f; |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
777 PyObject *v; |
|
12135
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
778 if (!PyArg_ParseTuple(args, "O:load", &f)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
779 return NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
780 if (!PyFile_Check(f)) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
781 PyErr_SetString(PyExc_TypeError, |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
782 "marshal.load() arg must be file"); |
| 267 | 783 return NULL; |
| 784 } | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
785 rf.fp = PyFile_AsFile(f); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
786 rf.str = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
787 rf.ptr = rf.end = NULL; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
788 PyErr_Clear(); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
789 v = r_object(&rf); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
790 if (PyErr_Occurred()) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
791 Py_XDECREF(v); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
792 v = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
793 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
794 return v; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
795 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
796 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
797 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
798 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
|
799 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
800 PyObject *x; |
|
12135
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
801 if (!PyArg_ParseTuple(args, "O:dumps", &x)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
802 return NULL; |
|
4039
23f280ab5409
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents:
3839
diff
changeset
|
803 return PyMarshal_WriteObjectToString(x); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
804 } |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
805 |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
806 static PyObject * |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
807 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
|
808 { |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
809 RFILE rf; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
810 PyObject *v; |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
811 char *s; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
812 int n; |
|
12135
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
813 if (!PyArg_ParseTuple(args, "s#:loads", &s, &n)) |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
814 return NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
815 rf.fp = NULL; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
816 rf.str = args; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
817 rf.ptr = s; |
|
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
818 rf.end = s + n; |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
819 PyErr_Clear(); |
|
1191
38f0054f44a7
Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents:
795
diff
changeset
|
820 v = r_object(&rf); |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
821 if (PyErr_Occurred()) { |
|
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
822 Py_XDECREF(v); |
| 267 | 823 v = NULL; |
| 824 } | |
| 825 return v; | |
| 826 } | |
| 827 | |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
828 static PyMethodDef marshal_methods[] = { |
|
12135
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
829 {"dump", marshal_dump, 1}, |
|
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
830 {"load", marshal_load, 1}, |
|
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
831 {"dumps", marshal_dumps, 1}, |
|
667878776933
Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents:
11976
diff
changeset
|
832 {"loads", marshal_loads, 1}, |
| 267 | 833 {NULL, NULL} /* sentinel */ |
| 834 }; | |
| 835 | |
| 836 void | |
|
13658
f79434ee41fa
Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents:
13447
diff
changeset
|
837 PyMarshal_Init(void) |
| 267 | 838 { |
|
5373
5880384d7c71
Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents:
5197
diff
changeset
|
839 (void) Py_InitModule("marshal", marshal_methods); |
| 267 | 840 } |
