diff options
author | Guido van Rossum <guido@python.org> | 1998-10-07 19:42:25 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-10-07 19:42:25 (GMT) |
commit | d076c73cc81a974794c9aa7e812931b74d6e03c2 (patch) | |
tree | 55b5c7b6c145d5491c2dd63780c9654c51aa2306 /Python/marshal.c | |
parent | 437ff8600a2959e87194f1491ba99116d73ea543 (diff) | |
download | cpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.zip cpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.tar.gz cpython-d076c73cc81a974794c9aa7e812931b74d6e03c2.tar.bz2 |
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.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 3d5f2e5..df7f51c 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; |