Base: Eliminate use of deprecated PyWeakref_GetObject

Co-authored-by: João Matos <joao@tritao.eu>
This commit is contained in:
Chris Hennes
2025-03-22 17:19:11 -05:00
committed by Kacper Donat
parent ebc0dc165d
commit af8a86f6bf

View File

@@ -264,7 +264,16 @@ PyObject* createWeakRef(PyObjectBase* ptr)
PyObjectBase* getFromWeakRef(PyObject* ref)
{
if (ref) {
#if PY_VERSION_HEX >= 0x030d0000
::PyObject* proxy;
int returnCode = PyWeakref_GetRef(ref, &proxy);
if (returnCode != 1) {
return nullptr;
}
Py_DECREF(proxy);
#else
PyObject* proxy = PyWeakref_GetObject(ref);
#endif
if (proxy && PyObject_TypeCheck(proxy, &PyBaseProxyType)) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
return static_cast<PyObjectBase*>(reinterpret_cast<PyBaseProxy*>(proxy)->baseobject);