Eo: Make eo_manual_free() return a success flag.
eo_manual_free() can fail in some cases, and it is useful for users of this API to know about it in order to decide what to do.
This commit is contained in:
parent
bb4a19b5ad
commit
d6ac2464bb
|
@ -910,10 +910,11 @@ EAPI void eo_manual_free_set(Eo *obj, Eina_Bool manual_free);
|
|||
* eo_manual_free_set has been called before with the parameter EINA_TRUE.
|
||||
* An error will be printed if this function is called when the manual
|
||||
* free option is not set to EINA_TRUE or the number of refs is not 0.
|
||||
* @return EINA_TRUE if successfully freed. EINA_FALSE otherwise.
|
||||
*
|
||||
* @see eo_manual_free_set()
|
||||
*/
|
||||
EAPI void eo_manual_free(Eo *obj);
|
||||
EAPI Eina_Bool eo_manual_free(Eo *obj);
|
||||
|
||||
/**
|
||||
* @brief Checks if the object was already descructed (only relevant for manual_free objects).
|
||||
|
|
|
@ -1531,7 +1531,7 @@ eo_manual_free_set(Eo *obj_id, Eina_Bool manual_free)
|
|||
obj->manual_free = manual_free;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
EAPI Eina_Bool
|
||||
eo_manual_free(Eo *obj_id)
|
||||
{
|
||||
EO_OBJ_POINTER_RETURN(obj_id, obj);
|
||||
|
@ -1539,15 +1539,17 @@ eo_manual_free(Eo *obj_id)
|
|||
if (EINA_FALSE == obj->manual_free)
|
||||
{
|
||||
ERR("Tried to manually free the object %p while the option has not been set; see eo_manual_free_set for more information.", obj);
|
||||
return;
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
if (!obj->del)
|
||||
{
|
||||
ERR("Tried deleting the object %p while still referenced(%d).", obj_id, obj->refcount);
|
||||
return;
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
_eo_free(obj);
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
|
|
|
@ -304,7 +304,7 @@ START_TEST(eo_man_free)
|
|||
|
||||
obj = eo_add(klass, NULL);
|
||||
fail_if(!obj);
|
||||
eo_manual_free(obj);
|
||||
fail_if(eo_manual_free(obj));
|
||||
eo_unref(obj);
|
||||
|
||||
_man_should_des = EINA_FALSE;
|
||||
|
@ -314,17 +314,17 @@ START_TEST(eo_man_free)
|
|||
|
||||
obj = eo_add(klass, NULL);
|
||||
fail_if(!obj);
|
||||
eo_manual_free(obj);
|
||||
fail_if(eo_manual_free(obj));
|
||||
fail_if(eo_destructed_is(obj));
|
||||
eo_unref(obj);
|
||||
fail_if(!eo_destructed_is(obj));
|
||||
eo_manual_free(obj);
|
||||
fail_if(!eo_manual_free(obj));
|
||||
|
||||
obj = eo_add(klass, NULL);
|
||||
fail_if(!obj);
|
||||
eo_unref(obj);
|
||||
fail_if(!eo_destructed_is(obj));
|
||||
eo_manual_free(obj);
|
||||
fail_if(!eo_manual_free(obj));
|
||||
|
||||
_man_should_con = EINA_FALSE;
|
||||
klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
|
||||
|
@ -333,7 +333,7 @@ START_TEST(eo_man_free)
|
|||
|
||||
obj = eo_add(klass, NULL);
|
||||
fail_if(!obj);
|
||||
eo_manual_free(obj);
|
||||
fail_if(eo_manual_free(obj));
|
||||
eo_unref(obj);
|
||||
|
||||
obj = eo_add(klass, NULL);
|
||||
|
@ -343,7 +343,7 @@ START_TEST(eo_man_free)
|
|||
eo_ref(obj);
|
||||
eo_unref(obj);
|
||||
eo_unref(obj);
|
||||
eo_manual_free(obj);
|
||||
fail_if(!eo_manual_free(obj));
|
||||
|
||||
obj = eo_add(klass, NULL);
|
||||
fail_if(!obj);
|
||||
|
@ -354,7 +354,7 @@ START_TEST(eo_man_free)
|
|||
eo_unref(obj);
|
||||
eo_unref(obj);
|
||||
eo_unref(obj);
|
||||
eo_manual_free(obj);
|
||||
fail_if(!eo_manual_free(obj));
|
||||
|
||||
eo_shutdown();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue