Skip to content

Commit 35f3b8e

Browse files
committed
fix GIL build, add lock held assertions
1 parent 858b668 commit 35f3b8e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Modules/_io/bytesio.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ _io_BytesIO_tell_impl(bytesio *self)
417417
static PyObject *
418418
read_bytes_lock_held(bytesio *self, Py_ssize_t size)
419419
{
420+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);
421+
420422
const char *output;
421423

422424
assert(self->buf != NULL);
@@ -841,6 +843,8 @@ _io_BytesIO_close_impl(bytesio *self)
841843
static PyObject *
842844
bytesio_getstate_lock_held(PyObject *op)
843845
{
846+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
847+
844848
bytesio *self = bytesio_CAST(op);
845849
PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
846850
PyObject *dict;
@@ -877,6 +881,8 @@ bytesio_getstate(PyObject *op, PyObject *Py_UNUSED(dummy))
877881
static PyObject *
878882
bytesio_setstate_lock_held(PyObject *op, PyObject *state)
879883
{
884+
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
885+
880886
PyObject *result;
881887
PyObject *position_obj;
882888
PyObject *dict;
@@ -1189,13 +1195,17 @@ bytesiobuf_getbuffer(PyObject *op, Py_buffer *view, int flags)
11891195
return -1;
11901196
}
11911197

1198+
#ifdef Py_GIL_DISABLED
11921199
bytesiobuf *obj = bytesiobuf_CAST(op);
11931200
bytesio *b = bytesio_CAST(obj->source);
11941201
int ret;
11951202
Py_BEGIN_CRITICAL_SECTION(b);
11961203
ret = bytesiobuf_getbuffer_lock_held(op, view, flags);
11971204
Py_END_CRITICAL_SECTION();
11981205
return ret;
1206+
#else
1207+
return bytesiobuf_getbuffer_lock_held(op, view, flags);
1208+
#endif
11991209
}
12001210

12011211
static void

0 commit comments

Comments
 (0)