summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2020-09-17 10:18:19 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-09-17 10:18:19 -0300
commit4f3fbec6c9917575ffe9370b44fa8efa1476a34a (patch)
treefa155ba7e939784cc10d3c42e447a0fa7bb0d010
parentd688766d0f83452abbeab2ded4c940f2e9650d2e (diff)
downloadefl-4f3fbec6c9917575ffe9370b44fa8efa1476a34a.tar.gz
ector: Rename EAPI macro to ECTOR_API in Ector 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/ector/Ector.h34
-rw-r--r--src/lib/ector/ector_api.h34
-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, 48 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 @@
#ifdef EFL_BETA_API_SUPPORT
#include <Efl.h>
#endif
-#ifdef EAPI
-# undef EAPI
-#endif
-#ifdef _WIN32
-# ifdef EFL_BUILD
-# ifdef DLL_EXPORT
-# define EAPI __declspec(dllexport)
-# else
-# define EAPI
-# endif
-# else
-# define EAPI __declspec(dllimport)
-# endif
-#else
-# ifdef __GNUC__
-# if __GNUC__ >= 4
-# define EAPI __attribute__ ((visibility("default")))
-# else
-# define EAPI
-# endif
-# else
-# define EAPI
-# endif
-#endif
+#include <ector_api.h>
#ifdef __cplusplus
extern "C" {
@@ -133,7 +110,7 @@ typedef enum _Ector_Update_Type
*
* @see ector_shutfown()
*/
-EAPI int ector_init(void);
+ECTOR_API int ector_init(void);
/**
* @brief Shutdown the ector subsystem
@@ -141,7 +118,7 @@ EAPI int ector_init(void);
*
* @see ector_init()
*/
-EAPI int ector_shutdown(void);
+ECTOR_API int ector_shutdown(void);
/**
* @brief Registers OpenGL API calls with the internal Ector_GL_API.
@@ -156,7 +133,7 @@ EAPI int ector_shutdown(void);
*
* @see dlsym()
*/
-EAPI Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib);
+ECTOR_API Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib);
/* Avoid redefinition of types */
#define _ECTOR_SURFACE_EO_CLASS_TYPE
@@ -177,7 +154,4 @@ EAPI Eina_Bool ector_glsym_set(void *(*glsym)(void *lib, const char *name), void
}
#endif
-#undef EAPI
-#define EAPI
-
#endif
diff --git a/src/lib/ector/ector_api.h b/src/lib/ector/ector_api.h
new file mode 100644
index 0000000000..af92dc05f2
--- /dev/null
+++ b/src/lib/ector/ector_api.h
@@ -0,0 +1,34 @@
+#ifndef _EFL_ECTOR_API_H
+#define _EFL_ECTOR_API_H
+
+#ifdef ECTOR_API
+#error ECTOR_API should not be already defined
+#endif
+
+#ifdef _WIN32
+# ifndef ECTOR_STATIC
+# ifdef ECTOR_BUILD
+# define ECTOR_API __declspec(dllexport)
+# else
+# define ECTOR_API __declspec(dllimport)
+# endif
+# else
+# define ECTOR_API
+# endif
+# define ECTOR_API_WEAK
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define ECTOR_API __attribute__ ((visibility("default")))
+# define ECTOR_API_WEAK __attribute__ ((weak))
+# else
+# define ECTOR_API
+# define ECTOR_API_WEAK
+# endif
+# else
+# define ECTOR_API
+# define ECTOR_API_WEAK
+# endif
+#endif
+
+#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;
static int _ector_main_count = 0;
-EAPI int
+ECTOR_API int
ector_init(void)
{
if (EINA_LIKELY(_ector_main_count > 0))
@@ -62,7 +62,7 @@ donothing(void)
{
}
-EAPI Eina_Bool
+ECTOR_API Eina_Bool
ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib)
{
Eina_Bool r = EINA_TRUE;
@@ -221,7 +221,7 @@ ector_glsym_set(void *(*glsym)(void *lib, const char *name), void *lib)
return r;
}
-EAPI int
+ECTOR_API int
ector_shutdown(void)
{
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 @@
#include <Ector.h>
-#ifdef EAPI
-# undef EAPI
-#endif
-
-#ifdef _WIN32
-# ifdef EFL_BUILD
-# ifdef DLL_EXPORT
-# define EAPI __declspec(dllexport)
-# else
-# define EAPI
-# endif
-# else
-# define EAPI __declspec(dllimport)
-# endif
-#else
-# ifdef __GNUC__
-# if __GNUC__ >= 4
-# define EAPI __attribute__ ((visibility("default")))
-# else
-# define EAPI
-# endif
-# else
-# define EAPI
-# endif
-#endif
+#include "ector_api.h"
#ifdef EFL_BETA_API_SUPPORT
@@ -48,7 +24,4 @@ typedef short GLshort;
#endif
-#undef EAPI
-#define EAPI
-
#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
'-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', 'ECTOR_API',
'-gchd', '@INPUT@'])
endforeach
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
'-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', 'ECTOR_API',
'-gchd', '@INPUT@'])
endforeach
@@ -76,6 +77,7 @@ foreach eo_file : pub_eo_types_files
command : eolian_gen + [ '-I', meson.current_source_dir(), eolian_include_directories,
'-o', 'h:' + join_paths(meson.current_build_dir(), eo_file + '.h'),
'-o', 'd:' + join_paths(meson.current_build_dir(), eo_file + '.d'),
+ '-e', 'ECTOR_API',
'-ghd', '@INPUT@'])
endforeach
@@ -89,7 +91,7 @@ ector_ext_deps += ector_opt_lib_dep
ector_lib = library('ector',
ector_src, pub_eo_file_target,
- c_args : package_c_args,
+ c_args : [package_c_args, '-DECTOR_BUILD'],
dependencies: ector_pub_deps + ector_ext_deps + ector_deps,
include_directories : config_dir,
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 @@
#include <Ector.h>
-#ifdef EAPI
-# undef EAPI
-#endif
-
-#ifdef _WIN32
-# ifdef EFL_BUILD
-# ifdef DLL_EXPORT
-# define EAPI __declspec(dllexport)
-# else
-# define EAPI
-# endif
-# else
-# define EAPI __declspec(dllimport)
-# endif
-#else
-# ifdef __GNUC__
-# if __GNUC__ >= 4
-# define EAPI __attribute__ ((visibility("default")))
-# else
-# define EAPI
-# endif
-# else
-# define EAPI
-# endif
-#endif
+#include "ector_api.h"
#ifdef EFL_BETA_API_SUPPORT
@@ -42,7 +18,4 @@
#endif
-#undef EAPI
-#define EAPI
-
#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
'-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', 'ECTOR_API',
'-gchd', '@INPUT@'])
endforeach