[Python-checkins] r62204 - python/trunk/Modules/bz2module.c python/trunk/Modules/cPickle.c
gregory.p.smith
python-checkins at python.org
Mon Apr 7 08:33:21 CEST 2008
Author: gregory.p.smith
Date: Mon Apr 7 08:33:21 2008
New Revision: 62204
Modified:
python/trunk/Modules/bz2module.c
python/trunk/Modules/cPickle.c
Log:
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*.
Modified: python/trunk/Modules/bz2module.c
==============================================================================
--- python/trunk/Modules/bz2module.c (original)
+++ python/trunk/Modules/bz2module.c Mon Apr 7 08:33:21 2008
@@ -1063,6 +1063,10 @@
} 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 @@
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 @@
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 @@
Util_CatchBZ2Error(bzerror);
goto error;
}
+ PyFile_IncUseCount(self->file);
self->mode = (mode_char == 'r') ? MODE_READ : MODE_WRITE;
@@ -1410,6 +1421,10 @@
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);
Modified: python/trunk/Modules/cPickle.c
==============================================================================
--- python/trunk/Modules/cPickle.c (original)
+++ python/trunk/Modules/cPickle.c Mon Apr 7 08:33:21 2008
@@ -431,9 +431,11 @@
return -1;
}
+ PyFile_IncUseCount((PyFileObject *)self->file);
Py_BEGIN_ALLOW_THREADS
nbyteswritten = fwrite(s, sizeof(char), n, self->fp);
Py_END_ALLOW_THREADS
+ PyFile_DecUseCount((PyFileObject *)self->file);
if (nbyteswritten != (size_t)n) {
PyErr_SetFromErrno(PyExc_IOError);
return -1;
@@ -542,9 +544,11 @@
self->buf_size = n;
}
+ PyFile_IncUseCount((PyFileObject *)self->file);
Py_BEGIN_ALLOW_THREADS
nbytesread = fread(self->buf, sizeof(char), n, self->fp);
Py_END_ALLOW_THREADS
+ PyFile_DecUseCount((PyFileObject *)self->file);
if (nbytesread != (size_t)n) {
if (feof(self->fp)) {
PyErr_SetNone(PyExc_EOFError);
More information about the Python-checkins
mailing list