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>
This commit is contained in:
Felipe Magno de Almeida 2020-10-16 16:46:40 -03:00
parent 95c2248065
commit 4a6882c2fd
4 changed files with 42 additions and 35 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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,