FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: Fail to compile wrap file generated with SWIG 4.4 · Issue #30122 · numpy/numpy · GitHub

/ numpy Public

BUG: Fail to compile wrap file generated with SWIG 4.4 #30122

Description

Describe the issue:

This simple example.i file:

%module example

%{
#include <numpy/arrayobject.h>
%}

%init
%{
    import_array();
%}

Compiles correctly when using SWIG 4.3:

$ swig -python example.i
$ gcc -c example_wrap.c $(pkgconf python3 --cflags) $(pkgconf numpy --cflags)

However, with SWIG 4.4, I get the following compilation error:

$ gcc -c example_wrap.c $(pkgconf python3 --cflags) $(pkgconf numpy --cflags)
example_wrap.c: In function ‘SWIG_mod_exec’:
example_wrap.c:4148:3: error: returning ‘void *’ from a function with return type ‘int’ makes integer from pointer without a cast [-Wint-conversion]
 4148 |   import_array();
      |   ^~~~~~~~~~~~

It seems that the problem stems from the change in how SWIG generates the wrap file. In version 4.4, the code generated by _core/code_generators/generate_numpy_api.py became incompatible. I traced the problem down and found that it can be resolved by amending the code starting at line 160:

#define import_array() { \
  if (_import_array() < 0) { \
    PyErr_Print(); \
    PyErr_SetString( \
        PyExc_ImportError, \
        "numpy._core.multiarray failed to import" \
    ); \
    return NULL; \
  } \
}

changing the NULL to 0:

#define import_array() { \
  if (_import_array() < 0) { \
    PyErr_Print(); \
    PyErr_SetString( \
        PyExc_ImportError, \
        "numpy._core.multiarray failed to import" \
    ); \
    return 0; \
  } \
}

With SWIG 4.3, the import_array macro was included into a function that returned void. With SWIG 4.4, that function returns int (hence the GCC error above).

Reproduce the code example:

# Not applicable

Error message:

Python and NumPy Versions:

2.3.4
3.13.9 (main, Oct 15 2025, 14:56:22) [GCC 15.2.0]

Runtime Environment:

[{'numpy_version': '2.3.4',
'python': '3.13.9 (main, Oct 15 2025, 14:56:22) [GCC 15.2.0]',
'uname': uname_result(system='Linux', node='dev', release='6.16.5+deb14-amd64', version='#1 SMP PREEMPT_DYNAMIC Debian 6.16.5-1 (2025-09-05)', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3', 'SSE41', 'POPCNT', 'SSE42'],
'not_found': ['AVX',
'F16C',
'FMA3',
'AVX2',
'AVX512F',
'AVX512CD',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'architecture': 'Nehalem',
'filepath': '/usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.30.so',
'internal_api': 'openblas',
'num_threads': 2,
'prefix': 'libopenblas',
'threading_layer': 'pthreads',
'user_api': 'blas',
'version': '0.3.30'}]

Context for the issue:

This bug is causing the plplot package in Debian FTBFS (fail to build from source). See Bug#1119760.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL