summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMark Shannon <mark@hotpy.org>2024-03-20 08:54:42 (GMT)
committerGitHub <noreply@github.com>2024-03-20 08:54:42 (GMT)
commit15309329b65a285cb7b3071f0f08ac964b61411b (patch)
tree83b5be564755d7ea396c76eda29e6d33faf535d9 /Objects
parentd5ebf8b71fd18d7a1f2f6b670a2c18749dc2b55e (diff)
downloadcpython-15309329b65a285cb7b3071f0f08ac964b61411b.zip
cpython-15309329b65a285cb7b3071f0f08ac964b61411b.tar.gz
cpython-15309329b65a285cb7b3071f0f08ac964b61411b.tar.bz2
GH-108362: Incremental Cycle GC (GH-116206)
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c21
-rw-r--r--Objects/structseq.c5
2 files changed, 25 insertions, 1 deletions
diff --git a/Objects/object.c b/Objects/object.c
index df14fe0..fcb8cf4 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -2402,6 +2402,27 @@ _Py_NewReferenceNoTotal(PyObject *op)
}
void
+_Py_SetImmortalUntracked(PyObject *op)
+{
+#ifdef Py_GIL_DISABLED
+ op->ob_tid = _Py_UNOWNED_TID;
+ op->ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL;
+ op->ob_ref_shared = 0;
+#else
+ op->ob_refcnt = _Py_IMMORTAL_REFCNT;
+#endif
+}
+
+void
+_Py_SetImmortal(PyObject *op)
+{
+ if (PyObject_IS_GC(op) && _PyObject_GC_IS_TRACKED(op)) {
+ _PyObject_GC_UNTRACK(op);
+ }
+ _Py_SetImmortalUntracked(op);
+}
+
+void
_Py_ResurrectReference(PyObject *op)
{
if (_PyRuntime.tracemalloc.config.tracing) {
diff --git a/Objects/structseq.c b/Objects/structseq.c
index 581d6ad..661d96a 100644
--- a/Objects/structseq.c
+++ b/Objects/structseq.c
@@ -603,6 +603,9 @@ _PyStructSequence_InitBuiltinWithFlags(PyInterpreterState *interp,
PyStructSequence_Desc *desc,
unsigned long tp_flags)
{
+ if (Py_TYPE(type) == NULL) {
+ Py_SET_TYPE(type, &PyType_Type);
+ }
Py_ssize_t n_unnamed_members;
Py_ssize_t n_members = count_members(desc, &n_unnamed_members);
PyMemberDef *members = NULL;
@@ -618,7 +621,7 @@ _PyStructSequence_InitBuiltinWithFlags(PyInterpreterState *interp,
}
initialize_static_fields(type, desc, members, tp_flags);
- _Py_SetImmortal(type);
+ _Py_SetImmortal((PyObject *)type);
}
#ifndef NDEBUG
else {