pylibfdt: fix with Python 3.10

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 <[email protected]>
Message-Id: <[email protected]>
[dwg: Adjust for new location of setup.py]
Tested-by: Rob Herring <[email protected]>
Signed-off-by: David Gibson <[email protected]>
diff --git a/setup.py b/setup.py
index 4b07be9..0a0daf1 100755
--- a/setup.py
+++ b/setup.py
@@ -30,6 +30,7 @@
 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')],