From 8959832be4b73fbb1aeb8358ed9440441f7c31fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 31 Jul 2013 23:37:06 +0200 Subject: [PATCH] eo2: fixed EO2_CLASS_FUNC_BODY and etc. functions. --- src/lib/eo/Eo.h | 22 ++++++++++++---------- src/lib/eo/eo.c | 27 +++++++++++++++++++++------ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 5446c5ce37..293261bd13 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -628,15 +628,17 @@ typedef struct _Eo2_Op_Call_Data // cache OP id, get real fct and object data then do the call #define _EO2_FUNC_COMMON(Name, Ret, Func, DefRet) \ static Eo_Op op = EO_NOOP; \ - if ( op == EO_NOOP ) op = eo2_api_op_id_get((void*)Name, NULL); \ + if ( op == EO_NOOP ) \ + op = eo2_api_op_id_get((void*)Name, EO_OP_TYPE_REGULAR); \ Eo2_Op_Call_Data call; \ if (!eo2_call_resolve(op, &call)) return DefRet; \ __##Name##_func _func_ = (__##Name##_func) call.func; \ return Func; \ -#define _EO2_CLASS_FUNC_COMMON(Name, Ret, Func, DefRet, Class) \ +#define _EO2_CLASS_FUNC_COMMON(Name, Ret, Func, DefRet) \ static Eo_Op op = EO_NOOP; \ - if ( op == EO_NOOP ) op = eo2_api_op_id_get((void*)Name, Class); \ + if ( op == EO_NOOP ) \ + op = eo2_api_op_id_get((void*)Name, EO_OP_TYPE_CLASS); \ Eo2_Op_Call_Data call; \ if (!eo2_call_resolve(op, &call)) return DefRet; \ __##Name##_func _func_ = (__##Name##_func) call.func; \ @@ -664,25 +666,25 @@ typedef struct _Eo2_Op_Call_Data #define EO2_VOID_FUNC_BODYV(Name, Func, ...) EO2_FUNC_BODYV(Name, void, Func, , __VA_ARGS__) // to define a EAPI class function -#define EO2_CLASS_FUNC_BODY(Name, Ret, DefRet, Class) \ +#define EO2_CLASS_FUNC_BODY(Name, Ret, DefRet) \ Ret \ Name(void) \ { \ typedef Ret (*__##Name##_func)(Eo_Class *); \ - _EO2_CLASS_FUNC_COMMON(Name, Ret, _func_(call.klass_id), DefRet, Class) \ + _EO2_CLASS_FUNC_COMMON(Name, Ret, _func_(call.klass_id), DefRet) \ } -#define EO2_VOID_CLASS_FUNC_BODY(Name, Class) EO2_CLASS_FUNC_BODY(Name, void, , Class) +#define EO2_VOID_CLASS_FUNC_BODY(Name) EO2_CLASS_FUNC_BODY(Name, void, ) -#define EO2_CLASS_FUNC_BODYV(Name, Ret, Func, DefRet, Class, ...) \ +#define EO2_CLASS_FUNC_BODYV(Name, Ret, Func, DefRet, ...) \ Ret \ Name(__VA_ARGS__) \ { \ typedef Ret (*__##Name##_func)(Eo_Class *, __VA_ARGS__); \ - _EO2_CLASS_FUNC_COMMON(Name, Ret, Func, DefRet, Class) \ + _EO2_CLASS_FUNC_COMMON(Name, Ret, Func, DefRet) \ } -#define EO2_VOID_CLASS_FUNC_BODYV(Name, Func, Class, ...) EO2_CLASS_FUNC_BODYV(Name, void, Func, , Class, __VA_ARGS__) +#define EO2_VOID_CLASS_FUNC_BODYV(Name, Func, ...) EO2_CLASS_FUNC_BODYV(Name, void, Func, , __VA_ARGS__) // OP ID of an overriding function #define EO2_OP_OVERRIDE ((Eo_Op) -1) @@ -694,7 +696,7 @@ typedef struct _Eo2_Op_Call_Data #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(void *api_func, const Eo_Class *klass); +EAPI Eo_Op eo2_api_op_id_get(const void *api_func, const Eo_Op_Type); // gets the real function pointer and the object data #define eo2_call_resolve(op, call) eo2_call_resolve_internal(NULL, op, call) diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index 57d0ad6468..b9af6e526e 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -487,7 +487,7 @@ eo2_call_resolve_internal(const Eo_Class *klass_id, Eo_Op op, Eo2_Op_Call_Data * static inline const Eo2_Op_Description * -_eo2_api_desc_get(void *api_func, const _Eo_Class *klass) +_eo2_api_desc_get(const void *api_func, const _Eo_Class *klass) { int imin, imax, imid; Eo2_Op_Description *op_desc; @@ -519,20 +519,35 @@ _eo2_api_desc_get(void *api_func, const _Eo_Class *klass) } EAPI Eo_Op -eo2_api_op_id_get(void *api_func, const Eo_Class *klass_id) +eo2_api_op_id_get(const void *api_func, const Eo_Op_Type op_type) { const Eo2_Op_Description *desc; const _Eo_Class *klass; - if (klass_id) - klass = _eo_class_pointer_get(klass_id); - else + if (op_type == EO_OP_TYPE_REGULAR) klass = eo2_call_stack.frame_ptr->obj->klass; + else if (op_type == EO_OP_TYPE_CLASS) + klass = eo2_call_stack.frame_ptr->klass; + else + { + ERR("api func %p, unknown op type %d", api_func, op_type); + return EO_NOOP; + } desc = _eo2_api_desc_get(api_func, klass); if (desc == NULL) - return EO_NOOP; + { + 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); + return EO_NOOP; + } return desc->op; }