[pypy-commit] cffi default: Add '#pragma GCC visibility push(default)' in case the user
arigo
pypy.commits at gmail.com
Tue Jan 17 09:15:31 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch:
Changeset: r2861:08a1e3c711a3
Date: 2017-01-17 15:14 +0100
http://bitbucket.org/cffi/cffi/changeset/08a1e3c711a3/
Log: Add '#pragma GCC visibility push(default)' in case the user
specifies -fvisibility=hidden
diff --git a/cffi/recompiler.py b/cffi/recompiler.py
--- a/cffi/recompiler.py
+++ b/cffi/recompiler.py
@@ -391,6 +391,10 @@
prnt()
#
# the init function
+ prnt('#ifdef __GNUC__')
+ prnt('# pragma GCC visibility push(default) /* for -fvisibility= */')
+ prnt('#endif')
+ prnt()
prnt('#ifdef PYPY_VERSION')
prnt('PyMODINIT_FUNC')
prnt('_cffi_pypyinit_%s(const void *p[])' % (base_module_name,))
@@ -429,6 +433,10 @@
self.module_name, version))
prnt('}')
prnt('#endif')
+ prnt()
+ prnt('#ifdef __GNUC__')
+ prnt('# pragma GCC visibility pop')
+ prnt('#endif')
def _to_py(self, x):
if isinstance(x, str):
diff --git a/testing/cffi1/test_recompiler.py b/testing/cffi1/test_recompiler.py
--- a/testing/cffi1/test_recompiler.py
+++ b/testing/cffi1/test_recompiler.py
@@ -31,6 +31,7 @@
kwds.setdefault('source_extension', '.cpp')
source = 'extern "C" {\n%s\n}' % (source,)
else:
+ # add '-Werror' to the existing 'extra_compile_args' flags
kwds['extra_compile_args'] = (kwds.get('extra_compile_args', []) +
['-Werror'])
return recompiler._verify(ffi, module_name, source, *args, **kwds)
@@ -2175,3 +2176,15 @@
" Such structs are only supported as return value if the function is "
"'API mode' and non-variadic (i.e. declared inside ffibuilder.cdef()"
"+ffibuilder.set_source() and not taking a final '...' argument)")
+
+def test_gcc_visibility_hidden():
+ if sys.platform == 'win32':
+ py.test.skip("test for gcc/clang")
+ ffi = FFI()
+ ffi.cdef("""
+ int f(int);
+ """)
+ lib = verify(ffi, "test_gcc_visibility_hidden", """
+ int f(int a) { return a + 40; }
+ """, extra_compile_args=['-fvisibility=hidden'])
+ assert lib.f(2) == 42
More information about the pypy-commit
mailing list