GH-131904: Fix Py_STACKREF_DEBUG build (GH-132022)

This commit is contained in:
Mark Shannon 2025-04-03 09:40:37 +01:00 committed by GitHub
parent b3e3cc054c
commit 275056a7fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 27 additions and 6 deletions

View file

@ -146,14 +146,15 @@ _PyStackRef_CLOSE(_PyStackRef ref, const char *filename, int linenumber)
#define PyStackRef_CLOSE(REF) _PyStackRef_CLOSE((REF), __FILE__, __LINE__) #define PyStackRef_CLOSE(REF) _PyStackRef_CLOSE((REF), __FILE__, __LINE__)
static inline void static inline void
PyStackRef_XCLOSE(_PyStackRef ref) _PyStackRef_XCLOSE(_PyStackRef ref, const char *filename, int linenumber)
{ {
if (PyStackRef_IsNull(ref)) { if (PyStackRef_IsNull(ref)) {
return; return;
} }
PyObject *obj = _Py_stackref_close(ref); PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
Py_DECREF(obj); Py_DECREF(obj);
} }
#define PyStackRef_XCLOSE(REF) _PyStackRef_XCLOSE((REF), __FILE__, __LINE__)
static inline _PyStackRef static inline _PyStackRef
_PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber) _PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
@ -164,7 +165,8 @@ _PyStackRef_DUP(_PyStackRef ref, const char *filename, int linenumber)
} }
#define PyStackRef_DUP(REF) _PyStackRef_DUP(REF, __FILE__, __LINE__) #define PyStackRef_DUP(REF) _PyStackRef_DUP(REF, __FILE__, __LINE__)
extern void PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct); extern void _PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber);
#define PyStackRef_CLOSE_SPECIALIZED(REF, DESTRUCT) _PyStackRef_CLOSE_SPECIALIZED(REF, DESTRUCT, __FILE__, __LINE__)
static inline _PyStackRef static inline _PyStackRef
PyStackRef_MakeHeapSafe(_PyStackRef ref) PyStackRef_MakeHeapSafe(_PyStackRef ref)
@ -175,7 +177,7 @@ PyStackRef_MakeHeapSafe(_PyStackRef ref)
static inline _PyStackRef static inline _PyStackRef
PyStackRef_Borrow(_PyStackRef ref) PyStackRef_Borrow(_PyStackRef ref)
{ {
return PyStackRef_DUP(ref) return PyStackRef_DUP(ref);
} }
#define PyStackRef_CLEAR(REF) \ #define PyStackRef_CLEAR(REF) \
@ -200,6 +202,18 @@ PyStackRef_IsHeapSafe(_PyStackRef ref)
return true; return true;
} }
static inline _PyStackRef
_PyStackRef_FromPyObjectNewMortal(PyObject *obj, const char *filename, int linenumber)
{
assert(!_Py_IsStaticImmortal(obj));
Py_INCREF(obj);
return _Py_stackref_create(obj, filename, linenumber);
}
#define PyStackRef_FromPyObjectNewMortal(obj) _PyStackRef_FromPyObjectNewMortal(_PyObject_CAST(obj), __FILE__, __LINE__)
#define PyStackRef_RefcountOnObject(REF) 1
extern int PyStackRef_Is(_PyStackRef a, _PyStackRef b);
#else #else
@ -616,6 +630,7 @@ PyStackRef_XCLOSE(_PyStackRef ref)
#define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS))) #define PyStackRef_Is(a, b) (((a).bits & (~Py_TAG_BITS)) == ((b).bits & (~Py_TAG_BITS)))
#endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG) #endif // !defined(Py_GIL_DISABLED) && defined(Py_STACKREF_DEBUG)
#define PyStackRef_TYPE(stackref) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref)) #define PyStackRef_TYPE(stackref) Py_TYPE(PyStackRef_AsPyObjectBorrow(stackref))

View file

@ -55,6 +55,12 @@ _Py_stackref_get_object(_PyStackRef ref)
return entry->obj; return entry->obj;
} }
int
PyStackRef_Is(_PyStackRef a, _PyStackRef b)
{
return _Py_stackref_get_object(a) == _Py_stackref_get_object(b);
}
PyObject * PyObject *
_Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber) _Py_stackref_close(_PyStackRef ref, const char *filename, int linenumber)
{ {
@ -182,9 +188,9 @@ _Py_stackref_report_leaks(PyInterpreterState *interp)
} }
void void
PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct) _PyStackRef_CLOSE_SPECIALIZED(_PyStackRef ref, destructor destruct, const char *filename, int linenumber)
{ {
PyObject *obj = _Py_stackref_close(ref); PyObject *obj = _Py_stackref_close(ref, filename, linenumber);
_Py_DECREF_SPECIALIZED(obj, destruct); _Py_DECREF_SPECIALIZED(obj, destruct);
} }