[meta-python][PATCH 2/4] python3-m2crypto: add SWIG py2/py3 C-API compat patch

Khem Raj <[email protected]>
Newsgroups org.openembedded.lists.openembedded-devel
Message-ID <[email protected]>
_rsa.i, _lib.i and _ec.i use the Python 2 C-API names PyInt_AsLong,
PyInt_FromLong and PyString_FromString. Python 3.14 no longer ships
any fallback definitions for them, so the generated _m2crypto_wrap.c
fails to compile:

  src/SWIG/_m2crypto_wrap.c:4895:21: error: call to undeclared function 'PyInt_AsLong'
  src/SWIG/_m2crypto_wrap.c:9842:26: error: call to undeclared function 'PyString_FromString'

Add a patch mapping them to their Python 3 equivalents in the shared
raw-C block emitted ahead of the %include'd modules that use them.

Signed-off-by: Khem Raj <[email protected]>
---
 ...to.i-add-py2-py3-C-API-compat-macros.patch | 41 +++++++++++++++++++
 .../python/python3-m2crypto_0.48.0.bb         |  1 +
 2 files changed, 42 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-m2crypto/0002-_m2crypto.i-add-py2-py3-C-API-compat-macros.patch

diff --git a/meta-python/recipes-devtools/python/python3-m2crypto/0002-_m2crypto.i-add-py2-py3-C-API-compat-macros.patch b/meta-python/recipes-devtools/python/python3-m2crypto/0002-_m2crypto.i-add-py2-py3-C-API-compat-macros.patch
new file mode 100644
index 0000000000..d65920341a
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-m2crypto/0002-_m2crypto.i-add-py2-py3-C-API-compat-macros.patch
@@ -0,0 +1,41 @@
+From: Khem Raj <[email protected]>
+Subject: _m2crypto.i: add py2/py3 C-API compat macros
+
+_rsa.i, _lib.i and _ec.i use the Python 2 C-API names PyInt_AsLong,
+PyInt_FromLong and PyString_FromString. Python 3.14 no longer ships
+any fallback definitions for them, so the generated _m2crypto_wrap.c
+fails to compile:
+
+  src/SWIG/_m2crypto_wrap.c:4895:21: error: call to undeclared function 'PyInt_AsLong'
+  src/SWIG/_m2crypto_wrap.c:9842:26: error: call to undeclared function 'PyString_FromString'
+
+Map them to their Python 3 equivalents in the shared raw-C block that
+is emitted ahead of the %include'd modules that use them.
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <[email protected]>
+---
+--- a/src/SWIG/_m2crypto.i
++++ b/src/SWIG/_m2crypto.i
+@@ -64,6 +64,21 @@
+ static PyObject *x509_store_verify_cb_func;
+ %}
+
++%{
++#ifndef PyInt_Check
++#define PyInt_Check(x) PyLong_Check(x)
++#endif
++#ifndef PyInt_AsLong
++#define PyInt_AsLong(x) PyLong_AsLong(x)
++#endif
++#ifndef PyInt_FromLong
++#define PyInt_FromLong(x) PyLong_FromLong(x)
++#endif
++#ifndef PyString_FromString
++#define PyString_FromString(x) PyUnicode_FromString(x)
++#endif
++%}
++
+ %include <openssl/opensslv.h>
+
+ /* Bring in STACK_OF macro definition */
diff --git a/meta-python/recipes-devtools/python/python3-m2crypto_0.48.0.bb b/meta-python/recipes-devtools/python/python3-m2crypto_0.48.0.bb
index 96c8a8797a..1a06fca017 100644
--- a/meta-python/recipes-devtools/python/python3-m2crypto_0.48.0.bb
+++ b/meta-python/recipes-devtools/python/python3-m2crypto_0.48.0.bb
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = "file://LICENSES/BSD-2-Clause.txt;md5=8099b0e569f862ece05740a
 SRC_URI[sha256sum] = "178e290f558ddf0379aaefd34c0a8ddb21f21502594e588f928dda85f1ad202b"

 SRC_URI += "file://0001-setup.py-Make-the-cmd-available.patch"
+SRC_URI += "file://0002-_m2crypto.i-add-py2-py3-C-API-compat-macros.patch"

 CVE_STATUS[CVE-2009-0127] = "disputed: upstream claims there is no bug"
 CVE_STATUS[CVE-2020-25657] = "fixed-version: the used version (0.46.2) contains the fix already"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.