summaryrefslogtreecommitdiff
path: root/Python/marshal.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1998-10-07 19:42:25 +0000
committerGuido van Rossum <guido@python.org>1998-10-07 19:42:25 +0000
commitd076c73cc81a974794c9aa7e812931b74d6e03c2 (patch)
tree55b5c7b6c145d5491c2dd63780c9654c51aa2306 /Python/marshal.c
parent437ff8600a2959e87194f1491ba99116d73ea543 (diff)
downloadcpython-git-d076c73cc81a974794c9aa7e812931b74d6e03c2.tar.gz
Changes to support other object types besides strings
as the code string of code objects, as long as they support the (readonly) buffer interface. By Greg Stein.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r--Python/marshal.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/Python/marshal.c b/Python/marshal.c
index 3d5f2e5315..df7f51c867 100644
--- a/Python/marshal.c
+++ b/Python/marshal.c
@@ -142,6 +142,7 @@ w_object(v, p)
WFILE *p;
{
int i, n;
+ PyBufferProcs *pb;
if (v == NULL) {
w_byte(TYPE_NULL, p);
@@ -251,7 +252,7 @@ w_object(v, p)
w_short(co->co_nlocals, p);
w_short(co->co_stacksize, p);
w_short(co->co_flags, p);
- w_object((PyObject *)co->co_code, p);
+ w_object(co->co_code, p);
w_object(co->co_consts, p);
w_object(co->co_names, p);
w_object(co->co_varnames, p);
@@ -260,6 +261,18 @@ w_object(v, p)
w_short(co->co_firstlineno, p);
w_object(co->co_lnotab, p);
}
+ else if ((pb = v->ob_type->tp_as_buffer) != NULL &&
+ pb->bf_getsegcount != NULL &&
+ pb->bf_getreadbuffer != NULL &&
+ (*pb->bf_getsegcount)(v, NULL) == 1)
+ {
+ /* Write unknown buffer-style objects as a string */
+ char *s;
+ w_byte(TYPE_STRING, p);
+ n = (*pb->bf_getreadbuffer)(v, 0, (void **)&s);
+ w_long((long)n, p);
+ w_string(s, n, p);
+ }
else {
w_byte(TYPE_UNKNOWN, p);
p->error = 1;
@@ -730,7 +743,7 @@ marshal_loads(self, args)
PyObject *v;
char *s;
int n;
- if (!PyArg_Parse(args, "s#", &s, &n))
+ if (!PyArg_Parse(args, "r#", &s, &n))
return NULL;
rf.fp = NULL;
rf.str = args;