summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-08-29 18:14:40 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2009-08-29 18:14:40 (GMT)
commitfff896b3090a9257a81f83eb812ea6940d15643d (patch)
tree7b2cc94c90a444ff3056b036e575f406646ad691 /Modules
parent3092ed977fa601c68469a61e7366eaa40c77bb7b (diff)
downloadcpython-fff896b3090a9257a81f83eb812ea6940d15643d.zip
cpython-fff896b3090a9257a81f83eb812ea6940d15643d.tar.gz
cpython-fff896b3090a9257a81f83eb812ea6940d15643d.tar.bz2
#6750: TextIOWrapped could duplicate output when several threads write to it.
this affect text files opened with io.open(), and the print() function of py3k
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/textio.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c
index c129303..3b627f2 100644
--- a/Modules/_io/textio.c
+++ b/Modules/_io/textio.c
@@ -1189,11 +1189,18 @@ findchar(const Py_UNICODE *s, Py_ssize_t size, Py_UNICODE ch)
static int
_textiowrapper_writeflush(textio *self)
{
- PyObject *b, *ret;
+ PyObject *pending, *b, *ret;
if (self->pending_bytes == NULL)
return 0;
- b = _PyBytes_Join(_PyIO_empty_bytes, self->pending_bytes);
+
+ pending = self->pending_bytes;
+ Py_INCREF(pending);
+ self->pending_bytes_count = 0;
+ Py_CLEAR(self->pending_bytes);
+
+ b = _PyBytes_Join(_PyIO_empty_bytes, pending);
+ Py_DECREF(pending);
if (b == NULL)
return -1;
ret = PyObject_CallMethodObjArgs(self->buffer,
@@ -1202,8 +1209,6 @@ _textiowrapper_writeflush(textio *self)
if (ret == NULL)
return -1;
Py_DECREF(ret);
- Py_CLEAR(self->pending_bytes);
- self->pending_bytes_count = 0;
return 0;
}