#include "config.h"
-typedef size_t Eo_Class_Id;
+/* The last id that should be reserved for statically allocated classes. */
+#define EO_STATIC_IDS_LAST 10
/* Used inside the class_get functions of classes, see #EO_DEFINE_CLASS */
EAPI Eina_Lock _eo_class_creation_lock;
static Eo_Class_Id _eo_classes_last_id;
static Eina_Bool _eo_init_count = 0;
-static void _eo_callback_remove_all(Eo *obj);
static void _eo_constructor(Eo *obj, const Eo_Class *klass);
static void _eo_destructor(Eo *obj, const Eo_Class *klass);
-static void eo_constructor_error_unset(Eo *obj);
+static inline Eina_Bool _eo_error_get(const Eo *obj);
+static inline void _eo_error_unset(Eo *obj);
static inline void *_eo_data_get(const Eo *obj, const Eo_Class *klass);
static inline Eo *_eo_ref(Eo *obj);
static inline void _eo_unref(Eo *obj);
-typedef struct _Eo_Callback_Description Eo_Callback_Description;
-
typedef struct
{
Eo_Op op;
const Eo_Class **kls_itr;
} Eo_Kls_Itr;
-#define EO_EINA_MAGIC 0xa186bc32 /* Nothing magical about this number. */
-#define EO_EINA_MAGIC_STR "Eo"
-#define EO_DELETED_EINA_MAGIC 0xa186bb32 /* Nothing magical about this number. */
-#define EO_DELETED_EINA_MAGIC_STR "Eo - Deleted object"
-#define EO_CLASS_EINA_MAGIC 0xa186ba32 /* Nothing magical about this number. */
-#define EO_CLASS_EINA_MAGIC_STR "Eo Class"
-
-#define EO_MAGIC_RETURN_VAL(d, magic, ret) \
- do { \
- if (!EINA_MAGIC_CHECK(d, magic)) \
- { \
- EINA_MAGIC_FAIL(d, magic); \
- return ret; \
- } \
- } while (0)
-
-#define EO_MAGIC_RETURN(d, magic) \
- do { \
- if (!EINA_MAGIC_CHECK(d, magic)) \
- { \
- EINA_MAGIC_FAIL(d, magic); \
- return; \
- } \
- } while (0)
-
struct _Eo {
EINA_MAGIC
+ EINA_INLIST;
Eo *parent;
+ Eina_Inlist *children;
const Eo_Class *klass;
int refcount;
#ifndef NDEBUG
Eina_List *composite_objects;
- Eina_Inlist *callbacks;
- int walking_list;
-
Eo_Kls_Itr mro_itr;
+ Eina_Bool composite:1;
Eina_Bool del:1;
Eina_Bool construct_error:1;
+ Eina_Bool manual_free:1;
};
/* Start of Dich */
#define DICH_CHAIN1(x) (((x) >> 16) & DICH_CHAIN1_MASK)
#define DICH_CHAIN_LAST(x) ((x) & DICH_CHAIN_LAST_MASK)
-#define OP_CLASS_OFFSET 16
-#define OP_CLASS_OFFSET_GET(x) (((x) >> OP_CLASS_OFFSET) & 0xffff)
+#define OP_CLASS_OFFSET_GET(x) (((x) >> EO_OP_CLASS_OFFSET) & 0xffff)
#define OP_CLASS_GET(op) ({ \
Eo_Class_Id tmp = OP_CLASS_OFFSET_GET(op); \
ID_CLASS_GET(tmp); \
size_t extn_data_size;
const Eo_Class **mro;
+ Eo_Kls_Itr mro_itr;
size_t data_offset; /* < Offset of the data within object data. */
{
size_t j;
const Eo_Class *op_klass = ID_CLASS_GET(i + 1);
+ /* Can be NULL because of future static classes. */
+ if (!op_klass)
+ continue;
+
size_t num_ops = op_klass->desc->ops.count;
_dich_chain_alloc(dc1, num_ops);
}
static inline void
-_eo_kls_itr_init(Eo *obj, Eo_Op op, Eo_Kls_Itr *prev_state)
+_eo_kls_itr_init(const Eo_Class *obj_klass, Eo_Kls_Itr *cur, Eo_Op op, Eo_Kls_Itr *prev_state)
{
- prev_state->op = obj->mro_itr.op;
- prev_state->kls_itr = obj->mro_itr.kls_itr;
+ prev_state->op = cur->op;
+ prev_state->kls_itr = cur->kls_itr;
/* If we are in a constructor/destructor or we changed an op - init. */
- if ((op == EO_NOOP) || (obj->mro_itr.op != op))
+ if ((op == EO_NOOP) || (cur->op != op))
{
- obj->mro_itr.op = op;
- obj->mro_itr.kls_itr = obj->klass->mro;
+ cur->op = op;
+ cur->kls_itr = obj_klass->mro;
}
}
static inline void
-_eo_kls_itr_end(Eo *obj, Eo_Kls_Itr *prev_state)
+_eo_kls_itr_end(Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state)
{
- if (obj->mro_itr.op != prev_state->op)
+ if (cur->op != prev_state->op)
{
- obj->mro_itr.op = prev_state->op;
- obj->mro_itr.kls_itr = prev_state->kls_itr;
+ cur->op = prev_state->op;
+ cur->kls_itr = prev_state->kls_itr;
}
}
static inline const Eo_Class *
-_eo_kls_itr_get(Eo *obj)
+_eo_kls_itr_get(Eo_Kls_Itr *cur)
{
- return (obj->mro_itr.kls_itr) ? *(obj->mro_itr.kls_itr) : NULL;
+ return (cur->kls_itr) ? *(cur->kls_itr) : NULL;
}
static inline const Eo_Class *
-_eo_kls_itr_next(Eo *obj, Eo_Op op)
+_eo_kls_itr_next(Eo_Kls_Itr *cur, Eo_Op op)
{
- if (obj->mro_itr.op != op)
+ if (cur->op != op)
{
- Eo_Op node_op = obj->mro_itr.op;
- ERR("Called with op %d ('%s') while expecting: %d ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
+ Eo_Op node_op = cur->op;
+ ERR("Called with op %x ('%s') while expecting: %x ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
op, _eo_op_id_name_get(op),
node_op, _eo_op_id_name_get(node_op));
return NULL;
}
- const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
+ const Eo_Class **kls_itr = cur->kls_itr;
if (*kls_itr)
{
if (op != EO_NOOP)
kls_itr++;
}
- obj->mro_itr.kls_itr = kls_itr;
+ cur->kls_itr = kls_itr;
return *kls_itr;
}
else
}
static inline Eina_Bool
-_eo_kls_itr_reached_end(const Eo *obj)
+_eo_kls_itr_reached_end(const Eo_Kls_Itr *cur)
{
- const Eo_Class **kls_itr = obj->mro_itr.kls_itr;
+ const Eo_Class **kls_itr = cur->kls_itr;
return !(*kls_itr && *(kls_itr + 1));
}
+static inline const op_type_funcs *
+_eo_kls_itr_func_get(const Eo_Class *klass, Eo_Kls_Itr *mro_itr, Eo_Op op, Eo_Kls_Itr *prev_state)
+{
+ _eo_kls_itr_init(klass, mro_itr, op, prev_state);
+ klass = _eo_kls_itr_get(mro_itr);
+ if (klass)
+ {
+ const op_type_funcs *func = _dich_func_get(klass, op);
+
+ if (func && func->func)
+ {
+ return func;
+ }
+ }
+
+ return NULL;
+}
+
+#define _EO_OP_ERR_NO_OP_PRINT(op, klass) \
+ do \
+ { \
+ const Eo_Class *op_klass = OP_CLASS_GET(op); \
+ const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL; \
+ ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.", \
+ op, _eo_op_id_name_get(op), _dom_name, \
+ (klass) ? klass->desc->name : NULL); \
+ } \
+ while (0)
+
static Eina_Bool
-_eo_op_internal(Eo *obj, Eina_Bool constant, Eo_Op op, va_list *p_list)
+_eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
{
- const Eo_Class *klass;
Eina_Bool ret = EINA_FALSE;
+#ifndef NDEBUG
const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
- if (op_desc &&
- ((constant == EINA_TRUE) && (op_desc->constant == EINA_FALSE)))
+ if (op_desc)
{
- ERR("Tried calling non-const or non-existant op '%s' (%d) from a const (query) function.", (op_desc) ? op_desc->name : NULL, op);
- return EINA_FALSE;
+ if (op_desc->op_type == EO_OP_TYPE_CLASS)
+ {
+ ERR("Tried calling a class op '%s' (%x) from a non-class context.", (op_desc) ? op_desc->name : NULL, op);
+ return EINA_FALSE;
+ }
+ else if ((op_type == EO_OP_TYPE_CONST) &&
+ (op_desc->op_type != EO_OP_TYPE_CONST))
+ {
+ ERR("Tried calling non-const or non-existant op '%s' (%x) from a const (query) function.", (op_desc) ? op_desc->name : NULL, op);
+ return EINA_FALSE;
+ }
}
+#endif
Eo_Kls_Itr prev_state;
- _eo_kls_itr_init(obj, op, &prev_state);
- klass = _eo_kls_itr_get(obj);
- if (klass)
- {
- const op_type_funcs *func = _dich_func_get(klass, op);
- if (func && func->func)
+ {
+ const op_type_funcs *func =
+ _eo_kls_itr_func_get(obj->klass, &obj->mro_itr, op, &prev_state);
+ if (func)
{
func->func(obj, _eo_data_get(obj, func->src), p_list);
ret = EINA_TRUE;
Eo *emb_obj;
EINA_LIST_FOREACH(obj->composite_objects, itr, emb_obj)
{
- if (_eo_op_internal(emb_obj, constant, op, p_list))
+ if (_eo_op_internal(emb_obj, op_type, op, p_list))
{
ret = EINA_TRUE;
goto end;
}
end:
- _eo_kls_itr_end(obj, &prev_state);
+ _eo_kls_itr_end(&obj->mro_itr, &prev_state);
return ret;
}
EAPI Eina_Bool
-eo_do_internal(Eo *obj, Eina_Bool constant, ...)
+eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
{
Eina_Bool ret = EINA_TRUE;
Eo_Op op = EO_NOOP;
_eo_ref(obj);
- va_start(p_list, constant);
+ va_start(p_list, op_type);
op = va_arg(p_list, Eo_Op);
while (op)
{
- if (!_eo_op_internal(obj, constant, op, &p_list))
+ if (!_eo_op_internal(obj, op_type, op, &p_list))
{
- const Eo_Class *op_klass = OP_CLASS_GET(op);
- const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
- ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
- op, _eo_op_id_name_get(op), _dom_name,
- obj->klass->desc->name);
+ _EO_OP_ERR_NO_OP_PRINT(op, obj->klass);
ret = EINA_FALSE;
break;
}
}
EAPI Eina_Bool
-eo_do_super_internal(Eo *obj, Eina_Bool constant, Eo_Op op, ...)
+eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...)
{
- const Eo_Class *obj_klass;
+ const Eo_Class *nklass;
Eina_Bool ret = EINA_TRUE;
va_list p_list;
EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
/* Advance the kls itr. */
- obj_klass = _eo_kls_itr_next(obj, op);
+ nklass = _eo_kls_itr_next(&obj->mro_itr, op);
if (obj->mro_itr.op != op)
return EINA_FALSE;
va_start(p_list, op);
- if (!_eo_op_internal(obj, constant, op, &p_list))
+ if (!_eo_op_internal(obj, op_type, op, &p_list))
{
- const Eo_Class *op_klass = OP_CLASS_GET(op);
- const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL;
- ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.",
- op, _eo_op_id_name_get(op), _dom_name,
- (obj_klass) ? obj_klass->desc->name : NULL);
+ _EO_OP_ERR_NO_OP_PRINT(op, nklass);
+ ret = EINA_FALSE;
+ }
+ va_end(p_list);
+
+ return ret;
+}
+
+static Eina_Bool
+_eo_class_op_internal(Eo_Class *klass, Eo_Op op, va_list *p_list)
+{
+ Eina_Bool ret = EINA_FALSE;
+
+#ifndef NDEBUG
+ const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
+
+ if (op_desc)
+ {
+ if (op_desc->op_type != EO_OP_TYPE_CLASS)
+ {
+ ERR("Tried calling an instance op '%s' (%x) from a class context.", (op_desc) ? op_desc->name : NULL, op);
+ return EINA_FALSE;
+ }
+ }
+#endif
+
+ Eo_Kls_Itr prev_state;
+
+ {
+ const op_type_funcs *func =
+ _eo_kls_itr_func_get(klass, &klass->mro_itr, op, &prev_state);
+ if (func)
+ {
+ ((eo_op_func_type_class) func->func)(klass, p_list);
+ ret = EINA_TRUE;
+ goto end;
+ }
+ }
+
+end:
+ _eo_kls_itr_end(&klass->mro_itr, &prev_state);
+ return ret;
+}
+
+EAPI Eina_Bool
+eo_class_do_internal(const Eo_Class *klass, ...)
+{
+ Eina_Bool ret = EINA_TRUE;
+ Eo_Op op = EO_NOOP;
+ va_list p_list;
+
+ EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
+
+ va_start(p_list, klass);
+
+ op = va_arg(p_list, Eo_Op);
+ while (op)
+ {
+ if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list))
+ {
+ _EO_OP_ERR_NO_OP_PRINT(op, klass);
+ ret = EINA_FALSE;
+ break;
+ }
+ op = va_arg(p_list, Eo_Op);
+ }
+
+ va_end(p_list);
+
+ return ret;
+}
+
+EAPI Eina_Bool
+eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...)
+{
+ const Eo_Class *nklass;
+ Eina_Bool ret = EINA_TRUE;
+ va_list p_list;
+ EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
+
+ /* Advance the kls itr. */
+ nklass = _eo_kls_itr_next(&((Eo_Class *) klass)->mro_itr, op);
+
+ if (klass->mro_itr.op != op)
+ return EINA_FALSE;
+
+ va_start(p_list, op);
+ if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list))
+ {
+ _EO_OP_ERR_NO_OP_PRINT(op, nklass);
ret = EINA_FALSE;
}
va_end(p_list);
if (!desc || !desc->ops.base_op_id)
return;
- /* FIXME: Depends on values defined above! */
- *(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
+ *(desc->ops.base_op_id) = EO_CLASS_ID_TO_BASE_ID(klass->class_id);
}
#ifndef NDEBUG
itr = func_descs;
if (itr)
{
- for ( ; itr->op != 0 ; itr++)
+ for ( ; itr->op_type != EO_OP_TYPE_INVALID ; itr++)
{
const Eo_Op_Description *op_desc = _eo_op_id_desc_get(itr->op);
- if (EINA_LIKELY(!op_desc || (itr->constant == op_desc->constant)))
+ if (EINA_UNLIKELY(!op_desc || (itr->op == EO_NOOP)))
+ {
+ ERR("Setting implementation for non-existent op %x for class '%s'. Func index: %d", itr->op, klass->desc->name, itr - func_descs);
+ }
+ else if (EINA_LIKELY(itr->op_type == op_desc->op_type))
{
_dich_func_set(klass, itr->op, itr->func);
}
else
{
- ERR("Set function's constant property (%d) is different than the one in the op description (%d) for op '%s' in class '%s'.", itr->constant, op_desc->constant, op_desc->name, klass->desc->name);
+ ERR("Set function's op type (%x) is different than the one in the op description (%d) for op '%s' in class '%s'. Func index: %d",
+ itr->op_type,
+ (op_desc) ? op_desc->op_type : EO_OP_TYPE_REGULAR,
+ (op_desc) ? op_desc->name : NULL,
+ klass->desc->name,
+ itr - func_descs);
}
}
}
/* DEVCHECK */
static Eina_Bool
-_eo_class_check_op_descs(const Eo_Class *klass)
+_eo_class_check_op_descs(const Eo_Class *klass, Eo_Class_Id id)
{
const Eo_Class_Description *desc = klass->desc;
const Eo_Op_Description *itr;
if (desc->ops.count > 0)
{
- if (!desc->ops.base_op_id)
+ if (((id == 0) || (id > EO_STATIC_IDS_LAST)) && !desc->ops.base_op_id)
{
ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
desc->name);
{
if (itr->name)
{
- ERR("Wrong order in Ops description for class '%s'. Expected %d and got %d", desc->name, i, itr->sub_op);
+ ERR("Wrong order in Ops description for class '%s'. Expected %x and got %x", desc->name, i, itr->sub_op);
}
else
{
- ERR("Found too few Ops description for class '%s'. Expected %d descriptions, but found %d.", desc->name, desc->ops.count, i);
+ ERR("Found too few Ops description for class '%s'. Expected %x descriptions, but found %x.", desc->name, desc->ops.count, i);
}
return EINA_FALSE;
}
}
EAPI const Eo_Class *
-eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...)
+eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *parent, ...)
{
Eo_Class *klass;
va_list p_list;
return NULL;
}
+ if (id > EO_STATIC_IDS_LAST)
+ {
+ ERR("Tried creating a class with the static id %d while the maximum static id is %d. Aborting.", id, EO_STATIC_IDS_LAST);
+ return NULL;
+ }
+
va_start(p_list, parent);
EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
EO_ALIGN_SIZE(klass->parent->desc->data_size);
}
- if (!_eo_class_check_op_descs(klass))
+ if (!_eo_class_check_op_descs(klass, id))
{
goto cleanup;
}
}
eina_lock_take(&_eo_class_creation_lock);
- klass->class_id = ++_eo_classes_last_id;
+
+ if (id == 0)
+ {
+ klass->class_id = ++_eo_classes_last_id;
+ }
+ else
+ {
+#ifndef NDEBUG
+ if (_eo_classes && _eo_classes[id - 1])
+ {
+ ERR("A class with id %d was already defined (%s). Aborting.", id,
+ _eo_classes[id - 1]->desc->name);
+ eina_lock_release(&_eo_class_creation_lock);
+ goto cleanup;
+ }
+#endif
+ klass->class_id = id;
+ }
+
+
{
/* FIXME: Handle errors. */
+ size_t arrsize = _eo_classes_last_id * sizeof(*_eo_classes);
Eo_Class **tmp;
- tmp = realloc(_eo_classes, _eo_classes_last_id * sizeof(*_eo_classes));
+ tmp = realloc(_eo_classes, arrsize);
+
+ /* If it's the first allocation, memset. */
+ if (!_eo_classes)
+ memset(tmp, 0, arrsize);
+
_eo_classes = tmp;
_eo_classes[klass->class_id - 1] = klass;
}
for ( ; *mro_itr ; mro_itr++)
;
- for ( mro_itr-- ; mro_itr >= klass->mro ; mro_itr--)
+ /* Skip ourselves. */
+ for ( mro_itr-- ; mro_itr > klass->mro ; mro_itr--)
{
_dich_copy_all(klass, *mro_itr);
}
return NULL;
}
+EAPI Eina_Bool
+eo_parent_set(Eo *obj, const Eo *parent)
+{
+ EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
+ if (parent)
+ EO_MAGIC_RETURN_VAL(parent, EO_EINA_MAGIC, EINA_FALSE);
+
+ if (obj->parent == parent)
+ return EINA_TRUE;
+
+ _eo_ref(obj);
+
+ if (eo_composite_is(obj))
+ {
+ eo_composite_object_detach(obj->parent, obj);
+ }
+
+ if (obj->parent)
+ {
+ obj->parent->children =
+ eina_inlist_remove(obj->parent->children, EINA_INLIST_GET(obj));
+ eo_xunref(obj, obj->parent);
+ }
+
+ obj->parent = (Eo *) parent;
+ if (obj->parent)
+ {
+ obj->parent->children =
+ eina_inlist_append(obj->parent->children, EINA_INLIST_GET(obj));
+ eo_xref(obj, obj->parent);
+ }
+
+ _eo_unref(obj);
+
+ return EINA_TRUE;
+}
+
EAPI Eo *
eo_add(const Eo_Class *klass, Eo *parent)
{
Eo *obj = calloc(1, EO_ALIGN_SIZE(sizeof(*obj)) +
(klass->data_offset + EO_ALIGN_SIZE(klass->desc->data_size)) +
klass->extn_data_size);
+ EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
+ obj->refcount++;
obj->klass = klass;
- obj->parent = parent;
- obj->refcount++;
+ eo_parent_set(obj, parent);
Eo_Kls_Itr prev_state;
- _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
- eo_constructor_error_unset(obj);
+ _eo_kls_itr_init(klass, &obj->mro_itr, EO_NOOP, &prev_state);
+ _eo_error_unset(obj);
- EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
_eo_ref(obj);
_eo_constructor(obj, klass);
- if (EINA_UNLIKELY(eo_constructor_error_get(obj)))
+ if (EINA_UNLIKELY(_eo_error_get(obj)))
{
ERR("Type '%s' - One of the object constructors have failed.", klass->desc->name);
goto fail;
}
- if (EINA_UNLIKELY(!_eo_kls_itr_reached_end(obj)))
+ if (EINA_UNLIKELY(!_eo_kls_itr_reached_end(&obj->mro_itr)))
{
ERR("Type '%s' - Not all of the object constructors have been executed.", klass->desc->name);
goto fail;
}
- _eo_kls_itr_end(obj, &prev_state);
+ _eo_kls_itr_end(&obj->mro_itr, &prev_state);
_eo_unref(obj);
return obj;
fail:
- _eo_kls_itr_end(obj, &prev_state);
+ _eo_kls_itr_end(&obj->mro_itr, &prev_state);
/* Unref twice, once for the ref above, and once for the basic object ref. */
_eo_unref(obj);
_eo_unref(obj);
xref->file = file;
xref->line = line;
- /* FIXME: Make it sorted. */
obj->xrefs = eina_inlist_prepend(obj->xrefs, EINA_INLIST_GET(xref));
#else
(void) ref_obj;
}
EAPI Eo *
-eo_ref(Eo *obj)
+eo_ref(const Eo *_obj)
{
+ Eo *obj = (Eo *) _obj;
EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
return _eo_ref(obj);
}
-static void
+static inline void
_eo_del_internal(Eo *obj)
{
- if (obj->del)
- return;
/* We need that for the event callbacks that may ref/unref. */
obj->refcount++;
- eo_event_callback_call(obj, EO_EV_DEL, NULL);
- obj->del = EINA_TRUE;
+ eo_do(obj, eo_event_callback_call(EO_EV_DEL, NULL, NULL));
const Eo_Class *klass = eo_class_get(obj);
Eo_Kls_Itr prev_state;
- _eo_kls_itr_init(obj, EO_NOOP, &prev_state);
- eo_constructor_error_unset(obj);
+ _eo_kls_itr_init(klass, &obj->mro_itr, EO_NOOP, &prev_state);
+ _eo_error_unset(obj);
_eo_destructor(obj, klass);
- if (eo_constructor_error_get(obj))
+ if (_eo_error_get(obj))
{
ERR("Type '%s' - One of the object destructors have failed.", klass->desc->name);
}
- if (!_eo_kls_itr_reached_end(obj))
+ if (!_eo_kls_itr_reached_end(&obj->mro_itr))
{
ERR("Type '%s' - Not all of the object destructors have been executed.", klass->desc->name);
}
- _eo_kls_itr_end(obj, &prev_state);
+ _eo_kls_itr_end(&obj->mro_itr, &prev_state);
/*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
- Eina_List *itr, *itr_n;
- Eo *emb_obj;
- EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
{
- eo_composite_object_detach(obj, emb_obj);
+ Eina_List *itr, *itr_n;
+ Eo *emb_obj;
+ EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
+ {
+ eo_composite_object_detach(obj, emb_obj);
+ }
+ }
+
+ while (obj->children)
+ {
+ eo_parent_set(EINA_INLIST_CONTAINER_GET(obj->children, Eo), NULL);
}
+ obj->del = EINA_TRUE;
obj->refcount--;
}
static inline void
+_eo_free(Eo *obj)
+{
+ EINA_MAGIC_SET(obj, EO_FREED_EINA_MAGIC);
+ free(obj);
+}
+
+static inline void
_eo_unref(Eo *obj)
{
if (--(obj->refcount) == 0)
{
- _eo_del_internal(obj);
- /* We need that for the event callbacks that may ref/unref. */
- obj->refcount++;
-
- eo_event_callback_call(obj, EO_EV_FREE, NULL);
+ if (obj->del)
+ {
+ ERR("Object %p already deleted.", obj);
+ return;
+ }
- obj->refcount--;
+ _eo_del_internal(obj);
#ifndef NDEBUG
- /* If for some reason it's not empty, clear it. */
- while (obj->xrefs)
- {
- WRN("obj->xrefs is not empty, possibly a bug, please report. - An error will be reported for each xref in the stack.");
- Eina_Inlist *nitr = obj->xrefs->next;
- free(EINA_INLIST_CONTAINER_GET(obj->xrefs, Eo_Xref_Node));
- obj->xrefs = nitr;
- }
+ /* If for some reason it's not empty, clear it. */
+ while (obj->xrefs)
+ {
+ WRN("obj->xrefs is not empty, possibly a bug, please report. - An error will be reported for each xref in the stack.");
+ Eina_Inlist *nitr = obj->xrefs->next;
+ free(EINA_INLIST_CONTAINER_GET(obj->xrefs, Eo_Xref_Node));
+ obj->xrefs = nitr;
+ }
#endif
- _eo_callback_remove_all(obj);
-
- EINA_MAGIC_SET(obj, EO_DELETED_EINA_MAGIC);
- free(obj);
+ if (!obj->manual_free)
+ _eo_free(obj);
+ else
+ _eo_ref(obj); /* If we manual free, we keep a phantom ref. */
}
}
EAPI void
-eo_unref(Eo *obj)
+eo_unref(const Eo *_obj)
{
+ Eo *obj = (Eo *) _obj;
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
_eo_unref(obj);
}
+EAPI void
+eo_del(const Eo *obj)
+{
+ eo_parent_set((Eo *) obj, NULL);
+ eo_unref(obj);
+}
+
EAPI int
eo_ref_get(const Eo *obj)
{
return obj->refcount;
}
-EAPI void
-eo_del(Eo *obj)
-{
- EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
-
- _eo_del_internal(obj);
- _eo_unref(obj);
-}
-
EAPI Eo *
eo_parent_get(const Eo *obj)
{
}
EAPI void
-eo_constructor_error_set(Eo *obj)
+eo_error_set_internal(const Eo *obj, const char *file, int line)
{
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
- obj->construct_error = EINA_TRUE;
+ ERR("Error with obj '%p' at %s:%d", obj, file, line);
+
+ ((Eo *) obj)->construct_error = EINA_TRUE;
}
-static void
-eo_constructor_error_unset(Eo *obj)
+static inline void
+_eo_error_unset(Eo *obj)
{
obj->construct_error = EINA_FALSE;
}
-EAPI Eina_Bool
-eo_constructor_error_get(const Eo *obj)
+/**
+ * @internal
+ * @brief Check if there was an error when constructing, destructing or calling a function of the object.
+ * @param obj the object to work on.
+ * @return @c EINA_TRUE if there was an error.
+ */
+static inline Eina_Bool
+_eo_error_get(const Eo *obj)
{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_TRUE);
-
return obj->construct_error;
}
{
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
- _eo_constructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
+ _eo_constructor(obj, _eo_kls_itr_next(&obj->mro_itr, EO_NOOP));
}
EAPI void
{
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
- _eo_destructor(obj, _eo_kls_itr_next(obj, EO_NOOP));
+ _eo_destructor(obj, _eo_kls_itr_next(&obj->mro_itr, EO_NOOP));
}
static inline void *
ret = _eo_data_get(obj, klass);
+#ifndef NDEBUG
if (!ret && (klass->desc->data_size == 0))
{
ERR("Tried getting data of class '%s', but it has none..", klass->desc->name);
}
+#endif
return ret;
}
eina_init();
_eo_classes = NULL;
- _eo_classes_last_id = 0;
+ _eo_classes_last_id = EO_STATIC_IDS_LAST;
_eo_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_LIGHTBLUE);
if (_eo_log_dom < 0)
{
}
eina_magic_string_static_set(EO_EINA_MAGIC, EO_EINA_MAGIC_STR);
- eina_magic_string_static_set(EO_DELETED_EINA_MAGIC,
- EO_DELETED_EINA_MAGIC_STR);
+ eina_magic_string_static_set(EO_FREED_EINA_MAGIC,
+ EO_FREED_EINA_MAGIC_STR);
eina_magic_string_static_set(EO_CLASS_EINA_MAGIC,
EO_CLASS_EINA_MAGIC_STR);
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
- eo_xref(emb_obj, obj);
+ emb_obj->composite = EINA_TRUE;
+ eo_parent_set(emb_obj, obj);
obj->composite_objects = eina_list_prepend(obj->composite_objects, emb_obj);
}
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
+ emb_obj->composite = EINA_FALSE;
obj->composite_objects = eina_list_remove(obj->composite_objects, emb_obj);
- eo_xunref(emb_obj, obj);
+ eo_parent_set(emb_obj, NULL);
}
EAPI Eina_Bool
-eo_composite_is(Eo *emb_obj)
+eo_composite_is(const Eo *emb_obj)
{
if (!EINA_MAGIC_CHECK(emb_obj, EO_EINA_MAGIC))
{
return EINA_FALSE;
}
- Eo *obj = eo_parent_get(emb_obj);
- Eina_List *itr;
- Eo *tmp;
-
- if (!obj)
- return EINA_FALSE;
-
- EINA_LIST_FOREACH(obj->composite_objects, itr, tmp)
- {
- if (tmp == emb_obj)
- return EINA_TRUE;
- }
-
- return EINA_FALSE;
-}
-
-/* Callbacks */
-struct _Eo_Callback_Description
-{
- EINA_INLIST;
- const Eo_Event_Description *event;
- Eo_Event_Cb func;
- void *func_data;
- Eo_Callback_Priority priority;
- Eina_Bool delete_me : 1;
-};
-
-/* Actually remove, doesn't care about walking list, or delete_me */
-static void
-_eo_callback_remove(Eo *obj, Eo_Callback_Description *cb)
-{
- obj->callbacks = eina_inlist_remove(obj->callbacks,
- EINA_INLIST_GET(cb));
- free(cb);
-}
-
-/* Actually remove, doesn't care about walking list, or delete_me */
-static void
-_eo_callback_remove_all(Eo *obj)
-{
- Eina_Inlist *initr;
- Eo_Callback_Description *cb = NULL;
- EINA_INLIST_FOREACH_SAFE(obj->callbacks, initr, cb)
- {
- _eo_callback_remove(obj, cb);
- }
+ return emb_obj->composite;
}
-static void
-_eo_callbacks_clear(Eo *obj)
-{
- Eina_Inlist *itn;
- Eo_Callback_Description *cb = NULL;
-
- /* Abort if we are currently walking the list. */
- if (obj->walking_list > 0)
- return;
-
- EINA_INLIST_FOREACH_SAFE(obj->callbacks, itn, cb)
- {
- if (cb->delete_me)
- {
- _eo_callback_remove(obj, cb);
- }
- }
-}
-
-static int
-_callback_priority_cmp(const void *_a, const void *_b)
-{
- const Eo_Callback_Description *a, *b;
- a = (const Eo_Callback_Description *) _a;
- b = (const Eo_Callback_Description *) _b;
- if (a->priority < b->priority)
- return -1;
- else
- return 1;
-}
-
-EAPI Eina_Bool
-eo_event_callback_priority_add(Eo *obj,
- const Eo_Event_Description *desc,
- Eo_Callback_Priority priority,
- Eo_Event_Cb func,
- const void *data)
+EAPI void
+eo_manual_free_set(Eo *obj, Eina_Bool manual_free)
{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
-
- Eo_Callback_Description *cb = calloc(1, sizeof(*cb));
- cb->event = desc;
- cb->func = func;
- cb->func_data = (void *) data;
- cb->priority = priority;
- obj->callbacks = eina_inlist_sorted_insert(obj->callbacks,
- EINA_INLIST_GET(cb), _callback_priority_cmp);
-
- eo_event_callback_call(obj, EO_EV_CALLBACK_ADD, desc);
-
- return EINA_TRUE;
+ EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
+ obj->manual_free = manual_free;
}
-EAPI void *
-eo_event_callback_del_lazy(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func)
+EAPI void
+eo_manual_free(Eo *obj)
{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
+ EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
- void *ret = NULL;
- Eo_Callback_Description *cb;
- EINA_INLIST_FOREACH(obj->callbacks, cb)
+ if (EINA_FALSE == obj->manual_free)
{
- if ((cb->event == desc) && (cb->func == func))
- {
- void *data;
-
- data = cb->func_data;
- cb->delete_me = EINA_TRUE;
- _eo_callbacks_clear(obj);
- ret = data;
- goto found;
- }
+ 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 NULL;
-
-found:
- eo_event_callback_call(obj, EO_EV_CALLBACK_DEL, desc);
- return ret;
-}
-
-EAPI void *
-eo_event_callback_del(Eo *obj, const Eo_Event_Description *desc, Eo_Event_Cb func, const void *user_data)
-{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
-
- void *ret = NULL;
- Eo_Callback_Description *cb;
- EINA_INLIST_FOREACH(obj->callbacks, cb)
+ if (!obj->del)
{
- if ((cb->event == desc) && (cb->func == func) &&
- (cb->func_data == user_data))
- {
- void *data;
-
- data = cb->func_data;
- cb->delete_me = EINA_TRUE;
- _eo_callbacks_clear(obj);
- ret = data;
- goto found;
- }
- }
-
- return NULL;
-
-found:
- eo_event_callback_call(obj, EO_EV_CALLBACK_DEL, desc);
- return ret;
-}
-
-EAPI Eina_Bool
-eo_event_callback_call(Eo *obj, const Eo_Event_Description *desc,
- const void *event_info)
-{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
-
- Eina_Bool ret = EINA_TRUE;
- Eo_Callback_Description *cb;
-
- _eo_ref(obj);
- obj->walking_list++;
-
- EINA_INLIST_FOREACH(obj->callbacks, cb)
- {
- if (!cb->delete_me && (cb->event == desc))
- {
- /* Abort callback calling if the func says so. */
- if (!cb->func((void *) cb->func_data, obj, desc,
- (void *) event_info))
- {
- ret = EINA_FALSE;
- break;
- }
- }
- if (obj->del)
- break;
+ ERR("Tried deleting the object %p while still referenced(%d).", obj, eo_ref_get(obj));
+ return;
}
- obj->walking_list--;
- _eo_callbacks_clear(obj);
- _eo_unref(obj);
- return ret;
-}
-
-static Eina_Bool
-_eo_event_forwarder_callback(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
-{
- (void) obj;
- Eo *new_obj = (Eo *) data;
- return eo_event_callback_call(new_obj, desc, event_info);
-}
-
-/* FIXME: Change default priority? Maybe call later? */
-EAPI Eina_Bool
-eo_event_callback_forwarder_add(Eo *obj, const Eo_Event_Description *desc, Eo *new_obj)
-{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
- EO_MAGIC_RETURN_VAL(new_obj, EO_EINA_MAGIC, EINA_FALSE);
-
- return eo_event_callback_add(obj, desc, _eo_event_forwarder_callback, new_obj);
-}
-
-EAPI Eina_Bool
-eo_event_callback_forwarder_del(Eo *obj, const Eo_Event_Description *desc, Eo *new_obj)
-{
- EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
- EO_MAGIC_RETURN_VAL(new_obj, EO_EINA_MAGIC, EINA_FALSE);
-
- eo_event_callback_del(obj, desc, _eo_event_forwarder_callback, new_obj);
- return EINA_TRUE;
+ _eo_free(obj);
}