efl: Rename EAPI macro to EFL_API in Efl sub-library

evil: Rename EAPI macro to EVIL_API in Evil 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-09-20 10:25:30 -03:00
parent b0f5c73ea3
commit 48e059c5a6
10 changed files with 94 additions and 97 deletions

View File

@ -7,44 +7,7 @@ extern "C" {
#include <Eo.h>
#ifdef EAPI
# undef EAPI
#endif
#ifdef EWAPI
# undef EWAPI
#endif
#ifdef EOAPI
# undef EOAPI
#endif
#ifdef _WIN32
# ifdef EFL_BUILD
# ifdef DLL_EXPORT
# define EAPI __declspec(dllexport)
# else
# define EAPI
# endif
# else
# define EAPI __declspec(dllimport)
# endif
# define EAPI_WEAK
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EAPI __attribute__ ((visibility("default")))
# define EAPI_WEAK __attribute__ ((weak))
# else
# define EAPI
# define EAPI_WEAK
# endif
# else
# define EAPI
# define EAPI_WEAK
# endif
#endif
#define EWAPI EAPI EAPI_WEAK
#define EOAPI EAPI EAPI_WEAK
#include <efl_api.h>
#define EFL_VERSION_1_18 1
#define EFL_VERSION_1_19 1
@ -83,39 +46,39 @@ typedef struct _Efl_Text_Attribute_Handle Efl_Text_Attribute_Handle;
#ifdef EFL_BETA_API_SUPPORT
/** No error on load */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_NONE;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_NONE;
/** A non-specific error occurred */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_GENERIC;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_GENERIC;
/** File (or file path) does not exist */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_DOES_NOT_EXIST;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_DOES_NOT_EXIST;
/** Permission denied to an existing file (or path) */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_PERMISSION_DENIED;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_PERMISSION_DENIED;
/** Allocation of resources failure prevented load */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_RESOURCE_ALLOCATION_FAILED;
/** File corrupt (but was detected as a known format) */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_CORRUPT_FILE;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_CORRUPT_FILE;
/** File is not a known format */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_UNKNOWN_FORMAT;
/** Reading operation has been cancelled during decoding */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_CANCELLED;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_CANCELLED;
/** (Edje only) The file pointed to is incompatible, i.e., it doesn't
* match the library's current version's format. */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_INCOMPATIBLE_FILE;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_INCOMPATIBLE_FILE;
/** (Edje only) The group/collection set to load from was not found in the file */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_UNKNOWN_COLLECTION;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_UNKNOWN_COLLECTION;
/** (Edje only) The group/collection set to load from had recursive references
* on its components */
extern EWAPI Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_RECURSIVE_REFERENCE;
EFL_API EFL_API_WEAK extern Eina_Error EFL_GFX_IMAGE_LOAD_ERROR_RECURSIVE_REFERENCE;
#endif /* EFL_BETA_API_SUPPORT */
#include "interfaces/efl_gfx_types.eot.h"
@ -231,11 +194,11 @@ typedef Efl_Gfx_Path_Command_Type Efl_Gfx_Path_Command;
*
* @since 1.21
*/
EAPI Efl_Object *efl_part(const Eo *obj, const char *name);
EFL_API Efl_Object *efl_part(const Eo *obj, const char *name);
#ifdef EFL_BETA_API_SUPPORT
EAPI void efl_observable_tuple_free(Efl_Observable_Tuple *tuple);
EFL_API void efl_observable_tuple_free(Efl_Observable_Tuple *tuple);
@ -342,13 +305,10 @@ efl_config_string_get(const Efl_Config *obj, const char *name)
#endif
/* work-around bug in gcc --as-needed link optimization */
EAPI void __efl_internal_init(void);
EFL_API void __efl_internal_init(void);
#if defined ( __cplusplus )
}
#endif
#undef EAPI
#define EAPI
#endif

View File

@ -3,22 +3,22 @@
#include <Eina.h>
EAPI extern Eina_Error EFL_MODEL_ERROR_UNKNOWN;
EAPI extern Eina_Error EFL_MODEL_ERROR_NOT_SUPPORTED;
EAPI extern Eina_Error EFL_MODEL_ERROR_NOT_FOUND;
EAPI extern Eina_Error EFL_MODEL_ERROR_READ_ONLY;
EAPI extern Eina_Error EFL_MODEL_ERROR_INIT_FAILED;
EAPI extern Eina_Error EFL_MODEL_ERROR_INCORRECT_VALUE;
EAPI extern Eina_Error EFL_MODEL_ERROR_PERMISSION_DENIED;
EAPI extern Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT; /**< @since 1.19 */
EFL_API extern Eina_Error EFL_MODEL_ERROR_UNKNOWN;
EFL_API extern Eina_Error EFL_MODEL_ERROR_NOT_SUPPORTED;
EFL_API extern Eina_Error EFL_MODEL_ERROR_NOT_FOUND;
EFL_API extern Eina_Error EFL_MODEL_ERROR_READ_ONLY;
EFL_API extern Eina_Error EFL_MODEL_ERROR_INIT_FAILED;
EFL_API extern Eina_Error EFL_MODEL_ERROR_INCORRECT_VALUE;
EFL_API extern Eina_Error EFL_MODEL_ERROR_PERMISSION_DENIED;
EFL_API extern Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT; /**< @since 1.19 */
EAPI extern Eina_Error EFL_PROPERTY_ERROR_INVALID_KEY; /**< Returned when the given key during a efl_ui_property_bind does not exist on the object. */
EFL_API extern Eina_Error EFL_PROPERTY_ERROR_INVALID_KEY; /**< Returned when the given key during a efl_ui_property_bind does not exist on the object. */
EAPI extern Eina_Error EFL_FACTORY_ERROR_NOT_SUPPORTED; /**< Returned error when factory got a request that it can't fullfil due to a set of unsupported parameters @since 1.22 */
EFL_API extern Eina_Error EFL_FACTORY_ERROR_NOT_SUPPORTED; /**< Returned error when factory got a request that it can't fullfil due to a set of unsupported parameters @since 1.22 */
#include "interfaces/efl_model.eo.h"
EAPI int efl_model_init(void);
EFL_API int efl_model_init(void);
/**
@ -29,7 +29,7 @@ EAPI int efl_model_init(void);
*
* @since 1.17
*/
EAPI void _efl_model_properties_changed_internal(const Efl_Model *model, ...);
EFL_API void _efl_model_properties_changed_internal(const Efl_Model *model, ...);
#define efl_model_properties_changed(Model, ...) _efl_model_properties_changed_internal(Model, ##__VA_ARGS__, NULL)
@ -41,7 +41,7 @@ EAPI void _efl_model_properties_changed_internal(const Efl_Model *model, ...);
*
* @since 1.17
*/
EAPI void efl_model_property_invalidated_notify(Efl_Model *model, const char *property);
EFL_API void efl_model_property_invalidated_notify(Efl_Model *model, const char *property);
/**
* @brief Callback to setup a member of @c Eina_Value_Struct
@ -62,7 +62,7 @@ typedef void (*Efl_Model_Value_Struct_Member_Setup_Cb)(void *data, int index, Ei
*
* @since 1.17
*/
EAPI Eina_Value_Struct_Desc *efl_model_value_struct_description_new(unsigned int member_count, Efl_Model_Value_Struct_Member_Setup_Cb setup_cb, void *data) EINA_ARG_NONNULL(2);
EFL_API Eina_Value_Struct_Desc *efl_model_value_struct_description_new(unsigned int member_count, Efl_Model_Value_Struct_Member_Setup_Cb setup_cb, void *data) EINA_ARG_NONNULL(2);
/**
* @brief Frees the memory allocated to the struct description.
@ -71,6 +71,6 @@ EAPI Eina_Value_Struct_Desc *efl_model_value_struct_description_new(unsigned int
*
* @since 1.17
*/
EAPI void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc);
EFL_API void efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc);
#endif

