annotate Python/marshal.c @ 13778:f6e4a9dd67cd legacy-trunk

Rename the "parser" package to "parsers" to be compatible with the PyXML project.
author Fred Drake <fdrake@acm.org>
date Mon, 31 Jul 2000 23:59:54 +0000
parents c90d94d287d7
children 6f6f965c5e2d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 /***********************************************************
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
2 Copyright (c) 2000, BeOpen.com.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
3 Copyright (c) 1995-2000, Corporation for National Research Initiatives.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
4 Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
5 All rights reserved.
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
6
13255
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
7 See the file "Misc/COPYRIGHT" for information on usage and
916fb024ce94 Change copyright notice.
Guido van Rossum <guido@python.org>
parents: 13106
diff changeset
8 redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 ******************************************************************/
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 /* Write Python objects to files and read them back.
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 This is intended for writing and reading compiled Python code only;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 a true persistent storage facility would be much harder, since
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 it would have to take circular links and sharing into account. */
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
16 #include "Python.h"
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 #include "longintrepr.h"
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 #include "compile.h"
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 #include "marshal.h"
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
21 /* 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
22 * 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
23 * raise an exception instead of continuing.
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
24 */
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
25 #define MAX_MARSHAL_STACK_DEPTH 5000
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
26
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 #define TYPE_NULL '0'
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 #define TYPE_NONE 'N'
4403
3b3f7c3f6da2 Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents: 4039
diff changeset
29 #define TYPE_ELLIPSIS '.'
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 #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
31 #define TYPE_INT64 'I'
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 #define TYPE_FLOAT 'f'
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
33 #define TYPE_COMPLEX 'x'
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
34 #define TYPE_LONG 'l'
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 #define TYPE_STRING 's'
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 #define TYPE_TUPLE '('
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 #define TYPE_LIST '['
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 #define TYPE_DICT '{'
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
39 #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
40 #define TYPE_UNICODE 'u'
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 #define TYPE_UNKNOWN '?'
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
42
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
43 typedef struct {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
44 FILE *fp;
3731
de1cb33219e3 Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents: 3620
diff changeset
45 int error;
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
46 int depth;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
47 /* 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
48 PyObject *str;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
49 char *ptr;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
50 char *end;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
51 } WFILE;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
52
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
53 #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
54 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
55 else w_more(c, p)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
56
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
57 static void
13672
bfc5b2a8c11f -- changed w_more to take an integer instead of a char
Fredrik Lundh <fredrik@pythonware.com>
parents: 13658
diff changeset
58 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
59 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
60 int size, newsize;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
61 if (p->str == NULL)
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
62 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
63 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
64 newsize = size + 1024;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
65 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
66 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
67 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
68 else {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
69 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
70 p->end =
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
71 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
72 *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
73 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
74 }
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 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
77 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
78 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
79 if (p->fp != NULL) {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
80 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
81 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
82 else {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
83 while (--n >= 0) {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
84 w_byte(*s, p);
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
85 s++;
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 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
88 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
89
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
90 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
91 w_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
92 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
93 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
94 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
95 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
96
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
97 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
98 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
99 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
100 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
101 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
102 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
103 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
104 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
105
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
106 #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
107 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
108 w_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
109 {
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
110 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
111 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
112 }
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
113 #endif
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
114
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
115 static void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
116 w_object(PyObject *v, WFILE *p)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 {
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
118 int i, n;
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
119 PyBufferProcs *pb;
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
120
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
121 p->depth++;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
122
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
123 if (p->depth > MAX_MARSHAL_STACK_DEPTH) {
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
124 p->error = 2;
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
125 }
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
126 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
127 w_byte(TYPE_NULL, p);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
128 }
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
129 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
130 w_byte(TYPE_NONE, p);
7982
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
131 }
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
132 else if (v == Py_Ellipsis) {
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
133 w_byte(TYPE_ELLIPSIS, p);
a909a2869ac5 Make new gcc -Wall happy
Guido van Rossum <guido@python.org>
parents: 5905
diff changeset
134 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
135 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
136 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
137 #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
138 long y = x>>31;
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
139 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
140 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
141 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
142 }
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
143 else
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
144 #endif
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
145 {
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
146 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
147 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
148 }
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
149 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
150 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
151 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
152 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
153 n = ob->ob_size;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
154 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
155 if (n < 0)
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
156 n = -n;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
157 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
158 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
159 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
160 else if (PyFloat_Check(v)) {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
161 extern void PyFloat_AsString(char *, PyFloatObject *);
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
162 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
163 PyFloat_AsString(buf, (PyFloatObject *)v);
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
164 n = strlen(buf);
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
165 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
166 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
167 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
168 }
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
169 #ifndef WITHOUT_COMPLEX
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
170 else if (PyComplex_Check(v)) {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
171 extern void PyFloat_AsString(char *, PyFloatObject *);
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));
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
177 PyFloat_AsString(buf, temp);
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));
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
184 PyFloat_AsString(buf, temp);
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 }
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
197 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
198 PyObject *utf8;
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
199 utf8 = PyUnicode_AsUTF8String(v);
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
200 if (utf8 == NULL) {
13106
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
201 p->depth--;
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
202 p->error = 1;
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
203 return;
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
204 }
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
205 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
206 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
207 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
208 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
209 Py_DECREF(utf8);
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
210 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
211 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
212 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
213 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
214 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
215 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
216 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
217 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
218 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
219 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
220 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
221 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
222 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
223 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
224 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
225 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
226 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
227 else if (PyDict_Check(v)) {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1270
diff changeset
228 int pos;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
229 PyObject *key, *value;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
230 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
231 /* This one is NULL object terminated! */
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1270
diff changeset
232 pos = 0;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
233 while (PyDict_Next(v, &pos, &key, &value)) {
1288
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1270
diff changeset
234 w_object(key, p);
9fed5726a36d Several changes in one:
Guido van Rossum <guido@python.org>
parents: 1270
diff changeset
235 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
236 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
237 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
238 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
239 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
240 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
241 w_byte(TYPE_CODE, p);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
242 w_short(co->co_argcount, p);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
243 w_short(co->co_nlocals, p);
4995
267ed480ec1b Marshal the new stacksize item in code objects.
Guido van Rossum <guido@python.org>
parents: 4656
diff changeset
244 w_short(co->co_stacksize, p);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
245 w_short(co->co_flags, p);
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
246 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
247 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
248 w_object(co->co_names, p);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
249 w_object(co->co_varnames, p);
1191
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_filename, p);
1257
1cabc2b6c970 * Changed all copyright messages to include 1993.
Guido van Rossum <guido@python.org>
parents: 1191
diff changeset
251 w_object(co->co_name, p);
5042
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
252 w_short(co->co_firstlineno, p);
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
253 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
254 }
9293
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
255 else if ((pb = v->ob_type->tp_as_buffer) != NULL &&
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
256 pb->bf_getsegcount != NULL &&
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
257 pb->bf_getreadbuffer != NULL &&
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
258 (*pb->bf_getsegcount)(v, NULL) == 1)
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
259 {
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;
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
262 w_byte(TYPE_STRING, p);
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
263 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
264 w_long((long)n, p);
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
265 w_string(s, n, p);
0a67db47e1d0 Changes to support other object types besides strings
Guido van Rossum <guido@python.org>
parents: 8465
diff changeset
266 }
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
267 else {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
268 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
269 p->error = 1;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
270 }
13106
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
271
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
272 p->depth--;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
273 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
274
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
275 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
276 PyMarshal_WriteLongToFile(long x, FILE *fp)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
277 {
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
278 WFILE wf;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
279 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
280 wf.error = 0;
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
281 wf.depth = 0;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
282 w_long(x, &wf);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
285 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
286 PyMarshal_WriteObjectToFile(PyObject *x, FILE *fp)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
287 {
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
288 WFILE wf;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
289 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
290 wf.error = 0;
13106
a6725acdf33b Urmpf. Quality control on this patch lapsed a bit. :-(
Guido van Rossum <guido@python.org>
parents: 13070
diff changeset
291 wf.depth = 0;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
292 w_object(x, &wf);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
293 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
294
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
295 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
296
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
297 #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
298
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 #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p))
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
300
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
301 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
302 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
303 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
304 if (p->fp != NULL)
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
305 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
306 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
307 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
308 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
309 p->ptr += n;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
310 return n;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
311 }
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 static int
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
314 r_short(RFILE *p)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
315 {
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
316 register short x;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
317 x = r_byte(p);
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) << 8;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
319 /* XXX If your short is > 16 bits, add sign-extension here!!! */
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
320 return x;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
321 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
322
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
323 static long
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
324 r_long(RFILE *p)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
325 {
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
326 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
327 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
328 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
329 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
330 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
331 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
332 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
333 }
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 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
335 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
336 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
337 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
338 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
339 }
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
340 #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
341 /* Sign extension for 64-bit machines */
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
342 x <<= (8*sizeof(long) - 32);
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
343 x >>= (8*sizeof(long) - 32);
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
344 #endif
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
345 return x;
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
346 }
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 static long
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
349 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
350 {
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
351 register long x;
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
352 x = r_long(p);
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
353 #if SIZEOF_LONG > 4
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
354 x = (x & 0xFFFFFFFF) | (r_long(p) << 32);
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
355 #else
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
356 if (r_long(p) != 0) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
357 PyObject *f = PySys_GetObject("stderr");
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
358 if (f != NULL)
5608
79e49cbce2ef PyFile_WriteString now returns an error indicator instead of calling
Guido van Rossum <guido@python.org>
parents: 5373
diff changeset
359 (void) PyFile_WriteString(
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
360 "Warning: un-marshal 64-bit int in 32-bit mode\n",
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
361 f);
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
362 }
4656
186c2ad4abf3 Better way to handle 64-bit ints, keeping gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 4592
diff changeset
363 #endif
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 return x;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
366
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
367 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
368 r_object(RFILE *p)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
370 PyObject *v, *v2;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
371 long i, n;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
372 int type = r_byte(p);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
373
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
374 switch (type) {
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
375
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
376 case EOF:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
377 PyErr_SetString(PyExc_EOFError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
378 "EOF read where object expected");
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
379 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
380
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
381 case TYPE_NULL:
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
383
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
384 case TYPE_NONE:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
385 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
386 return Py_None;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
387
4403
3b3f7c3f6da2 Ellipses -> Ellipsis rename (the dictionary really says that it should
Guido van Rossum <guido@python.org>
parents: 4039
diff changeset
388 case TYPE_ELLIPSIS:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
389 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
390 return Py_Ellipsis;
3839
22e29b1747e1 Changes for slice and ellipses
Guido van Rossum <guido@python.org>
parents: 3766
diff changeset
391
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
392 case TYPE_INT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
393 return PyInt_FromLong(r_long(p));
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
394
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
395 case TYPE_INT64:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
396 return PyInt_FromLong(r_long64(p));
4592
3bf9e2beaf8c Tentative changes to make this work better on 64-bit machines.
Guido van Rossum <guido@python.org>
parents: 4503
diff changeset
397
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
398 case TYPE_LONG:
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
399 {
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
400 int size;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
401 PyLongObject *ob;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
402 n = r_long(p);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
403 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
404 ob = _PyLong_New(size);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
405 if (ob == NULL)
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
406 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
407 ob->ob_size = n;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
408 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
409 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
410 return (PyObject *)ob;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
411 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
412
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
413 case TYPE_FLOAT:
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
414 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
415 extern double atof(const char *);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
416 char buf[256];
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5115
diff changeset
417 double dx;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
418 n = r_byte(p);
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
419 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
420 PyErr_SetString(PyExc_EOFError,
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
421 "EOF read where object expected");
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
422 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
423 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
424 buf[n] = '\0';
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5115
diff changeset
425 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
426 dx = atof(buf);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
427 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
428 return PyFloat_FromDouble(dx);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
429 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
430
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
431 #ifndef WITHOUT_COMPLEX
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
432 case TYPE_COMPLEX:
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
433 {
13447
a89f7f268de4 Nuke all remaining occurrences of Py_PROTO and Py_FPROTO.
Tim Peters <tim.peters@gmail.com>
parents: 13256
diff changeset
434 extern double atof(const char *);
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
435 char buf[256];
3766
516490c8192c Py_complex; and WITHOUT_COMPLEX added to getargs.c
Guido van Rossum <guido@python.org>
parents: 3731
diff changeset
436 Py_complex c;
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
437 n = r_byte(p);
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
438 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
439 PyErr_SetString(PyExc_EOFError,
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
440 "EOF read where object expected");
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
441 return NULL;
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
442 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
443 buf[n] = '\0';
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5115
diff changeset
444 PyFPE_START_PROTECT("atof", return 0)
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
445 c.real = atof(buf);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
446 PyFPE_END_PROTECT(c)
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
447 n = r_byte(p);
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
448 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
449 PyErr_SetString(PyExc_EOFError,
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
450 "EOF read where object expected");
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
451 return NULL;
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
452 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
453 buf[n] = '\0';
5119
bda01a374762 Changes for Lee Busby's SIGFPE patch set.
Guido van Rossum <guido@python.org>
parents: 5115
diff changeset
454 PyFPE_START_PROTECT("atof", return 0)
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
455 c.imag = atof(buf);
5197
74c12704a0bd New form of PyFPE_END_PROTECT macro.
Guido van Rossum <guido@python.org>
parents: 5119
diff changeset
456 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
457 return PyComplex_FromCComplex(c);
3323
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
458 }
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
459 #endif
6098aaa8ae7f changes for complex numbers
Guido van Rossum <guido@python.org>
parents: 3234
diff changeset
460
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
461 case TYPE_STRING:
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
462 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
463 if (n < 0) {
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
464 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
465 return NULL;
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
466 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
467 v = PyString_FromStringAndSize((char *)NULL, n);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
468 if (v != NULL) {
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
469 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
470 Py_DECREF(v);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
471 v = NULL;
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,
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
473 "EOF read where object expected");
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
474 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
475 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
476 return v;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
477
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
478 case TYPE_UNICODE:
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
479 {
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
480 char *buffer;
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
481
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
482 n = r_long(p);
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
483 if (n < 0) {
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
484 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
485 return NULL;
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
486 }
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12135
diff changeset
487 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
488 if (buffer == NULL)
12576
1c7c2dd1beb1 Vladimir Marangozov's long-awaited malloc restructuring.
Guido van Rossum <guido@python.org>
parents: 12135
diff changeset
489 return PyErr_NoMemory();
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
490 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
491 PyMem_DEL(buffer);
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
492 PyErr_SetString(PyExc_EOFError,
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
493 "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
494 return NULL;
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
495 }
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
496 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
497 PyMem_DEL(buffer);
11976
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
498 return v;
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
499 }
513354d87a85 Marc-Andre Lemburg: support marshalling Unicode objects (code 'u').
Guido van Rossum <guido@python.org>
parents: 9300
diff changeset
500
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
501 case TYPE_TUPLE:
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
502 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
503 if (n < 0) {
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
504 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
505 return NULL;
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
506 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
507 v = PyTuple_New((int)n);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
508 if (v == NULL)
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
509 return v;
3234
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
510 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
511 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
512 if ( v2 == NULL ) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
513 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
514 v = NULL;
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
515 break;
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
516 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
517 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
518 }
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
519 return v;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
520
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
521 case TYPE_LIST:
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
522 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
523 if (n < 0) {
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
524 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
525 return NULL;
0e6fbbe3b63c When unmarshalling, add test for negative lengths on strings, tuples
Guido van Rossum <guido@python.org>
parents: 8329
diff changeset
526 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
527 v = PyList_New((int)n);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
528 if (v == NULL)
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
529 return v;
3234
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
530 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
531 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
532 if ( v2 == NULL ) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
533 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
534 v = NULL;
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
535 break;
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
536 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
537 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
538 }
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
539 return v;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
540
279
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
541 case TYPE_DICT:
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
542 v = PyDict_New();
279
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
543 if (v == NULL)
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
544 return NULL;
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
545 for (;;) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
546 PyObject *key, *val;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
547 key = r_object(p);
279
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
548 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
549 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
550 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
551 if (val != NULL)
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
552 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
553 Py_DECREF(key);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
554 Py_XDECREF(val);
279
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
555 }
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
556 return v;
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
557
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
558 case TYPE_CODE:
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
559 {
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
560 int argcount = r_short(p);
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
561 int nlocals = r_short(p);
4995
267ed480ec1b Marshal the new stacksize item in code objects.
Guido van Rossum <guido@python.org>
parents: 4656
diff changeset
562 int stacksize = r_short(p);
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
563 int flags = r_short(p);
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
564 PyObject *code = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
565 PyObject *consts = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
566 PyObject *names = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
567 PyObject *varnames = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
568 PyObject *filename = NULL;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
569 PyObject *name = NULL;
5115
e3ab48988c77 Keep gcc -Wall happy.
Guido van Rossum <guido@python.org>
parents: 5042
diff changeset
570 int firstlineno = 0;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
571 PyObject *lnotab = NULL;
3234
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
572
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
573 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
574 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
575 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
576 if (names) varnames = r_object(p);
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
577 if (varnames) filename = r_object(p);
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
578 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
579 if (name) {
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
580 firstlineno = r_short(p);
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
581 lnotab = r_object(p);
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
582 }
3234
aafe7d634985 Made a bit more robust against out-of-memory situations
Jack Jansen <jack.jansen@cwi.nl>
parents: 3012
diff changeset
583
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
584 if (!PyErr_Occurred()) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
585 v = (PyObject *) PyCode_New(
4995
267ed480ec1b Marshal the new stacksize item in code objects.
Guido van Rossum <guido@python.org>
parents: 4656
diff changeset
586 argcount, nlocals, stacksize, flags,
2844
0261bf5b3819 keyword arguments and faster calls
Guido van Rossum <guido@python.org>
parents: 2503
diff changeset
587 code, consts, names, varnames,
5042
9b7e0cf51990 Marshal the line number table of code objects.
Guido van Rossum <guido@python.org>
parents: 4995
diff changeset
588 filename, name, firstlineno, lnotab);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
589 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
590 else
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
591 v = NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
592 Py_XDECREF(code);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
593 Py_XDECREF(consts);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
594 Py_XDECREF(names);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
595 Py_XDECREF(varnames);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
596 Py_XDECREF(filename);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
597 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
598 Py_XDECREF(lnotab);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
599
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
600 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
601 return v;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
602
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
603 default:
3731
de1cb33219e3 Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents: 3620
diff changeset
604 /* 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
605 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
606 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
607 return NULL;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
608
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
609 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
610 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
611
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
612 long
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
613 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
614 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
615 RFILE rf;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
616 rf.fp = fp;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
617 return r_long(&rf);
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
618 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
619
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
620 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
621 PyMarshal_ReadObjectFromFile(FILE *fp)
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
622 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
623 RFILE rf;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
624 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
625 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
626 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1929
diff changeset
627 }
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
628 rf.fp = fp;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
629 return r_object(&rf);
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
630 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
631
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
632 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
633 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
634 {
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
635 RFILE rf;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
636 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
637 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
638 return NULL;
d7e91437f0a2 Lots of changes, most minor (fatal() instead of abort(), use of
Guido van Rossum <guido@python.org>
parents: 1929
diff changeset
639 }
1270
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
640 rf.fp = NULL;
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
641 rf.str = NULL;
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
642 rf.ptr = str;
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
643 rf.end = str + len;
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
644 return r_object(&rf);
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
645 }
14369a5e6167 Support for frozen scripts; added -i option.
Guido van Rossum <guido@python.org>
parents: 1257
diff changeset
646
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
647 PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
648 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
649 {
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
650 WFILE wf;
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
651 wf.fp = NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
652 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
653 if (wf.str == NULL)
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
654 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
655 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
656 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
657 wf.error = 0;
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
658 wf.depth = 0;
4039
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
659 w_object(x, &wf);
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
660 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
661 _PyString_Resize(&wf.str,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
662 (int) (wf.ptr -
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
663 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
664 if (wf.error) {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
665 Py_XDECREF(wf.str);
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
666 PyErr_SetString(PyExc_ValueError,
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
667 (wf.error==1)?"unmarshallable object"
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
668 :"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
669 return NULL;
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
670 }
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
671 return wf.str;
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
672 }
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
673
279
9c924f9c3b16 Add marshalling for dictionaries.
Guido van Rossum <guido@python.org>
parents: 272
diff changeset
674 /* And an interface for Python programs... */
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
675
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
676 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
677 marshal_dump(PyObject *self, PyObject *args)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
678 {
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
679 WFILE wf;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
680 PyObject *x;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
681 PyObject *f;
12135
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
682 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
683 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
684 if (!PyFile_Check(f)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
685 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
686 "marshal.dump() 2nd arg must be file");
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
687 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
688 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
689 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
690 wf.str = NULL;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
691 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
692 wf.error = 0;
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
693 wf.depth = 0;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
694 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
695 if (wf.error) {
13070
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
696 PyErr_SetString(PyExc_ValueError,
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
697 (wf.error==1)?"unmarshallable object"
7392e71f6cce Michael Hudson <mwh21@cam.ac.uk>:
Fred Drake <fdrake@acm.org>
parents: 12576
diff changeset
698 :"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
699 return NULL;
de1cb33219e3 Jeremy's patches for more robust handling of unmarshallable types.
Guido van Rossum <guido@python.org>
parents: 3620
diff changeset
700 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
701 Py_INCREF(Py_None);
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
702 return Py_None;
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
703 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
704
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
705 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
706 marshal_load(PyObject *self, PyObject *args)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 {
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
708 RFILE rf;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
709 PyObject *f;
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
710 PyObject *v;
12135
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
711 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
712 return NULL;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
713 if (!PyFile_Check(f)) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
714 PyErr_SetString(PyExc_TypeError,
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
715 "marshal.load() arg must be file");
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
716 return NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
717 }
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
718 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
719 rf.str = NULL;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
720 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
721 PyErr_Clear();
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
722 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
723 if (PyErr_Occurred()) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
724 Py_XDECREF(v);
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
725 v = NULL;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
726 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
727 return v;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
728 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
729
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
730 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
731 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
732 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
733 PyObject *x;
12135
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
734 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
735 return NULL;
4039
23f280ab5409 Added *PyMarshal_WriteObjectToString() (moved the relevant code there
Guido van Rossum <guido@python.org>
parents: 3839
diff changeset
736 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
737 }
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
738
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
739 static PyObject *
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
740 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
741 {
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
742 RFILE rf;
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
743 PyObject *v;
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
744 char *s;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
745 int n;
12135
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
746 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
747 return NULL;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
748 rf.fp = NULL;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
749 rf.str = args;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
750 rf.ptr = s;
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
751 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
752 PyErr_Clear();
1191
38f0054f44a7 Added separate main program for the Mac: macmain.c
Guido van Rossum <guido@python.org>
parents: 795
diff changeset
753 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
754 if (PyErr_Occurred()) {
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
755 Py_XDECREF(v);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
756 v = NULL;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
757 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
758 return v;
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
759 }
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
760
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
761 static PyMethodDef marshal_methods[] = {
12135
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
762 {"dump", marshal_dump, 1},
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
763 {"load", marshal_load, 1},
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
764 {"dumps", marshal_dumps, 1},
667878776933 Use modern PyArg_ParseTuple style, with function names.
Guido van Rossum <guido@python.org>
parents: 11976
diff changeset
765 {"loads", marshal_loads, 1},
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
766 {NULL, NULL} /* sentinel */
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
767 };
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
768
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
769 void
13658
f79434ee41fa Mass ANSIfication of function definitions. Doesn't cover all 'extern'
Thomas Wouters <thomas@python.org>
parents: 13447
diff changeset
770 PyMarshal_Init(void)
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
771 {
5373
5880384d7c71 Quickly renamed the remaining files -- this directory is done.
Guido van Rossum <guido@python.org>
parents: 5197
diff changeset
772 (void) Py_InitModule("marshal", marshal_methods);
267
457661e47c7b Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
773 }