ecore_sdl: Rename EAPI macro to ECORE_SDL_API in Ecore SDL 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-07-06 09:06:16 -03:00
parent 24b6b8f459
commit 5e6945397f
4 changed files with 51 additions and 43 deletions

View File

@ -1,31 +1,7 @@
#ifndef _ECORE_SDL_H
#define _ECORE_SDL_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_sdl_api.h>
/**
* @file
@ -36,10 +12,10 @@
extern "C" {
#endif
EAPI extern int ECORE_SDL_EVENT_GOT_FOCUS;
EAPI extern int ECORE_SDL_EVENT_LOST_FOCUS;
EAPI extern int ECORE_SDL_EVENT_RESIZE;
EAPI extern int ECORE_SDL_EVENT_EXPOSE;
ECORE_SDL_API extern int ECORE_SDL_EVENT_GOT_FOCUS;
ECORE_SDL_API extern int ECORE_SDL_EVENT_LOST_FOCUS;
ECORE_SDL_API extern int ECORE_SDL_EVENT_RESIZE;
ECORE_SDL_API extern int ECORE_SDL_EVENT_EXPOSE;
typedef struct _Ecore_Sdl_Event_Video_Resize Ecore_Sdl_Event_Video_Resize;
struct _Ecore_Sdl_Event_Video_Resize
@ -55,9 +31,9 @@ struct _Ecore_Sdl_Event_Window
unsigned int windowID;
};
EAPI int ecore_sdl_init(const char *name);
EAPI int ecore_sdl_shutdown(void);
EAPI void ecore_sdl_feed_events(void);
ECORE_SDL_API int ecore_sdl_init(const char *name);
ECORE_SDL_API int ecore_sdl_shutdown(void);
ECORE_SDL_API void ecore_sdl_feed_events(void);
/* The following data structure have been deprecated since a long time */
@ -120,7 +96,4 @@ struct _Ecore_Sdl_Event_Mouse_Wheel /** SDL Mouse Wheel event */
}
#endif
#undef EAPI
#define EAPI
#endif

View File

@ -22,10 +22,10 @@ struct _Ecore_SDL_Pressed
SDL_Keycode key;
};
EAPI int ECORE_SDL_EVENT_GOT_FOCUS = 0;
EAPI int ECORE_SDL_EVENT_LOST_FOCUS = 0;
EAPI int ECORE_SDL_EVENT_RESIZE = 0;
EAPI int ECORE_SDL_EVENT_EXPOSE = 0;
ECORE_SDL_API int ECORE_SDL_EVENT_GOT_FOCUS = 0;
ECORE_SDL_API int ECORE_SDL_EVENT_LOST_FOCUS = 0;
ECORE_SDL_API int ECORE_SDL_EVENT_RESIZE = 0;
ECORE_SDL_API int ECORE_SDL_EVENT_EXPOSE = 0;
static int _ecore_sdl_init_count = 0;
static Eina_Rbtree *repeat = NULL;
@ -61,7 +61,7 @@ _ecore_sdl_pressed_node(const Ecore_SDL_Pressed *node,
* been initialised without being shut down.
* @ingroup Ecore_SDL_Library_Group
*/
EAPI int
ECORE_SDL_API int
ecore_sdl_init(const char *name EINA_UNUSED)
{
if(++_ecore_sdl_init_count != 1)
@ -92,7 +92,7 @@ ecore_sdl_init(const char *name EINA_UNUSED)
* being shut down.
* @ingroup Ecore_SDL_Library_Group
*/
EAPI int
ECORE_SDL_API int
ecore_sdl_shutdown(void)
{
if (--_ecore_sdl_init_count != 0)
@ -161,7 +161,7 @@ _ecore_sdl_event_key(SDL_Event *event, double timestamp)
* Poll SDL for mouse, keyboard, and window events, and add corresponding events to ecore.
* @ingroup Ecore_SDL_Library_Group
*/
EAPI void
ECORE_SDL_API void
ecore_sdl_feed_events(void)
{
SDL_Event event;

View File

@ -0,0 +1,34 @@
#ifndef _EFL_ECORE_SDL_API_H
#define _EFL_ECORE_SDL_API_H
#ifdef ECORE_SDL_API
#error ECORE_SDL_API should not be already defined
#endif
#ifdef _WIN32
# ifndef ECORE_SDL_STATIC
# ifdef ECORE_SDL_BUILD
# define ECORE_SDL_API __declspec(dllexport)
# else
# define ECORE_SDL_API __declspec(dllimport)
# endif
# else
# define ECORE_SDL_API
# endif
# define ECORE_SDL_API_WEAK
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define ECORE_SDL_API __attribute__ ((visibility("default")))
# define ECORE_SDL_API_WEAK __attribute__ ((weak))
# else
# define ECORE_SDL_API
# define ECORE_SDL_API_WEAK
# endif
# else
# define ECORE_SDL_API
# define ECORE_SDL_API_WEAK
# endif
#endif
#endif

View File

@ -8,6 +8,7 @@ ecore_sdl_src = files([
ecore_sdl_header_src = [
'Ecore_Sdl.h',
'ecore_sdl_api.h',
'Ecore_Sdl_Keys.h'
]
@ -18,7 +19,7 @@ ecore_sdl_lib = library('ecore_sdl',
dependencies: [ecore_sdl_deps, ecore_sdl_pub_deps, ecore_sdl_ext_deps],
include_directories : config_dir + [include_directories(join_paths('..','..'))],
install: true,
c_args : package_c_args,
c_args : [package_c_args, '-DECORE_SDL_BUILD'],
)
ecore_sdl = declare_dependency(