eo2: remove EO2_CLASS_FUNC_* macros

there is no more difference in class or regular functions prototypes and definitions

- eo2_api_op_id_get() uses _eo_is_a_class() at runtime
- add 'void *class_data EINA_UNUSED' parameter to eo2_base class functions
- Eo2_Op_Call_Data.klass is kept only for eo2_hook_call_pre end eo2_hook_call_post,
  but could be removed easily
This commit is contained in:
Jérémy Zurcher 2013-11-07 23:38:36 +01:00 committed by Tom Hacohen
parent 9a9fdb46fe
commit 23e2c29298
3 changed files with 29 additions and 86 deletions

View File

@ -616,7 +616,7 @@ EAPI Eina_Bool eo_shutdown(void);
typedef struct _Eo2_Op_Call_Data
{
Eo *obj;
Eo_Class *klass;
Eo_Class *klass; // remove this not necessary in Eo2_Hook_Call
void *func;
void *data;
} Eo2_Op_Call_Data;
@ -628,7 +628,6 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
// to pass the internal function call to EO2_FUNC_BODY (as Func parameter)
#define EO2_FUNC_CALL(...) __VA_ARGS__
#define EO2_CLASS_FUNC_CALL(...) __VA_ARGS__
#define EO2_HOOK_CALL_PREPARE(Hook) \
if (Hook) \
@ -639,11 +638,11 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
Hook(call.klass, call.obj, call.func, __VA_ARGS__);
// cache OP id, get real fct and object data then do the call
#define EO2_FUNC_COMMON_OP(Name, DefRet, Type) \
#define EO2_FUNC_COMMON_OP(Name, DefRet) \
Eo2_Op_Call_Data call; \
static Eo_Op op = EO_NOOP; \
if ( op == EO_NOOP ) \
op = eo2_api_op_id_get((void*)Name, Type); \
op = eo2_api_op_id_get((void*)Name); \
if (!eo2_call_resolve(#Name, op, &call)) return DefRet; \
__##Name##_func _func_ = (__##Name##_func) call.func; \
@ -654,7 +653,7 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
{ \
typedef Ret (*__##Name##_func)(Eo *, void *obj_data); \
Ret _r; \
EO2_FUNC_COMMON_OP(Name, DefRet, EO_OP_TYPE_REGULAR); \
EO2_FUNC_COMMON_OP(Name, DefRet); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_pre); \
_r = _func_(call.obj, call.data); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_post); \
@ -666,7 +665,7 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
Name(void) \
{ \
typedef void (*__##Name##_func)(Eo *, void *obj_data); \
EO2_FUNC_COMMON_OP(Name, , EO_OP_TYPE_REGULAR); \
EO2_FUNC_COMMON_OP(Name, ); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_pre); \
_func_(call.obj, call.data); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_post); \
@ -678,7 +677,7 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
{ \
typedef Ret (*__##Name##_func)(Eo *, void *obj_data, __VA_ARGS__); \
Ret _r; \
EO2_FUNC_COMMON_OP(Name, DefRet, EO_OP_TYPE_REGULAR); \
EO2_FUNC_COMMON_OP(Name, DefRet); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_pre, Arguments); \
_r = _func_(call.obj, call.data, Arguments); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_post, Arguments); \
@ -690,61 +689,12 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
Name(__VA_ARGS__) \
{ \
typedef void (*__##Name##_func)(Eo *, void *obj_data, __VA_ARGS__);\
EO2_FUNC_COMMON_OP(Name, , EO_OP_TYPE_REGULAR); \
EO2_FUNC_COMMON_OP(Name, ); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_pre, Arguments); \
_func_(call.obj, call.data, Arguments); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_post, Arguments); \
}
// to define a EAPI class function
#define EO2_CLASS_FUNC_BODY(Name, Ret, DefRet) \
Ret \
Name(void) \
{ \
typedef Ret (*__##Name##_func)(Eo_Class *); \
Ret _r; \
EO2_FUNC_COMMON_OP(Name, DefRet, EO_OP_TYPE_CLASS); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_pre); \
_r = _func_(call.klass); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_post); \
return _r; \
}
#define EO2_VOID_CLASS_FUNC_BODY(Name) \
void \
Name(void) \
{ \
typedef void (*__##Name##_func)(Eo_Class *); \
EO2_FUNC_COMMON_OP(Name, , EO_OP_TYPE_CLASS); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_pre); \
_func_(call.klass); \
EO2_HOOK_CALL_PREPARE(eo2_hook_call_post); \
}
#define EO2_CLASS_FUNC_BODYV(Name, Ret, DefRet, Arguments, ...) \
Ret \
Name(__VA_ARGS__) \
{ \
typedef Ret (*__##Name##_func)(Eo_Class *, __VA_ARGS__); \
Ret _r; \
EO2_FUNC_COMMON_OP(Name, DefRet, EO_OP_TYPE_CLASS); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_pre, Arguments); \
_r = _func_(call.klass, Arguments); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_post, Arguments); \
return _r; \
}
#define EO2_VOID_CLASS_FUNC_BODYV(Name, Arguments, ...) \
void \
Name(__VA_ARGS__) \
{ \
typedef void (*__##Name##_func)(Eo_Class *, __VA_ARGS__); \
EO2_FUNC_COMMON_OP(Name, , EO_OP_TYPE_CLASS); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_pre, Arguments); \
_func_(call.klass, Arguments); \
EO2_HOOK_CALL_PREPAREV(eo2_hook_call_post, Arguments); \
}
// OP ID of an overriding function
#define EO2_OP_OVERRIDE ((Eo_Op) -1)
@ -755,7 +705,7 @@ EAPI extern Eo2_Hook_Call eo2_hook_call_post;
#define EO2_OP_SENTINEL { NULL, NULL, 0, EO_OP_TYPE_INVALID, NULL}
// returns the OP id corresponding to the given api_func
EAPI Eo_Op eo2_api_op_id_get(const void *api_func, const Eo_Op_Type);
EAPI Eo_Op eo2_api_op_id_get(const void *api_func);
// gets the real function pointer and the object data
EAPI Eina_Bool eo2_call_resolve(const char *func_name, const Eo_Op op, Eo2_Op_Call_Data *call);

