Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 2 | Copyright (c) 2000, BeOpen.com. |
| 3 | Copyright (c) 1995-2000, Corporation for National Research Initiatives. |
| 4 | Copyright (c) 1990-1995, Stichting Mathematisch Centrum. |
| 5 | All rights reserved. |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 6 | |
Guido van Rossum | fd71b9e | 2000-06-30 23:50:40 +0000 | [diff] [blame] | 7 | See the file "Misc/COPYRIGHT" for information on usage and |
| 8 | redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 9 | ******************************************************************/ |
| 10 | |
| 11 | /* Write Python objects to files and read them back. |
| 12 | This is intended for writing and reading compiled Python code only; |
| 13 | a true persistent storage facility would be much harder, since |
| 14 | it would have to take circular links and sharing into account. */ |
| 15 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 16 | #include "Python.h" |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 17 | #include "longintrepr.h" |
| 18 | #include "compile.h" |
| 19 | #include "marshal.h" |
| 20 | |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 21 | /* High water mark to determine when the marshalled object is dangerously deep |
| 22 | * and risks coring the interpreter. When the object stack gets this deep, |
| 23 | * raise an exception instead of continuing. |
| 24 | */ |
| 25 | #define MAX_MARSHAL_STACK_DEPTH 5000 |
| 26 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 27 | #define TYPE_NULL '0' |
| 28 | #define TYPE_NONE 'N' |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 29 | #define TYPE_ELLIPSIS '.' |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 30 | #define TYPE_INT 'i' |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 31 | #define TYPE_INT64 'I' |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 32 | #define TYPE_FLOAT 'f' |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 33 | #define TYPE_COMPLEX 'x' |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 34 | #define TYPE_LONG 'l' |
| 35 | #define TYPE_STRING 's' |
| 36 | #define TYPE_TUPLE '(' |
| 37 | #define TYPE_LIST '[' |
| 38 | #define TYPE_DICT '{' |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 39 | #define TYPE_CODE 'c' |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 40 | #define TYPE_UNICODE 'u' |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 41 | #define TYPE_UNKNOWN '?' |
| 42 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 43 | typedef struct { |
| 44 | FILE *fp; |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 45 | int error; |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 46 | int depth; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 47 | /* If fp == NULL, the following are valid: */ |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 48 | PyObject *str; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 49 | char *ptr; |
| 50 | char *end; |
| 51 | } WFILE; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 52 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 53 | #define w_byte(c, p) if (((p)->fp)) putc((c), (p)->fp); \ |
| 54 | else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \ |
| 55 | else w_more(c, p) |
| 56 | |
| 57 | static void |
| 58 | w_more(c, p) |
| 59 | char c; |
| 60 | WFILE *p; |
| 61 | { |
| 62 | int size, newsize; |
| 63 | if (p->str == NULL) |
| 64 | return; /* An error already occurred */ |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 65 | size = PyString_Size(p->str); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 66 | newsize = size + 1024; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 67 | if (_PyString_Resize(&p->str, newsize) != 0) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 68 | p->ptr = p->end = NULL; |
| 69 | } |
| 70 | else { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 71 | p->ptr = PyString_AS_STRING((PyStringObject *)p->str) + size; |
| 72 | p->end = |
| 73 | PyString_AS_STRING((PyStringObject *)p->str) + newsize; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 74 | *p->ptr++ = c; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | static void |
| 79 | w_string(s, n, p) |
| 80 | char *s; |
| 81 | int n; |
| 82 | WFILE *p; |
| 83 | { |
| 84 | if (p->fp != NULL) { |
| 85 | fwrite(s, 1, n, p->fp); |
| 86 | } |
| 87 | else { |
| 88 | while (--n >= 0) { |
| 89 | w_byte(*s, p); |
| 90 | s++; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | static void |
| 96 | w_short(x, p) |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 97 | int x; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 98 | WFILE *p; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 99 | { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 100 | w_byte( x & 0xff, p); |
| 101 | w_byte((x>> 8) & 0xff, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 104 | static void |
| 105 | w_long(x, p) |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 106 | long x; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 107 | WFILE *p; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 108 | { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 109 | w_byte((int)( x & 0xff), p); |
| 110 | w_byte((int)((x>> 8) & 0xff), p); |
| 111 | w_byte((int)((x>>16) & 0xff), p); |
| 112 | w_byte((int)((x>>24) & 0xff), p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 115 | #if SIZEOF_LONG > 4 |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 116 | static void |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 117 | w_long64(x, p) |
| 118 | long x; |
| 119 | WFILE *p; |
| 120 | { |
| 121 | w_long(x, p); |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 122 | w_long(x>>32, p); |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 123 | } |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 124 | #endif |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 125 | |
| 126 | static void |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 127 | w_object(v, p) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 128 | PyObject *v; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 129 | WFILE *p; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 130 | { |
Guido van Rossum | 3a205f7 | 1995-02-17 15:10:07 +0000 | [diff] [blame] | 131 | int i, n; |
Guido van Rossum | d076c73 | 1998-10-07 19:42:25 +0000 | [diff] [blame] | 132 | PyBufferProcs *pb; |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 133 | |
| 134 | p->depth++; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 135 | |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 136 | if (p->depth > MAX_MARSHAL_STACK_DEPTH) { |
| 137 | p->error = 2; |
| 138 | } |
| 139 | else if (v == NULL) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 140 | w_byte(TYPE_NULL, p); |
Guido van Rossum | 730806d | 1998-04-10 22:27:42 +0000 | [diff] [blame] | 141 | } |
| 142 | else if (v == Py_None) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 143 | w_byte(TYPE_NONE, p); |
Guido van Rossum | 730806d | 1998-04-10 22:27:42 +0000 | [diff] [blame] | 144 | } |
| 145 | else if (v == Py_Ellipsis) { |
| 146 | w_byte(TYPE_ELLIPSIS, p); |
| 147 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 148 | else if (PyInt_Check(v)) { |
| 149 | long x = PyInt_AS_LONG((PyIntObject *)v); |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 150 | #if SIZEOF_LONG > 4 |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 151 | long y = x>>31; |
| 152 | if (y && y != -1) { |
| 153 | w_byte(TYPE_INT64, p); |
| 154 | w_long64(x, p); |
| 155 | } |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 156 | else |
| 157 | #endif |
| 158 | { |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 159 | w_byte(TYPE_INT, p); |
| 160 | w_long(x, p); |
| 161 | } |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 162 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 163 | else if (PyLong_Check(v)) { |
| 164 | PyLongObject *ob = (PyLongObject *)v; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 165 | w_byte(TYPE_LONG, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 166 | n = ob->ob_size; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 167 | w_long((long)n, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 168 | if (n < 0) |
| 169 | n = -n; |
| 170 | for (i = 0; i < n; i++) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 171 | w_short(ob->ob_digit[i], p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 172 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 173 | else if (PyFloat_Check(v)) { |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 174 | extern void PyFloat_AsString(char *, PyFloatObject *); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 175 | char buf[256]; /* Plenty to format any double */ |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 176 | PyFloat_AsString(buf, (PyFloatObject *)v); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 177 | n = strlen(buf); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 178 | w_byte(TYPE_FLOAT, p); |
Guido van Rossum | 3a205f7 | 1995-02-17 15:10:07 +0000 | [diff] [blame] | 179 | w_byte(n, p); |
| 180 | w_string(buf, n, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 181 | } |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 182 | #ifndef WITHOUT_COMPLEX |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 183 | else if (PyComplex_Check(v)) { |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 184 | extern void PyFloat_AsString(char *, PyFloatObject *); |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 185 | char buf[256]; /* Plenty to format any double */ |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 186 | PyFloatObject *temp; |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 187 | w_byte(TYPE_COMPLEX, p); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 188 | temp = (PyFloatObject*)PyFloat_FromDouble( |
| 189 | PyComplex_RealAsDouble(v)); |
| 190 | PyFloat_AsString(buf, temp); |
| 191 | Py_DECREF(temp); |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 192 | n = strlen(buf); |
| 193 | w_byte(n, p); |
| 194 | w_string(buf, n, p); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 195 | temp = (PyFloatObject*)PyFloat_FromDouble( |
| 196 | PyComplex_ImagAsDouble(v)); |
| 197 | PyFloat_AsString(buf, temp); |
| 198 | Py_DECREF(temp); |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 199 | n = strlen(buf); |
| 200 | w_byte(n, p); |
| 201 | w_string(buf, n, p); |
| 202 | } |
| 203 | #endif |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 204 | else if (PyString_Check(v)) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 205 | w_byte(TYPE_STRING, p); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 206 | n = PyString_GET_SIZE(v); |
Guido van Rossum | 3a205f7 | 1995-02-17 15:10:07 +0000 | [diff] [blame] | 207 | w_long((long)n, p); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 208 | w_string(PyString_AS_STRING(v), n, p); |
| 209 | } |
| 210 | else if (PyUnicode_Check(v)) { |
| 211 | PyObject *utf8; |
| 212 | utf8 = PyUnicode_AsUTF8String(v); |
| 213 | if (utf8 == NULL) { |
Guido van Rossum | 98626cd | 2000-06-28 23:24:19 +0000 | [diff] [blame] | 214 | p->depth--; |
| 215 | p->error = 1; |
| 216 | return; |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 217 | } |
| 218 | w_byte(TYPE_UNICODE, p); |
| 219 | n = PyString_GET_SIZE(utf8); |
| 220 | w_long((long)n, p); |
| 221 | w_string(PyString_AS_STRING(utf8), n, p); |
| 222 | Py_DECREF(utf8); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 223 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 224 | else if (PyTuple_Check(v)) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 225 | w_byte(TYPE_TUPLE, p); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 226 | n = PyTuple_Size(v); |
Guido van Rossum | 3a205f7 | 1995-02-17 15:10:07 +0000 | [diff] [blame] | 227 | w_long((long)n, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 228 | for (i = 0; i < n; i++) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 229 | w_object(PyTuple_GET_ITEM(v, i), p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 230 | } |
| 231 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 232 | else if (PyList_Check(v)) { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 233 | w_byte(TYPE_LIST, p); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 234 | n = PyList_GET_SIZE(v); |
Guido van Rossum | 3a205f7 | 1995-02-17 15:10:07 +0000 | [diff] [blame] | 235 | w_long((long)n, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 236 | for (i = 0; i < n; i++) { |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 237 | w_object(PyList_GET_ITEM(v, i), p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 238 | } |
| 239 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 240 | else if (PyDict_Check(v)) { |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 241 | int pos; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 242 | PyObject *key, *value; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 243 | w_byte(TYPE_DICT, p); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 244 | /* This one is NULL object terminated! */ |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 245 | pos = 0; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 246 | while (PyDict_Next(v, &pos, &key, &value)) { |
Guido van Rossum | 2583165 | 1993-05-19 14:50:45 +0000 | [diff] [blame] | 247 | w_object(key, p); |
| 248 | w_object(value, p); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 249 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 250 | w_object((PyObject *)NULL, p); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 251 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 252 | else if (PyCode_Check(v)) { |
| 253 | PyCodeObject *co = (PyCodeObject *)v; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 254 | w_byte(TYPE_CODE, p); |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 255 | w_short(co->co_argcount, p); |
| 256 | w_short(co->co_nlocals, p); |
Guido van Rossum | 98a9b31 | 1997-01-17 21:07:08 +0000 | [diff] [blame] | 257 | w_short(co->co_stacksize, p); |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 258 | w_short(co->co_flags, p); |
Guido van Rossum | d076c73 | 1998-10-07 19:42:25 +0000 | [diff] [blame] | 259 | w_object(co->co_code, p); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 260 | w_object(co->co_consts, p); |
| 261 | w_object(co->co_names, p); |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 262 | w_object(co->co_varnames, p); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 263 | w_object(co->co_filename, p); |
Guido van Rossum | 9bfef44 | 1993-03-29 10:43:31 +0000 | [diff] [blame] | 264 | w_object(co->co_name, p); |
Guido van Rossum | d031c89 | 1997-01-24 03:44:17 +0000 | [diff] [blame] | 265 | w_short(co->co_firstlineno, p); |
| 266 | w_object(co->co_lnotab, p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 267 | } |
Guido van Rossum | d076c73 | 1998-10-07 19:42:25 +0000 | [diff] [blame] | 268 | else if ((pb = v->ob_type->tp_as_buffer) != NULL && |
| 269 | pb->bf_getsegcount != NULL && |
| 270 | pb->bf_getreadbuffer != NULL && |
| 271 | (*pb->bf_getsegcount)(v, NULL) == 1) |
| 272 | { |
| 273 | /* Write unknown buffer-style objects as a string */ |
| 274 | char *s; |
| 275 | w_byte(TYPE_STRING, p); |
| 276 | n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s); |
| 277 | w_long((long)n, p); |
| 278 | w_string(s, n, p); |
| 279 | } |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 280 | else { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 281 | w_byte(TYPE_UNKNOWN, p); |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 282 | p->error = 1; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 283 | } |
Guido van Rossum | 98626cd | 2000-06-28 23:24:19 +0000 | [diff] [blame] | 284 | |
| 285 | p->depth--; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 286 | } |
| 287 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 288 | void |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 289 | PyMarshal_WriteLongToFile(x, fp) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 290 | long x; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 291 | FILE *fp; |
| 292 | { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 293 | WFILE wf; |
| 294 | wf.fp = fp; |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 295 | wf.error = 0; |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 296 | wf.depth = 0; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 297 | w_long(x, &wf); |
| 298 | } |
| 299 | |
| 300 | void |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 301 | PyMarshal_WriteObjectToFile(x, fp) |
| 302 | PyObject *x; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 303 | FILE *fp; |
| 304 | { |
| 305 | WFILE wf; |
| 306 | wf.fp = fp; |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 307 | wf.error = 0; |
Guido van Rossum | 98626cd | 2000-06-28 23:24:19 +0000 | [diff] [blame] | 308 | wf.depth = 0; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 309 | w_object(x, &wf); |
| 310 | } |
| 311 | |
| 312 | typedef WFILE RFILE; /* Same struct with different invariants */ |
| 313 | |
Guido van Rossum | 8d617a6 | 1995-03-09 12:12:11 +0000 | [diff] [blame] | 314 | #define rs_byte(p) (((p)->ptr != (p)->end) ? (unsigned char)*(p)->ptr++ : EOF) |
| 315 | |
| 316 | #define r_byte(p) ((p)->fp ? getc((p)->fp) : rs_byte(p)) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 317 | |
| 318 | static int |
| 319 | r_string(s, n, p) |
| 320 | char *s; |
| 321 | int n; |
| 322 | RFILE *p; |
| 323 | { |
| 324 | if (p->fp != NULL) |
| 325 | return fread(s, 1, n, p->fp); |
| 326 | if (p->end - p->ptr < n) |
| 327 | n = p->end - p->ptr; |
| 328 | memcpy(s, p->ptr, n); |
| 329 | p->ptr += n; |
| 330 | return n; |
| 331 | } |
| 332 | |
| 333 | static int |
| 334 | r_short(p) |
| 335 | RFILE *p; |
| 336 | { |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 337 | register short x; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 338 | x = r_byte(p); |
| 339 | x |= r_byte(p) << 8; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 340 | /* XXX If your short is > 16 bits, add sign-extension here!!! */ |
| 341 | return x; |
| 342 | } |
| 343 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 344 | static long |
| 345 | r_long(p) |
| 346 | RFILE *p; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 347 | { |
| 348 | register long x; |
Guido van Rossum | 8d617a6 | 1995-03-09 12:12:11 +0000 | [diff] [blame] | 349 | register FILE *fp = p->fp; |
| 350 | if (fp) { |
| 351 | x = getc(fp); |
| 352 | x |= (long)getc(fp) << 8; |
| 353 | x |= (long)getc(fp) << 16; |
| 354 | x |= (long)getc(fp) << 24; |
| 355 | } |
| 356 | else { |
| 357 | x = rs_byte(p); |
| 358 | x |= (long)rs_byte(p) << 8; |
| 359 | x |= (long)rs_byte(p) << 16; |
| 360 | x |= (long)rs_byte(p) << 24; |
| 361 | } |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 362 | #if SIZEOF_LONG > 4 |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 363 | /* Sign extension for 64-bit machines */ |
| 364 | x <<= (8*sizeof(long) - 32); |
| 365 | x >>= (8*sizeof(long) - 32); |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 366 | #endif |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 367 | return x; |
| 368 | } |
| 369 | |
| 370 | static long |
| 371 | r_long64(p) |
| 372 | RFILE *p; |
| 373 | { |
| 374 | register long x; |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 375 | x = r_long(p); |
| 376 | #if SIZEOF_LONG > 4 |
| 377 | x = (x & 0xFFFFFFFF) | (r_long(p) << 32); |
| 378 | #else |
| 379 | if (r_long(p) != 0) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 380 | PyObject *f = PySys_GetObject("stderr"); |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 381 | if (f != NULL) |
Guido van Rossum | 7e8d26d | 1997-05-22 22:35:47 +0000 | [diff] [blame] | 382 | (void) PyFile_WriteString( |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 383 | "Warning: un-marshal 64-bit int in 32-bit mode\n", |
| 384 | f); |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 385 | } |
Guido van Rossum | c1547d9 | 1996-12-10 15:39:04 +0000 | [diff] [blame] | 386 | #endif |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 387 | return x; |
| 388 | } |
| 389 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 390 | static PyObject * |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 391 | r_object(p) |
| 392 | RFILE *p; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 393 | { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 394 | PyObject *v, *v2; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 395 | long i, n; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 396 | int type = r_byte(p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 397 | |
| 398 | switch (type) { |
| 399 | |
| 400 | case EOF: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 401 | PyErr_SetString(PyExc_EOFError, |
| 402 | "EOF read where object expected"); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 403 | return NULL; |
| 404 | |
| 405 | case TYPE_NULL: |
| 406 | return NULL; |
| 407 | |
| 408 | case TYPE_NONE: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 409 | Py_INCREF(Py_None); |
| 410 | return Py_None; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 411 | |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 412 | case TYPE_ELLIPSIS: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 413 | Py_INCREF(Py_Ellipsis); |
Guido van Rossum | e449af7 | 1996-10-11 16:25:41 +0000 | [diff] [blame] | 414 | return Py_Ellipsis; |
Guido van Rossum | 8861b74 | 1996-07-30 16:49:37 +0000 | [diff] [blame] | 415 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 416 | case TYPE_INT: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 417 | return PyInt_FromLong(r_long(p)); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 418 | |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 419 | case TYPE_INT64: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 420 | return PyInt_FromLong(r_long64(p)); |
Guido van Rossum | b0c168c | 1996-12-05 23:15:02 +0000 | [diff] [blame] | 421 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 422 | case TYPE_LONG: |
| 423 | { |
| 424 | int size; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 425 | PyLongObject *ob; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 426 | n = r_long(p); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 427 | size = n<0 ? -n : n; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 428 | ob = _PyLong_New(size); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 429 | if (ob == NULL) |
| 430 | return NULL; |
| 431 | ob->ob_size = n; |
| 432 | for (i = 0; i < size; i++) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 433 | ob->ob_digit[i] = r_short(p); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 434 | return (PyObject *)ob; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | case TYPE_FLOAT: |
| 438 | { |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 439 | extern double atof(const char *); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 440 | char buf[256]; |
Guido van Rossum | 0ae748d | 1997-02-14 22:58:07 +0000 | [diff] [blame] | 441 | double dx; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 442 | n = r_byte(p); |
| 443 | if (r_string(buf, (int)n, p) != n) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 444 | PyErr_SetString(PyExc_EOFError, |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 445 | "EOF read where object expected"); |
| 446 | return NULL; |
| 447 | } |
| 448 | buf[n] = '\0'; |
Guido van Rossum | 0ae748d | 1997-02-14 22:58:07 +0000 | [diff] [blame] | 449 | PyFPE_START_PROTECT("atof", return 0) |
| 450 | dx = atof(buf); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 451 | PyFPE_END_PROTECT(dx) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 452 | return PyFloat_FromDouble(dx); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 455 | #ifndef WITHOUT_COMPLEX |
| 456 | case TYPE_COMPLEX: |
| 457 | { |
Tim Peters | dbd9ba6 | 2000-07-09 03:09:57 +0000 | [diff] [blame] | 458 | extern double atof(const char *); |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 459 | char buf[256]; |
Guido van Rossum | 530956d | 1996-07-21 02:27:43 +0000 | [diff] [blame] | 460 | Py_complex c; |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 461 | n = r_byte(p); |
| 462 | if (r_string(buf, (int)n, p) != n) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 463 | PyErr_SetString(PyExc_EOFError, |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 464 | "EOF read where object expected"); |
| 465 | return NULL; |
| 466 | } |
| 467 | buf[n] = '\0'; |
Guido van Rossum | 0ae748d | 1997-02-14 22:58:07 +0000 | [diff] [blame] | 468 | PyFPE_START_PROTECT("atof", return 0) |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 469 | c.real = atof(buf); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 470 | PyFPE_END_PROTECT(c) |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 471 | n = r_byte(p); |
| 472 | if (r_string(buf, (int)n, p) != n) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 473 | PyErr_SetString(PyExc_EOFError, |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 474 | "EOF read where object expected"); |
| 475 | return NULL; |
| 476 | } |
| 477 | buf[n] = '\0'; |
Guido van Rossum | 0ae748d | 1997-02-14 22:58:07 +0000 | [diff] [blame] | 478 | PyFPE_START_PROTECT("atof", return 0) |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 479 | c.imag = atof(buf); |
Guido van Rossum | 45b8391 | 1997-03-14 04:32:50 +0000 | [diff] [blame] | 480 | PyFPE_END_PROTECT(c) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 481 | return PyComplex_FromCComplex(c); |
Guido van Rossum | 8a5c5d2 | 1996-01-12 01:09:56 +0000 | [diff] [blame] | 482 | } |
| 483 | #endif |
| 484 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 485 | case TYPE_STRING: |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 486 | n = r_long(p); |
Guido van Rossum | a45cb45 | 1998-06-08 20:27:29 +0000 | [diff] [blame] | 487 | if (n < 0) { |
| 488 | PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
| 489 | return NULL; |
| 490 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 491 | v = PyString_FromStringAndSize((char *)NULL, n); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 492 | if (v != NULL) { |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 493 | if (r_string(PyString_AS_STRING(v), (int)n, p) != n) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 494 | Py_DECREF(v); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 495 | v = NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 496 | PyErr_SetString(PyExc_EOFError, |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 497 | "EOF read where object expected"); |
| 498 | } |
| 499 | } |
| 500 | return v; |
| 501 | |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 502 | case TYPE_UNICODE: |
| 503 | { |
| 504 | char *buffer; |
| 505 | |
| 506 | n = r_long(p); |
| 507 | if (n < 0) { |
| 508 | PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
| 509 | return NULL; |
| 510 | } |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 511 | buffer = PyMem_NEW(char, n); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 512 | if (buffer == NULL) |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 513 | return PyErr_NoMemory(); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 514 | if (r_string(buffer, (int)n, p) != n) { |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 515 | PyMem_DEL(buffer); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 516 | PyErr_SetString(PyExc_EOFError, |
| 517 | "EOF read where object expected"); |
| 518 | return NULL; |
| 519 | } |
| 520 | v = PyUnicode_DecodeUTF8(buffer, n, NULL); |
Guido van Rossum | b18618d | 2000-05-03 23:44:39 +0000 | [diff] [blame] | 521 | PyMem_DEL(buffer); |
Guido van Rossum | c279b53 | 2000-03-10 23:03:02 +0000 | [diff] [blame] | 522 | return v; |
| 523 | } |
| 524 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 525 | case TYPE_TUPLE: |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 526 | n = r_long(p); |
Guido van Rossum | a45cb45 | 1998-06-08 20:27:29 +0000 | [diff] [blame] | 527 | if (n < 0) { |
| 528 | PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
| 529 | return NULL; |
| 530 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 531 | v = PyTuple_New((int)n); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 532 | if (v == NULL) |
| 533 | return v; |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 534 | for (i = 0; i < n; i++) { |
| 535 | v2 = r_object(p); |
| 536 | if ( v2 == NULL ) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 537 | Py_DECREF(v); |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 538 | v = NULL; |
| 539 | break; |
| 540 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 541 | PyTuple_SET_ITEM(v, (int)i, v2); |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 542 | } |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 543 | return v; |
| 544 | |
| 545 | case TYPE_LIST: |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 546 | n = r_long(p); |
Guido van Rossum | a45cb45 | 1998-06-08 20:27:29 +0000 | [diff] [blame] | 547 | if (n < 0) { |
| 548 | PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
| 549 | return NULL; |
| 550 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 551 | v = PyList_New((int)n); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 552 | if (v == NULL) |
| 553 | return v; |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 554 | for (i = 0; i < n; i++) { |
| 555 | v2 = r_object(p); |
| 556 | if ( v2 == NULL ) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 557 | Py_DECREF(v); |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 558 | v = NULL; |
| 559 | break; |
| 560 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 561 | PyList_SetItem(v, (int)i, v2); |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 562 | } |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 563 | return v; |
| 564 | |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 565 | case TYPE_DICT: |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 566 | v = PyDict_New(); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 567 | if (v == NULL) |
| 568 | return NULL; |
| 569 | for (;;) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 570 | PyObject *key, *val; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 571 | key = r_object(p); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 572 | if (key == NULL) |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 573 | break; /* XXX Assume TYPE_NULL, not an error */ |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 574 | val = r_object(p); |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 575 | if (val != NULL) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 576 | PyDict_SetItem(v, key, val); |
| 577 | Py_DECREF(key); |
| 578 | Py_XDECREF(val); |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 579 | } |
| 580 | return v; |
| 581 | |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 582 | case TYPE_CODE: |
| 583 | { |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 584 | int argcount = r_short(p); |
| 585 | int nlocals = r_short(p); |
Guido van Rossum | 98a9b31 | 1997-01-17 21:07:08 +0000 | [diff] [blame] | 586 | int stacksize = r_short(p); |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 587 | int flags = r_short(p); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 588 | PyObject *code = NULL; |
| 589 | PyObject *consts = NULL; |
| 590 | PyObject *names = NULL; |
| 591 | PyObject *varnames = NULL; |
| 592 | PyObject *filename = NULL; |
| 593 | PyObject *name = NULL; |
Guido van Rossum | 0f4bbd2 | 1997-02-14 21:12:56 +0000 | [diff] [blame] | 594 | int firstlineno = 0; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 595 | PyObject *lnotab = NULL; |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 596 | |
| 597 | code = r_object(p); |
| 598 | if (code) consts = r_object(p); |
| 599 | if (consts) names = r_object(p); |
| 600 | if (names) varnames = r_object(p); |
| 601 | if (varnames) filename = r_object(p); |
| 602 | if (filename) name = r_object(p); |
Guido van Rossum | d031c89 | 1997-01-24 03:44:17 +0000 | [diff] [blame] | 603 | if (name) { |
| 604 | firstlineno = r_short(p); |
| 605 | lnotab = r_object(p); |
| 606 | } |
Jack Jansen | 9513f2c | 1995-10-27 13:21:28 +0000 | [diff] [blame] | 607 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 608 | if (!PyErr_Occurred()) { |
| 609 | v = (PyObject *) PyCode_New( |
Guido van Rossum | 98a9b31 | 1997-01-17 21:07:08 +0000 | [diff] [blame] | 610 | argcount, nlocals, stacksize, flags, |
Guido van Rossum | 681d79a | 1995-07-18 14:51:37 +0000 | [diff] [blame] | 611 | code, consts, names, varnames, |
Guido van Rossum | d031c89 | 1997-01-24 03:44:17 +0000 | [diff] [blame] | 612 | filename, name, firstlineno, lnotab); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 613 | } |
| 614 | else |
| 615 | v = NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 616 | Py_XDECREF(code); |
| 617 | Py_XDECREF(consts); |
| 618 | Py_XDECREF(names); |
| 619 | Py_XDECREF(varnames); |
| 620 | Py_XDECREF(filename); |
| 621 | Py_XDECREF(name); |
Guido van Rossum | 6fc06e7 | 1997-07-26 23:30:18 +0000 | [diff] [blame] | 622 | Py_XDECREF(lnotab); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 623 | |
| 624 | } |
| 625 | return v; |
| 626 | |
| 627 | default: |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 628 | /* Bogus data got written, which isn't ideal. |
| 629 | This will let you keep working and recover. */ |
Guido van Rossum | a45cb45 | 1998-06-08 20:27:29 +0000 | [diff] [blame] | 630 | PyErr_SetString(PyExc_ValueError, "bad marshal data"); |
| 631 | return NULL; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 632 | |
| 633 | } |
| 634 | } |
| 635 | |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 636 | long |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 637 | PyMarshal_ReadLongFromFile(fp) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 638 | FILE *fp; |
| 639 | { |
| 640 | RFILE rf; |
| 641 | rf.fp = fp; |
| 642 | return r_long(&rf); |
| 643 | } |
| 644 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 645 | PyObject * |
| 646 | PyMarshal_ReadObjectFromFile(fp) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 647 | FILE *fp; |
| 648 | { |
| 649 | RFILE rf; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 650 | if (PyErr_Occurred()) { |
Guido van Rossum | 1ae940a | 1995-01-02 19:04:15 +0000 | [diff] [blame] | 651 | fprintf(stderr, "XXX rd_object called with exception set\n"); |
| 652 | return NULL; |
| 653 | } |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 654 | rf.fp = fp; |
| 655 | return r_object(&rf); |
| 656 | } |
| 657 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 658 | PyObject * |
| 659 | PyMarshal_ReadObjectFromString(str, len) |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 660 | char *str; |
| 661 | int len; |
| 662 | { |
| 663 | RFILE rf; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 664 | if (PyErr_Occurred()) { |
Guido van Rossum | 1ae940a | 1995-01-02 19:04:15 +0000 | [diff] [blame] | 665 | fprintf(stderr, "XXX rds_object called with exception set\n"); |
| 666 | return NULL; |
| 667 | } |
Guido van Rossum | f56e3db | 1993-04-01 20:59:32 +0000 | [diff] [blame] | 668 | rf.fp = NULL; |
| 669 | rf.str = NULL; |
| 670 | rf.ptr = str; |
| 671 | rf.end = str + len; |
| 672 | return r_object(&rf); |
| 673 | } |
| 674 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 675 | PyObject * |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 676 | PyMarshal_WriteObjectToString(x) /* wrs_object() */ |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 677 | PyObject *x; |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 678 | { |
| 679 | WFILE wf; |
| 680 | wf.fp = NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 681 | wf.str = PyString_FromStringAndSize((char *)NULL, 50); |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 682 | if (wf.str == NULL) |
| 683 | return NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 684 | wf.ptr = PyString_AS_STRING((PyStringObject *)wf.str); |
| 685 | wf.end = wf.ptr + PyString_Size(wf.str); |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 686 | wf.error = 0; |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 687 | wf.depth = 0; |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 688 | w_object(x, &wf); |
| 689 | if (wf.str != NULL) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 690 | _PyString_Resize(&wf.str, |
| 691 | (int) (wf.ptr - |
| 692 | PyString_AS_STRING((PyStringObject *)wf.str))); |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 693 | if (wf.error) { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 694 | Py_XDECREF(wf.str); |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 695 | PyErr_SetString(PyExc_ValueError, |
| 696 | (wf.error==1)?"unmarshallable object" |
| 697 | :"object too deeply nested to marshal"); |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 698 | return NULL; |
| 699 | } |
| 700 | return wf.str; |
| 701 | } |
| 702 | |
Guido van Rossum | 64b4552 | 1991-06-07 13:58:22 +0000 | [diff] [blame] | 703 | /* And an interface for Python programs... */ |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 704 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 705 | static PyObject * |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 706 | marshal_dump(self, args) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 707 | PyObject *self; |
| 708 | PyObject *args; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 709 | { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 710 | WFILE wf; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 711 | PyObject *x; |
| 712 | PyObject *f; |
Guido van Rossum | 2efa369 | 2000-03-31 00:37:41 +0000 | [diff] [blame] | 713 | if (!PyArg_ParseTuple(args, "OO:dump", &x, &f)) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 714 | return NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 715 | if (!PyFile_Check(f)) { |
| 716 | PyErr_SetString(PyExc_TypeError, |
| 717 | "marshal.dump() 2nd arg must be file"); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 718 | return NULL; |
| 719 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 720 | wf.fp = PyFile_AsFile(f); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 721 | wf.str = NULL; |
| 722 | wf.ptr = wf.end = NULL; |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 723 | wf.error = 0; |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 724 | wf.depth = 0; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 725 | w_object(x, &wf); |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 726 | if (wf.error) { |
Fred Drake | 6da0b91 | 2000-06-28 18:47:56 +0000 | [diff] [blame] | 727 | PyErr_SetString(PyExc_ValueError, |
| 728 | (wf.error==1)?"unmarshallable object" |
| 729 | :"object too deeply nested to marshal"); |
Guido van Rossum | f215060 | 1996-06-26 20:41:23 +0000 | [diff] [blame] | 730 | return NULL; |
| 731 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 732 | Py_INCREF(Py_None); |
| 733 | return Py_None; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 736 | static PyObject * |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 737 | marshal_load(self, args) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 738 | PyObject *self; |
| 739 | PyObject *args; |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 740 | { |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 741 | RFILE rf; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 742 | PyObject *f; |
| 743 | PyObject *v; |
Guido van Rossum | 2efa369 | 2000-03-31 00:37:41 +0000 | [diff] [blame] | 744 | if (!PyArg_ParseTuple(args, "O:load", &f)) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 745 | return NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 746 | if (!PyFile_Check(f)) { |
| 747 | PyErr_SetString(PyExc_TypeError, |
| 748 | "marshal.load() arg must be file"); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 749 | return NULL; |
| 750 | } |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 751 | rf.fp = PyFile_AsFile(f); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 752 | rf.str = NULL; |
| 753 | rf.ptr = rf.end = NULL; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 754 | PyErr_Clear(); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 755 | v = r_object(&rf); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 756 | if (PyErr_Occurred()) { |
| 757 | Py_XDECREF(v); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 758 | v = NULL; |
| 759 | } |
| 760 | return v; |
| 761 | } |
| 762 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 763 | static PyObject * |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 764 | marshal_dumps(self, args) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 765 | PyObject *self; |
| 766 | PyObject *args; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 767 | { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 768 | PyObject *x; |
Guido van Rossum | 2efa369 | 2000-03-31 00:37:41 +0000 | [diff] [blame] | 769 | if (!PyArg_ParseTuple(args, "O:dumps", &x)) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 770 | return NULL; |
Guido van Rossum | 3f3bb3d | 1996-08-19 22:07:17 +0000 | [diff] [blame] | 771 | return PyMarshal_WriteObjectToString(x); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 772 | } |
| 773 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 774 | static PyObject * |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 775 | marshal_loads(self, args) |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 776 | PyObject *self; |
| 777 | PyObject *args; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 778 | { |
| 779 | RFILE rf; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 780 | PyObject *v; |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 781 | char *s; |
| 782 | int n; |
Guido van Rossum | 2efa369 | 2000-03-31 00:37:41 +0000 | [diff] [blame] | 783 | if (!PyArg_ParseTuple(args, "s#:loads", &s, &n)) |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 784 | return NULL; |
| 785 | rf.fp = NULL; |
| 786 | rf.str = args; |
| 787 | rf.ptr = s; |
| 788 | rf.end = s + n; |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 789 | PyErr_Clear(); |
Guido van Rossum | 0b0db8e | 1993-01-21 16:07:51 +0000 | [diff] [blame] | 790 | v = r_object(&rf); |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 791 | if (PyErr_Occurred()) { |
| 792 | Py_XDECREF(v); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 793 | v = NULL; |
| 794 | } |
| 795 | return v; |
| 796 | } |
| 797 | |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 798 | static PyMethodDef marshal_methods[] = { |
Guido van Rossum | 2efa369 | 2000-03-31 00:37:41 +0000 | [diff] [blame] | 799 | {"dump", marshal_dump, 1}, |
| 800 | {"load", marshal_load, 1}, |
| 801 | {"dumps", marshal_dumps, 1}, |
| 802 | {"loads", marshal_loads, 1}, |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 803 | {NULL, NULL} /* sentinel */ |
| 804 | }; |
| 805 | |
| 806 | void |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 807 | PyMarshal_Init() |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 808 | { |
Guido van Rossum | 79f25d9 | 1997-04-29 20:08:16 +0000 | [diff] [blame] | 809 | (void) Py_InitModule("marshal", marshal_methods); |
Guido van Rossum | dce2e3d | 1991-06-04 19:42:30 +0000 | [diff] [blame] | 810 | } |