diff options
author | Sam Gross <colesbury@gmail.com> | 2024-11-26 21:46:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-26 21:46:06 (GMT) |
commit | 71ede1142ddad2d31cc966b8fe4a5aff664f4d53 (patch) | |
tree | c8e17fd89be977bf04ffd1c01b352c4bbcb191f5 /Python/generated_cases.c.h | |
parent | f0d3f10c43c9029378adba11a65b3d1287e4be32 (diff) | |
download | cpython-71ede1142ddad2d31cc966b8fe4a5aff664f4d53.zip cpython-71ede1142ddad2d31cc966b8fe4a5aff664f4d53.tar.gz cpython-71ede1142ddad2d31cc966b8fe4a5aff664f4d53.tar.bz2 |
gh-115999: Add free-threaded specialization for `STORE_SUBSCR` (#127169)
The specialization only depends on the type, so no special thread-safety
considerations there.
STORE_SUBSCR_LIST_INT needs to lock the list before modifying it.
`_PyDict_SetItem_Take2` already internally locks the dictionary using a
critical section.
Diffstat (limited to 'Python/generated_cases.c.h')
-rw-r--r-- | Python/generated_cases.c.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 36ec727..c9a5132 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7629,7 +7629,7 @@ container = stack_pointer[-2]; uint16_t counter = read_u16(&this_instr[1].cache); (void)counter; - #if ENABLE_SPECIALIZATION + #if ENABLE_SPECIALIZATION_FT if (ADAPTIVE_COUNTER_TRIGGERS(counter)) { next_instr = this_instr; _PyFrame_SetStackPointer(frame, stack_pointer); @@ -7639,7 +7639,7 @@ } OPCODE_DEFERRED_INC(STORE_SUBSCR); ADVANCE_ADAPTIVE_COUNTER(this_instr[1].counter); - #endif /* ENABLE_SPECIALIZATION */ + #endif /* ENABLE_SPECIALIZATION_FT */ } // _STORE_SUBSCR { @@ -7704,12 +7704,17 @@ // Ensure nonnegative, zero-or-one-digit ints. DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub), STORE_SUBSCR); Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0]; + DEOPT_IF(!LOCK_OBJECT(list), STORE_SUBSCR); // Ensure index < len(list) - DEOPT_IF(index >= PyList_GET_SIZE(list), STORE_SUBSCR); + if (index >= PyList_GET_SIZE(list)) { + UNLOCK_OBJECT(list); + DEOPT_IF(true, STORE_SUBSCR); + } STAT_INC(STORE_SUBSCR, hit); PyObject *old_value = PyList_GET_ITEM(list, index); PyList_SET_ITEM(list, index, PyStackRef_AsPyObjectSteal(value)); assert(old_value != NULL); + UNLOCK_OBJECT(list); // unlock before decrefs! Py_DECREF(old_value); PyStackRef_CLOSE_SPECIALIZED(sub_st, (destructor)PyObject_Free); PyStackRef_CLOSE(list_st); |