Skip to content

Commit 03ea080

Browse files
committed
Make cold exits immortal safely
1 parent 0951d03 commit 03ea080

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Include/internal/pycore_object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
126126
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
127127

128128
extern void _Py_SetImmortal(PyObject *op);
129+
extern void _Py_SetImmortalUntracked(PyObject *op);
129130

130131
// Makes an immortal object mortal again with the specified refcnt. Should only
131132
// be used during runtime finalization.

Objects/object.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2402,11 +2402,8 @@ _Py_NewReferenceNoTotal(PyObject *op)
24022402
}
24032403

24042404
void
2405-
_Py_SetImmortal(PyObject *op)
2405+
_Py_SetImmortalUntracked(PyObject *op)
24062406
{
2407-
if (PyObject_IS_GC(op) && _PyObject_GC_IS_TRACKED(op)) {
2408-
_PyObject_GC_UNTRACK(op);
2409-
}
24102407
#ifdef Py_GIL_DISABLED
24112408
op->ob_tid = _Py_UNOWNED_TID;
24122409
op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL;
@@ -2416,6 +2413,15 @@ _Py_SetImmortal(PyObject *op)
24162413
#endif
24172414
}
24182415

2416+
void
2417+
_Py_SetImmortal(PyObject *op)
2418+
{
2419+
if (PyObject_IS_GC(op) && _PyObject_GC_IS_TRACKED(op)) {
2420+
_PyObject_GC_UNTRACK(op);
2421+
}
2422+
_Py_SetImmortalUntracked(op);
2423+
}
2424+
24192425
void
24202426
_Py_ResurrectReference(PyObject *op)
24212427
{

Python/optimizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ make_executor_from_uops(_PyUOpInstruction *buffer, const _PyBloomFilter *depende
969969
static int
970970
init_cold_exit_executor(_PyExecutorObject *executor, int oparg)
971971
{
972-
_Py_SetImmortal((PyObject *)executor);
972+
_Py_SetImmortalUntracked((PyObject *)executor);
973973
Py_SET_TYPE(executor, &_PyUOpExecutor_Type);
974974
executor->trace = (_PyUOpInstruction *)executor->exits;
975975
executor->code_size = 1;

0 commit comments

Comments
 (0)