Mailing List Archive

GH-115776: Static object are immortal, so mark them as such. (GH-117673)
https://github.com/python/cpython/commit/c053d52edd1e05ccc339e380b705749a3240d645
commit: c053d52edd1e05ccc339e380b705749a3240d645
branch: main
author: Mark Shannon <mark@hotpy.org>
committer: markshannon <mark@hotpy.org>
date: 2024-04-16T12:51:41+01:00
summary:

GH-115776: Static object are immortal, so mark them as such. (GH-117673)

files:
A Misc/NEWS.d/next/Core and Builtins/2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst
M Include/object.h

diff --git a/Include/object.h b/Include/object.h
index 13443329dfb5a2..ffcacf1a3ef4ed 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -115,8 +115,11 @@ check by comparing the reference count field to the immortality reference count.
// Kept for backward compatibility. It was needed by Py_TRACE_REFS build.
#define _PyObject_EXTRA_INIT

-// Make all internal uses of PyObject_HEAD_INIT immortal while preserving the
-// C-API expectation that the refcnt will be set to 1.
+/* Make all uses of PyObject_HEAD_INIT immortal.
+ *
+ * Statically allocated objects might be shared between
+ * interpreters, so must be marked as immortal.
+ */
#if defined(Py_GIL_DISABLED)
#define PyObject_HEAD_INIT(type) \
{ \
@@ -128,19 +131,13 @@ check by comparing the reference count field to the immortality reference count.
0, \
(type), \
},
-#elif defined(Py_BUILD_CORE)
+#else
#define PyObject_HEAD_INIT(type) \
{ \
{ _Py_IMMORTAL_REFCNT }, \
(type) \
},
-#else
-#define PyObject_HEAD_INIT(type) \
- { \
- { 1 }, \
- (type) \
- },
-#endif /* Py_BUILD_CORE */
+#endif

#define PyVarObject_HEAD_INIT(type, size) \
{ \
diff --git a/Misc/NEWS.d/next/Core and Builtins/2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst b/Misc/NEWS.d/next/Core and Builtins/2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst
new file mode 100644
index 00000000000000..5fc0080bcb9551
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst
@@ -0,0 +1,2 @@
+Statically allocated objects are, by definition, immortal so must be
+marked as such regardless of whether they are in extension modules or not.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-leave@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: list-python-checkins@lists.gossamer-threads.com