diff -r f9f9662dfb1f Include/pyport.h --- a/Include/pyport.h Sun Mar 06 01:53:19 2011 +0100 +++ b/Include/pyport.h Sat Mar 05 21:49:10 2011 -0800 @@ -699,37 +699,56 @@ # 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) -# ifdef Py_BUILD_CORE -# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE -# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE +#if (defined(Py_ENABLE_SHARED) || defined(__CYGWIN__)) \ + && defined(HAVE_DECLSPEC_DLL) +# ifdef Py_BUILD_CORE +# define PyAPI_FUNC(RTYPE) __declspec(dllexport) RTYPE +# define PyAPI_DATA(RTYPE) extern __declspec(dllexport) RTYPE /* module init functions inside the core need no external linkage */ /* except for Cygwin to handle embedding */ -# if defined(__CYGWIN__) -# define PyMODINIT_FUNC __declspec(dllexport) PyObject* -# else /* __CYGWIN__ */ -# define PyMODINIT_FUNC PyObject* -# endif /* __CYGWIN__ */ -# else /* Py_BUILD_CORE */ - /* Building an extension module, or an embedded situation */ - /* public Python functions and data are imported */ +# if defined(__CYGWIN__) +# define PyMODINIT_FUNC __declspec(dllexport) PyObject* +# else /* __CYGWIN__ */ +# define PyMODINIT_FUNC PyObject* +# endif /* __CYGWIN__ */ +# else /* Py_BUILD_CORE */ + /* Building an extension module, or an embedded situation. */ + /* Public Python functions and data are imported. */ /* Under Cygwin, auto-import functions to prevent compilation */ /* failures similar to those described at the bottom of 4.1: */ /* http://docs.python.org/extending/windows.html#a-cookbook-approach */ -# if !defined(__CYGWIN__) -# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE -# endif /* !__CYGWIN__ */ -# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE +# if !defined(__CYGWIN__) +# define PyAPI_FUNC(RTYPE) __declspec(dllimport) RTYPE +# endif /* !__CYGWIN__ */ +# define PyAPI_DATA(RTYPE) extern __declspec(dllimport) RTYPE /* module init functions outside the core must be exported */ -# if defined(__cplusplus) -# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject* -# else /* __cplusplus */ -# define PyMODINIT_FUNC __declspec(dllexport) PyObject* -# endif /* __cplusplus */ -# endif /* Py_BUILD_CORE */ -# endif /* HAVE_DECLSPEC */ +# if defined(__cplusplus) +# define PyMODINIT_FUNC extern "C" __declspec(dllexport) PyObject* +# else /* __cplusplus */ +# define PyMODINIT_FUNC __declspec(dllexport) PyObject* +# endif /* __cplusplus */ +# endif /* Py_BUILD_CORE */ +#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 -r f9f9662dfb1f Modules/_ctypes/_ctypes_test.c --- a/Modules/_ctypes/_ctypes_test.c Sun Mar 06 01:53:19 2011 +0100 +++ b/Modules/_ctypes/_ctypes_test.c Sat Mar 05 21:49:10 2011 -0800 @@ -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 -r f9f9662dfb1f Modules/_json.c --- a/Modules/_json.c Sun Mar 06 01:53:19 2011 +0100 +++ b/Modules/_json.c Sat Mar 05 21:49:10 2011 -0800 @@ -1756,7 +1756,7 @@ NULL }; -PyObject* +PyMODINIT_FUNC PyInit__json(void) { PyObject *m = PyModule_Create(&jsonmodule); diff -r f9f9662dfb1f Modules/cjkcodecs/cjkcodecs.h --- a/Modules/cjkcodecs/cjkcodecs.h Sun Mar 06 01:53:19 2011 +0100 +++ b/Modules/cjkcodecs/cjkcodecs.h Sat Mar 05 21:49:10 2011 -0800 @@ -402,7 +402,7 @@ NULL, \ NULL \ }; \ - PyObject* \ + PyMODINIT_FUNC \ PyInit__codecs_##loc(void) \ { \ PyObject *m = PyModule_Create(&__module); \ diff -r f9f9662dfb1f Modules/nismodule.c --- a/Modules/nismodule.c Sun Mar 06 01:53:19 2011 +0100 +++ b/Modules/nismodule.c Sat Mar 05 21:49:10 2011 -0800 @@ -456,8 +456,8 @@ NULL }; -PyObject* -PyInit_nis (void) +PyMODINIT_FUNC +PyInit_nis(void) { PyObject *m, *d; m = PyModule_Create(&nismodule); diff -r f9f9662dfb1f Python/getargs.c --- a/Python/getargs.c Sun Mar 06 01:53:19 2011 +0100 +++ b/Python/getargs.c Sat Mar 05 21:49:10 2011 -0800 @@ -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