Skip to content

Commit e1bf1f4

Browse files
committed
Check that inline values still valid after taking CS
1 parent 5aa68cc commit e1bf1f4

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Python/specialize.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,7 @@ specialize_inline_values_access_lock_held(
974974
return 0;
975975
}
976976
assert(index >= 0);
977+
assert(_PyObject_InlineValues(owner)->valid);
977978
char *value_addr = (char *)&_PyObject_InlineValues(owner)->values[index];
978979
Py_ssize_t offset = value_addr - (char *)owner;
979980
if (offset != (uint16_t)offset) {
@@ -1036,8 +1037,15 @@ specialize_dict_access(
10361037
!(base_op == STORE_ATTR && _PyObject_GetManagedDict(owner) != NULL))
10371038
{
10381039
Py_BEGIN_CRITICAL_SECTION(owner);
1039-
result = specialize_inline_values_access_lock_held(
1040-
owner, instr, type, tp_version, name, base_op, values_op);
1040+
if (_PyObject_GetManagedDict(owner)) {
1041+
// Somebody materialized the dict
1042+
SPECIALIZATION_FAIL(base_op, SPEC_FAIL_OTHER);
1043+
result = 0;
1044+
}
1045+
else {
1046+
result = specialize_inline_values_access_lock_held(
1047+
owner, instr, type, tp_version, name, base_op, values_op);
1048+
}
10411049
Py_END_CRITICAL_SECTION();
10421050
}
10431051
else {

0 commit comments

Comments
 (0)