Skip to content

Commit 623fb87

Browse files
Move non-isolated immortal objects to the right ref chain.
1 parent 884f398 commit 623fb87

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

Diff for: Objects/object.c

+18
Original file line numberDiff line numberDiff line change
@@ -2491,6 +2491,24 @@ _Py_ResurrectReference(PyObject *op)
24912491

24922492

24932493
#ifdef Py_TRACE_REFS
2494+
void
2495+
_Py_NormalizeImmortalReference(PyObject *op)
2496+
{
2497+
assert(_Py_IsImmortal(op));
2498+
PyInterpreterState *interp = _PyInterpreterState_GET();
2499+
if (!_PyRefchain_IsTraced(interp, op)) {
2500+
return;
2501+
}
2502+
PyInterpreterState *main_interp = _PyInterpreterState_Main();
2503+
if (interp != main_interp
2504+
&& interp->feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC)
2505+
{
2506+
assert(!_PyRefchain_IsTraced(main_interp, op));
2507+
_PyRefchain_Remove(interp, op);
2508+
_PyRefchain_Trace(main_interp, op);
2509+
}
2510+
}
2511+
24942512
void
24952513
_Py_ForgetReference(PyObject *op)
24962514
{

Diff for: Objects/unicodeobject.c

+7
Original file line numberDiff line numberDiff line change
@@ -15437,6 +15437,10 @@ _PyUnicode_InternStatic(PyInterpreterState *interp, PyObject **p)
1543715437
assert(*p);
1543815438
}
1543915439

15440+
#ifdef Py_TRACE_REFS
15441+
extern void _Py_NormalizeImmortalReference(PyObject *);
15442+
#endif
15443+
1544015444
static void
1544115445
immortalize_interned(PyObject *s)
1544215446
{
@@ -15452,6 +15456,9 @@ immortalize_interned(PyObject *s)
1545215456
#endif
1545315457
_PyUnicode_STATE(s).interned = SSTATE_INTERNED_IMMORTAL;
1545415458
_Py_SetImmortal(s);
15459+
#ifdef Py_TRACE_REFS
15460+
_Py_NormalizeImmortalReference(s);
15461+
#endif
1545515462
}
1545615463

1545715464
static /* non-null */ PyObject*

0 commit comments

Comments
 (0)