diff options
author | Guido van Rossum <guido@python.org> | 2007-06-12 23:30:11 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-06-12 23:30:11 (GMT) |
commit | da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e (patch) | |
tree | f3b0ab1f90be8ba18b1cefdb660cebd95c0f70d9 /Python/marshal.c | |
parent | 2d5c219fe09eacf81c139e5af9114fbbdd093d85 (diff) | |
download | cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.zip cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.tar.gz cpython-da5b8f2d28f2f7ce47be5d88244eaefc66f7de3e.tar.bz2 |
Rip out the file object's implementation.
Fixed test_import.py while I was at it.
However, there's still a problem in import.c -- get_file() can leak a
FILE struct (not a file descriptor though). I'm not sure how to fix
this; closing the FILE* closes the file descriptor, and that's the
wrong thing to do when there's still a Python file object keeping the
file descriptor open. I also would rather not mess with dup(), as it
won't port to Windows.
Diffstat (limited to 'Python/marshal.c')
-rw-r--r-- | Python/marshal.c | 87 |
1 files changed, 29 insertions, 58 deletions
diff --git a/Python/marshal.c b/Python/marshal.c index 262c185..85926ed 100644 --- a/Python/marshal.c +++ b/Python/marshal.c @@ -1138,81 +1138,52 @@ PyMarshal_WriteObjectToString(PyObject *x, int version) static PyObject * marshal_dump(PyObject *self, PyObject *args) { - WFILE wf; + /* XXX Quick hack -- need to do this differently */ PyObject *x; PyObject *f; int version = Py_MARSHAL_VERSION; + PyObject *s; + PyObject *res; if (!PyArg_ParseTuple(args, "OO|i:dump", &x, &f, &version)) return NULL; - if (!PyFile_Check(f)) { - /* XXX Quick hack -- need to do this differently */ - PyObject *s = PyMarshal_WriteObjectToString(x, version); - PyObject *res = NULL; - if (s != NULL) { - res = PyObject_CallMethod(f, "write", "O", s); - Py_DECREF(s); - } - return res; - } - wf.fp = PyFile_AsFile(f); - wf.str = NULL; - wf.ptr = wf.end = NULL; - wf.error = 0; - wf.depth = 0; - wf.strings = (version > 0) ? PyDict_New() : 0; - wf.version = version; - w_object(x, &wf); - Py_XDECREF(wf.strings); - if (wf.error) { - PyErr_SetString(PyExc_ValueError, - (wf.error==1)?"unmarshallable object" - :"object too deeply nested to marshal"); + s = PyMarshal_WriteObjectToString(x, version); + if (s == NULL) return NULL; - } - Py_INCREF(Py_None); - return Py_None; + res = PyObject_CallMethod(f, "write", "O", s); + Py_DECREF(s); + return res; } static PyObject * marshal_load(PyObject *self, PyObject *f) { + /* XXX Quick hack -- need to do this differently */ + PyObject *data, *result; RFILE rf; - PyObject *result; - if (!PyFile_Check(f)) { - /* XXX Quick hack -- need to do this differently */ - PyObject *data, *result; - RFILE rf; - data = PyObject_CallMethod(f, "read", ""); - if (data == NULL) - return NULL; - rf.fp = NULL; - if (PyString_Check(data)) { - rf.ptr = PyString_AS_STRING(data); - rf.end = rf.ptr + PyString_GET_SIZE(data); - } - else if (PyBytes_Check(data)) { - rf.ptr = PyBytes_AS_STRING(data); - rf.end = rf.ptr + PyBytes_GET_SIZE(data); - } - else { - PyErr_Format(PyExc_TypeError, - "f.read() returned neither string " - "nor bytes but %.100s", - data->ob_type->tp_name); - Py_DECREF(data); - return NULL; - } - rf.strings = PyList_New(0); - result = read_object(&rf); - Py_DECREF(rf.strings); + data = PyObject_CallMethod(f, "read", ""); + if (data == NULL) + return NULL; + rf.fp = NULL; + if (PyString_Check(data)) { + rf.ptr = PyString_AS_STRING(data); + rf.end = rf.ptr + PyString_GET_SIZE(data); + } + else if (PyBytes_Check(data)) { + rf.ptr = PyBytes_AS_STRING(data); + rf.end = rf.ptr + PyBytes_GET_SIZE(data); + } + else { + PyErr_Format(PyExc_TypeError, + "f.read() returned neither string " + "nor bytes but %.100s", + data->ob_type->tp_name); Py_DECREF(data); - return result; + return NULL; } - rf.fp = PyFile_AsFile(f); rf.strings = PyList_New(0); - rf.depth = 0; result = read_object(&rf); Py_DECREF(rf.strings); + Py_DECREF(data); return result; } |