Skip to content

Commit 1b85b34

Browse files
authored
GH-118074: Executors in the COLD_EXITS array are not GC'able (#118117)
1 parent fc21c7f commit 1b85b34

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Make sure that the Executor objects in the COLD_EXITS array aren't assumed
2+
to be GC-able (which would access bytes outside the object).

Python/optimizer.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,15 @@ executor_traverse(PyObject *o, visitproc visit, void *arg)
394394
return 0;
395395
}
396396

397+
static int
398+
executor_is_gc(PyObject *o)
399+
{
400+
if ((PyObject *)&COLD_EXITS[0] <= o && o < (PyObject *)&COLD_EXITS[COLD_EXIT_COUNT]) {
401+
return 0;
402+
}
403+
return 1;
404+
}
405+
397406
PyTypeObject _PyUOpExecutor_Type = {
398407
PyVarObject_HEAD_INIT(&PyType_Type, 0)
399408
.tp_name = "uop_executor",
@@ -405,6 +414,7 @@ PyTypeObject _PyUOpExecutor_Type = {
405414
.tp_methods = executor_methods,
406415
.tp_traverse = executor_traverse,
407416
.tp_clear = executor_clear,
417+
.tp_is_gc = executor_is_gc,
408418
};
409419

410420
/* TO DO -- Generate these tables */

0 commit comments

Comments
 (0)