Mercurial > cpython-lru_cache-weakref
diff Python/marshal.c @ 4039:23f280ab5409 legacy-trunk
Added *PyMarshal_WriteObjectToString() (moved the relevant code there
from marshal_loads()).
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 19 Aug 1996 22:07:17 +0000 |
| parents | 22e29b1747e1 |
| children | 3b3f7c3f6da2 |
line wrap: on
line diff
--- a/Python/marshal.c Mon Aug 19 22:05:27 1996 +0000 +++ b/Python/marshal.c Mon Aug 19 22:07:17 1996 +0000 @@ -535,6 +535,30 @@ 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 @@ 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 *
