summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertise.dev>2020-10-16 16:46:40 -0300
committerFelipe Magno de Almeida <felipe@expertise.dev>2020-12-14 13:22:33 -0300
commit61da7693070a5f8555162f14d2518a513bca458d (patch)
tree8635a69f688dadd02ab5a9cbabf5722054296d2c
parent9eff6d7cfa3e1991bd5bc28885f7dcaab9a8bbc5 (diff)
downloadefl-61da7693070a5f8555162f14d2518a513bca458d.tar.gz
ecore_avahi: Rename EAPI macro to ECORE_AVAHI_API in Ecore Avahi 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_avahi/Ecore_Avahi.h35
-rw-r--r--src/lib/ecore_avahi/ecore_avahi.c6
-rw-r--r--src/lib/ecore_avahi/ecore_avahi_api.h34
-rw-r--r--src/lib/ecore_avahi/meson.build2
4 files changed, 42 insertions, 35 deletions
diff --git a/src/lib/ecore_avahi/Ecore_Avahi.h b/src/lib/ecore_avahi/Ecore_Avahi.h
index ed19a12b03..3b1f1d3e74 100644
--- a/src/lib/ecore_avahi/Ecore_Avahi.h
+++ b/src/lib/ecore_avahi/Ecore_Avahi.h
@@ -7,31 +7,7 @@
#ifndef _ECORE_AVAHI_H
# define _ECORE_AVAHI_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 <ecore_avahi_api.h>
#ifdef __cplusplus
extern "C" {
@@ -55,7 +31,7 @@ typedef struct _Ecore_Avahi Ecore_Avahi; /**< A handle for an Avahi instance. */
* @return A handler that reference the AvahiPoll context
* @since 1.9
*/
-EAPI Ecore_Avahi *ecore_avahi_add(void);
+ECORE_AVAHI_API Ecore_Avahi *ecore_avahi_add(void);
/**
* @brief Deletes the specified handler of an AvahiPoll.
@@ -66,7 +42,7 @@ EAPI Ecore_Avahi *ecore_avahi_add(void);
* Be aware there should not be any reference still using that handler before
* destroying it.
*/
-EAPI void ecore_avahi_del(Ecore_Avahi *handler);
+ECORE_AVAHI_API void ecore_avahi_del(Ecore_Avahi *handler);
/**
* @brief Gets the AvahiPoll structure to integrate with Ecore main loop.
@@ -75,7 +51,7 @@ EAPI void ecore_avahi_del(Ecore_Avahi *handler);
* @return return the actual AvahiPoll structure to use with Avahi.
* @since 1.9
*/
-EAPI const void *ecore_avahi_poll_get(Ecore_Avahi *handler); // return AvahiPoll
+ECORE_AVAHI_API const void *ecore_avahi_poll_get(Ecore_Avahi *handler); // return AvahiPoll
/**
* @}
@@ -85,7 +61,4 @@ EAPI const void *ecore_avahi_poll_get(Ecore_Avahi *handler); // return AvahiPol
}
#endif
-#undef EAPI
-#define EAPI
-
#endif
diff --git a/src/lib/ecore_avahi/ecore_avahi.c b/src/lib/ecore_avahi/ecore_avahi.c
index 07f07d0626..5404264555 100644
--- a/src/lib/ecore_avahi/ecore_avahi.c
+++ b/src/lib/ecore_avahi/ecore_avahi.c
@@ -188,7 +188,7 @@ _ecore_avahi_timeout_free(AvahiTimeout *t)
}
#endif
-EAPI Ecore_Avahi *
+ECORE_AVAHI_API Ecore_Avahi *
ecore_avahi_add(void)
{
#ifdef HAVE_AVAHI
@@ -213,7 +213,7 @@ ecore_avahi_add(void)
#endif
}
-EAPI void
+ECORE_AVAHI_API void
ecore_avahi_del(Ecore_Avahi *handler)
{
#ifdef HAVE_AVAHI
@@ -238,7 +238,7 @@ ecore_avahi_del(Ecore_Avahi *handler)
#endif
}
-EAPI const void *
+ECORE_AVAHI_API const void *
ecore_avahi_poll_get(Ecore_Avahi *handler)
{
#ifdef HAVE_AVAHI
diff --git a/src/lib/ecore_avahi/ecore_avahi_api.h b/src/lib/ecore_avahi/ecore_avahi_api.h
new file mode 100644
index 0000000000..1176808df7
--- /dev/null
+++ b/src/lib/ecore_avahi/ecore_avahi_api.h
@@ -0,0 +1,34 @@
+#ifndef _EFL_ECORE_AVAHI_API_H
+#define _EFL_ECORE_AVAHI_API_H
+
+#ifdef ECORE_AVAHI_API
+#error ECORE_AVAHI_API should not be already defined
+#endif
+
+#ifdef _WIN32
+# ifndef ECORE_AVAHI_STATIC
+# ifdef ECORE_AVAHI_BUILD
+# define ECORE_AVAHI_API __declspec(dllexport)
+# else
+# define ECORE_AVAHI_API __declspec(dllimport)
+# endif
+# else
+# define ECORE_AVAHI_API
+# endif
+# define ECORE_AVAHI_API_WEAK
+#else
+# ifdef __GNUC__
+# if __GNUC__ >= 4
+# define ECORE_AVAHI_API __attribute__ ((visibility("default")))
+# define ECORE_AVAHI_API_WEAK __attribute__ ((weak))
+# else
+# define ECORE_AVAHI_API
+# define ECORE_AVAHI_API_WEAK
+# endif
+# else
+# define ECORE_AVAHI_API
+# define ECORE_AVAHI_API_WEAK
+# endif
+#endif
+
+#endif
diff --git a/src/lib/ecore_avahi/meson.build b/src/lib/ecore_avahi/meson.build
index 6a14a4e9e9..55184519ea 100644
--- a/src/lib/ecore_avahi/meson.build
+++ b/src/lib/ecore_avahi/meson.build
@@ -9,7 +9,7 @@ config_h.set('HAVE_AVAHI', '1')
ecore_avahi_lib = library('ecore_avahi',
ecore_avahi_src,
- c_args : package_c_args,
+ c_args : [package_c_args, '-DECORE_AVAHI_BUILD'],
dependencies: [m] + ecore_avahi_deps + ecore_avahi_pub_deps,
include_directories : config_dir + [include_directories(join_paths('..','..'))],
install: true,