From 43941a6575eb6c3a7d724c82c1f09392587b9aa5 Mon Sep 17 00:00:00 2001
From: Alexander Golubev <fatzer2@gmail.com>
Date: Sat, 26 Jul 2025 18:53:39 +0300
Subject: dev-python/sip4-tqt: fix FTBFS in stables

Also add missing python_optimize.

Bug: https://mirror.git.trinitydesktop.org/gitea/TDE/tde-packaging-gentoo/issues/405
Signed-off-by: Alexander Golubev <fatzer2@gmail.com>
---
 ...-14.1.2-Added-prototype-of-yylex-function.patch |  27 +++++
 ...ip4-tqt-14.1.2-Fix-FTBFS-with-Python-3.13.patch | 116 +++++++++++++++++++++
 dev-python/sip4-tqt/sip4-tqt-14.1.1-r1.ebuild      |  55 ++++++++++
 dev-python/sip4-tqt/sip4-tqt-14.1.1.ebuild         |  49 ---------
 dev-python/sip4-tqt/sip4-tqt-14.1.2-r1.ebuild      |  55 ++++++++++
 dev-python/sip4-tqt/sip4-tqt-14.1.2.ebuild         |  49 ---------
 dev-python/sip4-tqt/sip4-tqt-9999.ebuild           |   5 +-
 7 files changed, 256 insertions(+), 100 deletions(-)
 create mode 100644 dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Added-prototype-of-yylex-function.patch
 create mode 100644 dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Fix-FTBFS-with-Python-3.13.patch
 create mode 100644 dev-python/sip4-tqt/sip4-tqt-14.1.1-r1.ebuild
 delete mode 100644 dev-python/sip4-tqt/sip4-tqt-14.1.1.ebuild
 create mode 100644 dev-python/sip4-tqt/sip4-tqt-14.1.2-r1.ebuild
 delete mode 100644 dev-python/sip4-tqt/sip4-tqt-14.1.2.ebuild

