This is wrong, and as JP and Stefan said, breaks things. First of all, 
why add code to the non-debug variation? Also, if you're already adding 
to the non-debug variation, why not include it in the commit message? 
This is very misleading.

Anyhow, as the tests clearly show, efl_super() is also used with class 
functions, so it needs to work. The efl_isa() line should work on 
classes too (I think), but the is_object is plain-wrong, and definitely 
shouldn't be outside the ifdef, but also not inside. It just doesn't 
belong there.

Furthermore, while I'm all in favour of this test in the eo_debug 
scenario, I disagree with the statement in the commit message. If you 
have such mistakes you are doing something very wrong, because the 
recommended way of using efl_super is with the macro "MY_CLASS" that 
should be defined to the current relevant class in the source file in 
order to avoid such mistakes as you described...

--
Tom.

On 02/12/16 16:51, Gustavo Sverzut Barbieri wrote:
> barbieri pushed a commit to branch master.
>
> http://git.enlightenment.org/core/efl.git/commit/?id=04450c4ee03fd20271ec4f911667acea10ba1375
>
> commit 04450c4ee03fd20271ec4f911667acea10ba1375
> Author: Gustavo Sverzut Barbieri <barbi...@profusion.mobi>
> Date:   Fri Dec 2 14:49:06 2016 -0200
>
>     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.
> ---
>  src/lib/eo/eo.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
> index 9719034..e86f052 100644
> --- a/src/lib/eo/eo.c
> +++ b/src/lib/eo/eo.c
> @@ -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
>


------------------------------------------------------------------------------
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to