Eo: Change eo_add/del/unref behaviour.

Before this change eo_add() used to create an object with 1 ref, and if
the object had a parent, a second ref.
Now, eo_add() always returns an object with 1 ref, and eo_add_ref()
    preserves the old behaviour (for bindings).

eo_unref now un-parents if refcount is 0, and eo_del() is an alias for
eo_unref (will change to be a way to ensure an object is dead and goes
        to zombie-land even if still refed).
This commit is contained in:
Tom Hacohen 2014-09-25 15:51:17 +01:00
parent 2bc462f55b
commit a7560dbc61
36 changed files with 61 additions and 44 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -237,7 +237,6 @@ edje_edit_object_add(Evas *evas)
{
Evas_Object *e;
e = eo_add(MY_CLASS, evas);
eo_unref(e);
return e;
}

View File

@ -20,7 +20,6 @@ edje_object_add(Evas *evas)
{
Evas_Object *e;
e = eo_add(MY_CLASS, evas);
eo_unref(e);
return e;
}

View File

@ -260,7 +260,6 @@ emotion_object_add(Evas *evas)
{
Evas_Object *e;
e = eo_add(MY_CLASS, evas);
eo_unref(e);
return e;
}

View File

@ -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);
/**

View File

@ -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);
}

View File

@ -1,6 +1,7 @@
#ifndef _EO_PRIVATE_H
#define _EO_PRIVATE_H
#include <Eo.h>
#include <Eina.h>
#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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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[] = {

View File

@ -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);