evil: Rename EAPI macro to EVIL_API in Evil library

Summary:
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>

Reviewers: raster, vtorri, jptiz, lucas, woohyun

Reviewed By: vtorri, jptiz

Subscribers: ProhtMeyhet, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D12182
This commit is contained in:
Felipe Magno de Almeida 2020-11-12 13:47:38 -03:00
parent e9ee9cc3a0
commit 4cee5b05c9
25 changed files with 101 additions and 89 deletions

View File

@ -39,7 +39,7 @@ _dl_get_last_error(char *desc)
_dl_err_viewed = 0;
}
void *
EVIL_API void *
dlopen(const char* path, int mode EVIL_UNUSED)
{
HMODULE module = NULL;
@ -95,7 +95,7 @@ dlopen(const char* path, int mode EVIL_UNUSED)
return module;
}
int
EVIL_API int
dlclose(void* handle)
{
if (FreeLibrary(handle))
@ -107,7 +107,7 @@ dlclose(void* handle)
}
}
void *
EVIL_API void *
dlsym(void *handle, const char *symbol)
{
FARPROC fp = NULL;
@ -157,7 +157,7 @@ dlsym(void *handle, const char *symbol)
return fp;
}
char *
EVIL_API char *
dlerror (void)
{
if (!_dl_err_viewed)
@ -184,7 +184,7 @@ _dladdr_comp(const void *p1, const void *p2)
return ( *(int *)p1 - *(int *)p2);
}
int
EVIL_API int
dladdr (const void *addr, Dl_info *info)
{
TCHAR tpath[PATH_MAX];

View File

@ -2,6 +2,7 @@
#define __EVIL_DLFCN_H__
#include "evil_private.h"
#include <limits.h>
@ -142,7 +143,7 @@ struct Dl_info
*
* @ingroup Evil_Dlfcn
*/
EAPI void *dlopen(const char* path, int mode);
EVIL_API void *dlopen(const char* path, int mode);
#ifndef HAVE_DLOPEN
# define HAVE_DLOPEN 1
#endif
@ -168,7 +169,7 @@ EAPI void *dlopen(const char* path, int mode);
*
* @ingroup Evil_Dlfcn
*/
EAPI int dlclose(void* handle);
EVIL_API int dlclose(void* handle);
/**
* @brief Get the address of a symbol.
@ -192,7 +193,7 @@ EAPI int dlclose(void* handle);
*
* @ingroup Evil_Dlfcn
*/
EAPI void *dlsym(void* handle, const char* symbol);
EVIL_API void *dlsym(void* handle, const char* symbol);
#ifndef HAVE_DLSYM
# define HAVE_DLSYM 1
#endif
@ -221,7 +222,7 @@ EAPI void *dlsym(void* handle, const char* symbol);
*
* @ingroup Evil_Dlfcn
*/
EAPI int dladdr (const void *addr, Dl_info *info);
EVIL_API int dladdr(const void *addr, Dl_info *info);
#ifndef HAVE_DLADDR
# define HAVE_DLADDR 1
#endif
@ -248,7 +249,7 @@ EAPI int dladdr (const void *addr, Dl_info *info);
*
* @ingroup Evil_Dlfcn
*/
EAPI char *dlerror (void);
EVIL_API char *dlerror(void);
#endif /* __EVIL_DLFCN_H__ */

View File

@ -31,7 +31,8 @@ _is_socket(SOCKET s)
*
*/
int fcntl(int fd, int cmd, ...)
EVIL_API int
fcntl(int fd, int cmd, ...)
{
va_list va;
int res = -1;

View File

@ -105,7 +105,7 @@ struct flock
*
* @ingroup Evil
*/
EAPI int fcntl(int fd, int cmd, ...);
EVIL_API int fcntl(int fd, int cmd, ...);
#endif /* __EVIL_FCNTL_H__ */

View File

@ -19,7 +19,7 @@ replace(char *prev, char *value)
return strdup (value);
}
char *
EVIL_API char *
nl_langinfo(nl_item index)
{
static char *result = NULL;

View File

@ -39,7 +39,7 @@ enum {
# define CODESET _NL_CTYPE_CODESET
# define RADIXCHAR _NL_NUMERIC_RADIXCHAR
EAPI char *nl_langinfo(nl_item index);
EVIL_API char *nl_langinfo(nl_item index);
#endif /*__EVIL_LANGINFO_H__ */

View File

@ -12,21 +12,7 @@
#include <windows.h>
#undef WIN32_LEAN_AND_MEAN
#ifdef EAPI
# undef EAPI
#endif
#ifdef EFL_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif
#else
# define EAPI __declspec(dllimport)
#endif
#include "evil_locale.h" /* LC_MESSAGES */
#include "evil_private.h" /* LC_MESSAGES */
/*
* LOCALE_SISO639LANGNAME and LOCALE_SISO3166CTRYNAME need at least a buffer
@ -37,7 +23,8 @@ static char _evil_locale_buf[18];
#undef setlocale
char *evil_setlocale(int category, const char *locale)
EVIL_API char *
evil_setlocale(int category, const char *locale)
{
char buf[9];
int l1;

View File

@ -48,7 +48,7 @@
*
* @since 1.16
*/
EAPI char *evil_setlocale(int category, const char *locale);
EVIL_API char *evil_setlocale(int category, const char *locale);
/**

View File

@ -99,7 +99,7 @@
* When Evil is not used anymore, call evil_shutdown() to shut down
* the Evil library.
*/
EAPI int evil_init(void);
EVIL_API int evil_init(void);
/**
* @brief Shut down the Evil library.
@ -115,7 +115,7 @@ EAPI int evil_init(void);
* documentation anymore . You must call evil_init() again to use these
* functions again.
*/
EAPI int evil_shutdown(void);
EVIL_API int evil_shutdown(void);
/**

View File

@ -45,7 +45,7 @@ _evil_mmap_protection_get(int prot)
/***** API *****/
void *
EVIL_API void *
mmap(void *addr EVIL_UNUSED,
size_t len,
int prot,
@ -133,7 +133,7 @@ mmap(void *addr EVIL_UNUSED,
return data;
}
int
EVIL_API int
munmap(void *addr,
size_t len EVIL_UNUSED)
{
@ -147,7 +147,7 @@ munmap(void *addr,
return (res == 0) ? -1 : 0;
}
int
EVIL_API int
mprotect(void *addr, size_t len, int prot)
{
DWORD old;

View File

@ -107,7 +107,7 @@
*
* @ingroup Evil_Mman
*/
EAPI void *mmap(void *addr,
EVIL_API void *mmap(void *addr,
size_t len,
int prot,
int flags,
@ -138,7 +138,7 @@ EAPI void *mmap(void *addr,
*
* @ingroup Evil_Mman
*/
EAPI int munmap(void *addr,
EVIL_API int munmap(void *addr,
size_t len);
/**
@ -159,7 +159,7 @@ EAPI int munmap(void *addr,
*
* @ingroup Evil_Mman
*/
EAPI int mprotect(void *addr, size_t len, int prot);
EVIL_API int mprotect(void *addr, size_t len, int prot);
#endif /* __EVIL_SYS_MMAN_H__ */

View File

@ -26,18 +26,42 @@ extern "C" {
#include <sys/stat.h> /* for mkdir in evil_macro_wrapper */
#ifdef EAPI
# undef EAPI
#ifdef EVIL_API
#error EVIL_API should not be already defined
#endif
#ifdef EFL_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
#ifdef _WIN32
# ifndef EVIL_STATIC
# ifdef EVIL_BUILD
# define EVIL_API __declspec(dllexport)
# else
# define EVIL_API __declspec(dllimport)
# endif
# else
# define EAPI
# define EVIL_API
# endif
# define EVIL_API_WEAK
#elif defined(__GNUC__)
# if __GNUC__ >= 4
# define EVIL_API __attribute__ ((visibility("default")))
# define EVIL_API_WEAK __attribute__ ((weak))
# else
# define EVIL_API
# define EVIL_API_WEAK
# endif
#else
# define EAPI __declspec(dllimport)
/**
* @def EVIL_API
* @brief Used to export functions (by changing visibility).
*/
# define EVIL_API
/**
* @def EINA_API_WEAK
* @brief Weak symbol, primarily useful in defining library functions which
* can be overridden in user code.
* Note: Not supported on all platforms.
*/
# define EINA_API_WEAK
#endif
#ifndef PATH_MAX
@ -61,9 +85,6 @@ extern "C" {
#include "evil_macro_wrapper.h"
#undef EAPI
#define EAPI
#ifdef __cplusplus
}
#endif

View File

@ -9,7 +9,7 @@
#undef rename
int
EVIL_API int
evil_rename(const char *src, const char* dst)
{
DWORD res;
@ -24,7 +24,7 @@ evil_rename(const char *src, const char* dst)
return MoveFileEx(src, dst, MOVEFILE_REPLACE_EXISTING) ? 0 : -1;
}
int
EVIL_API int
evil_mkdir(const char *dirname, mode_t mode EVIL_UNUSED)
{
return _mkdir(dirname);

View File

@ -41,7 +41,7 @@
*
* @since 1.8
*/
EAPI int evil_rename(const char *src, const char *dst);
EVIL_API int evil_rename(const char *src, const char *dst);
/**
* @brief Wrap the _mkdir() function on Windows.
@ -54,7 +54,7 @@ EAPI int evil_rename(const char *src, const char *dst);
*
* @since 1.15
*/
EAPI int evil_mkdir(const char *dirname, mode_t mode);
EVIL_API int evil_mkdir(const char *dirname, mode_t mode);
/**
* @}

View File

@ -22,7 +22,7 @@
*
*/
int
EVIL_API int
setenv(const char *name,
const char *value,
int overwrite)
@ -65,7 +65,7 @@ setenv(const char *name,
return res;
}
int
EVIL_API int
unsetenv(const char *name)
{
return setenv(name, NULL, 1);
@ -77,7 +77,7 @@ unsetenv(const char *name)
*
*/
char *
EVIL_API char *
realpath(const char *file_name, char *resolved_name)
{
char *retname = NULL; /* we will return this, if we fail */

View File

@ -1,6 +1,7 @@
#ifndef __EVIL_STDLIB_H__
#define __EVIL_STDLIB_H__
#include "evil_private.h"
/**
* @file evil_stdlib.h
@ -40,7 +41,7 @@
*
* Supported OS: Windows XP.
*/
EAPI int setenv(const char *name,
EVIL_API int setenv(const char *name,
const char *value,
int overwrite);
@ -59,7 +60,7 @@ EAPI int setenv(const char *name,
*
* Supported OS: Windows XP.
*/
EAPI int unsetenv(const char *name);
EVIL_API int unsetenv(const char *name);
/*
@ -96,7 +97,7 @@ EAPI int unsetenv(const char *name);
*
* Supported OS: Windows XP.
*/
EAPI char *realpath(const char *file_name, char *resolved_name);
EVIL_API char *realpath(const char *file_name, char *resolved_name);
#ifndef HAVE_REALPATH
# define HAVE_REALPATH 1
#endif

View File

@ -14,7 +14,7 @@
*
*/
char *strcasestr(const char *haystack, const char *needle)
EVIL_API char *strcasestr(const char *haystack, const char *needle)
{
size_t length_needle;
size_t length_haystack;
@ -50,7 +50,7 @@ char *strcasestr(const char *haystack, const char *needle)
return NULL;
}
char *
EVIL_API char *
strsep (char **stringp, const char *delim)
{
char *begin, *end;

View File

@ -35,7 +35,7 @@
*
* Supported OS: Windows XP.
*/
EAPI char *strcasestr(const char *haystack, const char *needle);
EVIL_API char *strcasestr(const char *haystack, const char *needle);
/**
* @brief Implements the strsep function which is used to separate strings.
@ -61,7 +61,7 @@ EAPI char *strcasestr(const char *haystack, const char *needle);
* @since 1.8
*
*/
EAPI char *strsep(char **stringp, const char *delim);
EVIL_API char *strsep(char **stringp, const char *delim);
/**
* @}

View File

@ -173,7 +173,7 @@ conv_num(const unsigned char *buf, int *dest, unsigned int llim, unsigned int ul
return buf;
}
char *
EVIL_API char *
strptime(const char *buf, const char *fmt, struct tm *tm)
{
unsigned char c;

View File

@ -38,7 +38,7 @@ struct timezone
*
* @since 1.25
*/
EAPI int evil_gettimeofday(struct timeval *tv, struct timezone *tz);
EVIL_API int evil_gettimeofday(struct timeval *tv, struct timezone *tz);
#ifndef HAVE_GETTIMEOFDAY
# define HAVE_GETTIMEOFDAY 1
#endif
@ -61,7 +61,7 @@ EAPI int evil_gettimeofday(struct timeval *tv, struct timezone *tz);
*
* Supported OS: Windows XP.
*/
EAPI char *strptime(const char *buf, const char *fmt, struct tm *tm);
EVIL_API char *strptime(const char *buf, const char *fmt, struct tm *tm);
/**

View File

@ -23,7 +23,7 @@ LONGLONG _evil_time_count;
*
*/
double
EVIL_API double
evil_time_get(void)
{
LARGE_INTEGER count;
@ -39,7 +39,7 @@ evil_time_get(void)
*
*/
int
EVIL_API int
evil_sockets_init(void)
{
WSADATA wsa_data;
@ -61,7 +61,7 @@ evil_sockets_init(void)
return 0;
}
void
EVIL_API void
evil_sockets_shutdown(void)
{
WSACleanup();
@ -71,7 +71,7 @@ evil_sockets_shutdown(void)
* The code of the following functions has been kindly offered
* by Tor Lillqvist.
*/
int
EVIL_API int
evil_pipe(int *fds)
{
struct sockaddr_in saddr;

View File

@ -1,6 +1,7 @@
#ifndef __EVIL_UNISTD_H__
#define __EVIL_UNISTD_H__
#include "evil_private.h"
/**
* @file evil_unistd.h
@ -34,7 +35,7 @@
*
* Supported OS: Windows XP.
*/
EAPI double evil_time_get(void);
EVIL_API double evil_time_get(void);
/*
* Sockets and pipe related functions
@ -53,7 +54,7 @@ EAPI double evil_time_get(void);
*
* Supported OS: Windows XP.
*/
EAPI int evil_sockets_init(void);
EVIL_API int evil_sockets_init(void);
/**
* @brief Shutdown the Windows socket system.
@ -64,7 +65,7 @@ EAPI int evil_sockets_init(void);
*
* Supported OS: Windows XP.
*/
EAPI void evil_sockets_shutdown(void);
EVIL_API void evil_sockets_shutdown(void);
/**
* @brief Create a pair of sockets.
@ -80,7 +81,7 @@ EAPI void evil_sockets_shutdown(void);
*
* Supported OS: Windows XP.
*/
EAPI int evil_pipe(int *fds);
EVIL_API int evil_pipe(int *fds);
/**

View File

@ -15,7 +15,7 @@ DWORD _evil_tls_index;
/* static void _evil_error_display(const char *fct, LONG res); */
static void _evil_last_error_display(const char *fct);
wchar_t *
EVIL_API wchar_t *
evil_char_to_wchar(const char *text)
{
wchar_t *wtext;
@ -44,7 +44,7 @@ evil_char_to_wchar(const char *text)
return wtext;
}
char *
EVIL_API char *
evil_wchar_to_char(const wchar_t *text)
{
char *atext;
@ -74,7 +74,7 @@ evil_wchar_to_char(const wchar_t *text)
return atext;
}
char *
EVIL_API char *
evil_utf16_to_utf8(const wchar_t *text16)
{
char *text8;
@ -107,7 +107,7 @@ evil_utf16_to_utf8(const wchar_t *text16)
return text8;
}
wchar_t *
EVIL_API wchar_t *
evil_utf8_to_utf16(const char *text)
{
wchar_t *text16;
@ -135,7 +135,7 @@ evil_utf8_to_utf16(const char *text)
return text16;
}
const char *
EVIL_API const char *
evil_format_message(long err)
{
char *buf;
@ -174,7 +174,7 @@ evil_format_message(long err)
return (const char *)buf;
}
const char *
EVIL_API const char *
evil_last_error_get(void)
{
DWORD err;
@ -189,7 +189,7 @@ _evil_last_error_display(const char *fct)
fprintf(stderr, "[Evil] [%s] ERROR: %s\n", fct, evil_last_error_get());
}
int
EVIL_API int
evil_path_is_absolute(const char *path)
{
size_t length;

View File

@ -19,7 +19,7 @@
*
* @ingroup Evil
*/
EAPI wchar_t *evil_char_to_wchar(const char *text);
EVIL_API wchar_t *evil_char_to_wchar(const char *text);
/**
* @brief Convert a string from wchar_t * to char *.
@ -38,7 +38,7 @@ EAPI wchar_t *evil_char_to_wchar(const char *text);
*
* @ingroup Evil
*/
EAPI char *evil_wchar_to_char(const wchar_t *text);
EVIL_API char *evil_wchar_to_char(const wchar_t *text);
/**
* @brief Convert a string from UTF-16 to UTF-8.
@ -57,7 +57,7 @@ EAPI char *evil_wchar_to_char(const wchar_t *text);
*
* @ingroup Evil
*/
EAPI char *evil_utf16_to_utf8(const wchar_t *text);
EVIL_API char *evil_utf16_to_utf8(const wchar_t *text);
/**
* @brief Convert a string from UTF-8 to UTF-16.
@ -75,11 +75,11 @@ EAPI char *evil_utf16_to_utf8(const wchar_t *text);
*
* @ingroup Evil
*/
EAPI wchar_t *evil_utf8_to_utf16(const char *text);
EVIL_API wchar_t *evil_utf8_to_utf16(const char *text);
EAPI const char *evil_format_message(long err);
EVIL_API const char *evil_format_message(long err);
EAPI const char *evil_last_error_get(void);
EVIL_API const char *evil_last_error_get(void);
/**
* @brief check if the given path is absolute.
@ -102,6 +102,6 @@ EAPI const char *evil_last_error_get(void);
*
* @ingroup Evil
*/
EAPI int evil_path_is_absolute(const char *path);
EVIL_API int evil_path_is_absolute(const char *path);
#endif /* __EVIL_UTIL_H__ */

View File

@ -29,7 +29,7 @@ if target_machine.system() == 'windows'
evil_ext_deps += [psapi, ole32, ws2_32, secur32, uuid, regexp]
evil_lib = library('evil', evil_src,
c_args : package_c_args,
c_args : [package_c_args, '-DEVIL_BUILD'],
dependencies : evil_ext_deps,
include_directories : [config_dir],
install: true,