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

This commit is contained in:
Mark Shannon 2024-04-16 12:51:41 +01:00 committed by GitHub
parent cff0a2db00
commit c053d52edd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 10 deletions

View File

@ -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) \
{ \

View File

@ -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.