eo: if EO_DEBUG, check if efl_super() object 'isa' the given class.

A common error is to copy & paste efl_super() calls and forget to fix
the class. If usin EO_DEBUG, then use efl_isa() to error.
This commit is contained in:
Gustavo Sverzut Barbieri 2016-12-02 14:49:06 -02:00
parent 216e6e51e4
commit 04450c4ee0
1 changed files with 13 additions and 0 deletions

View File

@ -318,6 +318,11 @@ efl_super(const Eo *obj, const Efl_Class *cur_klass)
{
EO_CLASS_POINTER_GOTO(cur_klass, klass, err);
if (EINA_UNLIKELY(!_eo_is_a_obj(obj))) goto err_obj;
#ifdef EO_DEBUG
if (EINA_UNLIKELY(!efl_isa(obj, cur_klass))) goto err_obj_hierarchy;
#endif
/* FIXME: Switch to atomic operations intead of lock. */
eina_spinlock_take(&_super_class_lock);
_super_class = klass;
@ -326,6 +331,14 @@ efl_super(const Eo *obj, const Efl_Class *cur_klass)
err:
_EO_POINTER_ERR("Class (%p) is an invalid ref.", cur_klass);
return NULL;
err_obj:
_EO_POINTER_ERR("Object (%p) is an invalid ref, class=%p (%s).", obj, cur_klass, efl_class_name_get(cur_klass));
return NULL;
#ifdef EO_DEBUG
err_obj_hierarchy:
_EO_POINTER_ERR("Object (%p) class=%p (%s) is not an instance of class=%p (%s).", obj, efl_class_get(obj), efl_class_name_get(obj), cur_klass, efl_class_name_get(cur_klass));
#endif
return NULL;
}
EAPI Eina_Bool