mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
GH-125174: Mark objects as statically allocated. (#127797)
* Set a bit in the unused part of the refcount on 64 bit machines and the free-threaded build. * Use the top of the refcount range on 32 bit machines
This commit is contained in:
parent
dd9da738ad
commit
bc262de06b
7 changed files with 99 additions and 13 deletions
|
@ -71,7 +71,7 @@ whose size is determined when the object is allocated.
|
|||
#define PyObject_HEAD_INIT(type) \
|
||||
{ \
|
||||
0, \
|
||||
0, \
|
||||
_Py_STATICALLY_ALLOCATED_FLAG, \
|
||||
{ 0 }, \
|
||||
0, \
|
||||
_Py_IMMORTAL_REFCNT_LOCAL, \
|
||||
|
@ -81,7 +81,7 @@ whose size is determined when the object is allocated.
|
|||
#else
|
||||
#define PyObject_HEAD_INIT(type) \
|
||||
{ \
|
||||
{ _Py_IMMORTAL_INITIAL_REFCNT }, \
|
||||
{ _Py_STATIC_IMMORTAL_INITIAL_REFCNT }, \
|
||||
(type) \
|
||||
},
|
||||
#endif
|
||||
|
@ -120,9 +120,19 @@ struct _object {
|
|||
__pragma(warning(disable: 4201))
|
||||
#endif
|
||||
union {
|
||||
Py_ssize_t ob_refcnt;
|
||||
#if SIZEOF_VOID_P > 4
|
||||
PY_UINT32_T ob_refcnt_split[2];
|
||||
PY_INT64_T ob_refcnt_full; /* This field is needed for efficient initialization with Clang on ARM */
|
||||
struct {
|
||||
# if PY_BIG_ENDIAN
|
||||
PY_UINT32_T ob_flags;
|
||||
PY_UINT32_T ob_refcnt;
|
||||
# else
|
||||
PY_UINT32_T ob_refcnt;
|
||||
PY_UINT32_T ob_flags;
|
||||
# endif
|
||||
};
|
||||
#else
|
||||
Py_ssize_t ob_refcnt;
|
||||
#endif
|
||||
};
|
||||
#ifdef _MSC_VER
|
||||
|
@ -142,7 +152,7 @@ struct _object {
|
|||
// trashcan mechanism as a linked list pointer and by the GC to store the
|
||||
// computed "gc_refs" refcount.
|
||||
uintptr_t ob_tid;
|
||||
uint16_t _padding;
|
||||
uint16_t ob_flags;
|
||||
PyMutex ob_mutex; // per-object lock
|
||||
uint8_t ob_gc_bits; // gc-related state
|
||||
uint32_t ob_ref_local; // local reference count
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue