From 7b02a3290fe12894b9fe40c41362ea8cb32206a7 Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Wed, 9 Sep 2020 15:10:58 -0300 Subject: [PATCH] ecore_audio: Rename EAPI macro to ECORE_AUDIO_API in Ecore Audio library MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from a series of patches to rename EAPI symbols to specific library DSOs. EAPI was designed to be able to pass ```__attribute__ ((visibility ("default")))``` for symbols with GCC, which would mean that even if -fvisibility=hidden was used when compiling the library, the needed symbols would get exported. MSVC __almost__ works like GCC (or mingw) in which you can declare everything as export and it will just work (slower, but it will work). But there's a caveat: global variables will not work the same way for MSVC, but works for mingw and GCC. For global variables (as opposed to functions), MSVC requires correct DSO visibility for MSVC: instead of declaring a symbol as export for everything, you need to declare it as import when importing from another DSO and export when defining it locally. With current EAPI definitions, we get the following example working in mingw and MSVC (observe it doesn't define any global variables as exported symbols). Example 1: dll1: ``` EAPI void foo(void); EAPI void bar() { foo(); } ``` dll2: ``` EAPI void foo() { printf ("foo\n"); } ``` This works fine with API defined as __declspec(dllexport) in both cases and for gcc defining as ```__atttribute__((visibility("default")))```. However, the following: Example 2: dll1: ``` EAPI extern int foo; EAPI void foobar(void); EAPI void bar() { foo = 5; foobar(); } ``` dll2: ``` EAPI int foo = 0; EAPI void foobar() { printf ("foo %d\n", foo); } ``` This will work on mingw but will not work for MSVC. And that's why EAPI is the only solution that worked for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette Co-authored-by: Ricardo Campos Co-authored-by: Lucas Cavalcante de Sousa --- src/lib/ecore_audio/Ecore_Audio.h | 38 ++++----------------------- src/lib/ecore_audio/ecore_audio.c | 8 +++--- src/lib/ecore_audio/ecore_audio_api.h | 34 ++++++++++++++++++++++++ src/lib/ecore_audio/meson.build | 3 ++- 4 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 src/lib/ecore_audio/ecore_audio_api.h diff --git a/src/lib/ecore_audio/Ecore_Audio.h b/src/lib/ecore_audio/Ecore_Audio.h index 717c36c3fd..9283b0474f 100644 --- a/src/lib/ecore_audio/Ecore_Audio.h +++ b/src/lib/ecore_audio/Ecore_Audio.h @@ -3,32 +3,7 @@ #include #include - -#ifdef EAPI -#undef EAPI -#endif - -#ifdef _WIN32 -# ifdef EFL_BUILD -# ifdef DLL_EXPORT -# define EAPI __declspec(dllexport) -# else -# define EAPI -# endif -# else -# define EAPI __declspec(dllimport) -# endif -#else -# ifdef __GNUC__ -# if __GNUC__ >= 4 -# define EAPI __attribute__ ((visibility("default"))) -# else -# define EAPI -# endif -# else -# define EAPI -# endif -#endif +#include /** * @file Ecore_Audio.h @@ -176,7 +151,7 @@ typedef struct _Ecore_Audio_Vio Ecore_Audio_Vio; * When Ecore_Audio is not used anymore, call ecore_audio_shutdown() * to shut down the Ecore_Audio library. */ -EAPI int ecore_audio_init(void); +ECORE_AUDIO_API int ecore_audio_init(void); /** * @brief Shuts down the Ecore_Audio library. @@ -190,7 +165,7 @@ EAPI int ecore_audio_init(void); * been called the same number of times than ecore_audio_init(). In that case * it shuts down all the services it uses. */ -EAPI int ecore_audio_shutdown(void); +ECORE_AUDIO_API int ecore_audio_shutdown(void); //Legacy compatibility code @@ -200,14 +175,14 @@ EAPI int ecore_audio_shutdown(void); * @since 1.8 * */ -EAPI const char* ecore_audio_obj_name_get(const Efl_Object* obj); +ECORE_AUDIO_API const char* ecore_audio_obj_name_get(const Efl_Object* obj); /** * @brief Name of the object * * @since 1.8 * */ -EAPI void ecore_audio_obj_name_set(Efl_Object* obj, const char *name); +ECORE_AUDIO_API void ecore_audio_obj_name_set(Efl_Object* obj, const char *name); #include #include @@ -230,7 +205,4 @@ EAPI void ecore_audio_obj_name_set(Efl_Object* obj, const char *n } #endif -#undef EAPI -#define EAPI - #endif diff --git a/src/lib/ecore_audio/ecore_audio.c b/src/lib/ecore_audio/ecore_audio.c index be2e40c74c..91bf99b364 100644 --- a/src/lib/ecore_audio/ecore_audio.c +++ b/src/lib/ecore_audio/ecore_audio.c @@ -27,7 +27,7 @@ Ecore_Audio_Lib_Sndfile *ecore_audio_sndfile_lib = NULL; /* externally accessible functions */ -EAPI int +ECORE_AUDIO_API int ecore_audio_init(void) { @@ -60,7 +60,7 @@ ecore_audio_init(void) return _ecore_audio_init_count; } -EAPI int +ECORE_AUDIO_API int ecore_audio_shutdown(void) { DBG("Ecore_Audio shutdown"); @@ -263,13 +263,13 @@ ecore_audio_sndfile_lib_unload(void) #endif /* HAVE_SNDFILE */ -EAPI const char* +ECORE_AUDIO_API const char* ecore_audio_obj_name_get(const Efl_Object* obj) { return efl_name_get(obj); } -EAPI void +ECORE_AUDIO_API void ecore_audio_obj_name_set(Efl_Object* obj, const char *name) { efl_name_set(obj, name); diff --git a/src/lib/ecore_audio/ecore_audio_api.h b/src/lib/ecore_audio/ecore_audio_api.h new file mode 100644 index 0000000000..1ba364bfb5 --- /dev/null +++ b/src/lib/ecore_audio/ecore_audio_api.h @@ -0,0 +1,34 @@ +#ifndef _EFL_ECORE_AUDIO_API_H +#define _EFL_ECORE_AUDIO_API_H + +#ifdef ECORE_AUDIO_API +#error ECORE_AUDIO_API should not be already defined +#endif + +#ifdef _WIN32 +# ifndef ECORE_AUDIO_STATIC +# ifdef ECORE_AUDIO_BUILD +# define ECORE_AUDIO_API __declspec(dllexport) +# else +# define ECORE_AUDIO_API __declspec(dllimport) +# endif +# else +# define ECORE_AUDIO_API +# endif +# define ECORE_AUDIO_API_WEAK +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define ECORE_AUDIO_API __attribute__ ((visibility("default"))) +# define ECORE_AUDIO_API_WEAK __attribute__ ((weak)) +# else +# define ECORE_AUDIO_API +# define ECORE_AUDIO_API_WEAK +# endif +# else +# define ECORE_AUDIO_API +# define ECORE_AUDIO_API_WEAK +# endif +#endif + +#endif diff --git a/src/lib/ecore_audio/meson.build b/src/lib/ecore_audio/meson.build index 0376968a4b..95ffddf5b5 100644 --- a/src/lib/ecore_audio/meson.build +++ b/src/lib/ecore_audio/meson.build @@ -24,6 +24,7 @@ foreach eo_file : pub_eo_files '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'), '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'), + '-e', 'ECORE_AUDIO_API', '-gchd', '@INPUT@']) endforeach @@ -80,7 +81,7 @@ endif ecore_audio_lib = library('ecore_audio', ecore_audio_src, pub_eo_file_target, - c_args : package_c_args, + c_args : [package_c_args, '-DECORE_AUDIO_BUILD'], dependencies: ecore_audio_pub_deps + ecore_audio_deps + ecore_audio_ext_deps, include_directories : config_dir, install: true,