Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
{ \
Expand All @@ -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) \
{ \
Expand Down
Original file line number Diff line number Diff line change
@@ -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.