Skip to content

Commit 2b53423

Browse files
committed
Only track on replace
1 parent 64c20ff commit 2b53423

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

‎Objects/codeobject.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,8 +754,8 @@ _PyCode_New(struct _PyCodeConstructor *con)
754754

755755
#ifdef Py_GIL_DISABLED
756756
co->_co_unique_id = _PyObject_AssignUniqueId((PyObject *)co);
757-
#endif
758757
_PyObject_GC_TRACK(co);
758+
#endif
759759
Py_XDECREF(replacement_locations);
760760
return co;
761761
}
@@ -2827,6 +2827,11 @@ code_replace_impl(PyCodeObject *self, int co_argcount,
28272827
co_qualname, co_firstlineno,
28282828
co_linetable, co_exceptiontable);
28292829

2830+
#ifndef Py_GC_DISABLED
2831+
// not tracked by default w/ GIL, but replace can create cycles
2832+
_PyObject_GC_TRACK(co);
2833+
#endif
2834+
28302835
error:
28312836
Py_XDECREF(code);
28322837
Py_XDECREF(varnames);

0 commit comments

Comments
 (0)