summaryrefslogtreecommitdiff
path: root/src/lib/eo
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2017-05-29 11:28:13 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-05-29 13:29:03 +0900
commitac3abd1f5b29a978167b83ffd43fb7c56fa678d7 (patch)
treec93a6248c58f03ead5b32d0320d54af267dd2d9b /src/lib/eo
parent11d4daf90a04639dcb8c75f793bc6c976f3c1808 (diff)
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 :)
Diffstat (limited to 'src/lib/eo')
-rw-r--r--src/lib/eo/eo.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index a2db10382d..d4c3b49bae 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -357,12 +357,18 @@ _efl_super_cast(const Eo *eo_id, const Efl_Class *cur_klass, Eina_Bool super)
357 357
358#ifdef EO_DEBUG 358#ifdef EO_DEBUG
359 if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id) && !_eo_is_a_class(eo_id))) goto err_obj; 359 if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id) && !_eo_is_a_class(eo_id))) goto err_obj;
360 if (EINA_UNLIKELY(!efl_isa(eo_id, cur_klass))) goto err_obj_hierarchy;
361#endif 360#endif
362 361
363 if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id))) 362 if (EINA_UNLIKELY(!_eo_is_a_obj(eo_id)))
364 goto do_klass; 363 goto do_klass;
365 364
365#ifndef EO_DEBUG
366 if (!super && EINA_UNLIKELY(!efl_isa(eo_id, cur_klass)))
367#else
368 if (EINA_UNLIKELY(!efl_isa(eo_id, cur_klass)))
369#endif
370 goto err_obj_hierarchy;
371
366 EO_OBJ_POINTER_RETURN_VAL(eo_id, obj, NULL); 372 EO_OBJ_POINTER_RETURN_VAL(eo_id, obj, NULL);
367 obj->cur_klass = super_klass; 373 obj->cur_klass = super_klass;
368 obj->super = super; 374 obj->super = super;
@@ -383,10 +389,10 @@ err:
383err_obj: 389err_obj:
384 _EO_POINTER_ERR(eo_id, "Object (%p) is an invalid ref, class=%p (%s).", eo_id, cur_klass, efl_class_name_get(cur_klass)); 390 _EO_POINTER_ERR(eo_id, "Object (%p) is an invalid ref, class=%p (%s).", eo_id, cur_klass, efl_class_name_get(cur_klass));
385 return NULL; 391 return NULL;
392#endif
386err_obj_hierarchy: 393err_obj_hierarchy:
387 _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)); 394 _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));
388 return NULL; 395 return NULL;
389#endif
390} 396}
391 397
392EAPI Eo * 398EAPI Eo *