decoder.reset()
run_concurrently([decode_worker] * 2 + [reset_worker] * 2)
+
+
+class TextIOWrapperTest(TestCase):
+ def test_buffer_detach_race(self):
+ make = lambda: io.TextIOWrapper(io.BytesIO())
+ slot = [make()]
+
+ def reader():
+ for _ in range(1000):
+ try:
+ slot[0].buffer
+ except ValueError:
+ pass
+
+ def detacher():
+ for _ in range(1000):
+ slot[0] = make()
+ slot[0].detach()
+
+ run_concurrently([reader, detacher])
return return_value;
}
-/*[clinic end generated code: output=8c571c9dba87d2b1 input=a9049054013a1b77]*/
+
+#if !defined(_io_TextIOWrapper_buffer_DOCSTR)
+# define _io_TextIOWrapper_buffer_DOCSTR NULL
+#endif
+#if defined(_IO_TEXTIOWRAPPER_BUFFER_GETSETDEF)
+# undef _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF
+# define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, (setter)_io_TextIOWrapper_buffer_set, _io_TextIOWrapper_buffer_DOCSTR},
+#else
+# define _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF {"buffer", (getter)_io_TextIOWrapper_buffer_get, NULL, _io_TextIOWrapper_buffer_DOCSTR},
+#endif
+
+static PyObject *
+_io_TextIOWrapper_buffer_get_impl(textio *self);
+
+static PyObject *
+_io_TextIOWrapper_buffer_get(PyObject *self, void *Py_UNUSED(context))
+{
+ PyObject *return_value = NULL;
+
+ Py_BEGIN_CRITICAL_SECTION(self);
+ return_value = _io_TextIOWrapper_buffer_get_impl((textio *)self);
+ Py_END_CRITICAL_SECTION();
+
+ return return_value;
+}
+/*[clinic end generated code: output=e34c75e1d2a12084 input=a9049054013a1b77]*/
return 0;
}
+/*[clinic input]
+@critical_section
+@getter
+_io.TextIOWrapper.buffer
+[clinic start generated code]*/
+
+static PyObject *
+_io_TextIOWrapper_buffer_get_impl(textio *self)
+/*[clinic end generated code: output=d265a34555aa5d4b input=5951cfa148f7350a]*/
+{
+ return Py_XNewRef(buffer_access_safe(self));
+}
+
static PyMethodDef incrementalnewlinedecoder_methods[] = {
_IO_INCREMENTALNEWLINEDECODER_DECODE_METHODDEF
_IO_INCREMENTALNEWLINEDECODER_GETSTATE_METHODDEF
static PyMemberDef textiowrapper_members[] = {
{"encoding", _Py_T_OBJECT, offsetof(textio, encoding), Py_READONLY},
- {"buffer", _Py_T_OBJECT, offsetof(textio, buffer), Py_READONLY},
{"line_buffering", Py_T_BOOL, offsetof(textio, line_buffering), Py_READONLY},
{"write_through", Py_T_BOOL, offsetof(textio, write_through), Py_READONLY},
{"_finalizing", Py_T_BOOL, offsetof(textio, finalizing), 0},
_IO_TEXTIOWRAPPER_NEWLINES_GETSETDEF
_IO_TEXTIOWRAPPER_ERRORS_GETSETDEF
_IO_TEXTIOWRAPPER__CHUNK_SIZE_GETSETDEF
+ _IO_TEXTIOWRAPPER_BUFFER_GETSETDEF
{NULL}
};