Re: [PATCH] pylibfdt: Replace removed SWIG Python 2 compatibility macros

Peter Robinson <[email protected]>
Newsgroups gmane.comp.boot-loaders.u-boot.general,gmane.comp.boot-loaders.u-boot
Message-ID <CALeDE9MGbu5hfVmvtbydM2E3oXRAh_vVSdzTbKe8YQfTZHpVNA@mail.gmail.com>
On Tue, 11 Aug 2026 at 14:36, Jaipaul Cheernam
<[email protected]> wrote:
>
> SWIG 4.5.0 removed Python 2 compatibility macros (PyInt_*, PyString_*)
> from its runtime header pyhead.swg (see commit 79f7a2b7cb7d). Replace
> them with their Python 3 C API equivalents:
>
> - PyString_FromString -> PyUnicode_FromString
> - PyString_AsString -> PyBytes_AsString
> - PyInt_AsLong -> PyLong_AsLong
>
> The replacements are safe since the macros were already aliased to
> these exact functions in SWIG's Python 3 code path.
>
> This is a backport of dtc commit 5008d1d6a356 ("pylibfdt: Replace
> removed SWIG Python 2 compatibility macros").
>
> Signed-off-by: Jaipaul Cheernam <[email protected]>

As the person that pushed this to the upstream dtc it was on my list
to do exactly this patch so thanks for this.

Signed-off-by: Peter Robinson <[email protected]>
Reviewed-by: Peter Robinson <[email protected]>

> ---
>  scripts/dtc/pylibfdt/libfdt.i_shipped | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/dtc/pylibfdt/libfdt.i_shipped b/scripts/dtc/pylibfdt/libfdt.i_shipped
> index e4659489..326a15c7 100644
> --- a/scripts/dtc/pylibfdt/libfdt.i_shipped
> +++ b/scripts/dtc/pylibfdt/libfdt.i_shipped
> @@ -1033,7 +1033,7 @@ typedef uint32_t fdt32_t;
>         PyObject *buff;
>
>         if ($1) {
> -               resultobj = PyString_FromString(
> +               resultobj = PyUnicode_FromString(
>                         fdt_string(fdt1, fdt32_to_cpu($1->nameoff)));
>                 buff = PyByteArray_FromStringAndSize(
>                         (const char *)($1 + 1), fdt32_to_cpu($1->len));
> @@ -1064,13 +1064,13 @@ typedef uint32_t fdt32_t;
>          }
>          $1 = PyBytes_AsString($input);
>      %#else
> -        $1 = PyString_AsString($input);   /* char *str */
> +        $1 = PyBytes_AsString($input);   /* char *str */
>      %#endif
>  }
>
>  /* typemaps used for fdt_next_node() */
>  %typemap(in, numinputs=1) int *depth (int depth) {
> -   depth = (int) PyInt_AsLong($input);
> +   depth = (int) PyLong_AsLong($input);
>     $1 = &depth;
>  }
>
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.