Skip to content

gh-132551: make BytesIO object free-thread safe #132616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
May 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix GIL build, add lock held assertions
  • Loading branch information
tom-pytel committed May 8, 2025
commit 35f3b8eb0bed46eb6120c55b06958459ed5d5d47
10 changes: 10 additions & 0 deletions Modules/_io/bytesio.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,8 @@ _io_BytesIO_tell_impl(bytesio *self)
static PyObject *
read_bytes_lock_held(bytesio *self, Py_ssize_t size)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(self);

const char *output;

assert(self->buf != NULL);
Expand Down Expand Up @@ -841,6 +843,8 @@ _io_BytesIO_close_impl(bytesio *self)
static PyObject *
bytesio_getstate_lock_held(PyObject *op)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);

bytesio *self = bytesio_CAST(op);
PyObject *initvalue = _io_BytesIO_getvalue_impl(self);
PyObject *dict;
Expand Down Expand Up @@ -877,6 +881,8 @@ bytesio_getstate(PyObject *op, PyObject *Py_UNUSED(dummy))
static PyObject *
bytesio_setstate_lock_held(PyObject *op, PyObject *state)
{
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);

PyObject *result;
PyObject *position_obj;
PyObject *dict;
Expand Down Expand Up @@ -1189,13 +1195,17 @@ bytesiobuf_getbuffer(PyObject *op, Py_buffer *view, int flags)
return -1;
}

#ifdef Py_GIL_DISABLED
bytesiobuf *obj = bytesiobuf_CAST(op);
bytesio *b = bytesio_CAST(obj->source);
int ret;
Py_BEGIN_CRITICAL_SECTION(b);
ret = bytesiobuf_getbuffer_lock_held(op, view, flags);
Py_END_CRITICAL_SECTION();
return ret;
#else
return bytesiobuf_getbuffer_lock_held(op, view, flags);
#endif
}

static void
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy