diff options
| -rw-r--r-- | sources/pyside6/libpyside/dynamicslot.cpp | 2 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384ext.h | 2 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.cpp | 14 | ||||
| -rw-r--r-- | sources/shiboken6/libshiboken/pep384impl.h | 2 |
4 files changed, 19 insertions, 1 deletions
diff --git a/sources/pyside6/libpyside/dynamicslot.cpp b/sources/pyside6/libpyside/dynamicslot.cpp index b25928ea9..b0ae59470 100644 --- a/sources/pyside6/libpyside/dynamicslot.cpp +++ b/sources/pyside6/libpyside/dynamicslot.cpp @@ -150,7 +150,7 @@ TrackingMethodDynamicSlot::~TrackingMethodDynamicSlot() Shiboken::GilState gil; // weakrefs must not be de-refed after the object has been deleted, // else they get negative refcounts. - if (PyWeakref_GetObject(m_weakRef) != Py_None) + if (PepExt_Weakref_IsAlive(m_weakRef)) Py_DECREF(m_weakRef); } } diff --git a/sources/shiboken6/libshiboken/pep384ext.h b/sources/shiboken6/libshiboken/pep384ext.h index 021c53d16..0ce53d3a7 100644 --- a/sources/shiboken6/libshiboken/pep384ext.h +++ b/sources/shiboken6/libshiboken/pep384ext.h @@ -86,4 +86,6 @@ inline void PepExt_TypeCallFree(PyObject *object) PepExt_Type_GetFreeSlot(Py_TYPE(object))(object); } +LIBSHIBOKEN_API bool PepExt_Weakref_IsAlive(PyObject *weakRef); + #endif // PEP384EXT_H diff --git a/sources/shiboken6/libshiboken/pep384impl.cpp b/sources/shiboken6/libshiboken/pep384impl.cpp index eae968c20..283b2f3be 100644 --- a/sources/shiboken6/libshiboken/pep384impl.cpp +++ b/sources/shiboken6/libshiboken/pep384impl.cpp @@ -1299,3 +1299,17 @@ Pep384_Init() } } // extern "C" + +LIBSHIBOKEN_API bool PepExt_Weakref_IsAlive(PyObject *weakRef) +{ +#if defined(Py_LIMITED_API) || PY_VERSION_HEX < 0x030D0000 + return PyWeakref_GetObject(weakRef) != Py_None; +#else + // FIXME: Make this the default code path once Limited API has been raised to 3.13 + // Note: PyWeakref_GetObject() will be removed in 3.15. + PyObject *pobj = nullptr; + const bool result = PyWeakref_GetRef(weakRef, &pobj) == 1; + Py_XDECREF(pobj); + return result; +#endif +} diff --git a/sources/shiboken6/libshiboken/pep384impl.h b/sources/shiboken6/libshiboken/pep384impl.h index 06b24eaf7..0612d05cd 100644 --- a/sources/shiboken6/libshiboken/pep384impl.h +++ b/sources/shiboken6/libshiboken/pep384impl.h @@ -4,6 +4,8 @@ #ifndef PEP384IMPL_H #define PEP384IMPL_H +#include "shibokenmacros.h" + extern "C" { |
