From 00dce132da64afb533ce7149bdad4338067a69fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szabolcs=20Horv=C3=A1t?= Date: Sat, 28 Nov 2026 14:36:30 +0000 Subject: [PATCH] build: compile the C extension with hidden symbol visibility Only PyInit__igraph needs to be exported from the extension module, but GCC and Clang exported every non-static function, such as all igraphmodule_* helpers. Exported names can clash with symbols from other libraries and invite external code to depend on internals; abi3audit --strict also flags exported names with reserved prefixes. MSVC already exports nothing by default. Pass -fvisibility=hidden on non-MSVC compilers, and declare the module init function with PyMODINIT_FUNC so that it stays exported. Assisted-by: Claude Opus 5.5 --- CHANGELOG.md | 5 +++++ setup.py | 6 ++++++ src/_igraph/igraphmodule.c | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a259f12..5d01aa800 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. + ## 1.0.1 - 2025-12-26 ### Changed diff --git a/setup.py b/setup.py index 9af9599f2..5d57f699a 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 948ff0c83..8fdf4d91e 100644 --- a/src/_igraph/igraphmodule.c +++ b/src/_igraph/igraphmodule.c @@ -1063,7 +1063,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];