summaryrefslogtreecommitdiff
path: root/src/lib/elementary/elm_module_helper.h
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2021-04-17 16:07:55 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2021-04-17 16:07:56 -0300
commita331384eede6dd79610e2edcb232692055344769 (patch)
tree8db489e4e25ee6d9bca095ab208d62aa014bca56 /src/lib/elementary/elm_module_helper.h
parent65d528a3798b72dbd2e01b4f37caa898af50e359 (diff)
modules: Rename EAPI macro to MODAPI for modules
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, jptiz, woohyun, lucas, SPAM-smith78899 Reviewed By: vtorri, SPAM-smith78899 Subscribers: SPAM-smith78899, raster, SPAM-cabanacatalogs, cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12228
Diffstat (limited to '')
-rw-r--r--src/lib/elementary/elm_module_helper.h43
1 files changed, 14 insertions, 29 deletions
diff --git a/src/lib/elementary/elm_module_helper.h b/src/lib/elementary/elm_module_helper.h
index eba3237266..5c2f49ebdd 100644
--- a/src/lib/elementary/elm_module_helper.h
+++ b/src/lib/elementary/elm_module_helper.h
@@ -1,43 +1,28 @@
1/* A small helper header defining EAPI for elementary modules, it should be 1/* A small helper header defining ELM_API for elementary modules, it should be
2 * included last in the modules C files. 2 * included last in the modules C files.
3 */ 3 */
4 4
5#ifndef ELM_MODULE_HELPER_H 5#ifndef ELM_MODULE_HELPER_H
6#define ELM_MODULE_HELPER_H 6#define ELM_MODULE_HELPER_H
7 7
8#ifdef EAPI
9# undef EAPI
10#endif
11#ifdef EWAPI
12# undef EWAPI
13#endif
14
15#ifdef _WIN32 8#ifdef _WIN32
16# ifdef EFL_BUILD 9# ifndef EFL_MODULE_STATIC
17# ifdef DLL_EXPORT 10# define EMODAPI __declspec(dllexport)
18# define EAPI __declspec(dllexport)
19# else
20# define EAPI
21# endif
22# else 11# else
23# define EAPI __declspec(dllimport) 12# define EMODAPI
24# endif 13# endif
25# define EAPI_WEAK 14# define EMODAPI_WEAK
26#else 15#elif defined(__GNUC__)
27# ifdef __GNUC__ 16# if __GNUC__ >= 4
28# if __GNUC__ >= 4 17# define EMODAPI __attribute__ ((visibility("default")))
29# define EAPI __attribute__ ((visibility("default"))) 18# define EMODAPI_WEAK __attribute__ ((weak))
30# define EAPI_WEAK __attribute__ ((weak))
31# else
32# define EAPI
33# define EAPI_WEAK
34# endif
35# else 19# else
36# define EAPI 20# define EMODAPI
37# define EAPI_WEAK 21# define EMODAPI_WEAK
38# endif 22# endif
23#else
24# define EMODAPI
25# define EMODAPI_WEAK
39#endif 26#endif
40 27
41#define EWAPI EAPI EAPI_WEAK
42
43#endif 28#endif