GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||
GeezerVison is showing github.com — gh-129107: make bytearrayiter free-threading safe by tom-pytel · Pull Request #130096 · python/cpython Conversation
|
|
This PR is split off of #129108. Ping @kumaraditya303 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
EDIT: Removed, unnecessary critical sections in |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@kumaraditya303 I thought you would do the iterator first and backport it so removed an unnecessary critical section here if static PyObject * bytearrayiter_next(PyObject *self) { bytesiterobject *it = _bytesiterobject_CAST(self); int val; assert(it != NULL); Py_ssize_t index = FT_ATOMIC_LOAD_SSIZE_RELAXED(it->it_index); if (index < 0) { return NULL; } PyByteArrayObject *seq = it->it_seq; assert(PyByteArray_Check(seq)); Py_BEGIN_CRITICAL_SECTION(seq); if (index < PyByteArray_GET_SIZE(seq)) { val = (unsigned char)PyByteArray_AS_STRING(seq)[index]; } else { val = -1; } Py_END_CRITICAL_SECTION(); if (val == -1) { FT_ATOMIC_STORE_SSIZE_RELAXED(it->it_index, -1); #ifndef Py_GIL_DISABLED it->it_seq = NULL; Py_DECREF(seq); #endif return NULL; } FT_ATOMIC_STORE_SSIZE_RELAXED(it->it_index, index + 1); return _PyLong_FromUnsignedChar((unsigned char)val); } Though can also just use |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I don't intend to backport the thread safety of bytearray as change is large and there isn't much point in backporting the iterator while bytearray isn't thread safe. @colesbury Do you think we should backport the thread safety of Yes, it is not safe to read data without acquiring critical section of the seq, you need to add back the critical section, the change to use atomic makes sense. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I probably wouldn't backport the changes. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…e-129107._olg-L.rst Co-authored-by: Kumar Aditya <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM but I would like a review from @colesbury as well.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.