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