diff --git a/Include/pyport.h b/Include/pyport.h --- a/Include/pyport.h +++ b/Include/pyport.h @@ -699,6 +699,16 @@ # define HAVE_DECLSPEC_DLL #endif +/* + * GCC visibility support, introduced in GCC 4.0. Only matters when + * compiling with gcc's -fvisibility=hidden argument. This applies to all + * binaries and when embedding, not just libpython.so. See + * http://gcc.gnu.org/wiki/Visibility for more information. + */ +#if defined(__GNUC__) && __GNUC__ >= 4 +# define HAVE_ATTRIBUTE_VISIBILITY +#endif + /* only get special linkage if built as shared or platform is Cygwin */ #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) # if defined(HAVE_DECLSPEC_DLL) @@ -730,6 +740,16 @@ # endif /* __cplusplus */ # endif /* Py_BUILD_CORE */ # endif /* HAVE_DECLSPEC */ +#elif defined(HAVE_ATTRIBUTE_VISIBILITY) +# define PyAPI_FUNC(RTYPE) __attribute__((visibility("default"))) RTYPE +# define PyAPI_DATA(RTYPE) extern __attribute__((visibility("default"))) RTYPE +# ifdef Py_BUILD_CORE +# define PyMODINIT_FUNC PyObject* +# elif defined(__cplusplus) +# define PyMODINIT_FUNC extern "C" __attribute__((visibility("default"))) PyObject* +# else /* __cplusplus */ +# define PyMODINIT_FUNC __attribute__((visibility("default"))) PyObject* +# endif /* Py_BUILD_CORE */ #endif /* Py_ENABLE_SHARED */ /* If no external linkage macros defined by now, create defaults */ diff --git a/Modules/_ctypes/_ctypes_test.c b/Modules/_ctypes/_ctypes_test.c --- a/Modules/_ctypes/_ctypes_test.c +++ b/Modules/_ctypes/_ctypes_test.c @@ -6,6 +6,8 @@ #if defined(MS_WIN32) || defined(__CYGWIN__) #define EXPORT(x) __declspec(dllexport) x +#elif defined(HAVE_ATTRIBUTE_VISIBILITY) +#define EXPORT(x) __attribute__((visibility("default"))) x #else #define EXPORT(x) x #endif diff --git a/Modules/_json.c b/Modules/_json.c --- a/Modules/_json.c +++ b/Modules/_json.c @@ -1756,7 +1756,7 @@ NULL }; -PyObject* +PyMODINIT_FUNC PyInit__json(void) { PyObject *m = PyModule_Create(&jsonmodule); diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h --- a/Modules/cjkcodecs/cjkcodecs.h +++ b/Modules/cjkcodecs/cjkcodecs.h @@ -402,7 +402,7 @@ NULL, \ NULL \ }; \ - PyObject* \ + PyMODINIT_FUNC \ PyInit__codecs_##loc(void) \ { \ PyObject *m = PyModule_Create(&__module); \ diff --git a/Modules/nismodule.c b/Modules/nismodule.c --- a/Modules/nismodule.c +++ b/Modules/nismodule.c @@ -456,8 +456,8 @@ NULL }; -PyObject* -PyInit_nis (void) +PyMODINIT_FUNC +PyInit_nis(void) { PyObject *m, *d; m = PyModule_Create(&nismodule); diff --git a/Python/getargs.c b/Python/getargs.c --- a/Python/getargs.c +++ b/Python/getargs.c @@ -18,7 +18,6 @@ int PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *, const char *, char **, va_list); -#ifdef HAVE_DECLSPEC_DLL /* Export functions */ PyAPI_FUNC(int) _PyArg_Parse_SizeT(PyObject *, char *, ...); PyAPI_FUNC(int) _PyArg_ParseTuple_SizeT(PyObject *, char *, ...); @@ -28,7 +27,6 @@ PyAPI_FUNC(int) _PyArg_VaParse_SizeT(PyObject *, char *, va_list); PyAPI_FUNC(int) _PyArg_VaParseTupleAndKeywords_SizeT(PyObject *, PyObject *, const char *, char **, va_list); -#endif #define FLAG_COMPAT 1 #define FLAG_SIZE_T 2