Skip to content

Commit

Permalink
pylibfdt: fix with Python 3.10
Browse files Browse the repository at this point in the history
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@arm.com>
Message-Id: <20211111160536.2516573-1-ross.burton@arm.com>
[dwg: Adjust for new location of setup.py]
Tested-by: Rob Herring <robh@kernel.org>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
  • Loading branch information
rossburton authored and dgibson committed Nov 12, 2021
1 parent 23b56cb commit 383e148
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pylibfdt/libfdt.i
Expand Up @@ -1044,9 +1044,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
}

Expand Down
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -30,6 +30,7 @@ def get_top_builddir():
libfdt_module = Extension(
'_libfdt',
sources=[os.path.join(srcdir, 'pylibfdt/libfdt.i')],
define_macros=[('PY_SSIZE_T_CLEAN', None)],
include_dirs=[os.path.join(srcdir, 'libfdt')],
libraries=['fdt'],
library_dirs=[os.path.join(top_builddir, 'libfdt')],
Expand Down

0 comments on commit 383e148

Please sign in to comment.