summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2021-01-01 17:31:37 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2021-01-01 17:34:01 -0300
commit6f23a9daa18c4536ee8a530411cd249bd5e5f239 (patch)
tree960f718bdc67e32735e92dee0944fb9ff9f59eba /src/lib
parentff73049593e52a0bafc1d8aa8727d6dbf8a286b6 (diff)
ector: Rename EAPI macro to ECTOR_API in Ector library
Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. = The Rationale = 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> Reviewers: vtorri, woohyun, jptiz, lucas Reviewed By: vtorri Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12226
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ector/Ector.h34
-rw-r--r--src/lib/ector/ector_api.h32
-rw-r--r--src/lib/ector/ector_main.c6
-rw-r--r--src/lib/ector/gl/Ector_GL.h29
-rw-r--r--src/lib/ector/gl/meson.build1
-rw-r--r--src/lib/ector/meson.build4
-rw-r--r--src/lib/ector/software/Ector_Software.h29
-rw-r--r--src/lib/ector/software/meson.build1
8 files changed, 46 insertions, 90 deletions
diff --git a/src/lib/ector/Ector.h b/src/lib/ector/Ector.h
index 9a7a7d3706..ba93fbddae 100644
--- a/src/lib/ector/Ector.h
+++ b/src/lib/ector/Ector.h
@@ -6,31 +6,8 @@
6#ifdef EFL_BETA_API_SUPPORT 6#ifdef EFL_BETA_API_SUPPORT
7#include <Efl.h> 7#include <Efl.h>
8#endif 8#endif
9#ifdef EAPI
10# undef EAPI
11#endif
12 9
13#ifdef _WIN32 10#include <ector_api.h>
14# ifdef EFL_BUILD
15# ifdef DLL_EXPORT
16# define EAPI __declspec(dllexport)
17# else
18# define EAPI
19# endif
20# else
21# define EAPI __declspec(dllimport)
22# endif
23#else
24# ifdef __GNUC__
25# if __GNUC__ >= 4
26# define EAPI __attribute__ ((visibility("default")))
27# else
28# define EAPI
29# endif
30# else
31# define EAPI
32# endif
33#endif
34 11
35#ifdef __cplusplus 12#ifdef __cplusplus
36extern "C" { 13extern "C" {
@@ -133,7 +110,7 @@ typedef enum _Ector_Update_Type
133 * 110 *
134 * @see ector_shutfown() 111 * @see ector_shutfown()
135 */ 112 */
136EAPI int ector_init(void); 113ECTOR_API int ector_init(void);
137 114
138/** 115/**
139 * @brief Shutdown the ector subsystem 116 * @brief Shutdown the ector subsystem
@@ -141,7 +118,7 @@ EAPI int ector_init(void);
141 * 118 *
142 * @see ector_init() 119 * @see ector_init()
143 */ 120 */
144EAPI int ector_shutdown(void); 121ECTOR_API int ector_shutdown(void);
145 122
146/** 123/**
147 * @brief Registers OpenGL API calls with the internal Ector_GL_API. 124 * @brief Registers OpenGL API calls with the internal Ector_GL_API.
@@ -156,7 +133,7 @@ EAPI int ector_shutdown(void);
156 * 133 *
157 * @see dlsym() 134 * @see dlsym()
158 */ 135 */
159EAPI Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib); 136ECTOR_API Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib);
160 137
161/* Avoid redefinition of types */ 138/* Avoid redefinition of types */
162#define _ECTOR_SURFACE_EO_CLASS_TYPE 139#define _ECTOR_SURFACE_EO_CLASS_TYPE
@@ -177,7 +154,4 @@ EAPI Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void
177} 154}
178#endif 155#endif
179 156
180#undef EAPI
181#define EAPI
182
183#endif 157#endif
diff --git a/src/lib/ector/ector_api.h b/src/lib/ector/ector_api.h
new file mode 100644
index 0000000000..f0549582d0
--- /dev/null
+++ b/src/lib/ector/ector_api.h
@@ -0,0 +1,32 @@
1#ifndef _EFL_ECTOR_API_H
2#define _EFL_ECTOR_API_H
3
4#ifdef ECTOR_API
5#error ECTOR_API should not be already defined
6#endif
7
8#ifdef _WIN32
9# ifndef ECTOR_STATIC
10# ifdef ECTOR_BUILD
11# define ECTOR_API __declspec(dllexport)
12# else
13# define ECTOR_API __declspec(dllimport)
14# endif
15# else
16# define ECTOR_API
17# endif
18# define ECTOR_API_WEAK
19#elif defined(__GNUC__)
20# if __GNUC__ >= 4
21# define ECTOR_API __attribute__ ((visibility("default")))
22# define ECTOR_API_WEAK __attribute__ ((weak))
23# else
24# define ECTOR_API
25# define ECTOR_API_WEAK
26# endif
27#else
28# define ECTOR_API
29# define ECTOR_API_WEAK
30#endif
31
32#endif
diff --git a/src/lib/ector/ector_main.c b/src/lib/ector/ector_main.c
index db65c44ea4..5a8dcc25fa 100644
--- a/src/lib/ector/ector_main.c
+++ b/src/lib/ector/ector_main.c
@@ -27,7 +27,7 @@ int _ector_log_dom_global = 0;
27 27
28static int _ector_main_count = 0; 28static int _ector_main_count = 0;
29 29
30EAPI int 30ECTOR_API int
31ector_init(void) 31ector_init(void)
32{ 32{
33 if (EINA_LIKELY(_ector_main_count > 0)) 33 if (EINA_LIKELY(_ector_main_count > 0))
@@ -62,7 +62,7 @@ donothing(void)
62{ 62{
63} 63}
64 64
65EAPI Eina_Bool 65ECTOR_API Eina_Bool
66ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib) 66ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib)
67{ 67{
68 Eina_Bool r = EINA_TRUE; 68 Eina_Bool r = EINA_TRUE;
@@ -221,7 +221,7 @@ ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib)
221 return r; 221 return r;
222} 222}
223 223
224EAPI int 224ECTOR_API int
225ector_shutdown(void) 225ector_shutdown(void)
226{ 226{
227 if (_ector_main_count <= 0) 227 if (_ector_main_count <= 0)
diff --git a/src/lib/ector/gl/Ector_GL.h b/src/lib/ector/gl/Ector_GL.h
index 88b6c6bae1..6a9efe27de 100644
--- a/src/lib/ector/gl/Ector_GL.h
+++ b/src/lib/ector/gl/Ector_GL.h
@@ -3,31 +3,7 @@
3 3
4#include <Ector.h> 4#include <Ector.h>
5 5
6#ifdef EAPI 6#include "ector_api.h"
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef EFL_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif
17# else
18# define EAPI __declspec(dllimport)
19# endif
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif
31 7
32#ifdef EFL_BETA_API_SUPPORT 8#ifdef EFL_BETA_API_SUPPORT
33 9
@@ -48,7 +24,4 @@ typedef short GLshort;
48 24
49#endif 25#endif
50 26
51#undef EAPI
52#define EAPI
53
54#endif 27#endif
diff --git a/src/lib/ector/gl/meson.build b/src/lib/ector/gl/meson.build
index 4bb792c3a7..3837f0ece8 100644
--- a/src/lib/ector/gl/meson.build
+++ b/src/lib/ector/gl/meson.build
@@ -31,6 +31,7 @@ foreach eo_file : pub_eo_files
31 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), 31 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'),
32 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'), 32 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'),
33 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'), 33 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'),
34 '-e', 'ECTOR_API',
34 '-gchd', '@INPUT@']) 35 '-gchd', '@INPUT@'])
35endforeach 36endforeach
36 37
diff --git a/src/lib/ector/meson.build b/src/lib/ector/meson.build
index 0d044b5404..9a9545fee8 100644
--- a/src/lib/ector/meson.build
+++ b/src/lib/ector/meson.build
@@ -46,6 +46,7 @@ foreach eo_file : pub_eo_files
46 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), 46 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'),
47 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'), 47 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'),
48 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'), 48 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'),
49 '-e', 'ECTOR_API',
49 '-gchd', '@INPUT@']) 50 '-gchd', '@INPUT@'])
50endforeach 51endforeach
51 52
@@ -76,6 +77,7 @@ foreach eo_file : pub_eo_types_files
76 command : eolian_gen + [ '-I', meson.current_source_dir(), eolian_include_directories, 77 command : eolian_gen + [ '-I', meson.current_source_dir(), eolian_include_directories,
77 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), 78 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'),
78 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'), 79 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'),
80 '-e', 'ECTOR_API',
79 '-ghd', '@INPUT@']) 81 '-ghd', '@INPUT@'])
80endforeach 82endforeach
81 83
@@ -89,7 +91,7 @@ ector_ext_deps += ector_opt_lib_dep
89 91
90ector_lib = library('ector', 92ector_lib = library('ector',
91 ector_src, pub_eo_file_target, 93 ector_src, pub_eo_file_target,
92 c_args : package_c_args, 94 c_args : [package_c_args, '-DECTOR_BUILD'],
93 dependencies: ector_pub_deps + ector_ext_deps + ector_deps, 95 dependencies: ector_pub_deps + ector_ext_deps + ector_deps,
94 include_directories : config_dir, 96 include_directories : config_dir,
95 install: true, 97 install: true,
diff --git a/src/lib/ector/software/Ector_Software.h b/src/lib/ector/software/Ector_Software.h
index 85529e6f21..249e8a638a 100644
--- a/src/lib/ector/software/Ector_Software.h
+++ b/src/lib/ector/software/Ector_Software.h
@@ -3,31 +3,7 @@
3 3
4#include <Ector.h> 4#include <Ector.h>
5 5
6#ifdef EAPI 6#include "ector_api.h"
7# undef EAPI
8#endif
9
10#ifdef _WIN32
11# ifdef EFL_BUILD
12# ifdef DLL_EXPORT
13# define EAPI __declspec(dllexport)
14# else
15# define EAPI
16# endif
17# else
18# define EAPI __declspec(dllimport)
19# endif
20#else
21# ifdef __GNUC__
22# if __GNUC__ >= 4
23# define EAPI __attribute__ ((visibility("default")))
24# else
25# define EAPI
26# endif
27# else
28# define EAPI
29# endif
30#endif
31 7
32#ifdef EFL_BETA_API_SUPPORT 8#ifdef EFL_BETA_API_SUPPORT
33 9
@@ -42,7 +18,4 @@
42 18
43#endif 19#endif
44 20
45#undef EAPI
46#define EAPI
47
48#endif 21#endif
diff --git a/src/lib/ector/software/meson.build b/src/lib/ector/software/meson.build
index 75d217142a..a87f66efa5 100644
--- a/src/lib/ector/software/meson.build
+++ b/src/lib/ector/software/meson.build
@@ -33,6 +33,7 @@ foreach eo_file : pub_eo_files
33 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'), 33 '-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'),
34 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'), 34 '-o', 'c:' + join_paths(meson.current_build_dir(), eo_file + '.c'),
35 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'), 35 '-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'),
36 '-e', 'ECTOR_API',
36 '-gchd', '@INPUT@']) 37 '-gchd', '@INPUT@'])
37endforeach 38endforeach
38 39