From af8a86f6bfaa5c8d943ce7424e4879977a910647 Mon Sep 17 00:00:00 2001 From: Chris Hennes Date: Sat, 22 Mar 2025 17:19:11 -0500 Subject: [PATCH] Base: Eliminate use of deprecated PyWeakref_GetObject MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: João Matos --- src/Base/PyObjectBase.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/Base/PyObjectBase.cpp b/src/Base/PyObjectBase.cpp index 5ecfcb64a2..a90ac36e88 100644 --- a/src/Base/PyObjectBase.cpp +++ b/src/Base/PyObjectBase.cpp @@ -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(reinterpret_cast(proxy)->baseobject);