efl/src/tests/eo/function_overrides/function_overrides_simple.c

84 lines
2.0 KiB
C
Raw Normal View History

#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "Eo.h"
2012-09-25 23:56:52 -07:00
#include "function_overrides_simple.h"
#include "../eunit_tests.h"
#define MY_CLASS SIMPLE_CLASS
Eina_Bool class_print_called = EINA_FALSE;
Eina_Bool class_print2_called = EINA_FALSE;
static void
_a_set(Eo *obj EINA_UNUSED, void *class_data, int a)
{
Simple_Public_Data *pd = class_data;
printf("%s %d\n", efl_class_name_get(MY_CLASS), a);
pd->a = a;
}
static Eina_Bool
_a_print(Eo *obj EINA_UNUSED, void *class_data)
{
Simple_Public_Data *pd = class_data;
printf("Print %s %d\n", efl_class_name_get(MY_CLASS), pd->a);
return EINA_TRUE;
}
static Eina_Bool
_class_print(Efl_Class *klass, void *class_data EINA_UNUSED)
{
printf("Print %s-%s\n", efl_class_name_get(klass), efl_class_name_get(MY_CLASS));
Eina_Bool called = EINA_FALSE;
called = simple_class_print(efl_super(klass, MY_CLASS));
fail_if(called);
called = simple_class_print2(efl_super(klass, MY_CLASS));
fail_if(called);
return EINA_TRUE;
}
static Eina_Bool
_class_print2(Efl_Class *klass, void *class_data EINA_UNUSED)
{
printf("Print %s-%s\n", efl_class_name_get(klass), efl_class_name_get(MY_CLASS));
return EINA_TRUE;
}
eo: Rename EAPI macro to EO_API in Eo library Summary: Patch from a series of patches to rename EAPI symbols to specific library DSOs. = The Rationale = This patch is 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 LIBAPI is the only solution that works for MSVC. Co-authored-by: João Paulo Taylor Ienczak Zanette <jpaulotiz@gmail.com> Co-authored-by: Lucas Cavalcante de Sousa <lucks.sousa@gmail.com> Co-authored-by: Ricardo Campos <ricardo.campos@expertise.dev> Reviewers: jptiz, lucas, vtorri, woohyun Reviewed By: jptiz, lucas, vtorri Subscribers: cedric, #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D12203
2020-12-09 08:50:29 -08:00
EFL_VOID_FUNC_BODYV(simple_a_set, EFL_FUNC_CALL(a), int a);
EFL_FUNC_BODY(simple_a_print, Eina_Bool, EINA_FALSE);
EFL_FUNC_BODY_CONST(simple_class_print, Eina_Bool, EINA_FALSE);
EFL_FUNC_BODY_CONST(simple_class_print2, Eina_Bool, EINA_FALSE);
2014-04-02 01:46:34 -07:00
static Eina_Bool
_class_initializer(Efl_Class *klass)
{
EFL_OPS_DEFINE(ops,
EFL_OBJECT_OP_FUNC(simple_a_set, _a_set),
EFL_OBJECT_OP_FUNC(simple_a_print, _a_print),
EFL_OBJECT_OP_FUNC(simple_class_print, _class_print),
EFL_OBJECT_OP_FUNC(simple_class_print2, _class_print2),
);
return efl_class_functions_set(klass, &ops, NULL);
}
static const Efl_Class_Description class_desc = {
2014-04-02 01:46:34 -07:00
EO_VERSION,
"Simple",
EFL_CLASS_TYPE_REGULAR,
sizeof(Simple_Public_Data),
_class_initializer,
NULL,
NULL
};
EFL_DEFINE_CLASS(simple_class_get, &class_desc, EO_CLASS, NULL);