Skip to content

Commit fdd4511

Browse files
fix race on utf8
1 parent 454d143 commit fdd4511

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Objects/unicodeobject.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ NOTE: In the interpreter's initialization phase, some globals are currently
125125
(assert(_PyUnicode_CHECK(op)), \
126126
PyUnicode_IS_COMPACT_ASCII(op) ? \
127127
_PyASCIIObject_CAST(op)->length : \
128-
FT_ATOMIC_LOAD_SSIZE(_PyUnicode_UTF8_LENGTH(op)))
128+
FT_ATOMIC_LOAD_SSIZE_RELAXED(_PyUnicode_UTF8_LENGTH(op)))
129129

130130
#define _PyUnicode_LENGTH(op) \
131131
(_PyASCIIObject_CAST(op)->length)
@@ -668,15 +668,15 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
668668
CHECK(data != NULL);
669669
if (ascii->state.ascii) {
670670
CHECK(FT_ATOMIC_LOAD_PTR(compact->utf8) == data);
671-
CHECK(FT_ATOMIC_LOAD_SSIZE(compact->utf8_length) == ascii->length);
671+
CHECK(FT_ATOMIC_LOAD_SSIZE_RELAXED(compact->utf8_length) == ascii->length);
672672
}
673673
else {
674674
CHECK(FT_ATOMIC_LOAD_PTR(compact->utf8) != data);
675675
}
676676
}
677677

678678
if (FT_ATOMIC_LOAD_PTR(compact->utf8) == NULL)
679-
CHECK(FT_ATOMIC_LOAD_SSIZE(compact->utf8_length) == ascii->length);
679+
CHECK(FT_ATOMIC_LOAD_SSIZE_RELAXED(compact->utf8_length) == 0);
680680
}
681681

682682
/* check that the best kind is used: O(n) operation */
@@ -5825,7 +5825,7 @@ unicode_fill_utf8(PyObject *unicode)
58255825
assert(!PyUnicode_IS_ASCII(unicode));
58265826
int ret = 0;
58275827
Py_BEGIN_CRITICAL_SECTION(unicode);
5828-
if (FT_ATOMIC_LOAD_PTR_RELAXED(_PyUnicode_UTF8(unicode))) {
5828+
if (FT_ATOMIC_LOAD_PTR(_PyUnicode_UTF8(unicode))) {
58295829
goto exit;
58305830
}
58315831
int kind = PyUnicode_KIND(unicode);

0 commit comments

Comments
 (0)