View File

@ -461,12 +461,12 @@ eo2_call_resolve(const char *func_name, const Eo_Op op, Eo2_Op_Call_Data *call)
if (EINA_LIKELY(func->func && func->src ))
{
call->obj = (Eo *)fptr->eo_id;
call->klass = _eo_class_id_get(klass);
call->func = func->func;
call->klass = _eo_class_id_get(klass);
if (obj)
{
call->obj = (Eo *)fptr->eo_id;
if (func->src == obj->klass)
{
if (fptr->obj_data == EO2_INVALID_DATA)
@ -478,7 +478,10 @@ eo2_call_resolve(const char *func_name, const Eo_Op op, Eo2_Op_Call_Data *call)
call->data = _eo_data_scope_get(obj, func->src);
}
else
call->data = NULL;
{
call->obj = call->klass;
call->data = NULL;
}
return EINA_TRUE;
}
@ -569,33 +572,23 @@ _eo2_api_desc_get(const void *api_func, const _Eo_Class *klass, const _Eo_Class
}
EAPI Eo_Op
eo2_api_op_id_get(const void *api_func, const Eo_Op_Type op_type)
eo2_api_op_id_get(const void *api_func)
{
const Eo2_Op_Description *desc;
const _Eo_Class *klass;
if (op_type == EO_OP_TYPE_REGULAR)
klass = eo2_call_stack.frame_ptr->obj->klass;
else if (op_type == EO_OP_TYPE_CLASS)
Eina_Bool class_ref = _eo_is_a_class(eo2_call_stack.frame_ptr->eo_id);
if (class_ref)
klass = eo2_call_stack.frame_ptr->cur_klass;
else
{
ERR("api func %p, unknown op type %d", api_func, op_type);
return EO_NOOP;
}
klass = eo2_call_stack.frame_ptr->obj->klass;
desc = _eo2_api_desc_get(api_func, klass, klass->extensions);
if (desc == NULL)
{
ERR("unable to resolve api func %p, op type %d", api_func,op_type);
return EO_NOOP;
}
if (desc->op_type != op_type)
{
ERR("api func %p resolves to %d, op type %d instead of %d",
api_func, (int) desc->op, desc->op_type, op_type);
ERR("unable to resolve %s api func %p", (class_ref ? "class" : "regular"), api_func);
return EO_NOOP;
}

View File

@ -784,14 +784,14 @@ _ev_freeze_get(Eo *obj EINA_UNUSED, void *class_data)
EAPI EO2_FUNC_BODY(eo2_event_freeze_get, int, 0);
static void
_ev_global_freeze(const Eo_Class *klass EINA_UNUSED)
_ev_global_freeze(const Eo_Class *klass EINA_UNUSED, void *class_data EINA_UNUSED)
{
event_freeze_count++;
}
EAPI EO2_VOID_CLASS_FUNC_BODY(eo2_event_global_freeze);
EAPI EO2_VOID_FUNC_BODY(eo2_event_global_freeze);
static void
_ev_global_thaw(const Eo_Class *klass EINA_UNUSED)
_ev_global_thaw(const Eo_Class *klass EINA_UNUSED, void *class_data EINA_UNUSED)
{
if (event_freeze_count > 0)
{
@ -802,14 +802,14 @@ _ev_global_thaw(const Eo_Class *klass EINA_UNUSED)
ERR("Global events have already been thawed.");
}
}
EAPI EO2_VOID_CLASS_FUNC_BODY(eo2_event_global_thaw);
EAPI EO2_VOID_FUNC_BODY(eo2_event_global_thaw);
static int
_ev_global_freeze_get(const Eo_Class *klass EINA_UNUSED)
_ev_global_freeze_get(const Eo_Class *klass EINA_UNUSED, void *class_data EINA_UNUSED)
{
return event_freeze_count;
}
EAPI EO2_CLASS_FUNC_BODY(eo2_event_global_freeze_get, int, 0);
EAPI EO2_FUNC_BODY(eo2_event_global_freeze_get, int, 0);
/* Eo_Dbg */
EAPI void
@ -970,9 +970,9 @@ static Eo2_Op_Description op_descs [] = {
EO2_OP_FUNC(_ev_freeze, eo2_event_freeze, "Freezes events."),
EO2_OP_FUNC(_ev_thaw, eo2_event_thaw, "Thaws events."),
EO2_OP_FUNC(_ev_freeze_get, eo2_event_freeze_get, "Get event freeze counter."),
EO2_OP_CLASS_FUNC(_ev_global_freeze, eo2_event_global_freeze, "Freezes events globally."),
EO2_OP_CLASS_FUNC(_ev_global_thaw, eo2_event_global_thaw, "Thaws events globally."),
EO2_OP_CLASS_FUNC(_ev_global_freeze_get, eo2_event_global_freeze_get, "Get global event freeze counter."),
EO2_OP_FUNC(_ev_global_freeze, eo2_event_global_freeze, "Freezes events globally."),
EO2_OP_FUNC(_ev_global_thaw, eo2_event_global_thaw, "Thaws events globally."),
EO2_OP_FUNC(_ev_global_freeze_get, eo2_event_global_freeze_get, "Get global event freeze counter."),
EO2_OP_FUNC(_dbg_info_get, eo2_dbg_info_get, "Get debug info list for obj."),
EO2_OP_SENTINEL
};