Skip to content

Fix Python wrappers for SWIG 4.5.0 - #232

Open
lahwaacz wants to merge 1 commit into
malaterre:masterfrom
lahwaacz:fix-swig-4.5-python-compat
Open

lahwaacz wants to merge 1 commit into
malaterre:masterfrom
lahwaacz:fix-swig-4.5-python-compat

Conversation

@lahwaacz

Copy link
Copy Markdown

GDCM fails to compile with SWIG 4.5.0, which removed the Python 2 compatibility aliases, causing compiler errors like

error: 'PyString_AsString' was not declared in this scope
error: 'PyInt_FromLong' was not declared in this scope

Since Python 2 is long dead, these should be replaced in the hand-written gdcmswig.i and gdcmcommon.i files.

SWIG 4.5.0 removed the Python 2 compatibility aliases that pyhead.swg
previously injected into every generated Python wrapper:

    #define PyString_AsString(str) PyBytes_AsString(str)
    #define PyString_Size(str) PyBytes_Size(str)
    #define PyInt_FromLong(x) PyLong_FromLong(x)
    ...

GDCM's hand-written typemaps still use the Python 2 names, so with
SWIG 4.5.0 the generated gdcmswigPYTHON_wrap.cxx fails to compile:

    error: 'PyString_AsString' was not declared in this scope
    error: 'PyInt_FromLong' was not declared in this scope

Replace them with the Python 3 C-API calls the aliases expanded to,
which is also behavior-identical to what SWIG <= 4.4 produced when
targeting Python 3 (byte string argument, list of ints).

Assisted-by: Sisyphus (Kimi K3) via OpenCode
@exoosh

exoosh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Yep, I also had pointed this out earlier. The Python detection itself is still Python 2.x as far as I recall (see d528f5e).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants