* Modules/bz2module.c

(BZ2File_dealloc): Call Util_DropReadAhead().
  (*): Included aesthetic changes by Neal Norwitz.
This commit is contained in:
Gustavo Niemeyer 2002-11-08 14:31:49 +00:00
parent 15628fe7bc
commit 49ea7be7e9
1 changed files with 21 additions and 12 deletions

View File

@ -211,7 +211,7 @@ Util_GetLine(BZ2FileObject *self, int n)
self->pos++; self->pos++;
if (bzerror != BZ_OK || buf == end) if (bzerror != BZ_OK || buf == end)
break; break;
if (skipnextlf ) { if (skipnextlf) {
skipnextlf = 0; skipnextlf = 0;
if (c == '\n') { if (c == '\n') {
/* Seeing a \n here with /* Seeing a \n here with
@ -498,7 +498,8 @@ BZ2File_read(BZ2FileObject *self, PyObject *args)
buffersize = bytesrequested; buffersize = bytesrequested;
if (buffersize > INT_MAX) { if (buffersize > INT_MAX) {
PyErr_SetString(PyExc_OverflowError, PyErr_SetString(PyExc_OverflowError,
"requested number of bytes is more than a Python string can hold"); "requested number of bytes is "
"more than a Python string can hold");
goto cleanup; goto cleanup;
} }
ret = PyString_FromStringAndSize((char *)NULL, buffersize); ret = PyString_FromStringAndSize((char *)NULL, buffersize);
@ -1223,13 +1224,15 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
default: default:
error = 1; error = 1;
break;
} }
if (error) { if (error) {
PyErr_SetString(PyExc_ValueError, "invalid mode"); PyErr_Format(PyExc_ValueError,
"invalid mode char %c", *mode);
return -1; return -1;
} }
mode++; mode++;
if (*mode == 0) if (*mode == '\0')
break; break;
} }
@ -1240,7 +1243,10 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs)
file_args = Py_BuildValue("(ssi)", name, mode, buffering); file_args = Py_BuildValue("(ssi)", name, mode, buffering);
if (!file_args) if (!file_args)
goto error; return -1;
/* From now on, we have stuff to dealloc, so jump to error label
* instead of returning */
if (PyFile_Type.tp_init((PyObject *)self, file_args, NULL) < 0) if (PyFile_Type.tp_init((PyObject *)self, file_args, NULL) < 0)
goto error; goto error;
@ -1299,6 +1305,7 @@ BZ2File_dealloc(BZ2FileObject *self)
0, NULL, NULL); 0, NULL, NULL);
break; break;
} }
Util_DropReadAhead(self);
((PyObject*)self)->ob_type->tp_free((PyObject *)self); ((PyObject*)self)->ob_type->tp_free((PyObject *)self);
} }
@ -1362,7 +1369,7 @@ newlines are available only when reading.\n\
#endif #endif
; ;
statichere PyTypeObject BZ2File_Type = { static PyTypeObject BZ2File_Type = {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"bz2.BZ2File", /*tp_name*/ "bz2.BZ2File", /*tp_name*/
@ -1435,8 +1442,8 @@ BZ2Comp_compress(BZ2CompObject *self, PyObject *args)
ACQUIRE_LOCK(self); ACQUIRE_LOCK(self);
if (!self->running) { if (!self->running) {
PyErr_SetString(PyExc_ValueError, "this object was already " PyErr_SetString(PyExc_ValueError,
"flushed"); "this object was already flushed");
goto error; goto error;
} }
@ -1551,8 +1558,10 @@ error:
} }
static PyMethodDef BZ2Comp_methods[] = { static PyMethodDef BZ2Comp_methods[] = {
{"compress", (PyCFunction)BZ2Comp_compress, METH_VARARGS, BZ2Comp_compress__doc__}, {"compress", (PyCFunction)BZ2Comp_compress, METH_VARARGS,
{"flush", (PyCFunction)BZ2Comp_flush, METH_NOARGS, BZ2Comp_flush__doc__}, BZ2Comp_compress__doc__},
{"flush", (PyCFunction)BZ2Comp_flush, METH_NOARGS,
BZ2Comp_flush__doc__},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
@ -1625,7 +1634,7 @@ compress() function instead. The compresslevel parameter, if given,\n\
must be a number between 1 and 9.\n\ must be a number between 1 and 9.\n\
"); ");
statichere PyTypeObject BZ2Comp_Type = { static PyTypeObject BZ2Comp_Type = {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"bz2.BZ2Compressor", /*tp_name*/ "bz2.BZ2Compressor", /*tp_name*/
@ -1842,7 +1851,7 @@ data sequentially. If you want to decompress data in one shot, use the\n\
decompress() function instead.\n\ decompress() function instead.\n\
"); ");
statichere PyTypeObject BZ2Decomp_Type = { static PyTypeObject BZ2Decomp_Type = {
PyObject_HEAD_INIT(NULL) PyObject_HEAD_INIT(NULL)
0, /*ob_size*/ 0, /*ob_size*/
"bz2.BZ2Decompressor", /*tp_name*/ "bz2.BZ2Decompressor", /*tp_name*/