Skip to content
Prev Previous commit
cleanup
  • Loading branch information
Fidget-Spinner committed Jul 17, 2024
commit a058c345ce90f044ed4bd3691f84c0b78408f6d9
20 changes: 7 additions & 13 deletions Include/internal/pycore_stackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ typedef union _PyStackRef {
uintptr_t bits;
} _PyStackRef;

struct _Py_stackref_entry {
PyObject *obj;
int is_live;
};

struct _Py_stackref_state {
PyMutex lock;
_Py_hashtable_t *entries;
Expand Down Expand Up @@ -118,7 +113,7 @@ PyAPI_FUNC(_PyStackRef) _PyStackRef_Dup(_PyStackRef stackref);
static const _PyStackRef PyStackRef_None = { .bits = 3 << RESERVED_BITS };
# else
# define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) | Py_TAG_DEFERRED })
#endif
# endif
#else
# define PyStackRef_None ((_PyStackRef){.bits = ((uintptr_t)&_Py_NoneStruct) })
#endif
Expand All @@ -128,15 +123,15 @@ PyAPI_FUNC(_PyStackRef) _PyStackRef_Dup(_PyStackRef stackref);
#ifdef Py_GIL_DISABLED
static inline int
PyStackRef_Is(_PyStackRef a, _PyStackRef b) {
# if defined(Py_STACKREF_DEBUG)
# ifdef Py_STACKREF_DEBUG
// Note: stackrefs are unique. So even immortal objects will produce different stackrefs.
return _Py_stackref_to_object_transition(a, BORROW) == _Py_stackref_to_object_transition(b, BORROW);
# else
return a.bits == b.bits;
# endif
}
#else
#define PyStackRef_Is(a, b) ((a).bits == (b).bits)
# define PyStackRef_Is(a, b) ((a).bits == (b).bits)
#endif

static inline int
Expand All @@ -154,7 +149,7 @@ PyStackRef_IsNull(_PyStackRef stackref)
static inline PyObject *
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
{
# if defined(Py_STACKREF_DEBUG)
# ifdef Py_STACKREF_DEBUG
return _Py_stackref_to_object_transition(stackref, BORROW);
# else
PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
Expand All @@ -171,14 +166,14 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
static inline PyObject *
PyStackRef_AsPyObjectSteal(_PyStackRef stackref)
{
#ifdef Py_STACKREF_DEBUG
# ifdef Py_STACKREF_DEBUG
return _Py_stackref_to_object_transition(stackref, STEAL);
#else
# else
if (!PyStackRef_IsNull(stackref) && PyStackRef_IsDeferred(stackref)) {
return Py_NewRef(PyStackRef_AsPyObjectBorrow(stackref));
}
return PyStackRef_AsPyObjectBorrow(stackref);
#endif
# endif
}
#else
# define PyStackRef_AsPyObjectSteal(stackref) PyStackRef_AsPyObjectBorrow(stackref)
Expand Down Expand Up @@ -301,7 +296,6 @@ PyStackRef_CLOSE(_PyStackRef stackref)
static inline _PyStackRef
PyStackRef_DUP(_PyStackRef stackref)
{
#ifdef Py_GIL_DISABLED
# ifdef Py_STACKREF_DEBUG
stackref = _PyStackRef_Dup(stackref);
# endif
Expand Down