diff options
author | Guido van Rossum <guido@python.org> | 1996-08-19 22:07:17 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-08-19 22:07:17 (GMT) |
commit | 3f3bb3d3c9a616fa22b2cf7ca70c9b05295f61f3 (patch) | |
tree | c6408ab5faf437a3423dc577dab74413b2133a11 | |
parent | 49c70a7a4dd851f472cb59dc55ab68a1850c3c4a (diff) | |
download | cpython-3f3bb3d3c9a616fa22b2cf7ca70c9b05295f61f3.zip cpython-3f3bb3d3c9a616fa22b2cf7ca70c9b05295f61f3.tar.gz cpython-3f3bb3d3c9a616fa22b2cf7ca70c9b05295f61f3.tar.bz2 |
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
from marshal_loads()).
-rw-r--r-- | Python/marshal.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 4a2701a..08ad790 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -535,6 +535,30 @@ rds_object(str, len) return r_object(&rf); } +object * +PyMarshal_WriteObjectToString(x) /* wrs_object() */ + object *x; +{ + WFILE wf; + wf.fp = NULL; + wf.str = newsizedstringobject((char *)NULL, 50); + if (wf.str == NULL) + return NULL; + wf.ptr = GETSTRINGVALUE((stringobject *)wf.str); + wf.end = wf.ptr + getstringsize(wf.str); + wf.error = 0; + w_object(x, &wf); + if (wf.str != NULL) + resizestring(&wf.str, + (int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str))); + if (wf.error) { + XDECREF(wf.str); + err_setstr(ValueError, "unmarshallable object"); + return NULL; + } + return wf.str; +} + /* And an interface for Python programs... */ static object * @@ -595,27 +619,10 @@ marshal_dumps(self, args) object *self; object *args; { - WFILE wf; object *x; if (!getargs(args, "O", &x)) return NULL; - wf.fp = NULL; - wf.str = newsizedstringobject((char *)NULL, 50); - if (wf.str == NULL) - return NULL; - wf.ptr = GETSTRINGVALUE((stringobject *)wf.str); - wf.end = wf.ptr + getstringsize(wf.str); - wf.error = 0; - w_object(x, &wf); - if (wf.str != NULL) - resizestring(&wf.str, - (int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str))); - if (wf.error) { - XDECREF(wf.str); - err_setstr(ValueError, "unmarshallable object"); - return NULL; - } - return wf.str; + return PyMarshal_WriteObjectToString(x); } static object * |