eo: Make efl_cast() return NULL if invalid cast
This makes it work like C++ dynamic_cast<> operator, so that the return value will be NULL if the object is not an instance of the given class. In case of efl_super() we don't do it as efl_super is used A LOT inside EFL itself (all constructors & destructors, for a start) and efl_isa is in fact a bit expensive. efl_cast isn't really used and is intended to be something like dynamic_cast. For @cedric :)
This commit is contained in:
parent
11d4daf90a
commit
ac3abd1f5b
|
@ -357,12 +357,18 @@ _efl_super_cast(const Eo *eo_id, const Efl_Class *cur_klass, Eina_Bool super)
|
||||||
|
|
||||||
#ifdef EO_DEBUG
|
#ifdef EO_DEBUG
|
||||||
if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id) && !_eo_is_a_class(eo_id))) goto err_obj;
|
if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id) && !_eo_is_a_class(eo_id))) goto err_obj;
|
||||||
if (EINA_UNLIKELY(!efl_isa(eo_id, cur_klass))) goto err_obj_hierarchy;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id)))
|
if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id)))
|
||||||
goto do_klass;
|
goto do_klass;
|
||||||
|
|
||||||
|
#ifndef EO_DEBUG
|
||||||
|
if (!super && EINA_UNLIKELY(!efl_isa(eo_id, cur_klass)))
|
||||||
|
#else
|
||||||
|
if (EINA_UNLIKELY(!efl_isa(eo_id, cur_klass)))
|
||||||
|
#endif
|
||||||
|
goto err_obj_hierarchy;
|
||||||
|
|
||||||
EO_OBJ_POINTER_RETURN_VAL(eo_id, obj, NULL);
|
EO_OBJ_POINTER_RETURN_VAL(eo_id, obj, NULL);
|
||||||
obj->cur_klass = super_klass;
|
obj->cur_klass = super_klass;
|
||||||
obj->super = super;
|
obj->super = super;
|
||||||
|
@ -383,10 +389,10 @@ err:
|
||||||
err_obj:
|
err_obj:
|
||||||
_EO_POINTER_ERR(eo_id, "Object (%p) is an invalid ref, class=%p (%s).", eo_id, cur_klass, efl_class_name_get(cur_klass));
|
_EO_POINTER_ERR(eo_id, "Object (%p) is an invalid ref, class=%p (%s).", eo_id, cur_klass, efl_class_name_get(cur_klass));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#endif
|
||||||
err_obj_hierarchy:
|
err_obj_hierarchy:
|
||||||
_EO_POINTER_ERR(eo_id, "Object (%p) class=%p (%s) is not an instance of class=%p (%s).", eo_id, efl_class_get(eo_id), efl_class_name_get(eo_id), cur_klass, efl_class_name_get(cur_klass));
|
_EO_POINTER_ERR(eo_id, "Object (%p) class=%p (%s) is not an instance of class=%p (%s).", eo_id, efl_class_get(eo_id), efl_class_name_get(eo_id), cur_klass, efl_class_name_get(cur_klass));
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI Eo *
|
EAPI Eo *
|
||||||
|
|
Loading…
Reference in New Issue