Eo: Merge common part of class and object.

First step toward getting rid of "handle".
This commit is contained in:
Tom Hacohen 2013-09-27 10:59:41 +01:00
parent 8dbbc16731
commit 5e90d51013
4 changed files with 33 additions and 30 deletions

View File

@ -161,7 +161,7 @@ static inline
Eo * _eo_class_id_get(const _Eo_Class *klass)
{
#ifdef HAVE_EO_ID
return (Eo *) klass->class_id;
return (Eo *) klass->header.id;
#else
return (Eo *) HANDLE_FROM_EO(klass);
#endif
@ -306,7 +306,7 @@ _eo_op_internal(const char *file, int line, _Eo eo_ptr, const _Eo_Class *cur_kla
if (op_type == EO_OP_TYPE_REGULAR)
{
func_data = _eo_data_scope_get(eo_ptr.obj, func->src);
calling_obj = (Eo *)eo_ptr.obj->obj_id;
calling_obj = (Eo *)eo_ptr.obj->header.id;
}
else
{
@ -779,9 +779,9 @@ eo_class_new(const Eo_Class_Description *desc, const Eo *parent_id, ...)
_Eo_Class *parent = _eo_class_pointer_get(parent_id);
#ifndef HAVE_EO_ID
if (parent && !EINA_MAGIC_CHECK(parent, EO_CLASS_EINA_MAGIC))
if (parent && !EINA_MAGIC_CHECK((Eo_Header *) parent, EO_CLASS_EINA_MAGIC))
{
EINA_MAGIC_FAIL(parent, EO_CLASS_EINA_MAGIC);
EINA_MAGIC_FAIL((Eo_Header *) parent, EO_CLASS_EINA_MAGIC);
return NULL;
}
#endif
@ -907,7 +907,7 @@ eo_class_new(const Eo_Class_Description *desc, const Eo *parent_id, ...)
hndl = calloc(1, _eo_handle_sz + _eo_class_sz + extn_sz + mro_sz + mixins_sz);
hndl->is_a_class = 1;
klass = (_Eo_Class *) EO_FROM_HANDLE(hndl);
EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC);
EINA_MAGIC_SET((Eo_Header *) klass, EO_CLASS_EINA_MAGIC);
#endif
eina_lock_new(&klass->objects.trash_lock);
eina_lock_new(&klass->iterators.trash_lock);
@ -1024,7 +1024,7 @@ eo_class_new(const Eo_Class_Description *desc, const Eo *parent_id, ...)
}
eina_lock_take(&_eo_class_creation_lock);
klass->class_id = ++_eo_classes_last_id;
klass->header.id = ++_eo_classes_last_id;
{
/* FIXME: Handle errors. */
size_t arrsize = _eo_classes_last_id * sizeof(*_eo_classes);
@ -1036,7 +1036,7 @@ eo_class_new(const Eo_Class_Description *desc, const Eo *parent_id, ...)
memset(tmp, 0, arrsize);
_eo_classes = tmp;
_eo_classes[klass->class_id - 1] = klass;
_eo_classes[klass->header.id - 1] = klass;
}
eina_lock_release(&_eo_class_creation_lock);
@ -1114,10 +1114,10 @@ eo_add_internal(const char *file, int line, const Eo *klass_id, Eo *parent_id, .
obj->klass = klass;
#ifndef HAVE_EO_ID
EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
EINA_MAGIC_SET((Eo_Header *) obj, EO_EINA_MAGIC);
#endif
Eo_Id obj_id = _eo_id_allocate(obj);
obj->obj_id = obj_id;
obj->header.id = obj_id;
_eo_condtor_reset(obj);
@ -1303,7 +1303,7 @@ _eo_data_xref_internal(const char *file, int line, _Eo_Object *obj, const _Eo_Cl
(obj->datarefcount)++;
#ifdef EO_DEBUG
Eo_Xref_Node *xref = calloc(1, sizeof(*xref));
xref->ref_obj = (Eo *)ref_obj->obj_id;
xref->ref_obj = (Eo *)ref_obj->header.id;
xref->file = file;
xref->line = line;
@ -1325,14 +1325,14 @@ _eo_data_xunref_internal(_Eo_Object *obj, void *data, const _Eo_Object *ref_obj)
((char *)data < (((char *) obj) + klass->obj_size)));
if (!in_range)
{
ERR("Data %p is not in the data range of the object %p (%s).", data, (Eo *)obj->obj_id, obj->klass->desc->name);
ERR("Data %p is not in the data range of the object %p (%s).", data, (Eo *)obj->headr.id, obj->klass->desc->name);
}
#else
(void) data;
#endif
if (obj->datarefcount == 0)
{
ERR("Data for object %lx (%s) is already not referenced.", (unsigned long)obj->obj_id, obj->klass->desc->name);
ERR("Data for object %lx (%s) is already not referenced.", (unsigned long)obj->header.id, obj->klass->desc->name);
}
else
{
@ -1342,7 +1342,7 @@ _eo_data_xunref_internal(_Eo_Object *obj, void *data, const _Eo_Object *ref_obj)
Eo_Xref_Node *xref = NULL;
EINA_INLIST_FOREACH(obj->data_xrefs, xref)
{
if (xref->ref_obj == (Eo *)ref_obj->obj_id)
if (xref->ref_obj == (Eo *)ref_obj->header.id)
break;
}
@ -1353,7 +1353,7 @@ _eo_data_xunref_internal(_Eo_Object *obj, void *data, const _Eo_Object *ref_obj)
}
else
{
ERR("ref_obj (0x%lx) does not reference data (%p) of obj (0x%lx).", (unsigned long)ref_obj->obj_id, data, (unsigned long)obj->obj_id);
ERR("ref_obj (0x%lx) does not reference data (%p) of obj (0x%lx).", (unsigned long)ref_obj->header.id, data, (unsigned long)obj->header.id);
}
#else
(void) ref_obj;

View File

@ -57,6 +57,7 @@ extern int _eo_log_dom;
typedef uintptr_t Eo_Id;
typedef struct _Eo_Class _Eo_Class;
typedef struct _Eo_Object _Eo_Object;
typedef struct _Eo_Header Eo_Header;
typedef struct _Eo_Handle _Eo_Handle;
typedef union _Eo {
_Eo_Object *obj;
@ -81,12 +82,17 @@ struct _Eo_Handle {
Eina_Bool is_a_class:1;
};
struct _Eo_Object {
struct _Eo_Header
{
#ifndef HAVE_EO_ID
EINA_MAGIC
#endif
Eo_Id obj_id;
Eo_Id id;
};
struct _Eo_Object
{
Eo_Header header;
Eo *parent;
Eina_List *children;
const _Eo_Class *klass;
@ -129,10 +135,7 @@ typedef struct
struct _Eo_Class
{
#ifndef HAVE_EO_ID
EINA_MAGIC
#endif
Eo_Id class_id;
Eo_Header header;
const _Eo_Class *parent;
const Eo_Class_Description *desc;
@ -190,13 +193,13 @@ _eo_del_internal(const char *file, int line, _Eo_Object *obj)
/* We need that for the event callbacks that may ref/unref. */
obj->refcount++;
eo_do((Eo *) obj->obj_id, eo_event_callback_call(EO_EV_DEL, NULL, NULL));
eo_do((Eo *) obj->header.id, eo_event_callback_call(EO_EV_DEL, NULL, NULL));
const _Eo_Class *klass = obj->klass;
_eo_condtor_reset(obj);
do_err = eo_do((Eo *)obj->obj_id, eo_destructor());
do_err = eo_do((Eo *)obj->header.id, eo_destructor());
if (EINA_UNLIKELY(!do_err))
{
ERR("in %s:%d: Object of class '%s' - One of the object destructors have failed.",
@ -215,7 +218,7 @@ _eo_del_internal(const char *file, int line, _Eo_Object *obj)
Eo *emb_obj;
EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
{
eo_composite_detach(emb_obj, (Eo *)obj->obj_id);
eo_composite_detach(emb_obj, (Eo *)obj->header.id);
}
}
@ -234,7 +237,7 @@ _eo_free(_Eo_Object *obj)
ERR("Object %p data still referenced %d time(s).", obj, obj->datarefcount);
}
#endif
_eo_id_release(obj->obj_id);
_eo_id_release(obj->header.id);
eina_lock_take(&klass->objects.trash_lock);
if (klass->objects.trash_count <= 8)
@ -287,7 +290,7 @@ _eo_unref(_Eo_Object *obj)
{
Eina_Inlist *nitr = obj->data_xrefs->next;
Eo_Xref_Node *xref = EINA_INLIST_CONTAINER_GET(obj->data_xrefs, Eo_Xref_Node);
ERR("Data of object 0x%lx is still referenced by object %p", (unsigned long)obj->obj_id, xref->ref_obj);
ERR("Data of object 0x%lx is still referenced by object %p", (unsigned long)obj->header.id, xref->ref_obj);
free(xref);
obj->data_xrefs = nitr;

View File

@ -42,28 +42,28 @@
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, ret); \
EO_MAGIC_RETURN_VAL((Eo_Header *) obj, EO_EINA_MAGIC, ret); \
} while (0)
#define EO_OBJ_POINTER_RETURN(obj_id, obj) \
_Eo_Object *obj; \
do { \
obj = _eo_obj_pointer_get((Eo_Id)obj_id); \
EO_MAGIC_RETURN(obj, EO_EINA_MAGIC); \
EO_MAGIC_RETURN((Eo_Header *) obj, EO_EINA_MAGIC); \
} while (0)
#define EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, ret) \
_Eo_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, ret); \
EO_MAGIC_RETURN_VAL((Eo_Header *) klass, EO_CLASS_EINA_MAGIC, ret); \
} while (0)
#define EO_CLASS_POINTER_RETURN(klass_id, klass) \
_Eo_Class *klass; \
do { \
klass = _eo_class_pointer_get(klass_id); \
EO_MAGIC_RETURN(klass, EO_CLASS_EINA_MAGIC); \
EO_MAGIC_RETURN((Eo_Header *) klass, EO_CLASS_EINA_MAGIC); \
} while (0)
#endif

View File

@ -456,7 +456,7 @@ _eo_id_release(const Eo_Id obj_id)
ERR("obj_id %p is not pointing to a valid object. Maybe it has already been freed.", (void *)obj_id);
#else
EINA_MAGIC_SET(EO_FROM_HANDLE(obj_id), EO_FREED_EINA_MAGIC);
EINA_MAGIC_SET((Eo_Header *) obj_id, EO_FREED_EINA_MAGIC);
#endif
}