diff --git a/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Added-prototype-of-yylex-function.patch b/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Added-prototype-of-yylex-function.patch
new file mode 100644
index 00000000..6b511623
--- /dev/null
+++ b/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Added-prototype-of-yylex-function.patch
@@ -0,0 +1,27 @@
+From 7f3c0748d4c8d3c601a3ff1c6913e6fc6ea4cfcd Mon Sep 17 00:00:00 2001
+From: ormorph <roma251078@mail.ru>
+Date: Tue, 16 Jul 2024 16:50:34 +0300
+Subject: [PATCH 1/9] Added prototype of yylex() function Required for building
+ with the new gcc-14
+
+Signed-off-by: ormorph <roma251078@mail.ru>
+(cherry picked from commit dc7ba7a6d7019e4cd4fc2f33fbee4ec53ff8420a)
+---
+ sipgen/parser.y | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/sipgen/parser.y b/sipgen/parser.y
+index 2ed1b4e..05a12c1 100644
+--- a/sipgen/parser.y
++++ b/sipgen/parser.y
+@@ -24,6 +24,7 @@
+ #include "sip.h"
+ 
+ void yyerror(char* s);
++int yylex();
+ 
+ #define MAX_NESTED_IF       10
+ #define MAX_NESTED_SCOPE    10
+-- 
+2.49.1
+
diff --git a/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Fix-FTBFS-with-Python-3.13.patch b/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Fix-FTBFS-with-Python-3.13.patch
new file mode 100644
index 00000000..f2901957
--- /dev/null
+++ b/dev-python/sip4-tqt/files/sip4-tqt-14.1.2-Fix-FTBFS-with-Python-3.13.patch
@@ -0,0 +1,116 @@
+From fa5e4646122884c24513931d95b363ee47f62520 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Fran=C3=A7ois=20Andriot?= <francois.andriot@thalesgroup.com>
+Date: Wed, 25 Sep 2024 20:51:56 +0200
+Subject: [PATCH] Fix FTBFS with Python 3.13. This solves issue #26.
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: François Andriot <albator78@libertysurf.fr>
+(cherry picked from commit 4ab9fdc0fc73f41d54bab0c9030d9645ac0bf18e)
+---
+ siplib/siplib.c | 50 +++++++++++++++++++++++++++++++++++++++----------
+ siplib/tqtlib.c |  2 +-
+ 2 files changed, 41 insertions(+), 11 deletions(-)
+
+diff --git a/siplib/siplib.c b/siplib/siplib.c
+index f2ac7be..27b9e35 100644
+--- a/siplib/siplib.c
++++ b/siplib/siplib.c
+@@ -1691,7 +1691,7 @@ static PyObject *sip_api_call_method(int *isErr, PyObject *method,
+     va_start(va,fmt);
+ 
+     if ((args = PyTuple_New(strlen(fmt))) != NULL && buildObject(args,fmt,va) != NULL)
+-        res = PyEval_CallObject(method,args);
++        res = PyObject_CallObject(method,args);
+     else
+     {
+         res = NULL;
+@@ -9635,18 +9635,37 @@ static PyObject *parseString_AsEncodedString(PyObject *bytes, PyObject *obj,
+ static int parseBytes_AsCharArray(PyObject *obj, const char **ap,
+         SIP_SSIZE_T *aszp)
+ {
++    const char *a;
++    SIP_SSIZE_T asz;
++
+     if (obj == Py_None)
+     {
+-        *ap = NULL;
+-        *aszp = 0;
++        a = NULL;
++        asz = 0;
+     }
+     else if (PyBytes_Check(obj))
+     {
+-        *ap = PyBytes_AS_STRING(obj);
+-        *aszp = PyBytes_GET_SIZE(obj);
++        a = PyBytes_AS_STRING(obj);
++        asz = PyBytes_GET_SIZE(obj);
+     }
+-    else if (PyObject_AsCharBuffer(obj, ap, aszp) < 0)
+-        return -1;
++    else
++    {
++        Py_buffer view;
++
++        if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) < 0)
++            return -1;
++
++        a = view.buf;
++        asz = view.len;
++
++        PyBuffer_Release(&view);
++    }
++
++    if (ap)
++        *ap = a;
++
++    if (aszp)
++        *aszp = asz;
+ 
+     return 0;
+ }
+@@ -9665,13 +9684,24 @@ static int parseBytes_AsChar(PyObject *obj, char *ap)
+         chp = PyBytes_AS_STRING(obj);
+         sz = PyBytes_GET_SIZE(obj);
+     }
+-    else if (PyObject_AsCharBuffer(obj, &chp, &sz) < 0)
+-        return -1;
++    else
++    {
++        Py_buffer view;
++
++        if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) < 0)
++            return -1;
++
++        chp = view.buf;
++        sz = view.len;
++
++        PyBuffer_Release(&view);
++    }
+ 
+     if (sz != 1)
+         return -1;
+ 
+-    *ap = *chp;
++    if (ap)
++        *ap = *chp;
+ 
+     return 0;
+ }
+diff --git a/siplib/tqtlib.c b/siplib/tqtlib.c
+index d59c138..1fa8cfa 100644
+--- a/siplib/tqtlib.c
++++ b/siplib/tqtlib.c
+@@ -196,7 +196,7 @@ PyObject *sip_api_invoke_slot(const sipSlot *slot, PyObject *sigargs)
+     {
+         PyObject *nsa, *xtype, *xvalue, *xtb, *resobj;
+ 
+-        if ((resobj = PyEval_CallObject(sfunc, sa)) != NULL)
++        if ((resobj = PyObject_CallObject(sfunc, sa)) != NULL)
+         {
+             Py_DECREF(sfunc);
+             Py_XDECREF(sref);
+-- 
+2.49.1
+
diff --git a/dev-python/sip4-tqt/sip4-tqt-14.1.1-r1.ebuild b/dev-python/sip4-tqt/sip4-tqt-14.1.1-r1.ebuild
new file mode 100644
index 00000000..1261d8d3
--- /dev/null
+++ b/dev-python/sip4-tqt/sip4-tqt-14.1.1-r1.ebuild
@@ -0,0 +1,55 @@
+# Copyright 2022-2025 The Trinity Desktop Project
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="8"
+
+TRINITY_MODULE_TYPE="dependencies"
+PYTHON_COMPAT=( python3_{8..13} )
+
+inherit trinity-base-2 python-single-r1 flag-o-matic
+
+DESCRIPTION="Python/C++ bindings generator runtime library"
+HOMEPAGE="https://trinitydesktop.org"
+LICENSE="|| ( GPL-2 GPL-3 SIP )"
+SLOT="0"
+if [[ ${PV} != *9999* ]] ; then
+	KEYWORDS="~amd64 ~arm64 ~x86"
+fi
+REQUIRED_USE="${PYTHON_REQUIRED_USE}"
+
+DEPEND="${PYTHON_DEPS}
+	~x11-libs/tqscintilla-${PV}
+	~dev-tqt/tqtinterface-${PV}
+"
+RDEPEND="${DEPEND}"
+
+TQTDIR="/usr/tqt3"
+BUILD_DIR="${S}"
+
+PATCHES=(
+	"${FILESDIR}/${PN}-14.1.2-Added-prototype-of-yylex-function.patch"
+	"${FILESDIR}/${PN}-14.1.2-Fix-FTBFS-with-Python-3.13.patch"
+)
+
+src_prepare() {
+	default
+}
+
+src_configure() {
+	local myconf
+	append-cflags "-I/usr/include/tqt -I/${TQTDIR}/include"
+	myconf=(
+	-b "${TDEDIR}/bin"
+	-e "${TDEDIR}/include"
+	)
+	echo yes | "${EPYTHON}" configure.py "${myconf[@]}" CFLAGS="${CFLAGS}" LIBS="${LDFLAGS}" || die
+}
+
+src_compile() {
+	emake
+}
+
+src_install() {
+	emake install DESTDIR="${D}"
+	python_optimize
+}
diff --git a/dev-python/sip4-tqt/sip4-tqt-14.1.1.ebuild b/dev-python/sip4-tqt/sip4-tqt-14.1.1.ebuild
deleted file mode 100644
index 0708a71e..00000000
--- a/dev-python/sip4-tqt/sip4-tqt-14.1.1.ebuild
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2022 The Trinity Desktop Project
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI="8"
-
-TRINITY_MODULE_TYPE="dependencies"
-PYTHON_COMPAT=( python3_{8..13} )
-
-inherit trinity-base-2 python-single-r1 flag-o-matic
-
-DESCRIPTION="Python/C++ bindings generator runtime library"
-HOMEPAGE="https://trinitydesktop.org"
-LICENSE="|| ( GPL-2 GPL-3 SIP )"
-SLOT="0"
-if [[ ${PV} != *9999* ]] ; then
-	KEYWORDS="~amd64 ~arm64 ~x86"
-fi
-REQUIRED_USE="${PYTHON_REQUIRED_USE}"
-
-DEPEND="${PYTHON_DEPS}
-	~x11-libs/tqscintilla-${PV}
-	~dev-tqt/tqtinterface-${PV}
-"
-RDEPEND="${DEPEND}"
-
-TQTDIR="/usr/tqt3"
-BUILD_DIR="${S}"
-
-src_prepare() {
-	eapply_user
-}
-
-src_configure() {
-	local myconf
-	append-cflags "-I/usr/include/tqt -I/${TQTDIR}/include"
-	myconf=(
-	-b "${TDEDIR}/bin"
-	-e "${TDEDIR}/include"
-	)
-	echo yes | "${EPYTHON}" configure.py "${myconf[@]}" CFLAGS="${CFLAGS}" LIBS="${LDFLAGS}" || die
-}
-
-src_compile() {
-	emake
-}
-
-src_install() {
-	emake install DESTDIR="${D}"
-}
diff --git a/dev-python/sip4-tqt/sip4-tqt-14.1.2-r1.ebuild b/dev-python/sip4-tqt/sip4-tqt-14.1.2-r1.ebuild
new file mode 100644
index 00000000..387be49a
--- /dev/null
+++ b/dev-python/sip4-tqt/sip4-tqt-14.1.2-r1.ebuild
@@ -0,0 +1,55 @@
+# Copyright 2022-2025 The Trinity Desktop Project
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI="8"
+
+TRINITY_MODULE_TYPE="dependencies"
+PYTHON_COMPAT=( python3_{8..13} )
+
+inherit trinity-base-2 python-single-r1 flag-o-matic
+
+DESCRIPTION="Python/C++ bindings generator runtime library"
+HOMEPAGE="https://trinitydesktop.org"
+LICENSE="|| ( GPL-2 GPL-3 SIP )"
+SLOT="0"
+if [[ ${PV} != *9999* ]] ; then
+	KEYWORDS="~amd64 ~arm64 ~x86"
+fi
+REQUIRED_USE="${PYTHON_REQUIRED_USE}"
+
+DEPEND="${PYTHON_DEPS}
+	~x11-libs/tqscintilla-${PV}
+	~dev-tqt/tqtinterface-${PV}
+"
+RDEPEND="${DEPEND}"
+
+TQTDIR="/usr/tqt3"
+BUILD_DIR="${S}"
+
+PATCHES=(
+	"${FILESDIR}/${P}-Added-prototype-of-yylex-function.patch"
+	"${FILESDIR}/${P}-Fix-FTBFS-with-Python-3.13.patch"
+)
+
+src_prepare() {
+	default
+}
+
+src_configure() {
+	local myconf
+	append-cflags "-I/usr/include/tqt -I/${TQTDIR}/include"
+	myconf=(
+	-b "${TDEDIR}/bin"
+	-e "${TDEDIR}/include"
+	)
+	echo yes | "${EPYTHON}" configure.py "${myconf[@]}" CFLAGS="${CFLAGS}" LIBS="${LDFLAGS}" || die
+}
+
+src_compile() {
+	emake
+}
+
+src_install() {
+	emake install DESTDIR="${D}"
+	python_optimize
+}
diff --git a/dev-python/sip4-tqt/sip4-tqt-14.1.2.ebuild b/dev-python/sip4-tqt/sip4-tqt-14.1.2.ebuild
deleted file mode 100644
index 10a7f524..00000000
--- a/dev-python/sip4-tqt/sip4-tqt-14.1.2.ebuild
+++ /dev/null
@@ -1,49 +0,0 @@
-# Copyright 2022-2024 The Trinity Desktop Project
-# Distributed under the terms of the GNU General Public License v2
-
-EAPI="8"
-
-TRINITY_MODULE_TYPE="dependencies"
-PYTHON_COMPAT=( python3_{8..13} )
-
-inherit trinity-base-2 python-single-r1 flag-o-matic
-
-DESCRIPTION="Python/C++ bindings generator runtime library"
-HOMEPAGE="https://trinitydesktop.org"
-LICENSE="|| ( GPL-2 GPL-3 SIP )"
-SLOT="0"
-if [[ ${PV} != *9999* ]] ; then
-	KEYWORDS="~amd64 ~arm64 ~x86"
-fi
-REQUIRED_USE="${PYTHON_REQUIRED_USE}"
-
-DEPEND="${PYTHON_DEPS}
-	~x11-libs/tqscintilla-${PV}
-	~dev-tqt/tqtinterface-${PV}
-"
-RDEPEND="${DEPEND}"
-
-TQTDIR="/usr/tqt3"
-BUILD_DIR="${S}"
-
-src_prepare() {
-	eapply_user
-}
-
-src_configure() {
-	local myconf
-	append-cflags "-I/usr/include/tqt -I/${TQTDIR}/include"
-	myconf=(
-	-b "${TDEDIR}/bin"
-	-e "${TDEDIR}/include"
-	)
-	echo yes | "${EPYTHON}" configure.py "${myconf[@]}" CFLAGS="${CFLAGS}" LIBS="${LDFLAGS}" || die
-}
-
-src_compile() {
-	emake
-}
-
-src_install() {
-	emake install DESTDIR="${D}"
-}
diff --git a/dev-python/sip4-tqt/sip4-tqt-9999.ebuild b/dev-python/sip4-tqt/sip4-tqt-9999.ebuild
index ae14f7b2..4d8f86f6 100644
--- a/dev-python/sip4-tqt/sip4-tqt-9999.ebuild
+++ b/dev-python/sip4-tqt/sip4-tqt-9999.ebuild
@@ -1,4 +1,4 @@
-# Copyright 2022 The Trinity Desktop Project
+# Copyright 2022-2025 The Trinity Desktop Project
 # Distributed under the terms of the GNU General Public License v2
 
 EAPI="8"
@@ -27,7 +27,7 @@ TQTDIR="/usr/tqt3"
 BUILD_DIR="${S}"
 
 src_prepare() {
-	eapply_user
+	default
 }
 
 src_configure() {
@@ -46,4 +46,5 @@ src_compile() {
 
 src_install() {
 	emake install DESTDIR="${D}"
+	python_optimize
 }
-- 
cgit v1.2.3

