summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2020-10-30 10:53:34 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-12-14 13:22:42 -0300
commit8ba326b443b279c361f9516f674bcd21da11779f (patch)
treee8d4a2c09334fc1e6f8d4af002ecf743954dff76
parentd924100b42be59d50152fda4ad2591a5fc275db7 (diff)
downloadefl-8ba326b443b279c361f9516f674bcd21da11779f.tar.gz
efl_canvas_wl: Rename EAPI macro to EFL_CANVAS_WL_API in Efl Canvas WL library
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 <jpaulotiz@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com>
-rw-r--r--src/lib/efl_canvas_wl/Efl_Canvas_Wl.h25
-rw-r--r--src/lib/efl_canvas_wl/efl_canvas_wl_api.h34
-rw-r--r--src/lib/efl_canvas_wl/meson.build3
3 files changed, 38 insertions, 24 deletions
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 <Evas.h>
#include <Efl_Core.h>
-#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 <efl_canvas_wl_api.h>
#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',