From 5913f78b4ff540cf40a783c7110f0042ccfce9c3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 26 Sep 2013 23:12:06 +0200 Subject: [PATCH] eo: if !HAVE_EO_ID front-pad _Eo_Class and _Eo_Object with _Eo_Handle this is the first step on the road to remove class specific EAPI from Eo.h using this handle we will know if a Eo* is a class or an object pointer Conflicts: src/lib/eo/eo.c --- src/lib/eo/eo.c | 36 +++++++++++++++++++++++++++++++----- src/lib/eo/eo_private.h | 9 +++++++++ src/lib/eo/eo_ptr_indirection.x | 13 ++++++++++--- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index 0bf4275..06bbe81 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -23,6 +23,7 @@ static Eo_Op _eo_ops_last_id = 0; static size_t _eo_sz = 0; static size_t _eo_class_sz = 0; +static size_t _eo_handle_sz = 0; static void _eo_condtor_reset(_Eo *obj); static inline void *_eo_data_scope_get(const _Eo *obj, const _Eo_Class *klass); @@ -47,8 +48,6 @@ static const Eo_Op_Description *_eo_op_id_desc_get(Eo_Op op); (_eo_classes[id - 1]) : NULL); \ }) -#define EO_ALIGN_SIZE(size) eina_mempool_alignof(size) - static inline void _dich_chain_alloc(Dich_Chain1 *chain1) { @@ -141,7 +140,7 @@ _eo_class_pointer_get(const Eo_Class *klass_id) #ifdef HAVE_EO_ID return ID_CLASS_GET((Eo_Class_Id)klass_id); #else - return (_Eo_Class *)klass_id; + return (_Eo_Class *) EO_FROM_HANDLE(klass_id); #endif } @@ -151,7 +150,7 @@ Eo_Class * _eo_class_id_get(const _Eo_Class *klass) #ifdef HAVE_EO_ID return (Eo_Class *)klass->class_id; #else - return (Eo_Class *)klass; + return (Eo_Class *) HANDLE_FROM_EO(klass); #endif } @@ -692,7 +691,11 @@ eo_class_free(_Eo_Class *klass) } EINA_TRASH_CLEAN(&klass->objects.trash, data) +#ifdef HAVE_EO_ID free(data); +#else + free((void *) HANDLE_FROM_EO(data)); +#endif EINA_TRASH_CLEAN(&klass->iterators.trash, data) free(data); @@ -700,7 +703,11 @@ eo_class_free(_Eo_Class *klass) eina_lock_free(&klass->objects.trash_lock); eina_lock_free(&klass->iterators.trash_lock); +#ifdef HAVE_EO_ID free(klass); +#else + free((void *) HANDLE_FROM_EO(klass)); +#endif } /* DEVCHECK */ @@ -764,6 +771,7 @@ EAPI const Eo_Class * eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...) { _Eo_Class *klass; + _Eo_Handle *hndl; va_list p_list; size_t extn_sz, mro_sz, mixins_sz; Eina_List *extn_list, *mro, *mixins; @@ -891,8 +899,13 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...) DBG("Finished building Mixins list for class '%s'", desc->name); } +#ifdef HAVE_EO_ID + hndl = NULL; klass = calloc(1, _eo_class_sz + extn_sz + mro_sz + mixins_sz); -#ifndef HAVE_EO_ID +#else + 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); #endif eina_lock_new(&klass->objects.trash_lock); @@ -961,7 +974,11 @@ eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent_id, ...) extn_data_itr->offset = 0; } +#ifdef HAVE_EO_ID klass->obj_size = _eo_sz + extn_data_off; +#else + klass->obj_size = _eo_handle_sz + _eo_sz + extn_data_off; +#endif if (getenv("EO_DEBUG")) { fprintf(stderr, "Eo class '%s' will take %u bytes per object.\n", @@ -1058,6 +1075,7 @@ eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent { Eina_Bool do_err; _Eo *obj; + _Eo_Handle *hndl; EO_CLASS_POINTER_RETURN_VAL(klass_id, klass, NULL); if (parent_id) @@ -1080,7 +1098,14 @@ eo_add_internal(const char *file, int line, const Eo_Class *klass_id, Eo *parent } else { +#ifdef HAVE_EO_ID + hndl = NULL; obj = calloc(1, klass->obj_size); +#else + hndl = calloc(1, klass->obj_size); + hndl->is_a_class = 0; + obj = EO_FROM_HANDLE(hndl); +#endif } eina_lock_release(&klass->objects.trash_lock); @@ -1419,6 +1444,7 @@ eo_init(void) _eo_sz = EO_ALIGN_SIZE(sizeof (_Eo)); _eo_class_sz = EO_ALIGN_SIZE(sizeof (_Eo_Class)); + _eo_handle_sz = EO_ALIGN_SIZE(sizeof (_Eo_Handle)); _eo_classes = NULL; _eo_classes_last_id = EO_CLASS_IDS_FIRST - 1; diff --git a/src/lib/eo/eo_private.h b/src/lib/eo/eo_private.h index 6c0ce73..8b5367b 100644 --- a/src/lib/eo/eo_private.h +++ b/src/lib/eo/eo_private.h @@ -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; +typedef struct _Eo_Handle _Eo_Handle; /* Retrieves the pointer to the object from the id */ static inline _Eo *_eo_obj_pointer_get(const Eo_Id obj_id); @@ -72,6 +73,10 @@ static inline void _eo_free_ids_tables(void); void _eo_condtor_done(Eo *obj); +struct _Eo_Handle { + Eina_Bool is_a_class:1; +}; + struct _Eo_Object { #ifndef HAVE_EO_ID EINA_MAGIC @@ -241,7 +246,11 @@ _eo_free(_Eo *obj) } else { +#ifdef HAVE_EO_ID free(obj); +#else + free(((char *) obj) - eina_mempool_alignof(sizeof (_Eo_Handle))); +#endif } eina_lock_release(&klass->objects.trash_lock); } diff --git a/src/lib/eo/eo_ptr_indirection.x b/src/lib/eo/eo_ptr_indirection.x index 00bcbae..3b99c4a 100644 --- a/src/lib/eo/eo_ptr_indirection.x +++ b/src/lib/eo/eo_ptr_indirection.x @@ -184,6 +184,13 @@ _eo_id_mem_protect(void *ptr, Eina_Bool may_not_write) # define UNPROTECT(_ptr_) #endif +#define EO_ALIGN_SIZE(size) eina_mempool_alignof(size) + +#ifndef HAVE_EO_ID +# define HANDLE_FROM_EO(eo) (Eo_Id)( eo ? (((char *) eo) - EO_ALIGN_SIZE(sizeof (_Eo_Handle))) : NULL ) +# define EO_FROM_HANDLE(hndl) (_Eo *) ( hndl ? (((char *) hndl) + EO_ALIGN_SIZE(sizeof (_Eo_Handle))) : NULL ) +#endif + /* Entry */ typedef struct { @@ -270,7 +277,7 @@ _eo_obj_pointer_get(const Eo_Id obj_id) return NULL; #else - return (_Eo *)obj_id; + return EO_FROM_HANDLE(obj_id); #endif } @@ -390,7 +397,7 @@ _eo_id_allocate(const _Eo *obj) (entry - _current_table->entries), entry->generation); #else - return (Eo_Id)obj; + return HANDLE_FROM_EO(obj); #endif } @@ -445,7 +452,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 *) obj_id, EO_FREED_EINA_MAGIC); + EINA_MAGIC_SET(EO_FROM_HANDLE(obj_id), EO_FREED_EINA_MAGIC); #endif } -- 2.7.4