1 #ifndef Py_EXPORTS_H 2 #define Py_EXPORTS_H 3 4 /* Declarations for symbol visibility. 5 6 PyAPI_FUNC(type): Declares a public Python API function and return type 7 PyAPI_DATA(type): Declares public Python data and its type 8 PyMODINIT_FUNC: A Python module init function. If these functions are 9 inside the Python core, they are private to the core. 10 If in an extension module, it may be declared with 11 external linkage depending on the platform. 12 13 As a number of platforms support/require "__declspec(dllimport/dllexport)", 14 we support a HAVE_DECLSPEC_DLL macro to save duplication. 15 */ 16 17 /* 18 All windows ports, except cygwin, are handled in PC/pyconfig.h. 19 20 Cygwin is the only other autoconf platform requiring special 21 linkage handling and it uses __declspec(). 22 */ 23 #if defined(__CYGWIN__) 24 # define HAVE_DECLSPEC_DLL 25 #endif 26 27 #if defined(_WIN32) || defined(__CYGWIN__) 28 #if defined(Py_ENABLE_SHARED) 29 #define Py_IMPORTED_SYMBOL __declspec(dllimport) 30 #define Py_EXPORTED_SYMBOL __declspec(dllexport) 31 #define Py_LOCAL_SYMBOL 32 #else 33 #define Py_IMPORTED_SYMBOL 34 #define Py_EXPORTED_SYMBOL 35 #define Py_LOCAL_SYMBOL 36 #endif 37 #else 38 /* 39 * If we only ever used gcc >= 5, we could use __has_attribute(visibility) 40 * as a cross-platform way to determine if visibility is supported. However, 41 * we may still need to support gcc >= 4, as some Ubuntu LTS and Centos versions 42 * have 4 < gcc < 5. 43 */ 44 #ifndef __has_attribute 45 #define __has_attribute(x) 0 // Compatibility with non-clang compilers. 46 #endif 47 #if (defined(__GNUC__) && (__GNUC__ >= 4)) ||\ 48 (defined(__clang__) && __has_attribute(visibility)) 49 #define Py_IMPORTED_SYMBOL __attribute__ ((visibility ("default"))) 50 #define Py_EXPORTED_SYMBOL __attribute__ ((visibility ("default"))) 51 #define Py_LOCAL_SYMBOL __attribute__ ((visibility ("hidden"))) 52 #else 53 #define Py_IMPORTED_SYMBOL 54 #define Py_EXPORTED_SYMBOL 55 #define Py_LOCAL_SYMBOL 56 #endif 57 #endif 58 59 /* only get special linkage if built as shared or platform is Cygwin */ 60 #if defined(Py_ENABLE_SHARED) || defined(__CYGWIN__) 61 # if defined(HAVE_DECLSPEC_DLL) 62 # if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE) 63 # define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE 64 # define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE 65 /* module init functions inside the core need no external linkage */ 66 /* except for Cygwin to handle embedding */ 67 # if defined(__CYGWIN__) 68 # define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject* 69 # else /* __CYGWIN__ */ 70 # define PyMODINIT_FUNC PyObject* 71 # endif /* __CYGWIN__ */ 72 # else /* Py_BUILD_CORE */ 73 /* Building an extension module, or an embedded situation */ 74 /* public Python functions and data are imported */ 75 /* Under Cygwin, auto-import functions to prevent compilation */ 76 /* failures similar to those described at the bottom of 4.1: */ 77 /* http://docs.python.org/extending/windows.html#a-cookbook-approach */ 78 # if !defined(__CYGWIN__) 79 # define PyAPI_FUNC(RTYPE) Py_IMPORTED_SYMBOL RTYPE 80 # endif /* !__CYGWIN__ */ 81 # define PyAPI_DATA(RTYPE) extern Py_IMPORTED_SYMBOL RTYPE 82 /* module init functions outside the core must be exported */ 83 # if defined(__cplusplus) 84 # define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject* 85 # else /* __cplusplus */ 86 # define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject* 87 # endif /* __cplusplus */ 88 # endif /* Py_BUILD_CORE */ 89 # endif /* HAVE_DECLSPEC_DLL */ 90 #endif /* Py_ENABLE_SHARED */ 91 92 /* If no external linkage macros defined by now, create defaults */ 93 #ifndef PyAPI_FUNC 94 # define PyAPI_FUNC(RTYPE) Py_EXPORTED_SYMBOL RTYPE 95 #endif 96 #ifndef PyAPI_DATA 97 # define PyAPI_DATA(RTYPE) extern Py_EXPORTED_SYMBOL RTYPE 98 #endif 99 #ifndef PyMODINIT_FUNC 100 # if defined(__cplusplus) 101 # define PyMODINIT_FUNC extern "C" Py_EXPORTED_SYMBOL PyObject* 102 # else /* __cplusplus */ 103 # define PyMODINIT_FUNC Py_EXPORTED_SYMBOL PyObject* 104 # endif /* __cplusplus */ 105 #endif 106 107 108 #endif /* Py_EXPORTS_H */ 109