diff --git a/src/lib/ecore/ecore_anim.c b/src/lib/ecore/ecore_anim.c index 7116538b7d..6dee5ad0b4 100644 --- a/src/lib/ecore/ecore_anim.c +++ b/src/lib/ecore/ecore_anim.c @@ -204,7 +204,6 @@ ecore_animator_add(Ecore_Task_Cb func, animator = eo_add(MY_CLASS, _ecore_parent, ecore_animator_constructor(func, data)); - eo_unref(animator); return animator; } @@ -224,7 +223,6 @@ ecore_animator_timeline_add(double runtime, Ecore_Animator *animator; animator = eo_add(MY_CLASS, _ecore_parent, ecore_animator_timeline_constructor(runtime, func, data)); - eo_unref(animator); return animator; } diff --git a/src/lib/ecore/ecore_idle_enterer.c b/src/lib/ecore/ecore_idle_enterer.c index f6d5b9997d..038b5c9946 100644 --- a/src/lib/ecore/ecore_idle_enterer.c +++ b/src/lib/ecore/ecore_idle_enterer.c @@ -64,7 +64,6 @@ ecore_idle_enterer_add(Ecore_Task_Cb func, { Ecore_Idle_Enterer *ie = NULL; ie = eo_add(MY_CLASS, _ecore_parent, ecore_idle_enterer_after_constructor(func, data)); - eo_unref(ie); return ie; } @@ -86,7 +85,6 @@ ecore_idle_enterer_before_add(Ecore_Task_Cb func, { Ecore_Idle_Enterer *ie = NULL; ie = eo_add(MY_CLASS, _ecore_parent, ecore_idle_enterer_before_constructor(func, data)); - eo_unref(ie); return ie; } diff --git a/src/lib/ecore/ecore_idle_exiter.c b/src/lib/ecore/ecore_idle_exiter.c index 51c7d357e4..b755fc702c 100644 --- a/src/lib/ecore/ecore_idle_exiter.c +++ b/src/lib/ecore/ecore_idle_exiter.c @@ -38,7 +38,6 @@ ecore_idle_exiter_add(Ecore_Task_Cb func, { Ecore_Idle_Exiter *ie = NULL; ie = eo_add(MY_CLASS, _ecore_parent, ecore_idle_exiter_constructor(func, data)); - eo_unref(ie); return ie; } diff --git a/src/lib/ecore/ecore_idler.c b/src/lib/ecore/ecore_idler.c index 0ac1bc6e72..5faed546fb 100644 --- a/src/lib/ecore/ecore_idler.c +++ b/src/lib/ecore/ecore_idler.c @@ -40,7 +40,6 @@ ecore_idler_add(Ecore_Task_Cb func, _ecore_lock(); ie = eo_add(MY_CLASS, _ecore_parent, ecore_idler_constructor(func, data)); - eo_unref(ie); _ecore_unlock(); return ie; diff --git a/src/lib/ecore/ecore_job.c b/src/lib/ecore/ecore_job.c index ef2b9c0660..b148f5682e 100644 --- a/src/lib/ecore/ecore_job.c +++ b/src/lib/ecore/ecore_job.c @@ -50,7 +50,6 @@ ecore_job_add(Ecore_Cb func, const void *data) { Ecore_Job *job = eo_add(MY_CLASS, _ecore_parent, ecore_job_constructor(func, data)); - eo_unref(job); return job; } diff --git a/src/lib/ecore/ecore_poller.c b/src/lib/ecore/ecore_poller.c index e7fca873db..61fb7684e3 100644 --- a/src/lib/ecore/ecore_poller.c +++ b/src/lib/ecore/ecore_poller.c @@ -239,7 +239,6 @@ ecore_poller_add(Ecore_Poller_Type type EINA_UNUSED, Ecore_Poller *poller; poller = eo_add(MY_CLASS, _ecore_parent, ecore_poller_constructor(type, interval, func, data)); - eo_unref(poller); return poller; } diff --git a/src/lib/ecore/ecore_timer.c b/src/lib/ecore/ecore_timer.c index e2cb43b686..9d20d27685 100644 --- a/src/lib/ecore/ecore_timer.c +++ b/src/lib/ecore/ecore_timer.c @@ -98,7 +98,6 @@ ecore_timer_add(double in, EINA_MAIN_LOOP_CHECK_RETURN_VAL(NULL); timer = eo_add(MY_CLASS, _ecore_parent, ecore_obj_timer_constructor(in, func, data)); - eo_unref(timer); return timer; } @@ -400,7 +399,6 @@ _ecore_timer_loop_add(double in, { Ecore_Timer *timer = NULL; timer = eo_add(MY_CLASS, _ecore_parent, ecore_obj_timer_loop_constructor(in, func, data)); - eo_unref(timer); return timer; } diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c index f51e2299a9..532c6e58ad 100644 --- a/src/lib/edje/edje_edit.c +++ b/src/lib/edje/edje_edit.c @@ -237,7 +237,6 @@ edje_edit_object_add(Evas *evas) { Evas_Object *e; e = eo_add(MY_CLASS, evas); - eo_unref(e); return e; } diff --git a/src/lib/edje/edje_smart.c b/src/lib/edje/edje_smart.c index 5974b66e1b..a077a96e79 100644 --- a/src/lib/edje/edje_smart.c +++ b/src/lib/edje/edje_smart.c @@ -20,7 +20,6 @@ edje_object_add(Evas *evas) { Evas_Object *e; e = eo_add(MY_CLASS, evas); - eo_unref(e); return e; } diff --git a/src/lib/emotion/emotion_smart.c b/src/lib/emotion/emotion_smart.c index b1ea284d1b..90825702a0 100644 --- a/src/lib/emotion/emotion_smart.c +++ b/src/lib/emotion/emotion_smart.c @@ -260,7 +260,6 @@ emotion_object_add(Evas *evas) { Evas_Object *e; e = eo_add(MY_CLASS, evas); - eo_unref(e); return e; } diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 561665bb7b..b2807979bd 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -621,6 +621,13 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line); /** * @def eo_add * @brief Create a new object with the default constructor. + * + * The object returned by this function always has at least 1 ref. If the object + * has a parent, it returns with 1 ref, and even if it doesn't have a parent + * it's returned with 1 ref. This is convenient in C. + * + * If you want a more "consistent" behaviour, take a look at #eo_add_ref. + * * @param klass the class of the object to create. * @param parent the parent to set to the object. * @param ... The ops to run. @@ -638,6 +645,25 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line); _tmp_obj; \ }) +/** + * @def eo_add_ref + * @brief Create a new object with the default constructor. + * + * The object returned by this function has 1 ref for itself, 1 ref from the + * parent (if exists) and possible other refs if were added during construction. + * + * @param klass the class of the object to create. + * @param parent the parent to set to the object. + * @param ... The ops to run. + * @return An handle to the new object on success, NULL otherwise. + */ +#define eo_add_ref(klass, parent, ...) \ + ({ \ + Eo *_tmp_obj_ref = eo_add(klass, parent, __VA_ARGS__); \ + if (eo_do(_tmp_obj_ref, eo_parent_get())) eo_ref(_tmp_obj_ref); \ + _tmp_obj_ref; \ + }) + EAPI Eo * _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent); /** diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index b6c6efa72e..fa64ce135f 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -904,16 +904,23 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo #ifndef HAVE_EO_ID EINA_MAGIC_SET((Eo_Base *) obj, EO_EINA_MAGIC); #endif - Eo_Id eo_id = _eo_id_allocate(obj); - obj->header.id = eo_id; + obj->header.id = _eo_id_allocate(obj); + Eo *eo_id = _eo_id_get(obj); _eo_condtor_reset(obj); _eo_ref(obj); - eo_do(_eo_id_get(obj), eo_parent_set(parent_id)); + eo_do(eo_id, eo_parent_set(parent_id)); - return _eo_id_get(obj); + /* If there's a parent. Unref. Eo_add should return an object with either a + * parent ref, or with the lack of, just a ref. */ + if (eo_do(eo_id, eo_parent_get())) + { + _eo_unref(obj); + } + + return eo_id; } Eo * @@ -1539,8 +1546,6 @@ eo_unref(const Eo *obj_id) EAPI void eo_del(const Eo *obj) { - EO_OBJ_POINTER_RETURN(obj, _obj); - eo_do((Eo *) obj, eo_parent_set(NULL)); eo_unref(obj); } diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h index c7b6348953..1c21d2255e 100644 --- a/src/lib/eo/eo_private.h +++ b/src/lib/eo/eo_private.h @@ -1,6 +1,7 @@ #ifndef _EO_PRIVATE_H #define _EO_PRIVATE_H +#include #include #define EO_EINA_MAGIC 0xa186bc32 @@ -283,6 +284,16 @@ _eo_unref(_Eo_Object *obj) return; } + /* Unparent if parented. */ + { + Eo *eo_id = _eo_id_get(obj); + obj->refcount = 2; /* Needs to be high enough that parent set to null won't delete the object. */ + + eo_do(eo_id, eo_parent_set(NULL)); + + obj->refcount = 0; + } + _eo_del_internal(__FILE__, __LINE__, obj); #ifdef EO_DEBUG diff --git a/src/lib/evas/canvas/evas_3d_camera.c b/src/lib/evas/canvas/evas_3d_camera.c index 896d563bd3..08a8ab6b15 100644 --- a/src/lib/evas/canvas/evas_3d_camera.c +++ b/src/lib/evas/canvas/evas_3d_camera.c @@ -85,7 +85,6 @@ evas_3d_camera_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_light.c b/src/lib/evas/canvas/evas_3d_light.c index 9f6b3c73e3..74718b2aa1 100644 --- a/src/lib/evas/canvas/evas_3d_light.c +++ b/src/lib/evas/canvas/evas_3d_light.c @@ -73,7 +73,6 @@ evas_3d_light_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_material.c b/src/lib/evas/canvas/evas_3d_material.c index 1391ed3f52..87364037c3 100644 --- a/src/lib/evas/canvas/evas_3d_material.c +++ b/src/lib/evas/canvas/evas_3d_material.c @@ -85,7 +85,6 @@ evas_3d_material_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_mesh.c b/src/lib/evas/canvas/evas_3d_mesh.c index bc19481ccb..2cbf852f0d 100644 --- a/src/lib/evas/canvas/evas_3d_mesh.c +++ b/src/lib/evas/canvas/evas_3d_mesh.c @@ -242,7 +242,6 @@ evas_3d_mesh_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_node.c b/src/lib/evas/canvas/evas_3d_node.c index 25c01a72b8..c7f3604547 100644 --- a/src/lib/evas/canvas/evas_3d_node.c +++ b/src/lib/evas/canvas/evas_3d_node.c @@ -776,7 +776,6 @@ evas_3d_node_add(Evas *e, Evas_3D_Node_Type type) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e, evas_3d_node_constructor(type)); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_scene.c b/src/lib/evas/canvas/evas_3d_scene.c index 42f620f352..6db897ec39 100644 --- a/src/lib/evas/canvas/evas_3d_scene.c +++ b/src/lib/evas/canvas/evas_3d_scene.c @@ -55,7 +55,6 @@ evas_3d_scene_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_3d_texture.c b/src/lib/evas/canvas/evas_3d_texture.c index 94e537b7c9..6d345914f2 100644 --- a/src/lib/evas/canvas/evas_3d_texture.c +++ b/src/lib/evas/canvas/evas_3d_texture.c @@ -299,7 +299,6 @@ evas_3d_texture_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_box.c b/src/lib/evas/canvas/evas_object_box.c index b28eff4026..f4148bcf35 100644 --- a/src/lib/evas/canvas/evas_object_box.c +++ b/src/lib/evas/canvas/evas_object_box.c @@ -456,7 +456,6 @@ EAPI Evas_Object * evas_object_box_add(Evas *evas) { Evas_Object *obj = eo_add(MY_CLASS, evas); - eo_unref(obj); return obj; } diff --git a/src/lib/evas/canvas/evas_object_grid.c b/src/lib/evas/canvas/evas_object_grid.c index 8d153cdbe1..3e612010bb 100644 --- a/src/lib/evas/canvas/evas_object_grid.c +++ b/src/lib/evas/canvas/evas_object_grid.c @@ -258,7 +258,6 @@ EAPI Evas_Object * evas_object_grid_add(Evas *evas) { Evas_Object *obj = eo_add(MY_CLASS, evas); - eo_unref(obj); return obj; } diff --git a/src/lib/evas/canvas/evas_object_image.c b/src/lib/evas/canvas/evas_object_image.c index ea8fc8a4b6..6cdb965637 100644 --- a/src/lib/evas/canvas/evas_object_image.c +++ b/src/lib/evas/canvas/evas_object_image.c @@ -381,7 +381,6 @@ evas_object_image_add(Evas *eo_e) EINA_SAFETY_ON_NULL_RETURN_VAL(e, NULL); EINA_SAFETY_ON_NULL_RETURN_VAL(e->engine.func, NULL); Evas_Object *eo_obj = eo_add(EVAS_IMAGE_CLASS, eo_e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_line.c b/src/lib/evas/canvas/evas_object_line.c index 48db646952..4c2d7891b1 100644 --- a/src/lib/evas/canvas/evas_object_line.c +++ b/src/lib/evas/canvas/evas_object_line.c @@ -97,7 +97,6 @@ evas_object_line_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_LINE_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_main.c b/src/lib/evas/canvas/evas_object_main.c index 29706fa622..162b1f3daf 100644 --- a/src/lib/evas/canvas/evas_object_main.c +++ b/src/lib/evas/canvas/evas_object_main.c @@ -621,8 +621,7 @@ evas_object_del(Evas_Object *eo_obj) obj->eo_del_called = EINA_TRUE; - eo_do(eo_obj, eo_parent_set(NULL)); -// eo_del(eo_obj); + eo_del(eo_obj); } EOLIAN static void diff --git a/src/lib/evas/canvas/evas_object_polygon.c b/src/lib/evas/canvas/evas_object_polygon.c index 53d8316201..cd27199282 100644 --- a/src/lib/evas/canvas/evas_object_polygon.c +++ b/src/lib/evas/canvas/evas_object_polygon.c @@ -98,7 +98,6 @@ evas_object_polygon_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_POLYGON_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_rectangle.c b/src/lib/evas/canvas/evas_object_rectangle.c index aa114258ab..3633bc001a 100644 --- a/src/lib/evas/canvas/evas_object_rectangle.c +++ b/src/lib/evas/canvas/evas_object_rectangle.c @@ -86,7 +86,6 @@ evas_object_rectangle_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_RECTANGLE_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_smart.c b/src/lib/evas/canvas/evas_object_smart.c index 42da500947..73b078d466 100644 --- a/src/lib/evas/canvas/evas_object_smart.c +++ b/src/lib/evas/canvas/evas_object_smart.c @@ -536,7 +536,6 @@ evas_object_smart_add(Evas *eo_e, Evas_Smart *s) MAGIC_CHECK_END(); eo_obj = eo_add(EVAS_OBJECT_SMART_CLASS, eo_e); eo_do(eo_obj, evas_obj_smart_attach(s)); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_table.c b/src/lib/evas/canvas/evas_object_table.c index a9259a8739..99cd84a17f 100644 --- a/src/lib/evas/canvas/evas_object_table.c +++ b/src/lib/evas/canvas/evas_object_table.c @@ -960,7 +960,6 @@ EAPI Evas_Object * evas_object_table_add(Evas *evas) { Evas_Object *obj = eo_add(MY_CLASS, evas); - eo_unref(obj); return obj; } diff --git a/src/lib/evas/canvas/evas_object_text.c b/src/lib/evas/canvas/evas_object_text.c index 37a4c563cf..6a1e1df71f 100644 --- a/src/lib/evas/canvas/evas_object_text.c +++ b/src/lib/evas/canvas/evas_object_text.c @@ -371,7 +371,6 @@ evas_object_text_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_TEXT_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_textblock.c b/src/lib/evas/canvas/evas_object_textblock.c index e0c286e65f..520761d9ee 100644 --- a/src/lib/evas/canvas/evas_object_textblock.c +++ b/src/lib/evas/canvas/evas_object_textblock.c @@ -5672,7 +5672,6 @@ evas_object_textblock_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_TEXTBLOCK_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_object_textgrid.c b/src/lib/evas/canvas/evas_object_textgrid.c index 309efa2f69..e2742011bb 100644 --- a/src/lib/evas/canvas/evas_object_textgrid.c +++ b/src/lib/evas/canvas/evas_object_textgrid.c @@ -1056,7 +1056,6 @@ evas_object_textgrid_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(EVAS_TEXTGRID_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/lib/evas/canvas/evas_out.c b/src/lib/evas/canvas/evas_out.c index 48a87557d6..27f459e37c 100644 --- a/src/lib/evas/canvas/evas_out.c +++ b/src/lib/evas/canvas/evas_out.c @@ -20,7 +20,6 @@ evas_out_add(Evas *e) return NULL; MAGIC_CHECK_END(); Evas_Object *eo_obj = eo_add(MY_CLASS, e); - eo_unref(eo_obj); return eo_obj; } diff --git a/src/tests/eo/children/children_simple.c b/src/tests/eo/children/children_simple.c index cd351d3001..a85767cb43 100644 --- a/src/tests/eo/children/children_simple.c +++ b/src/tests/eo/children/children_simple.c @@ -18,5 +18,5 @@ static const Eo_Class_Description class_desc = { NULL }; -EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_CLASS, NULL) +EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL) diff --git a/src/tests/eo/composite_objects/composite_objects_comp.c b/src/tests/eo/composite_objects/composite_objects_comp.c index d880c9823e..17cd95cff2 100644 --- a/src/tests/eo/composite_objects/composite_objects_comp.c +++ b/src/tests/eo/composite_objects/composite_objects_comp.c @@ -32,8 +32,6 @@ _constructor(Eo *obj, void *class_data EINA_UNUSED) fail_if(!eo_composite_is(simple)); eo_do(obj, eo_key_data_set("simple-obj", simple, NULL)); - - eo_unref(simple); } static Eo_Op_Description op_descs[] = { diff --git a/src/tests/eo/suite/eo_test_general.c b/src/tests/eo/suite/eo_test_general.c index 114d2443a4..77fca9cc61 100644 --- a/src/tests/eo/suite/eo_test_general.c +++ b/src/tests/eo/suite/eo_test_general.c @@ -435,7 +435,7 @@ START_TEST(eo_refs) /* Check hierarchy */ obj = eo_add(SIMPLE_CLASS, NULL); - obj2 = eo_add(SIMPLE_CLASS, obj); + obj2 = eo_ref(eo_add(SIMPLE_CLASS, obj)); Eo *wref = NULL; eo_do(obj2, eo_wref_add(&wref)); @@ -449,6 +449,16 @@ START_TEST(eo_refs) fail_if(wref); + /* eo_add_ref and normal eo_add */ + obj = eo_add(SIMPLE_CLASS, NULL); + obj2 = eo_add(SIMPLE_CLASS, obj); + obj3 = eo_add_ref(SIMPLE_CLASS, obj); + + ck_assert_int_eq(eo_ref_get(obj), 1); + ck_assert_int_eq(eo_ref_get(obj2), 1); + ck_assert_int_eq(eo_ref_get(obj3), 2); + + /* Just check it doesn't seg atm. */ obj = eo_add(SIMPLE_CLASS, NULL); eo_ref(obj);