Eo: Remove eo_error_set() and clean up finalizer()

This is another cleanup in perparation for the Eo stable release.
This is no longer needed thanks to the proper error reporting with
eo_constructor()'s new return value.

The finalizer change cleans it up a bit so it catches more cases/issues.
This also means that the finalizer cleans up the object in all cases,
and not only some.

@feature.
This commit is contained in:
Tom Hacohen 2015-05-20 14:56:45 +01:00
parent 7c769163d9
commit 92fb2917cb
27 changed files with 133 additions and 76 deletions

View File

@ -177,7 +177,6 @@ _ecore_animator_add(Ecore_Animator *obj,
{
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
}
@ -186,7 +185,6 @@ _ecore_animator_add(Ecore_Animator *obj,
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return EINA_FALSE;
}
@ -526,6 +524,17 @@ _ecore_animator_eo_base_destructor(Eo *obj, Ecore_Animator_Data *pd)
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_animator_eo_base_finalize(Eo *obj, Ecore_Animator_Data *pd)
{
if (!pd->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
EAPI void
ecore_animator_frametime_set(double frametime)
{

View File

@ -22,6 +22,7 @@ class Ecore.Animator (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
Eo.Base.event_freeze;
Eo.Base.event_thaw;
}

View File

@ -39,7 +39,6 @@ _ecore_idle_enterer_add(Ecore_Idle_Enterer *obj,
{
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
}
@ -48,7 +47,6 @@ _ecore_idle_enterer_add(Ecore_Idle_Enterer *obj,
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return EINA_FALSE;
}
@ -135,6 +133,17 @@ _ecore_idle_enterer_eo_base_destructor(Eo *obj, Ecore_Idle_Enterer_Data *idle_en
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_idle_enterer_eo_base_finalize(Eo *obj, Ecore_Idle_Enterer_Data *idle_enterer)
{
if (!idle_enterer->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
void
_ecore_idle_enterer_shutdown(void)
{

View File

@ -21,6 +21,7 @@ class Ecore.Idle.Enterer (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
}
constructors {
.before_constructor;

View File

@ -47,7 +47,6 @@ _ecore_idle_exiter_constructor(Eo *obj, Ecore_Idle_Exiter_Data *ie, Ecore_Task_C
_ecore_lock();
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN;
}
@ -57,7 +56,6 @@ _ecore_idle_exiter_constructor(Eo *obj, Ecore_Idle_Exiter_Data *ie, Ecore_Task_C
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return;
}
@ -93,6 +91,16 @@ _ecore_idle_exiter_del(Ecore_Idle_Exiter *obj)
return idle_exiter->data;
}
EOLIAN static Eo *
_ecore_idle_exiter_eo_base_finalize(Eo *obj, Ecore_Idle_Exiter_Data *idle_exiter)
{
if (!idle_exiter)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
EOLIAN static void
_ecore_idle_exiter_eo_base_destructor(Eo *obj, Ecore_Idle_Exiter_Data *idle_exiter)

View File

@ -13,6 +13,7 @@ class Ecore.Idle.Exiter (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
}
constructors {
.constructor;

View File

@ -50,7 +50,6 @@ _ecore_idler_constructor(Eo *obj, Ecore_Idler_Data *ie, Ecore_Task_Cb func, cons
{
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN;
}
@ -59,7 +58,6 @@ _ecore_idler_constructor(Eo *obj, Ecore_Idler_Data *ie, Ecore_Task_Cb func, cons
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return;
}
@ -103,6 +101,17 @@ _ecore_idler_eo_base_destructor(Eo *obj, Ecore_Idler_Data *idler)
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_idler_eo_base_finalize(Eo *obj, Ecore_Idler_Data *idler)
{
if (!idler->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
void
_ecore_idler_shutdown(void)
{

View File

@ -13,6 +13,7 @@ class Ecore.Idler (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
}
constructors {
.constructor;

View File

@ -58,14 +58,12 @@ _ecore_job_constructor(Eo *obj, Ecore_Job_Data *job, Ecore_Cb func, const void *
{
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN;
}
eo_manual_free_set(obj, EINA_TRUE);
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return;
}
@ -73,7 +71,6 @@ _ecore_job_constructor(Eo *obj, Ecore_Job_Data *job, Ecore_Cb func, const void *
job->event = ecore_event_add(ecore_event_job_type, job, _ecore_job_event_free, obj);
if (!job->event)
{
eo_error_set(obj);
ERR("no event was assigned to object '%p' of class '%s'", obj, MY_CLASS_NAME);
return;
}
@ -102,6 +99,17 @@ _ecore_job_eo_base_destructor(Eo *obj, Ecore_Job_Data *_pd EINA_UNUSED)
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_job_eo_base_finalize(Eo *obj, Ecore_Job_Data *pd)
{
if (!pd->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
static Eina_Bool
_ecore_job_event_handler(void *data EINA_UNUSED,
int type EINA_UNUSED,

View File

@ -13,6 +13,7 @@ class Ecore.Job (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
}
constructors {
.constructor;

View File

@ -251,7 +251,6 @@ _ecore_poller_constructor(Eo *obj, Ecore_Poller_Data *poller, Ecore_Poller_Type
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN;
}
@ -259,7 +258,6 @@ _ecore_poller_constructor(Eo *obj, Ecore_Poller_Data *poller, Ecore_Poller_Type
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return;
}
@ -376,6 +374,17 @@ _ecore_poller_eo_base_destructor(Eo *obj, Ecore_Poller_Data *pd)
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_poller_eo_base_finalize(Eo *obj, Ecore_Poller_Data *pd)
{
if (!pd->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
void
_ecore_poller_shutdown(void)
{

View File

@ -37,6 +37,7 @@ class Ecore.Poller (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
}
constructors {
.constructor;

View File

@ -112,7 +112,6 @@ _ecore_timer_add(Ecore_Timer *obj,
if (EINA_UNLIKELY(!eina_main_loop_is()))
{
eo_error_set(obj);
EINA_MAIN_LOOP_CHECK_RETURN_VAL(EINA_FALSE);
}
@ -121,7 +120,6 @@ _ecore_timer_add(Ecore_Timer *obj,
if (!func)
{
eo_error_set(obj);
ERR("callback function must be set up for an object of class: '%s'", MY_CLASS_NAME);
return EINA_FALSE;
}
@ -465,6 +463,17 @@ _ecore_timer_eo_base_destructor(Eo *obj, Ecore_Timer_Data *pd)
eo_do_super(obj, MY_CLASS, eo_destructor());
}
EOLIAN static Eo *
_ecore_timer_eo_base_finalize(Eo *obj, Ecore_Timer_Data *pd)
{
if (!pd->func)
{
return NULL;
}
return eo_do_super_ret(obj, MY_CLASS, obj, eo_finalize());
}
void
_ecore_timer_shutdown(void)
{

View File

@ -67,6 +67,7 @@ class Ecore.Timer (Eo.Base)
}
implements {
Eo.Base.destructor;
Eo.Base.finalize;
Eo.Base.event_freeze;
/* XXX: can't document overriden methods
* Pauses a running timer.

View File

@ -458,17 +458,16 @@ _efl_network_url_eo_base_constructor(Efl_Network_Url *url_obj, Efl_Network_Url_D
{
url_obj = eo_do_super_ret(url_obj, MY_CLASS, url_obj, eo_constructor());
if (!_init_count) eo_error_set(url_obj);
if (!_c_init())
if (!_init_count || !_c_init())
{
eo_error_set(url_obj);
ERR("Failed");
return NULL;
}
url_con->curl_easy = _c->curl_easy_init();
if (!url_con->curl_easy)
{
eo_error_set(url_obj);
ERR("Failed");
return NULL;
}

View File

@ -623,19 +623,6 @@ EAPI Eo * _eo_add_end(void);
*/
EAPI const Eo_Class *eo_class_get(const Eo *obj);
/**
* @def eo_error_set
* @brief Notify eo that there was an error when constructing, destructing or calling a function of the object.
* @param obj the object to work on.
*
* @see eo_error_get()
*/
#define eo_error_set(obj) eo_error_set_internal(obj, __FILE__, __LINE__)
/* @cond 0 */
EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line);
/* @endcond */
#define _eo_add_common(klass, parent, is_ref, ...) \
( \
_eo_do_start(_eo_add_internal_start(__FILE__, __LINE__, klass, parent, is_ref), \

View File

@ -935,7 +935,7 @@ _eo_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo
return eo_id;
}
Eo *
static Eo *
_eo_add_internal_end(Eo *eo_id)
{
Eo_Stack_Frame *fptr;
@ -943,7 +943,7 @@ _eo_add_internal_end(Eo *eo_id)
fptr = stack->frame_ptr;
if ((fptr == NULL) || (fptr->eo_id != eo_id))
if ((fptr == NULL) || (eo_id && (fptr->eo_id != eo_id)))
{
ERR("Something very wrong happend to the call stack.");
return NULL;
@ -955,16 +955,23 @@ _eo_add_internal_end(Eo *eo_id)
return NULL;
}
if (!fptr->o.obj->condtor_done || fptr->o.obj->do_error)
{
const _Eo_Class *klass = (fptr->cur_klass) ?
fptr->cur_klass : fptr->o.obj->klass;
ERR("Object of class '%s' - Not all of the object constructors have been executed.",
klass->desc->name);
/* Unref twice, once for the ref in _eo_add_internal_start, and once for the basic object ref. */
_eo_unref(fptr->o.obj);
_eo_unref(fptr->o.obj);
return NULL;
if (!fptr->o.obj->condtor_done)
{
ERR("Object of class '%s' - Not all of the object constructors have been executed.",
klass->desc->name);
goto cleanup;
}
if (!eo_id)
{
ERR("Object of class '%s' - Finalizing the object failed.",
klass->desc->name);
goto cleanup;
}
}
fptr->o.obj->finalized = EINA_TRUE;
@ -972,12 +979,19 @@ _eo_add_internal_end(Eo *eo_id)
_eo_unref(fptr->o.obj);
return (Eo *)eo_id;
cleanup:
/* Unref twice, once for the ref in _eo_add_internal_start, and once for the basic object ref. */
_eo_unref(fptr->o.obj);
_eo_unref(fptr->o.obj);
return NULL;
}
EAPI Eo *
_eo_add_end(void)
{
Eo *ret = eo_finalize();
ret = _eo_add_internal_end(ret);
_eo_do_end();
return ret;
}
@ -1588,16 +1602,6 @@ eo_ref_get(const Eo *obj_id)
return obj->refcount;
}
EAPI void
eo_error_set_internal(const Eo *obj_id, const char *file, int line)
{
EO_OBJ_POINTER_RETURN(obj_id, obj);
ERR("Error with obj '%p' at %s:%d.", obj, file, line);
obj->do_error = EINA_TRUE;
}
void
_eo_condtor_done(Eo *obj_id)
{

View File

@ -997,7 +997,7 @@ _eo_base_destructor(Eo *obj, Eo_Base_Data *pd)
EOLIAN static Eo *
_eo_base_finalize(Eo *obj, Eo_Base_Data *pd EINA_UNUSED)
{
return _eo_add_internal_end(obj);
return obj;
}
EOLIAN static void

View File

@ -76,7 +76,6 @@ static inline void _eo_id_release(const Eo_Id obj_id);
/* Free all the entries and the tables */
static inline void _eo_free_ids_tables(void);
Eo *_eo_add_internal_end(Eo *obj);
void _eo_condtor_done(Eo *obj);
struct _Eo_Base
@ -101,7 +100,6 @@ struct _Eo_Object
int refcount;
int datarefcount;
Eina_Bool do_error:1;
Eina_Bool condtor_done:1;
Eina_Bool finalized:1;

View File

@ -309,7 +309,7 @@ _evas_object_image_cleanup(Evas_Object *eo_obj, Evas_Object_Protected_Data *obj,
}
static Eina_Bool
_init_cow(Eo *eo_obj)
_init_cow(void)
{
if (!evas_object_image_load_opts_cow ||
!evas_object_image_pixels_cow ||
@ -335,7 +335,7 @@ _init_cow(Eo *eo_obj)
!evas_object_image_pixels_cow ||
!evas_object_image_state_cow)
{
eo_error_set(eo_obj);
ERR("Failed to init cow.");
return EINA_FALSE;
}
@ -358,7 +358,7 @@ _evas_image_eo_base_constructor(Eo *eo_obj, Evas_Image_Data *o)
evas_object_image_init(eo_obj);
evas_object_inject(eo_obj, obj, eo_e);
if (!_init_cow(eo_obj))
if (!_init_cow())
return NULL;
o->load_opts = eina_cow_alloc(evas_object_image_load_opts_cow);

View File

@ -95,7 +95,7 @@ _evas_object_eo_base_constructor(Eo *eo_obj, Evas_Object_Protected_Data *obj)
if (!obj || !_init_cow() || !eo_isa(parent, EVAS_COMMON_INTERFACE_INTERFACE))
{
eo_error_set(eo_obj);
ERR("Failed");
return NULL;
}

View File

@ -247,8 +247,10 @@ _efl_vg_base_eo_base_constructor(Eo *obj,
obj = eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
if (!_efl_vg_base_parent_checked_get(obj, &parent, &cd))
eo_error_set(obj);
if (!_efl_vg_base_parent_checked_get(obj, &parent, &cd)) {
ERR("Failed");
return NULL;
}
eo_do(obj, eo_event_callback_add(EFL_GFX_CHANGED, _efl_vg_base_property_changed, pd));
pd->changed = EINA_TRUE;
@ -309,7 +311,6 @@ _efl_vg_base_eo_base_parent_set(Eo *obj,
return ;
on_error:
eo_error_set(obj);
return ;
}
@ -338,7 +339,7 @@ _efl_vg_base_efl_gfx_stack_raise(Eo *obj, Efl_VG_Base_Data *pd EINA_UNUSED)
return ;
on_error:
eo_error_set(obj);
ERR("Err");
}
static void
@ -368,7 +369,7 @@ _efl_vg_base_efl_gfx_stack_stack_above(Eo *obj,
return ;
on_error:
eo_error_set(obj);
ERR("Err");
}
static void
@ -398,7 +399,7 @@ _efl_vg_base_efl_gfx_stack_stack_below(Eo *obj,
return ;
on_error:
eo_error_set(obj);
ERR("Err");
}
static void
@ -426,7 +427,7 @@ _efl_vg_base_efl_gfx_stack_lower(Eo *obj, Efl_VG_Base_Data *pd EINA_UNUSED)
return ;
on_error:
eo_error_set(obj);
ERR("Err");
}
static Eo *

View File

@ -56,7 +56,7 @@ _efl_vg_root_node_eo_base_parent_set(Eo *obj,
eo_do_super(obj, EFL_VG_BASE_CLASS, eo_parent_set(parent));
if (parent && !eo_isa(parent, EVAS_VG_CLASS))
{
eo_error_set(obj);
ERR("Parent of VG_ROOT_NODE must be a VG_CLASS");
}
else
{
@ -76,8 +76,10 @@ _efl_vg_root_node_eo_base_constructor(Eo *obj,
// Nice little hack, jump over parent constructor in Efl_VG_Root
obj = eo_do_super_ret(obj, EFL_VG_BASE_CLASS, obj, eo_constructor());
eo_do(obj, parent = eo_parent_get());
if (!eo_isa(parent, EVAS_VG_CLASS))
eo_error_set(obj);
if (!eo_isa(parent, EVAS_VG_CLASS)) {
ERR("Parent of VG_ROOT_NODE must be a VG_CLASS");
return NULL;
}
cd = eo_data_scope_get(obj, EFL_VG_CONTAINER_CLASS);
cd->children = NULL;

View File

@ -53,10 +53,13 @@ _finalize(Eo *obj, void *class_data EINA_UNUSED)
Eo *ret;
Private_Data *pd = class_data;
if (pd->a < 0) eo_error_set(obj);
eo_do_super(obj, MY_CLASS, ret = eo_finalize());
if (pd->a < 0)
{
return NULL;
}
return ret;
}

View File

@ -13,8 +13,7 @@ _constructor(Eo *obj, void *class_data EINA_UNUSED)
{
obj = eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());
eo_error_set(obj);
return obj;
return NULL;
}
static Eo_Op_Description op_descs[] = {

View File

@ -12,8 +12,6 @@ static void
_destructor(Eo *obj, void *class_data EINA_UNUSED)
{
eo_do_super(obj, MY_CLASS, eo_destructor());
eo_error_set(obj);
}
static Eo_Op_Description op_descs [] = {

View File

@ -683,8 +683,6 @@ START_TEST(eo_magic_checks)
fail_if(wref);
fail_if(parent);
eo_error_set((Eo *) buf);
fail_if(eo_data_scope_get((Eo *) buf, SIMPLE_CLASS));
eo_do(obj, eo_composite_attach((Eo *) buf));