Skip to content

Commit 455bfba

Browse files
committed
Add a test.
1 parent 25d2f27 commit 455bfba

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

Lib/test/test_memoryio.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55

66
import unittest
77
from test import support
8+
from test.support import threading_helper
89

910
import gc
1011
import io
1112
import _pyio as pyio
1213
import pickle
1314
import sys
1415
import weakref
16+
import threading
1517

1618
class IntLike:
1719
def __init__(self, num):
@@ -723,6 +725,22 @@ def test_newline_argument(self):
723725
for newline in (None, "", "\n", "\r", "\r\n"):
724726
self.ioclass(newline=newline)
725727

728+
@unittest.skipUnless(support.Py_GIL_DISABLED, "only meaningful under free-threading")
729+
@threading_helper.requires_working_threading()
730+
def test_concurrent_use(self):
731+
memio = self.ioclass("")
732+
733+
def use():
734+
memio.write("x" * 10)
735+
memio.readlines()
736+
737+
threads = [threading.Thread(target=use) for _ in range(8)]
738+
with threading_helper.catch_threading_exception() as cm:
739+
with threading_helper.start_threads(threads):
740+
pass
741+
742+
self.assertIsNone(cm.exc_value)
743+
726744

727745
class PyStringIOTest(MemoryTestMixin, MemorySeekTestMixin,
728746
TextIOTestMixin, unittest.TestCase):
@@ -890,6 +908,7 @@ def test_setstate(self):
890908
self.assertRaises(ValueError, memio.__setstate__, ("closed", "", 0, None))
891909

892910

911+
893912
class CStringIOPickleTest(PyStringIOPickleTest):
894913
UnsupportedOperation = io.UnsupportedOperation
895914

Modules/_io/stringio.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ static int _io_StringIO___init__(PyObject *self, PyObject *args, PyObject *kwarg
7979
static int
8080
resize_buffer(stringio *self, size_t size)
8181
{
82-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
8382
/* Here, unsigned types are used to avoid dealing with signed integer
8483
overflow, which is undefined in C. */
8584
size_t alloc = self->buf_size;
@@ -132,7 +131,6 @@ resize_buffer(stringio *self, size_t size)
132131
static PyObject *
133132
make_intermediate(stringio *self)
134133
{
135-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
136134
PyObject *intermediate = PyUnicodeWriter_Finish(self->writer);
137135
self->writer = NULL;
138136
self->state = STATE_REALIZED;
@@ -155,7 +153,6 @@ make_intermediate(stringio *self)
155153
static int
156154
realize(stringio *self)
157155
{
158-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
159156
Py_ssize_t len;
160157
PyObject *intermediate;
161158

@@ -191,7 +188,6 @@ realize(stringio *self)
191188
static Py_ssize_t
192189
write_str(stringio *self, PyObject *obj)
193190
{
194-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
195191
Py_ssize_t len;
196192
PyObject *decoded = NULL;
197193

@@ -359,7 +355,6 @@ _io_StringIO_read_impl(stringio *self, Py_ssize_t size)
359355
static PyObject *
360356
_stringio_readline(stringio *self, Py_ssize_t limit)
361357
{
362-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
363358
Py_UCS4 *start, *end, old_char;
364359
Py_ssize_t len, consumed;
365360

@@ -411,7 +406,6 @@ _io_StringIO_readline_impl(stringio *self, Py_ssize_t size)
411406
static PyObject *
412407
stringio_iternext_lock_held(PyObject *op)
413408
{
414-
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
415409
PyObject *line;
416410
stringio *self = stringio_CAST(op);
417411

0 commit comments

Comments
 (0)