diff options
author | Gregory P. Smith <greg@mad-scientist.com> | 2008-04-07 06:33:21 (GMT) |
---|---|---|
committer | Gregory P. Smith <greg@mad-scientist.com> | 2008-04-07 06:33:21 (GMT) |
commit | c20adf8ef2d9ec938069d08fdcf66cff1d4a6905 (patch) | |
tree | 41872a64c0efdbe7ae55b94f09a07b7313a50b8f /Modules/bz2module.c | |
parent | d918e4e068f22c3e79c771c27be3c8f91a9e0446 (diff) | |
download | cpython-c20adf8ef2d9ec938069d08fdcf66cff1d4a6905.zip cpython-c20adf8ef2d9ec938069d08fdcf66cff1d4a6905.tar.gz cpython-c20adf8ef2d9ec938069d08fdcf66cff1d4a6905.tar.bz2 |
Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly
within the standard library. These modules use PyFile_AsFile and later
release the GIL while operating on the previously returned FILE*.
Diffstat (limited to 'Modules/bz2module.c')
-rw-r--r-- | Modules/bz2module.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/bz2module.c b/Modules/bz2module.c index fc14a06..6e5ed14 100644 --- a/Modules/bz2module.c +++ b/Modules/bz2module.c @@ -1063,6 +1063,10 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args) } else { /* we cannot move back, so rewind the stream */ BZ2_bzReadClose(&bzerror, self->fp); + if (self->fp) { + PyFile_DecUseCount(self->file); + self->fp = NULL; + } if (bzerror != BZ_OK) { Util_CatchBZ2Error(bzerror); goto cleanup; @@ -1075,6 +1079,8 @@ BZ2File_seek(BZ2FileObject *self, PyObject *args) self->pos = 0; self->fp = BZ2_bzReadOpen(&bzerror, PyFile_AsFile(self->file), 0, 0, NULL, 0); + if (self->fp) + PyFile_IncUseCount(self->file); if (bzerror != BZ_OK) { Util_CatchBZ2Error(bzerror); goto cleanup; @@ -1174,6 +1180,10 @@ BZ2File_close(BZ2FileObject *self) 0, NULL, NULL); break; } + if (self->fp) { + PyFile_DecUseCount(self->file); + self->fp = NULL; + } self->mode = MODE_CLOSED; ret = PyObject_CallMethod(self->file, "close", NULL); if (bzerror != BZ_OK) { @@ -1376,6 +1386,7 @@ BZ2File_init(BZ2FileObject *self, PyObject *args, PyObject *kwargs) Util_CatchBZ2Error(bzerror); goto error; } + PyFile_IncUseCount(self->file); self->mode = (mode_char == 'r') ? MODE_READ : MODE_WRITE; @@ -1410,6 +1421,10 @@ BZ2File_dealloc(BZ2FileObject *self) 0, NULL, NULL); break; } + if (self->fp) { + PyFile_DecUseCount(self->file); + self->fp = NULL; + } Util_DropReadAhead(self); Py_XDECREF(self->file); Py_TYPE(self)->tp_free((PyObject *)self); |