summaryrefslogtreecommitdiffstats
path: root/Modules/_fileio.c
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2008-08-12 14:49:50 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2008-08-12 14:49:50 (GMT)
commitf91d46a17d85da323895950852093117bc21f860 (patch)
treec6a3e68cf22a6a102f9c1dc780438f0307b6588f /Modules/_fileio.c
parentaa8efbf08469c3667ed22362c0e10b83ae124c0b (diff)
downloadcpython-f91d46a17d85da323895950852093117bc21f860.zip
cpython-f91d46a17d85da323895950852093117bc21f860.tar.gz
cpython-f91d46a17d85da323895950852093117bc21f860.tar.bz2
Issue #3139: Make buffer-interface thread-safe wrt. PyArg_ParseTuple,
by denying s# to parse objects that have a releasebuffer procedure, and introducing s*. More module might need to get converted to use s*.
Diffstat (limited to 'Modules/_fileio.c')
-rw-r--r--Modules/_fileio.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/Modules/_fileio.c b/Modules/_fileio.c
index 21608f1..58462dd 100644
--- a/Modules/_fileio.c
+++ b/Modules/_fileio.c
@@ -357,7 +357,7 @@ fileio_seekable(PyFileIOObject *self)
static PyObject *
fileio_readinto(PyFileIOObject *self, PyObject *args)
{
- char *ptr;
+ Py_buffer pbuf;
Py_ssize_t n;
if (self->fd < 0)
@@ -365,13 +365,14 @@ fileio_readinto(PyFileIOObject *self, PyObject *args)
if (!self->readable)
return err_mode("reading");
- if (!PyArg_ParseTuple(args, "w#", &ptr, &n))
+ if (!PyArg_ParseTuple(args, "w*", &pbuf))
return NULL;
Py_BEGIN_ALLOW_THREADS
errno = 0;
- n = read(self->fd, ptr, n);
+ n = read(self->fd, pbuf.buf, pbuf.len);
Py_END_ALLOW_THREADS
+ PyBuffer_Release(&pbuf);
if (n < 0) {
if (errno == EAGAIN)
Py_RETURN_NONE;
@@ -489,22 +490,24 @@ fileio_read(PyFileIOObject *self, PyObject *args)
static PyObject *
fileio_write(PyFileIOObject *self, PyObject *args)
{
+ Py_buffer pbuf;
Py_ssize_t n;
- char *ptr;
if (self->fd < 0)
return err_closed();
if (!self->writable)
return err_mode("writing");
- if (!PyArg_ParseTuple(args, "s#", &ptr, &n))
+ if (!PyArg_ParseTuple(args, "s*", &pbuf))
return NULL;
Py_BEGIN_ALLOW_THREADS
errno = 0;
- n = write(self->fd, ptr, n);
+ n = write(self->fd, pbuf.buf, pbuf.len);
Py_END_ALLOW_THREADS
+ PyBuffer_Release(&pbuf);
+
if (n < 0) {
if (errno == EAGAIN)
Py_RETURN_NONE;