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*.
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 2a05c06..b9b95c8 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -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);