From a2b4a751604529e3f10d2de4a3ac21b545c6d369 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 9 Apr 2024 11:29:53 +0100 Subject: [PATCH 1/3] Statically allocated objects are immortal, so make sure they are declared as such. --- Include/object.h | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Include/object.h b/Include/object.h index 13443329dfb5a2..a1183bff920229 100644 --- a/Include/object.h +++ b/Include/object.h @@ -128,19 +128,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) \ { \ From 76a357277473bfca607747fafb51420193a133a5 Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Tue, 9 Apr 2024 11:31:47 +0100 Subject: [PATCH 2/3] Add news --- .../2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst 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..2683e75b73a145 --- /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 should be +marked as such regardless of whether they are in extension modules or not. From d941a188882af8a9ccca54fd5c7b88b99045066c Mon Sep 17 00:00:00 2001 From: Mark Shannon Date: Fri, 12 Apr 2024 14:25:21 +0100 Subject: [PATCH 3/3] Update comment and tweak change note --- Include/object.h | 7 +++++-- .../2024-04-09-11-31-25.gh-issue-115776.5Nthd0.rst | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Include/object.h b/Include/object.h index a1183bff920229..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) \ { \ 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 index 2683e75b73a145..5fc0080bcb9551 100644 --- 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 @@ -1,2 +1,2 @@ -Statically allocated objects are, by definition, immortal so should be +Statically allocated objects are, by definition, immortal so must be marked as such regardless of whether they are in extension modules or not.