[pygobject] Use -fvisibility=hidden if supported.



commit 98ead7404600dff60028849c1ec07a51cdadd4a4
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Wed Mar 28 18:19:03 2018 +0200

    Use -fvisibility=hidden if supported.
    
    We only need to export the module init function for Python.

 gi/pygi-python-compat.h | 14 ++++++++++----
 setup.py                |  9 +++++----
 2 files changed, 15 insertions(+), 8 deletions(-)
---
diff --git a/gi/pygi-python-compat.h b/gi/pygi-python-compat.h
index 6f3b2e5a..9f607adf 100644
--- a/gi/pygi-python-compat.h
+++ b/gi/pygi-python-compat.h
@@ -37,6 +37,12 @@ PyObject * PYGLIB_PyImport_ImportModule(const char *name);
 
 #define PYGLIB_MODULE_ERROR_RETURN NULL
 
+#ifdef __GNUC__
+#define PYGI_MODINIT_FUNC __attribute__((visibility("default"))) PyMODINIT_FUNC
+#else
+#define PYGI_MODINIT_FUNC PyMODINIT_FUNC
+#endif
+
 /* Compilation on Python 2.x */
 #if PY_VERSION_HEX < 0x03000000
 
@@ -93,8 +99,8 @@ PyObject * PYGLIB_PyImport_ImportModule(const char *name);
 
 #define PYGLIB_MODULE_START(symbol, modname)           \
 PyObject * pyglib_##symbol##_module_create(void);       \
-DL_EXPORT(void) init##symbol(void);                     \
-DL_EXPORT(void) init##symbol(void) {                    \
+PYGI_MODINIT_FUNC init##symbol(void);                   \
+PYGI_MODINIT_FUNC init##symbol(void) {                  \
     pyglib_##symbol##_module_create();                  \
 };                                                      \
 PyObject * pyglib_##symbol##_module_create(void)        \
@@ -137,8 +143,8 @@ PyTypeObject symbol = {                                 \
     NULL                                                \
 };                                                      \
 PyObject * pyglib_##symbol##_module_create(void);       \
-PyMODINIT_FUNC PyInit_##symbol(void);                   \
-PyMODINIT_FUNC PyInit_##symbol(void) {                  \
+PYGI_MODINIT_FUNC PyInit_##symbol(void);                \
+PYGI_MODINIT_FUNC PyInit_##symbol(void) {               \
     return pyglib_##symbol##_module_create();           \
 };                                                      \
 PyObject * pyglib_##symbol##_module_create(void)        \
diff --git a/setup.py b/setup.py
index 399a94ce..52af46f2 100755
--- a/setup.py
+++ b/setup.py
@@ -518,7 +518,7 @@ class build_tests(Command):
         add_ext_pkg_config_dep(ext, compiler.compiler_type, "glib-2.0")
         add_ext_pkg_config_dep(ext, compiler.compiler_type, "gio-2.0")
         add_ext_pkg_config_dep(ext, compiler.compiler_type, "cairo")
-        add_ext_warn_flags(ext, compiler)
+        add_ext_compiler_flags(ext, compiler)
 
         dist = Distribution({"ext_modules": [ext]})
 
@@ -758,7 +758,7 @@ def add_ext_pkg_config_dep(ext, compiler_type, name):
         ext.libraries += pkg_config_parse("--libs-only-l", name)
 
 
-def add_ext_warn_flags(ext, compiler, _cache={}):
+def add_ext_compiler_flags(ext, compiler, _cache={}):
     cache_key = compiler.compiler[0]
     if cache_key not in _cache:
 
@@ -815,6 +815,7 @@ def add_ext_warn_flags(ext, compiler, _cache={}):
 
         args += [
             "-fno-strict-aliasing",
+            "-fvisibility=hidden",
         ]
 
         _cache[cache_key] = filter_compiler_arguments(compiler, args)
@@ -879,7 +880,7 @@ class build_ext(du_build_ext):
         add_dependency(gi_ext, "gio-2.0")
         add_dependency(gi_ext, "gobject-introspection-1.0")
         add_dependency(gi_ext, "libffi")
-        add_ext_warn_flags(gi_ext, compiler)
+        add_ext_compiler_flags(gi_ext, compiler)
 
         gi_cairo_ext = ext["gi._gi_cairo"]
         add_dependency(gi_cairo_ext, "glib-2.0")
@@ -889,7 +890,7 @@ class build_ext(du_build_ext):
         add_dependency(gi_cairo_ext, "cairo")
         add_dependency(gi_cairo_ext, "cairo-gobject")
         add_pycairo(gi_cairo_ext)
-        add_ext_warn_flags(gi_cairo_ext, compiler)
+        add_ext_compiler_flags(gi_cairo_ext, compiler)
 
     def run(self):
         self._write_config_h()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]