summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2020-07-06 09:06:16 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-12-14 13:22:42 -0300
commit0dfc72d4275e73e7f3457cd26688b78ae51f3b24 (patch)
tree7d6f4f7f0c33c8f1b16e6a861441fe355373f8b8
parent697724cd413f280c08d91e8901b2b9341ab0fa9e (diff)
ecore_sdl: Rename EAPI macro to ECORE_SDL_API in Ecore SDL 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/ecore_sdl/Ecore_Sdl.h43
-rw-r--r--src/lib/ecore_sdl/ecore_sdl.c14
-rw-r--r--src/lib/ecore_sdl/ecore_sdl_api.h34
-rw-r--r--src/lib/ecore_sdl/meson.build3
4 files changed, 51 insertions, 43 deletions
diff --git a/src/lib/ecore_sdl/Ecore_Sdl.h b/src/lib/ecore_sdl/Ecore_Sdl.h
index c110f14f3d..dcb8a694ca 100644
--- a/src/lib/ecore_sdl/Ecore_Sdl.h
+++ b/src/lib/ecore_sdl/Ecore_Sdl.h
@@ -1,31 +1,7 @@
1#ifndef _ECORE_SDL_H 1#ifndef _ECORE_SDL_H
2#define _ECORE_SDL_H 2#define _ECORE_SDL_H
3 3
4#ifdef EAPI 4#include <ecore_sdl_api.h>
5# undef EAPI
6#endif
7
8#ifdef _WIN32
9# ifdef EFL_BUILD
10# ifdef DLL_EXPORT
11# define EAPI __declspec(dllexport)
12# else
13# define EAPI
14# endif
15# else
16# define EAPI __declspec(dllimport)
17# endif
18#else
19# ifdef __GNUC__
20# if __GNUC__ >= 4
21# define EAPI __attribute__ ((visibility("default")))
22# else
23# define EAPI
24# endif
25# else
26# define EAPI
27# endif
28#endif
29 5
30/** 6/**
31 * @file 7 * @file
@@ -36,10 +12,10 @@
36extern "C" { 12extern "C" {
37#endif 13#endif
38 14
39EAPI extern int ECORE_SDL_EVENT_GOT_FOCUS; 15ECORE_SDL_API extern int ECORE_SDL_EVENT_GOT_FOCUS;
40EAPI extern int ECORE_SDL_EVENT_LOST_FOCUS; 16ECORE_SDL_API extern int ECORE_SDL_EVENT_LOST_FOCUS;
41EAPI extern int ECORE_SDL_EVENT_RESIZE; 17ECORE_SDL_API extern int ECORE_SDL_EVENT_RESIZE;
42EAPI extern int ECORE_SDL_EVENT_EXPOSE; 18ECORE_SDL_API extern int ECORE_SDL_EVENT_EXPOSE;
43 19
44typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize; 20typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize;
45struct _Ecore_Sdl_Event_Video_Resize 21struct _Ecore_Sdl_Event_Video_Resize
@@ -55,9 +31,9 @@ struct _Ecore_Sdl_Event_Window
55 unsigned int windowID; 31 unsigned int windowID;
56}; 32};
57 33
58EAPI int ecore_sdl_init(const char *name); 34ECORE_SDL_API int ecore_sdl_init(const char *name);
59EAPI int ecore_sdl_shutdown(void); 35ECORE_SDL_API int ecore_sdl_shutdown(void);
60EAPI void ecore_sdl_feed_events(void); 36ECORE_SDL_API void ecore_sdl_feed_events(void);
61 37
62 /* The following data structure have been deprecated since a long time */ 38 /* The following data structure have been deprecated since a long time */
63 39
@@ -120,7 +96,4 @@ struct _Ecore_Sdl_Event_Mouse_Wheel /** SDL Mouse Wheel event */
120} 96}
121#endif 97#endif
122 98
123#undef EAPI
124#define EAPI
125
126#endif 99#endif
diff --git a/src/lib/ecore_sdl/ecore_sdl.c b/src/lib/ecore_sdl/ecore_sdl.c
index b711058ac4..cd671dabeb 100644
--- a/src/lib/ecore_sdl/ecore_sdl.c
+++ b/src/lib/ecore_sdl/ecore_sdl.c
@@ -22,10 +22,10 @@ struct _Ecore_SDL_Pressed
22 SDL_Keycode key; 22 SDL_Keycode key;
23}; 23};
24 24
25EAPI int ECORE_SDL_EVENT_GOT_FOCUS = 0; 25ECORE_SDL_API int ECORE_SDL_EVENT_GOT_FOCUS = 0;
26EAPI int ECORE_SDL_EVENT_LOST_FOCUS = 0; 26ECORE_SDL_API int ECORE_SDL_EVENT_LOST_FOCUS = 0;
27EAPI int ECORE_SDL_EVENT_RESIZE = 0; 27ECORE_SDL_API int ECORE_SDL_EVENT_RESIZE = 0;
28EAPI int ECORE_SDL_EVENT_EXPOSE = 0; 28ECORE_SDL_API int ECORE_SDL_EVENT_EXPOSE = 0;
29 29
30static int _ecore_sdl_init_count = 0; 30static int _ecore_sdl_init_count = 0;
31static Eina_Rbtree *repeat = NULL; 31static Eina_Rbtree *repeat = NULL;
@@ -61,7 +61,7 @@ _ecore_sdl_pressed_node(const Ecore_SDL_Pressed *node,
61 * been initialised without being shut down. 61 * been initialised without being shut down.
62 * @ingroup Ecore_SDL_Library_Group 62 * @ingroup Ecore_SDL_Library_Group
63 */ 63 */
64EAPI int 64ECORE_SDL_API int
65ecore_sdl_init(const char *name EINA_UNUSED) 65ecore_sdl_init(const char *name EINA_UNUSED)
66{ 66{
67 if(++_ecore_sdl_init_count != 1) 67 if(++_ecore_sdl_init_count != 1)
@@ -92,7 +92,7 @@ ecore_sdl_init(const char *name EINA_UNUSED)
92 * being shut down. 92 * being shut down.
93 * @ingroup Ecore_SDL_Library_Group 93 * @ingroup Ecore_SDL_Library_Group
94 */ 94 */
95EAPI int 95ECORE_SDL_API int
96ecore_sdl_shutdown(void) 96ecore_sdl_shutdown(void)
97{ 97{
98 if (--_ecore_sdl_init_count != 0) 98 if (--_ecore_sdl_init_count != 0)
@@ -161,7 +161,7 @@ _ecore_sdl_event_key(SDL_Event *event, double timestamp)
161 * Poll SDL for mouse, keyboard, and window events, and add corresponding events to ecore. 161 * Poll SDL for mouse, keyboard, and window events, and add corresponding events to ecore.
162 * @ingroup Ecore_SDL_Library_Group 162 * @ingroup Ecore_SDL_Library_Group
163 */ 163 */
164EAPI void 164ECORE_SDL_API void
165ecore_sdl_feed_events(void) 165ecore_sdl_feed_events(void)
166{ 166{
167 SDL_Event event; 167 SDL_Event event;
diff --git a/src/lib/ecore_sdl/ecore_sdl_api.h b/src/lib/ecore_sdl/ecore_sdl_api.h
new file mode 100644
index 0000000000..593a607876
--- /dev/null
+++ b/src/lib/ecore_sdl/ecore_sdl_api.h
@@ -0,0 +1,34 @@
1#ifndef _EFL_ECORE_SDL_API_H
2#define _EFL_ECORE_SDL_API_H
3
4#ifdef ECORE_SDL_API
5#error ECORE_SDL_API should not be already defined
6#endif
7
8#ifdef _WIN32
9# ifndef ECORE_SDL_STATIC
10# ifdef ECORE_SDL_BUILD
11# define ECORE_SDL_API __declspec(dllexport)
12# else
13# define ECORE_SDL_API __declspec(dllimport)
14# endif
15# else
16# define ECORE_SDL_API
17# endif
18# define ECORE_SDL_API_WEAK
19#else
20# ifdef __GNUC__
21# if __GNUC__ >= 4
22# define ECORE_SDL_API __attribute__ ((visibility("default")))
23# define ECORE_SDL_API_WEAK __attribute__ ((weak))
24# else
25# define ECORE_SDL_API
26# define ECORE_SDL_API_WEAK
27# endif
28# else
29# define ECORE_SDL_API
30# define ECORE_SDL_API_WEAK
31# endif
32#endif
33
34#endif
diff --git a/src/lib/ecore_sdl/meson.build b/src/lib/ecore_sdl/meson.build
index f3cd70428d..d94ab0fa78 100644
--- a/src/lib/ecore_sdl/meson.build
+++ b/src/lib/ecore_sdl/meson.build
@@ -8,6 +8,7 @@ ecore_sdl_src = files([
8 8
9ecore_sdl_header_src = [ 9ecore_sdl_header_src = [
10 'Ecore_Sdl.h', 10 'Ecore_Sdl.h',
11 'ecore_sdl_api.h',
11 'Ecore_Sdl_Keys.h' 12 'Ecore_Sdl_Keys.h'
12] 13]
13 14
@@ -18,7 +19,7 @@ ecore_sdl_lib = library('ecore_sdl',
18 dependencies: [ecore_sdl_deps, ecore_sdl_pub_deps, ecore_sdl_ext_deps], 19 dependencies: [ecore_sdl_deps, ecore_sdl_pub_deps, ecore_sdl_ext_deps],
19 include_directories : config_dir + [include_directories(join_paths('..','..'))], 20 include_directories : config_dir + [include_directories(join_paths('..','..'))],
20 install: true, 21 install: true,
21 c_args : package_c_args, 22 c_args : [package_c_args, '-DECORE_SDL_BUILD'],
22) 23)
23 24
24ecore_sdl = declare_dependency( 25ecore_sdl = declare_dependency(