From 64c21a541e4ddbb2dec02e1bfc1b97ea6e8b07d6 Mon Sep 17 00:00:00 2001 From: Moshe Zadka Date: Sat, 31 Mar 2001 08:31:13 +0000 Subject: Fixing #233200 - cPickle did not use Py_BEGIN_ALLOW_THREADS. --- Misc/NEWS | 2 ++ Modules/cPickle.c | 29 +++++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index 575bee5..7bc5b56 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -83,6 +83,8 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=&group_id=5470&atid - #128053 - posixmodule.c - #ifdef for including "tmpfile" in the posix_methods[] array was wrong -- should be HAVE_TMPFILE +- #233200 - cPickle did not use Py_BEGIN_ALLOW_THREADS. + What's New in Python 2.0? ========================= diff --git a/Modules/cPickle.c b/Modules/cPickle.c index aac2e61..ec36a8f 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -401,13 +401,18 @@ cPickle_ErrFormat(PyObject *ErrType, char *stringformat, char *format, ...) return NULL; } -static int +static int write_file(Picklerobject *self, char *s, int n) { + size_t nbyteswritten; + if (s == NULL) { return 0; } - if (fwrite(s, sizeof(char), n, self->fp) != (size_t)n) { + Py_BEGIN_ALLOW_THREADS + nbyteswritten = fwrite(s, sizeof(char), n, self->fp); + Py_END_ALLOW_THREADS + if (nbyteswritten != (size_t)n) { PyErr_SetFromErrno(PyExc_IOError); return -1; } @@ -472,21 +477,22 @@ write_other(Picklerobject *self, char *s, int n) { if (junk) Py_DECREF(junk); else return -1; } - else + else PDATA_PUSH(self->file, py_str, -1); - - self->buf_size = 0; + + self->buf_size = 0; return n; } -static int +static int read_file(Unpicklerobject *self, char **s, int n) { + size_t nbytesread; if (self->buf_size == 0) { int size; - size = ((n < 32) ? 32 : n); + size = ((n < 32) ? 32 : n); UNLESS (self->buf = (char *)malloc(size * sizeof(char))) { PyErr_NoMemory(); return -1; @@ -499,11 +505,14 @@ read_file(Unpicklerobject *self, char **s, int n) { PyErr_NoMemory(); return -1; } - + self->buf_size = n; } - - if (fread(self->buf, sizeof(char), n, self->fp) != (size_t)n) { + + Py_BEGIN_ALLOW_THREADS + nbytesread = fread(self->buf, sizeof(char), n, self->fp); + Py_END_ALLOW_THREADS + if (nbytesread != (size_t)n) { if (feof(self->fp)) { PyErr_SetNone(PyExc_EOFError); return -1; -- cgit v0.12