8000 gh-117139: A StackRef Debugging Mode by Fidget-Spinner · Pull Request #121134 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-117139: A StackRef Debugging Mode #121134

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

Closed
wants to merge 11 commits into from
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/main' into stackref_debug_real
  • Loading branch information
Fidget-Spinner committed Jul 17, 2024
commit a6e6576585513483379599ae5aa18fb24f9dde52
34 changes: 10 additions & 24 deletions Include/internal/pycore_stackref.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,27 @@ PyAPI_FUNC(_PyStackRef) _PyStackRef_Dup(_PyStackRef stackref);

// Note: the following are all macros because MSVC (Windows) has trouble inlining them.

#ifdef Py_GIL_DISABLED
static inline int
PyStackRef_Is(_PyStackRef a, _PyStackRef b) {
#if defined(Py_STACKREF_DEBUG) && defined(Py_GIL_DISABLED)
# if defined(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
# else
return a.bits == b.bits;
#endif
# endif
}
#else
#define PyStackRef_Is(a, b) ((a).bits == (b).bits)
#endif

static inline int
PyStackRef_IsNull(_PyStackRef stackref)
{
return PyStackRef_Is(stackref, PyStackRef_NULL);
}


#define PyStackRef_IsDeferred(ref) (((ref).bits & Py_TAG_BITS) == Py_TAG_DEFERRED)


Expand All @@ -149,17 +154,12 @@ PyStackRef_IsNull(_PyStackRef stackref)
static inline PyObject *
PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
{
#ifdef Py_GIL_DISABLED
# if defined(Py_STACKREF_DEBUG)
return _Py_stackref_to_object_transition(stackref, BORROW);
# else
PyObject *cleared = ((PyObject *)((stackref).bits & (~Py_TAG_BITS)));
return cleared;
# endif

#else
return ((PyObject *)(stackref).bits);
#endif
}
#else
# define PyStackRef_AsPyObjectBorrow(stackref) ((PyObject *)(stackref).bits)
Expand All @@ -171,17 +171,13 @@ PyStackRef_AsPyObjectBorrow(_PyStackRef stackref)
static inline PyObject *
PyStackRef_AsPyObjectSteal(_PyStackRef stackref)
{
#ifdef Py_GIL_DISABLED
# 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
#else
return PyStackRef_AsPyObjectBorrow(stackref);
#endif
}
#else
Expand All @@ -207,9 +203,6 @@ _PyStackRef_FromPyObjectSteal(PyObject *obj)
# else
return ((_PyStackRef){.bits = ((uintptr_t)(obj)) | tag});
# endif
#else
return ((_PyStackRef){.bits = ((uintptr_t)(obj))});
#endif
}
# define PyStackRef_FromPyObjectSteal(obj) _PyStackRef_FromPyObjectSteal(_PyObject_CAST(obj))
#else
Expand Down Expand Up @@ -260,10 +253,6 @@ PyStackRef_FromPyObjectImmortal(PyObject *obj)
# else
return (_PyStackRef){ .bits = (uintptr_t)obj | Py_TAG_DEFERRED };
# endif
#else
assert(_Py_IsImmortal(obj));
return ((_PyStackRef){ .bits = (uintptr_t)(obj) });
#endif
}
# define PyStackRef_FromPyObjectImmortal(obj) PyStackRef_FromPyObjectImmortal(_PyObject_CAST(obj))
#else
Expand Down Expand Up @@ -294,9 +283,6 @@ PyStackRef_CLOSE(_PyStackRef stackref)
# ifdef Py_STACKREF_DEBUG
_PyStackRef_Close(stackref);
# endif
#else
Py_DECREF(PyStackRef_AsPyObjectBorrow(stackref));
#endif
}
#else
# define PyStackRef_CLOSE(stackref) Py_DECREF(PyStackRef_AsPyObjectBorrow(stackref));
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0