[PATCH 4/4] pylibfdt: fix with Python 3.10

Simon Glass sjg at chromium.org
Mon Aug 29 15:57:07 CEST 2022


From: Ross Burton <ross.burton at arm.com>

Since Python 2.5 the argument parsing functions when parsing expressions
such as s# (string plus length) expect the length to be an int or a
ssize_t, depending on whether PY_SSIZE_T_CLEAN is defined or not.

Python 3.8 deprecated the use of int, and with Python 3.10 this symbol
must be defined and ssize_t used[1].

Define the magic symbol when building the extension, and cast the ints
from the libfdt API to ssize_t as appropriate.

[1] https://docs.python.org/3.10/whatsnew/3.10.html#id2

Signed-off-by: Ross Burton <ross.burton at arm.com>
[dwg: Adjust for new location of setup.py]
Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
Modified for U-Boot:
Signed-off-by: Simon Glass <sjg at chromium.org>
---

 scripts/dtc/pylibfdt/libfdt.i_shipped | 4 ++--
 scripts/dtc/pylibfdt/setup.py         | 1 +
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped
index 27c29ea2603..7ee43393e11 100644
--- a/scripts/dtc/pylibfdt/libfdt.i_shipped
+++ b/scripts/dtc/pylibfdt/libfdt.i_shipped
@@ -1045,9 +1045,9 @@ typedef uint32_t fdt32_t;
 		$result = Py_None;
 	else
         %#if PY_VERSION_HEX >= 0x03000000
-            $result = Py_BuildValue("y#", $1, *arg4);
+            $result = Py_BuildValue("y#", $1, (Py_ssize_t)*arg4);
         %#else
-            $result = Py_BuildValue("s#", $1, *arg4);
+            $result = Py_BuildValue("s#", $1, (Py_ssize_t)*arg4);
         %#endif
 }
 
diff --git a/scripts/dtc/pylibfdt/setup.py b/scripts/dtc/pylibfdt/setup.py
index 992cdec30f5..d0aa9676cc9 100755
--- a/scripts/dtc/pylibfdt/setup.py
+++ b/scripts/dtc/pylibfdt/setup.py
@@ -110,6 +110,7 @@ libfdt_module = Extension(
     sources = files,
     extra_compile_args = cflags,
     swig_opts = swig_opts,
+    define_macros=[('PY_SSIZE_T_CLEAN', None)],
 )
 
 setup(
-- 
2.37.2.672.g94769d06f0-goog



More information about the U-Boot mailing list