From f2e10eb84ea608a534f47de7339839ecac021806 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 19 Apr 2024 18:45:13 -0700 Subject: [PATCH] Executors in the COLD_EXITS array are not GC'able Implement a `tp_is_gc` slot that tests for this. --- Python/optimizer.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Python/optimizer.c b/Python/optimizer.c index bb537c9111a51f..ab343ff126a2c6 100644 --- a/Python/optimizer.c +++ b/Python/optimizer.c @@ -394,6 +394,15 @@ executor_traverse(PyObject *o, visitproc visit, void *arg) return 0; } +static int +executor_is_gc(PyObject *o) +{ + if ((void*)COLD_EXITS <= (void*)o && (void*)o < (void*)COLD_EXITS + UOP_MAX_TRACE_LENGTH) { + return 0; + } + return 1; +} + PyTypeObject _PyUOpExecutor_Type = { PyVarObject_HEAD_INIT(&PyType_Type, 0) .tp_name = "uop_executor", @@ -405,6 +414,7 @@ PyTypeObject _PyUOpExecutor_Type = { .tp_methods = executor_methods, .tp_traverse = executor_traverse, .tp_clear = executor_clear, + .tp_is_gc = executor_is_gc, }; /* TO DO -- Generate these tables */