34
src/lib/efl/efl_api.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef _EFL_EFL_API_H
#define _EFL_EFL_API_H
#ifdef EFL_API
#error EFL_API should not be already defined
#endif
#ifdef _WIN32
# ifndef EFL_STATIC
# ifdef EFL_BUILD
# define EFL_API __declspec(dllexport)
# else
# define EFL_API __declspec(dllimport)
# endif
# else
# define EFL_API
# endif
# define EFL_API_WEAK
#else
# ifdef __GNUC__
# if __GNUC__ >= 4
# define EFL_API __attribute__ ((visibility("default")))
# define EFL_API_WEAK __attribute__ ((weak))
# else
# define EFL_API
# define EFL_API_WEAK
# endif
# else
# define EFL_API
# define EFL_API_WEAK
# endif
#endif
#endif

View File

@ -167,7 +167,7 @@ _efl_file_efl_object_finalize(Eo *obj, Efl_File_Data *pd)
////////////////////////////////////////////////////////////////////////////
EAPI Eina_Bool
EFL_API Eina_Bool
efl_file_simple_load(Eo *obj, const char *file, const char *key)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
@ -192,7 +192,7 @@ fail:
return EINA_FALSE;
}
EAPI Eina_Bool
EFL_API Eina_Bool
efl_file_simple_mmap_load(Eo *obj, const Eina_File *file, const char *key)
{
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
@ -213,7 +213,7 @@ fail:
return EINA_FALSE;
}
EAPI void
EFL_API void
efl_file_simple_get(const Eo *obj, const char **file, const char **key)
{
efl_ref((Eo*)obj);
@ -222,7 +222,7 @@ efl_file_simple_get(const Eo *obj, const char **file, const char **key)
efl_unref((Eo*)obj);
}
EAPI void
EFL_API void
efl_file_simple_mmap_get(const Eo *obj, const Eina_File **file, const char **key)
{
efl_ref((Eo*)obj);

View File

@ -2,9 +2,9 @@
# define _EFL_FILE_H
/* add doc note about needing ref/unref when passing efl_part to these functions */
EAPI Eina_Bool efl_file_simple_load(Eo *obj, const char *file, const char *key);
EAPI Eina_Bool efl_file_simple_mmap_load(Eo *obj, const Eina_File *file, const char *key);
EAPI void efl_file_simple_get(const Eo *obj, const char **file, const char **key);
EAPI void efl_file_simple_mmap_get(const Eo *obj, const Eina_File **file, const char **key);
EFL_API Eina_Bool efl_file_simple_load(Eo *obj, const char *file, const char *key);
EFL_API Eina_Bool efl_file_simple_mmap_load(Eo *obj, const Eina_File *file, const char *key);
EFL_API void efl_file_simple_get(const Eo *obj, const char **file, const char **key);
EFL_API void efl_file_simple_mmap_get(const Eo *obj, const Eina_File **file, const char **key);
#endif

View File

@ -85,7 +85,7 @@ _noref_death(void *data EINA_UNUSED, const Efl_Event *event)
efl_del(event->object);
}
EAPI Efl_Object *
EFL_API Efl_Object *
efl_part(const Eo *obj, const char *name)
{
Efl_Object *r;
@ -105,7 +105,7 @@ efl_part(const Eo *obj, const char *name)
return efl_ref(r);
}
EAPI void
EFL_API void
__efl_internal_init(void)
{
efl_model_init();

View File

@ -5,17 +5,17 @@
#include "Efl.h"
#include "Efl_MVVM_Common.h"
EAPI Eina_Error EFL_MODEL_ERROR_UNKNOWN = 0;
EAPI Eina_Error EFL_MODEL_ERROR_NOT_SUPPORTED = 0;
EAPI Eina_Error EFL_MODEL_ERROR_NOT_FOUND = 0;
EAPI Eina_Error EFL_MODEL_ERROR_READ_ONLY = 0;
EAPI Eina_Error EFL_MODEL_ERROR_INIT_FAILED = 0;
EAPI Eina_Error EFL_MODEL_ERROR_PERMISSION_DENIED = 0;
EAPI Eina_Error EFL_MODEL_ERROR_INCORRECT_VALUE = 0;
EAPI Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_UNKNOWN = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_NOT_SUPPORTED = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_NOT_FOUND = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_READ_ONLY = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_INIT_FAILED = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_PERMISSION_DENIED = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_INCORRECT_VALUE = 0;
EFL_API Eina_Error EFL_MODEL_ERROR_INVALID_OBJECT = 0;
EAPI Eina_Error EFL_FACTORY_ERROR_NOT_SUPPORTED = 0;
EAPI Eina_Error EFL_PROPERTY_ERROR_INVALID_KEY = 0;
EFL_API Eina_Error EFL_FACTORY_ERROR_NOT_SUPPORTED = 0;
EFL_API Eina_Error EFL_PROPERTY_ERROR_INVALID_KEY = 0;
static const char EFL_MODEL_ERROR_UNKNOWN_STR[] = "Unknown Error";
static const char EFL_MODEL_ERROR_NOT_SUPPORTED_STR[] = "Operation not supported";
@ -31,7 +31,7 @@ static const char EFL_FACTORY_ERROR_NOT_SUPPORTED_STR[] = "Operation not suppo
static const char EFL_PROPERTY_ERROR_INVALID_KEY_STR[] = "Incorrect key provided";
EAPI int
EFL_API int
efl_model_init(void)
{
#define _ERROR(Name) EFL_MODEL_ERROR_##Name = eina_error_msg_static_register(EFL_MODEL_ERROR_##Name##_STR);
@ -57,7 +57,7 @@ efl_model_init(void)
#undef _ERROR
EAPI void
EFL_API void
_efl_model_properties_changed_internal(const Efl_Model *model, ...)
{
Efl_Model_Property_Event ev = { 0 };
@ -84,7 +84,7 @@ _efl_model_properties_changed_internal(const Efl_Model *model, ...)
eina_array_free(properties);
}
EAPI void
EFL_API void
efl_model_property_invalidated_notify(Efl_Model *model, const char *property)
{
Eina_Array *invalidated_properties = eina_array_new(1);
@ -112,7 +112,7 @@ struct _Efl_Model_Value_Struct_Desc
Eina_Value_Struct_Member members[];
};
EAPI Eina_Value_Struct_Desc *
EFL_API Eina_Value_Struct_Desc *
efl_model_value_struct_description_new(unsigned int member_count, Efl_Model_Value_Struct_Member_Setup_Cb setup_cb, void *data)
{
Efl_Model_Value_Struct_Desc *desc;
@ -152,7 +152,7 @@ efl_model_value_struct_description_new(unsigned int member_count, Efl_Model_Valu
return &desc->base;
}
EAPI void
EFL_API void
efl_model_value_struct_description_free(Eina_Value_Struct_Desc *desc)
{
size_t i;

View File

@ -257,7 +257,7 @@ _efl_observable_iterator_tuple_new(Eo *obj, Efl_Observable_Data *pd)
return &it->iterator;
}
EAPI void
EFL_API void
efl_observable_tuple_free(Efl_Observable_Tuple *tuple)
{
//key is not owned

View File

@ -25,6 +25,7 @@ foreach eo_file : pub_legacy_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', 'EFL_API',
'-gchd', '@INPUT@'])
endforeach
@ -107,6 +108,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', 'EFL_API',
'-gchd', '@INPUT@'])
endforeach
@ -129,6 +131,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', 'EFL_API',
'-ghd', '@INPUT@'])
endforeach

View File

@ -14,7 +14,7 @@ package_header_subdirs += 'interfaces'
efl_lib = library('efl',
efl_src, pub_eo_file_target,
c_args : package_c_args,
c_args : [package_c_args, '-DEFL_BUILD'],
dependencies: [efl_deps, efl_pub_deps, efl_ext_deps],
install: true,
version : meson.project_version()