mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +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
|
@ -73,15 +73,25 @@ PyAPI_FUNC(int) _PyObject_IsFreed(PyObject *);
|
|||
#define _PyObject_HEAD_INIT(type) \
|
||||
{ \
|
||||
.ob_ref_local = _Py_IMMORTAL_REFCNT_LOCAL, \
|
||||
.ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
|
||||
.ob_type = (type) \
|
||||
}
|
||||
#else
|
||||
#if SIZEOF_VOID_P > 4
|
||||
#define _PyObject_HEAD_INIT(type) \
|
||||
{ \
|
||||
.ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
|
||||
.ob_flags = _Py_STATICALLY_ALLOCATED_FLAG, \
|
||||
.ob_type = (type) \
|
||||
}
|
||||
#else
|
||||
#define _PyObject_HEAD_INIT(type) \
|
||||
{ \
|
||||
.ob_refcnt = _Py_IMMORTAL_INITIAL_REFCNT, \
|
||||
.ob_refcnt = _Py_STATIC_IMMORTAL_INITIAL_REFCNT, \
|
||||
.ob_type = (type) \
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
#define _PyVarObject_HEAD_INIT(type, size) \
|
||||
{ \
|
||||
.ob_base = _PyObject_HEAD_INIT(type), \
|
||||
|
@ -127,7 +137,11 @@ static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
|
|||
_Py_AddRefTotal(_PyThreadState_GET(), n);
|
||||
#endif
|
||||
#if !defined(Py_GIL_DISABLED)
|
||||
#if SIZEOF_VOID_P > 4
|
||||
op->ob_refcnt += (PY_UINT32_T)n;
|
||||
#else
|
||||
op->ob_refcnt += n;
|
||||
#endif
|
||||
#else
|
||||
if (_Py_IsOwnedByCurrentThread(op)) {
|
||||
uint32_t local = op->ob_ref_local;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue