GH-143026: Fix assertion error in executor management. (GH-143104)

This commit is contained in:
Mark Shannon 2025-12-23 17:19:34 +00:00 committed by GitHub
parent 25c294b6ea
commit 20aeb3a463
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 28 additions and 28 deletions

View file

@ -252,25 +252,6 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
}
}
static inline void
_Py_DECREF_NO_DEALLOC(PyObject *op)
{
if (_Py_IsImmortal(op)) {
_Py_DECREF_IMMORTAL_STAT_INC();
return;
}
_Py_DECREF_STAT_INC();
#ifdef Py_REF_DEBUG
_Py_DEC_REFTOTAL(PyInterpreterState_Get());
#endif
op->ob_refcnt--;
#ifdef Py_DEBUG
if (op->ob_refcnt <= 0) {
_Py_FatalRefcountError("Expected a positive remaining refcount");
}
#endif
}
#else
// TODO: implement Py_DECREF specializations for Py_GIL_DISABLED build
static inline void
@ -279,12 +260,6 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
Py_DECREF(op);
}
static inline void
_Py_DECREF_NO_DEALLOC(PyObject *op)
{
Py_DECREF(op);
}
static inline int
_Py_REF_IS_MERGED(Py_ssize_t ob_ref_shared)
{

View file

@ -27,6 +27,7 @@ typedef struct {
uint8_t valid;
uint8_t chain_depth; // Must be big enough for MAX_CHAIN_DEPTH - 1.
bool warm;
uint8_t pending_deletion;
int32_t index; // Index of ENTER_EXECUTOR (if code isn't NULL, below).
_PyBloomFilter bloom;
_PyExecutorLinkListNode links;

View file

@ -3114,6 +3114,26 @@ def testfunc(n):
self.assertNotIn("_POP_TOP_INT", uops)
self.assertIn("_POP_TOP_NOP", uops)
def test_143026(self):
# https://github.com/python/cpython/issues/143026
result = script_helper.run_python_until_end('-c', textwrap.dedent("""
import gc
thresholds = gc.get_threshold()
try:
gc.set_threshold(1)
def f1():
for i in range(5000):
globals()[''] = i
f1()
finally:
gc.set_threshold(*thresholds)
"""), PYTHON_JIT="1")
self.assertEqual(result[0].rc, 0, result)
def global_identity(x):
return x

View file

@ -310,7 +310,7 @@ _Py_ClearExecutorDeletionList(PyInterpreterState *interp)
while (ts) {
_PyExecutorObject *current = (_PyExecutorObject *)ts->current_executor;
if (current != NULL) {
_Py_DECREF_NO_DEALLOC((PyObject *)current);
Py_DECREF((PyObject *)current);
}
ts = ts->next;
}
@ -320,6 +320,10 @@ _Py_ClearExecutorDeletionList(PyInterpreterState *interp)
static void
add_to_pending_deletion_list(_PyExecutorObject *self)
{
if (self->vm_data.pending_deletion) {
return;
}
self->vm_data.pending_deletion = 1;
PyInterpreterState *interp = PyInterpreterState_Get();
self->vm_data.links.previous = NULL;
self->vm_data.links.next = interp->executor_deletion_list_head;
@ -627,7 +631,7 @@ _PyJit_translate_single_bytecode_to_trace(
uint32_t target = 0;
target = Py_IsNone((PyObject *)old_code)
? (int)(target_instr - _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS_PTR)
? (uint32_t)(target_instr - _Py_INTERPRETER_TRAMPOLINE_INSTRUCTIONS_PTR)
: INSTR_IP(target_instr, old_code);
// Rewind EXTENDED_ARG so that we see the whole thing.
@ -1666,6 +1670,7 @@ void
_Py_ExecutorInit(_PyExecutorObject *executor, const _PyBloomFilter *dependency_set)
{
executor->vm_data.valid = true;
executor->vm_data.pending_deletion = 0;
for (int i = 0; i < _Py_BLOOM_FILTER_WORDS; i++) {
executor->vm_data.bloom.bits[i] = dependency_set->bits[i];
}

View file

@ -673,7 +673,6 @@ def has_error_without_pop(op: parser.CodeDef) -> bool:
"_PyUnicode_Equal",
"_PyUnicode_JoinArray",
"_Py_CHECK_EMSCRIPTEN_SIGNALS_PERIODICALLY",
"_Py_DECREF_NO_DEALLOC",
"_Py_ID",
"_Py_IsImmortal",
"_Py_IsOwnedByCurrentThread",