Skip to content

Commit d8212c2

Browse files
committed
gh-154930: Use atomic loads in UnicodeDecodeError.__str__
1 parent 4bbc20b commit d8212c2

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use atomic loads for ``UnicodeDecodeError.start`` and
2+
``UnicodeDecodeError.end`` in ``UnicodeDecodeError.__str__()`` to avoid a
3+
data race in free-threaded builds.

Objects/exceptions.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3945,7 +3945,8 @@ UnicodeDecodeError_str(PyObject *self)
39453945
goto done;
39463946
}
39473947
Py_ssize_t len = PyBytes_GET_SIZE(exc->object);
3948-
Py_ssize_t start = exc->start, end = exc->end;
3948+
Py_ssize_t start = FT_ATOMIC_LOAD_SSIZE_RELAXED(exc->start);
3949+
Py_ssize_t end = FT_ATOMIC_LOAD_SSIZE_RELAXED(exc->end);
39493950

39503951
if ((start >= 0 && start < len) && (end >= 0 && end <= len) && end == start + 1) {
39513952
int badbyte = (int)(PyBytes_AS_STRING(exc->object)[start] & 0xff);

0 commit comments

Comments
 (0)