aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-08-26 10:02:01 +0100
committerTom Hacohen <tom@stosb.com>2015-08-26 10:11:18 +0100
commit9c78ee0bf4125c095e85f7fcf9921586cda64a52 (patch)
tree0172745b12d86536b3a829cecd96a55d1e43ec34
parentedje_cc_out: Fix edje_cc compile error with script on Windows. (diff)
downloadefl-9c78ee0bf4125c095e85f7fcf9921586cda64a52.tar.gz
Eo base: Change parent_set to be an assignment of ref.
After this change, parent_set assigns a ref, so for example: obj = eo_add(CLASS, parent); /* Ref is 1 */ eo_do(obj, eo_parent_set(parent2)); /* Ref is 1 */ eo_ref(obj); /* Ref is 2 */ eo_do(obj, eo_parent_set(NULL)); /* Ref is 1, giving the ref to NULL */ eo_do(obj, eo_parent_set(parent)); /* Ref is 1 */ This is following a discussion on the ML about commit 8689d54471aafdd7a5b5a27ce116bf2ab68c1042. @feature
-rw-r--r--src/lib/eo/eo.c6
-rw-r--r--src/lib/eo/eo_base_class.c8
-rw-r--r--src/tests/eo/suite/eo_test_general.c23
3 files changed, 32 insertions, 5 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index b5e24a91a5..4cd992dc71 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -917,13 +917,13 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo
eo_do(eo_id, eo_parent_set(parent_id));
- /* If there's a parent. Unref. Eo_add should return an object with either a
+ /* If there's a parent. Ref. Eo_add should return an object with either a
* parent ref, or with the lack of, just a ref. */
{
Eo *parent_tmp;
- if (!ref && eo_do_ret(eo_id, parent_tmp, eo_parent_get()))
+ if (ref && eo_do_ret(eo_id, parent_tmp, eo_parent_get()))
{
- _eo_unref(obj);
+ _eo_ref(obj);
}
}
diff --git a/src/lib/eo/eo_base_class.c b/src/lib/eo/eo_base_class.c
index 0c5f3ef01d..bbdf426ee7 100644
--- a/src/lib/eo/eo_base_class.c
+++ b/src/lib/eo/eo_base_class.c
@@ -124,7 +124,12 @@ _eo_base_parent_set(Eo *obj, Eo_Base_Data *pd, Eo *parent_id)
ERR("CONTACT DEVS!!! SHOULD NEVER HAPPEN!!! Old parent %p for object %p is not a valid Eo object.",
pd->parent, obj);
}
- eo_unref(obj);
+
+ /* Only unref if we don't have a new parent instead. */
+ if (!parent_id)
+ {
+ eo_unref(obj);
+ }
}
/* Set new parent */
@@ -138,7 +143,6 @@ _eo_base_parent_set(Eo *obj, Eo_Base_Data *pd, Eo *parent_id)
pd->parent = parent_id;
parent_pd->children = eina_list_append(parent_pd->children, obj);
pd->parent_list = eina_list_last(parent_pd->children);
- eo_ref(obj);
}
else
{
diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c
index 47064cf373..9121f8fac0 100644
--- a/src/tests/eo/suite/eo_test_general.c
+++ b/src/tests/eo/suite/eo_test_general.c
@@ -464,6 +464,29 @@ START_TEST(eo_refs)
ck_assert_int_eq(eo_ref_get(obj2), 1);
ck_assert_int_eq(eo_ref_get(obj3), 2);
+ /* Setting and removing parents. */
+ obj = eo_add(SIMPLE_CLASS, NULL);
+ obj2 = eo_ref(eo_add(SIMPLE_CLASS, obj));
+ obj3 = eo_ref(eo_add(SIMPLE_CLASS, NULL));
+
+ eo_do(obj2, eo_parent_set(obj3));
+ eo_do(obj3, eo_parent_set(obj));
+ ck_assert_int_eq(eo_ref_get(obj2), 2);
+ ck_assert_int_eq(eo_ref_get(obj3), 2);
+
+ eo_do(obj2, eo_parent_set(NULL));
+ eo_do(obj3, eo_parent_set(NULL));
+ ck_assert_int_eq(eo_ref_get(obj2), 1);
+ ck_assert_int_eq(eo_ref_get(obj3), 1);
+
+ eo_do(obj2, eo_parent_set(obj));
+ eo_do(obj3, eo_parent_set(obj));
+ ck_assert_int_eq(eo_ref_get(obj2), 1);
+ ck_assert_int_eq(eo_ref_get(obj3), 1);
+
+ eo_del(obj);
+ eo_del(obj2);
+ eo_del(obj3);
/* Just check it doesn't seg atm. */
obj = eo_add(SIMPLE_CLASS, NULL);