From 8ba326b443b279c361f9516f674bcd21da11779f Mon Sep 17 00:00:00 2001 From: Felipe Magno de Almeida Date: Fri, 30 Oct 2020 10:53:34 -0300 Subject: efl_canvas_wl: Rename EAPI macro to EFL_CANVAS_WL_API in Efl Canvas WL 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/efl_canvas_wl/Efl_Canvas_Wl.h | 25 ++--------------------- src/lib/efl_canvas_wl/efl_canvas_wl_api.h | 34 +++++++++++++++++++++++++++++++ src/lib/efl_canvas_wl/meson.build | 3 ++- 3 files changed, 38 insertions(+), 24 deletions(-) create mode 100644 src/lib/efl_canvas_wl/efl_canvas_wl_api.h diff --git a/src/lib/efl_canvas_wl/Efl_Canvas_Wl.h b/src/lib/efl_canvas_wl/Efl_Canvas_Wl.h index b0c0772ab8..d3d35d7803 100644 --- a/src/lib/efl_canvas_wl/Efl_Canvas_Wl.h +++ b/src/lib/efl_canvas_wl/Efl_Canvas_Wl.h @@ -3,24 +3,7 @@ #include #include -#ifdef EAPI -# undef EAPI -#endif -#ifdef EAPI_WEAK -# undef EAPI_WEAK -#endif - -# ifdef __GNUC__ -# if __GNUC__ >= 4 -# define EAPI __attribute__ ((visibility("default"))) -# define EAPI_WEAK -# else -# define EAPI -# define EAPI_WEAK -# endif -# endif - -#define EWAPI EAPI EAPI_WEAK +#include #ifdef WAYLAND_UTIL_H typedef struct wl_surface Efl_Canvas_Wl_Wl_Surface; @@ -53,9 +36,5 @@ typedef struct Efl_Canvas_Wl_Xkb_State Efl_Canvas_Wl_Xkb_State; * @return The Evas_Object of the surface, NULL on failure * @since 1.24 */ -EAPI Evas_Object *efl_canvas_wl_extracted_surface_object_find(void *surface_resource); -#undef EAPI -#define EAPI -#undef EAPI_WEAK -#define EAPI_WEAK +EFL_CANVAS_WL_API Evas_Object *efl_canvas_wl_extracted_surface_object_find(void *surface_resource); #endif diff --git a/src/lib/efl_canvas_wl/efl_canvas_wl_api.h b/src/lib/efl_canvas_wl/efl_canvas_wl_api.h new file mode 100644 index 0000000000..349a3bc850 --- /dev/null +++ b/src/lib/efl_canvas_wl/efl_canvas_wl_api.h @@ -0,0 +1,34 @@ +#ifndef _EFL_EFL_CANVAS_WL_API_H +#define _EFL_EFL_CANVAS_WL_API_H + +#ifdef EFL_CANVAS_WL_API +#error EFL_CANVAS_WL_API should not be already defined +#endif + +#ifdef _WIN32 +# ifndef EFL_CANVAS_WL_STATIC +# ifdef EFL_CANVAS_WL_BUILD +# define EFL_CANVAS_WL_API __declspec(dllexport) +# else +# define EFL_CANVAS_WL_API __declspec(dllimport) +# endif +# else +# define EFL_CANVAS_WL_API +# endif +# define EFL_CANVAS_WL_API_WEAK +#else +# ifdef __GNUC__ +# if __GNUC__ >= 4 +# define EFL_CANVAS_WL_API __attribute__ ((visibility("default"))) +# define EFL_CANVAS_WL_API_WEAK __attribute__ ((weak)) +# else +# define EFL_CANVAS_WL_API +# define EFL_CANVAS_WL_API_WEAK +# endif +# else +# define EFL_CANVAS_WL_API +# define EFL_CANVAS_WL_API_WEAK +# endif +#endif + +#endif diff --git a/src/lib/efl_canvas_wl/meson.build b/src/lib/efl_canvas_wl/meson.build index 5955da62eb..9ae2b8051e 100644 --- a/src/lib/efl_canvas_wl/meson.build +++ b/src/lib/efl_canvas_wl/meson.build @@ -23,6 +23,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', 'EFL_CANVAS_WL_API', '-gchd', '@INPUT@']) endforeach @@ -31,7 +32,7 @@ efl_canvas_wl_src = files([ 'efl_canvas_wl.c', ]) -efl_canvas_wl_header_src = ['Efl_Canvas_Wl.h'] +efl_canvas_wl_header_src = ['Efl_Canvas_Wl.h', 'efl_canvas_wl_api.h'] eolian_include_directories += ['-I', meson.current_source_dir()] efl_canvas_wl_lib = library('efl_canvas_wl', -- cgit v1.2.1