From fd3d5802fe620e39cf56b6de110d56685857f962 Mon Sep 17 00:00:00 2001
From: Michele Calgaro <michele.calgaro@yahoo.it>
Date: Fri, 9 Oct 2026 10:22:41 +0900
Subject: Fix FTBFS with python 3.15

This resolves issue #41.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
---
 siplib/tqtlib.c | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/siplib/tqtlib.c b/siplib/tqtlib.c
index 1fa8cfa..26ae879 100644
--- a/siplib/tqtlib.c
+++ b/siplib/tqtlib.c
@@ -115,11 +115,27 @@ PyObject *sip_api_invoke_slot(const sipSlot *slot, PyObject *sigargs)
         Py_INCREF(sref);
     }
     else if (slot -> weakSlot == NULL)
+    {
         sref = NULL;
-    else if ((sref = PyWeakref_GetObject(slot -> weakSlot)) == NULL)
-        return NULL;
+    }
     else
-        Py_INCREF(sref);
+    {
+#if PY_VERSION_HEX >= 0x030D0000
+        if (PyWeakref_GetRef(slot->weakSlot, &sref) <= 0 || sref == NULL)
+        {
+            return NULL;
+        }
+#else
+        if ((sref = PyWeakref_GetObject(slot->weakSlot)) == NULL)
+        {
+            return NULL;
+        }
+        else
+        {
+            Py_INCREF(sref);
+        }
+#endif
+    }
 
     if (sref == Py_None)
     {
-- 
cgit v1.2.3

