summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2015-08-26 10:47:06 +0100
committerTom Hacohen <tom@stosb.com>2015-08-26 10:47:06 +0100
commitacc158a2bfb2f1f1edc587386d7f0ac5ed456e20 (patch)
tree0172745b12d86536b3a829cecd96a55d1e43ec34
parent37abea3831f62ac612b377bb48ce6c90e076dd25 (diff)
Revert "Revert "Eo base: Change parent_set to be an assignment of ref.""
Had to revert it until I pushed the changes to elm, which I had issues with. Now the patch can safely go back in. This reverts commit 37abea3831f62ac612b377bb48ce6c90e076dd25.
-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
917 917
918 eo_do(eo_id, eo_parent_set(parent_id)); 918 eo_do(eo_id, eo_parent_set(parent_id));
919 919
920 /* If there's a parent. Unref. Eo_add should return an object with either a 920 /* If there's a parent. Ref. Eo_add should return an object with either a
921 * parent ref, or with the lack of, just a ref. */ 921 * parent ref, or with the lack of, just a ref. */
922 { 922 {
923 Eo *parent_tmp; 923 Eo *parent_tmp;
924 if (!ref && eo_do_ret(eo_id, parent_tmp, eo_parent_get())) 924 if (ref && eo_do_ret(eo_id, parent_tmp, eo_parent_get()))
925 { 925 {
926 _eo_unref(obj); 926 _eo_ref(obj);
927 } 927 }
928 } 928 }
929 929
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)
124 ERR("CONTACT DEVS!!! SHOULD NEVER HAPPEN!!! Old parent %p for object %p is not a valid Eo object.", 124 ERR("CONTACT DEVS!!! SHOULD NEVER HAPPEN!!! Old parent %p for object %p is not a valid Eo object.",
125 pd->parent, obj); 125 pd->parent, obj);
126 } 126 }
127 eo_unref(obj); 127
128 /* Only unref if we don't have a new parent instead. */
129 if (!parent_id)
130 {
131 eo_unref(obj);
132 }
128 } 133 }
129 134
130 /* Set new parent */ 135 /* Set new parent */
@@ -138,7 +143,6 @@ _eo_base_parent_set(Eo *obj, Eo_Base_Data *pd, Eo *parent_id)
138 pd->parent = parent_id; 143 pd->parent = parent_id;
139 parent_pd->children = eina_list_append(parent_pd->children, obj); 144 parent_pd->children = eina_list_append(parent_pd->children, obj);
140 pd->parent_list = eina_list_last(parent_pd->children); 145 pd->parent_list = eina_list_last(parent_pd->children);
141 eo_ref(obj);
142 } 146 }
143 else 147 else
144 { 148 {
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)
464 ck_assert_int_eq(eo_ref_get(obj2), 1); 464 ck_assert_int_eq(eo_ref_get(obj2), 1);
465 ck_assert_int_eq(eo_ref_get(obj3), 2); 465 ck_assert_int_eq(eo_ref_get(obj3), 2);
466 466
467 /* Setting and removing parents. */
468 obj = eo_add(SIMPLE_CLASS, NULL);
469 obj2 = eo_ref(eo_add(SIMPLE_CLASS, obj));
470 obj3 = eo_ref(eo_add(SIMPLE_CLASS, NULL));
471
472 eo_do(obj2, eo_parent_set(obj3));
473 eo_do(obj3, eo_parent_set(obj));
474 ck_assert_int_eq(eo_ref_get(obj2), 2);
475 ck_assert_int_eq(eo_ref_get(obj3), 2);
476
477 eo_do(obj2, eo_parent_set(NULL));
478 eo_do(obj3, eo_parent_set(NULL));
479 ck_assert_int_eq(eo_ref_get(obj2), 1);
480 ck_assert_int_eq(eo_ref_get(obj3), 1);
481
482 eo_do(obj2, eo_parent_set(obj));
483 eo_do(obj3, eo_parent_set(obj));
484 ck_assert_int_eq(eo_ref_get(obj2), 1);
485 ck_assert_int_eq(eo_ref_get(obj3), 1);
486
487 eo_del(obj);
488 eo_del(obj2);
489 eo_del(obj3);
467 490
468 /* Just check it doesn't seg atm. */ 491 /* Just check it doesn't seg atm. */
469 obj = eo_add(SIMPLE_CLASS, NULL); 492 obj = eo_add(SIMPLE_CLASS, NULL);