Skip to content

Commit

Permalink
fix race on utf8
Browse files Browse the repository at this point in the history
  • Loading branch information
kumaraditya303 committed Dec 17, 2024
1 parent 559e0a1 commit f185a6b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ NOTE: In the interpreter's initialization phase, some globals are currently
(assert(_PyUnicode_CHECK(op)), \
PyUnicode_IS_COMPACT_ASCII(op) ? \
_PyASCIIObject_CAST(op)->length : \
FT_ATOMIC_LOAD_SSIZE(_PyUnicode_UTF8_LENGTH(op)))
FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_UTF8_LENGTH(op)))

#define _PyUnicode_LENGTH(op) \
(_PyASCIIObject_CAST(op)->length)
Expand Down Expand Up @@ -668,15 +668,15 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
CHECK(data != NULL);
if (ascii->state.ascii) {
CHECK(FT_ATOMIC_LOAD_PTR(compact->utf8) == data);
CHECK(FT_ATOMIC_LOAD_SSIZE(compact->utf8_length) == ascii->length);
CHECK(FT_ATOMIC_LOAD_SSIZE_RELAXED(compact->utf8_length) == ascii->length);
}
else {
CHECK(FT_ATOMIC_LOAD_PTR(compact->utf8) != data);
}
}

if (FT_ATOMIC_LOAD_PTR(compact->utf8) == NULL)
CHECK(FT_ATOMIC_LOAD_SSIZE(compact->utf8_length) == ascii->length);
CHECK(FT_ATOMIC_LOAD_SSIZE_RELAXED(compact->utf8_length) == 0);
}

/* check that the best kind is used: O(n) operation */
Expand Down Expand Up @@ -5825,7 +5825,7 @@ unicode_fill_utf8(PyObject *unicode)
assert(!PyUnicode_IS_ASCII(unicode));
int ret = 0;
Py_BEGIN_CRITICAL_SECTION(unicode);
if (FT_ATOMIC_LOAD_PTR_RELAXED(_PyUnicode_UTF8(unicode))) {
if (FT_ATOMIC_LOAD_PTR(_PyUnicode_UTF8(unicode))) {
goto exit;
}
int kind = PyUnicode_KIND(unicode);
Expand Down

0 comments on commit f185a6b

Please sign in to comment.