Charles Waldman writes:

"""
Problem description:

	Run the following script:

import test.test_cpickle
for x in xrange(1000000):
    reload(test.test_cpickle)

Watch Python's memory use go up up and away!

In the course of debugging this I also saw that cPickle is
inconsistent with pickle - if you attempt a pickle.load or pickle.dump
on a closed file, you get a ValueError, whereas the corresponding
cPickle operations give an IOError.  Since cPickle is advertised as
being compatible with pickle, I changed these exceptions to match.
"""
This commit is contained in:
Guido van Rossum 2000-04-21 20:49:36 +00:00
parent 2dd8dddef4
commit 83addc7a0f
1 changed files with 11 additions and 14 deletions

View File

@ -2152,18 +2152,17 @@ newPicklerobject(PyObject *file, int bin) {
else else
file=Pdata_New(); file=Pdata_New();
self->file = file; UNLESS (self->file = file)
goto err;
UNLESS (self->memo = PyDict_New()) { UNLESS (self->memo = PyDict_New())
Py_XDECREF((PyObject *)self); goto err;
return NULL;
}
if (PyFile_Check(file)) { if (PyFile_Check(file)) {
self->fp = PyFile_AsFile(file); self->fp = PyFile_AsFile(file);
if (self->fp == NULL) { if (self->fp == NULL) {
PyErr_SetString(PyExc_IOError, "output file closed"); PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
return NULL; goto err;
} }
self->write_func = write_file; self->write_func = write_file;
} }
@ -4054,10 +4053,8 @@ newUnpicklerobject(PyObject *f) {
self->safe_constructors = NULL; self->safe_constructors = NULL;
self->find_class = NULL; self->find_class = NULL;
UNLESS (self->memo = PyDict_New()) { UNLESS (self->memo = PyDict_New())
Py_XDECREF((PyObject *)self); goto err;
return NULL;
}
Py_INCREF(f); Py_INCREF(f);
self->file = f; self->file = f;
@ -4066,8 +4063,8 @@ newUnpicklerobject(PyObject *f) {
if (PyFile_Check(f)) { if (PyFile_Check(f)) {
self->fp = PyFile_AsFile(f); self->fp = PyFile_AsFile(f);
if (self->fp == NULL) { if (self->fp == NULL) {
PyErr_SetString(PyExc_IOError, "input file closed"); PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
return NULL; goto err;
} }
self->read_func = read_file; self->read_func = read_file;
self->readline_func = readline_file; self->readline_func = readline_file;