cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=0cc07f4e6bdd6762fcb3327e7a127356b22eef04

commit 0cc07f4e6bdd6762fcb3327e7a127356b22eef04
Author: Cedric BAIL <ced...@osg.samsung.com>
Date:   Tue May 15 15:35:48 2018 -0700

    eo: try to make efl_add and efl_add_ref refcounting sane in all case.
---
 src/lib/eo/eo.c            | 30 +++++++++++++-----------------
 src/lib/eo/eo_base_class.c |  3 +--
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 5396a12ee4..f75f376c9b 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -873,7 +873,7 @@ _efl_add_internal_start(const char *file, int line, const 
Efl_Class *klass_id, E
    // Check that in the case of efl_add we do pass a parent.
    if (!ref && !parent_id)
      ERR("Creation of '%s' object at line %i in '%s' is done without parent. 
This should use efl_add_ref.",
-        klass->desc->name, line, file);
+         klass->desc->name, line, file);
 
    if (parent_id)
      {
@@ -898,7 +898,7 @@ _efl_add_internal_start(const char *file, int line, const 
Efl_Class *klass_id, E
    eina_spinlock_release(&klass->objects.trash_lock);
 
    obj->opt = eina_cow_alloc(efl_object_optional_cow);
-   obj->refcount++;
+   _efl_ref(obj);
    obj->klass = klass;
 
    obj->header.id = _eo_id_allocate(obj, parent_id);
@@ -927,11 +927,11 @@ ok_nomatch_back:
 ok_nomatch:
      {
         EO_OBJ_POINTER_GOTO_PROXY(eo_id, new_obj, err_newid);
-        /* We have two refs at this point. */
+        efl_ref(eo_id);
+        /* We might have two refs on the old object at this point. */
+        efl_parent_set((Eo *) obj->header.id, NULL);
+        efl_unref(_eo_obj_id_get(obj));
         _efl_unref(obj);
-        if (parent_id) efl_del((Eo *) obj->header.id);
-        else _efl_unref(obj);
-        _efl_ref(new_obj);
         EO_OBJ_DONE(eo_id);
      }
    goto ok_nomatch_back;
@@ -939,10 +939,10 @@ ok_nomatch:
 err_noid:
    ERR("in %s:%d: Object of class '%s' - Error while constructing object",
        file, line, klass->desc->name);
-   /* We have two refs at this point. */
+   /* We might have two refs at this point. */
+   efl_parent_set((Eo *) obj->header.id, NULL);
+   efl_unref(_eo_obj_id_get(obj));
    _efl_unref(obj);
-   if (parent_id) efl_del((Eo *) obj->header.id);
-   else _efl_unref(obj);
 err_newid:
    if (parent_id) EO_OBJ_DONE(parent_id);
    return NULL;
@@ -992,9 +992,9 @@ err_condtor:
               klass->desc->name);
      }
 cleanup:
+   efl_parent_set((Eo *) obj->header.id, NULL);
+   efl_unref((Eo *) obj->header.id);
    _efl_unref(obj);
-   if (efl_parent_get(eo_id)) efl_del((Eo *) obj->header.id);
-   else _efl_unref(obj);
    EO_OBJ_DONE(eo_id);
    return NULL;
 }
@@ -1006,13 +1006,9 @@ _efl_add_end(Eo *eo_id, Eina_Bool is_ref, Eina_Bool 
is_fallback)
    Eo *ret = efl_finalize(eo_id);
    ret = _efl_add_internal_end(eo_id, ret);
 
-   if (ret && is_ref)
+   if (ret && !is_ref)
      {
-        if (efl_parent_get(eo_id))
-          {
-             efl_ref(eo_id);
-          }
-        _efl_object_parent_sink_set(eo_id, EINA_TRUE);
+        efl_unref(ret);
      }
 
    if (is_fallback)
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 01a7addbe5..66ae601b05 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -771,8 +771,7 @@ _efl_object_parent_set(Eo *obj, Efl_Object_Data *pd, Eo 
*parent_id)
              pd->parent = parent_id;
              parent_pd->children = eina_inlist_append(parent_pd->children,
                                                       EINA_INLIST_GET(eo_obj));
-             if (!prev_parent && pd->parent_sunk) efl_ref(obj);
-             pd->parent_sunk = EINA_TRUE;
+             if (!prev_parent) efl_ref(obj);
           }
         else
           {

-- 


Reply via email to