diff --git a/CHANGELOG.md b/CHANGELOG.md index 5253ef92f..ce2624727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,11 @@ - Dropped support for Python 3.9 and 3.10 as they have reached their end of life. The minimum supported Python version is now 3.11. +- The C extension is now compiled with hidden symbol visibility on non-MSVC + compilers, so it exports only its module initialization function. Other + extensions that need the C API of python-igraph should use the + `igraph._igraph._C_API` capsule. + - The `abi3` wheels now target the stable ABI of Python 3.11 and are tagged `cp311-abi3` instead of `cp39-abi3`. diff --git a/setup.py b/setup.py index 6cc95866b..c5cc7fb03 100644 --- a/setup.py +++ b/setup.py @@ -535,6 +535,12 @@ def run(self): "-fdiagnostics-color", ] + # Export only the module initialization function from the + # extension; everything else is internal. MSVC does this by + # default. Other extensions should use the C API capsule. + if not building_on_windows_msvc(): + buildcfg.extra_compile_args.append("-fvisibility=hidden") + # Add extra libraries that may have been specified if "IGRAPH_EXTRA_DYNAMIC_LIBRARIES" in os.environ: extra_libraries = os.environ[ diff --git a/src/_igraph/igraphmodule.c b/src/_igraph/igraphmodule.c index ffb7ca715..c760bdacb 100644 --- a/src/_igraph/igraphmodule.c +++ b/src/_igraph/igraphmodule.c @@ -1066,7 +1066,7 @@ extern PyObject* igraphmodule_InternalError; extern PyObject* igraphmodule_arpack_options_default; #define INITERROR return NULL -PyObject* PyInit__igraph(void) +PyMODINIT_FUNC PyInit__igraph(void) { PyObject* m; static void *PyIGraph_API[PyIGraph_API_pointers];