From bbab74320a9c0e44c11b706f9e0c89b79cba733c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 1 Aug 2013 09:47:21 +0200 Subject: [PATCH] eo2: fix eo2 custom constructors --- src/lib/eo/Eo.h | 20 ++++++++++++++++- src/lib/eo/eo.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index c2dfe3178b..77ec6a741f 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -874,7 +874,13 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line); #define eo2_add(klass, parent, ...) \ ({ \ const Eo_Class *_tmp_klass = klass; \ - eo_add_internal(__FILE__, __LINE__, _tmp_klass, parent, ## __VA_ARGS__, EO_NOOP); \ + Eo *_tmp_obj = eo2_add_internal_start(__FILE__, __LINE__, _tmp_klass, parent); \ + eo2_do(_tmp_obj, \ + eo2_constructor(); \ + __VA_ARGS__; \ + _tmp_obj = eo2_add_internal_end(__FILE__, __LINE__, _tmp_obj); \ + ); \ + _tmp_obj; \ }) /** @@ -892,6 +898,16 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line); const Eo_Class *_tmp_klass = klass; \ eo_add_internal(__FILE__, __LINE__, _tmp_klass, parent, ## __VA_ARGS__, EO_NOOP); \ }) +#define eo2_add_custom(klass, parent, ...) \ + ({ \ + const Eo_Class *_tmp_klass = klass; \ + Eo *_tmp_obj = eo2_add_internal_start(__FILE__, __LINE__, _tmp_klass, parent); \ + eo2_do(_tmp_obj, \ + __VA_ARGS__; \ + _tmp_obj = eo2_add_internal_end(__FILE__, __LINE__, _tmp_obj); \ + ); \ + _tmp_obj; \ + }) /** * @brief Create a new object. @@ -906,6 +922,8 @@ EAPI void eo_error_set_internal(const Eo *obj, const char *file, int line); * @see #eo_add */ EAPI Eo *eo_add_internal(const char *file, int line, const Eo_Class *klass, Eo *parent, ...); +EAPI Eo * eo2_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id); +EAPI Eo * eo2_add_internal_end(const char *file, int line, const Eo *obj); /** * @brief Get a pointer to the data of an object for a specific class. diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index 8e1b1f1e84..8ff4912209 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -449,7 +449,6 @@ eo2_call_resolve_internal(const Eo_Class *klass_id, const Eo_Op op, Eo2_Op_Call_ return EINA_FALSE; } - func = _dich_func_get(klass, op); if (EINA_LIKELY(func != NULL)) { @@ -614,6 +613,64 @@ _eo2_class_funcs_set(_Eo_Class *klass) } } +EAPI Eo * +eo2_add_internal_start(const char *file, int line, const Eo_Class *klass_id, Eo *parent_id) +{ + _Eo_Class *klass = _eo_class_pointer_get(klass_id); + EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL); + + if (parent_id) + { + EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, NULL); + } + + if (EINA_UNLIKELY(klass->desc->type != EO_CLASS_TYPE_REGULAR)) + { + ERR("in %s:%d: Class '%s' is not instantiate-able. Aborting.", file, line, klass->desc->name); + return NULL; + } + + _Eo *obj = calloc(1, klass->obj_size); + obj->refcount++; + obj->klass = klass; + +#ifndef HAVE_EO_ID + EINA_MAGIC_SET(obj, EO_EINA_MAGIC); +#endif + Eo_Id obj_id = _eo_id_allocate(obj); + obj->obj_id = obj_id; + eo_parent_set((Eo *)obj_id, parent_id); + + _eo_condtor_reset(obj); + + return (Eo *)obj_id; +} + +EAPI Eo * +eo2_add_internal_end(const char *file, int line, const Eo *obj_id) +{ + Eo2_Stack_Frame *fptr; + + fptr = eo2_call_stack.frame_ptr; + + if ((fptr == NULL) || (fptr->obj_id != obj_id)) + { + ERR("in %s:%d - Something very wrong happend to the call stack.", file, line); + return NULL; + } + + if (!fptr->obj->condtor_done) + { + ERR("in %s:%d: Object of class '%s' - Not all of the object constructors have been executed.", + file, line, fptr->klass->desc->name); + /* for the for the basic object ref. */ + _eo_unref(fptr->obj); + return NULL; + } + + return (Eo *)fptr->obj_id; +} + /*****************************************************************************/ #define _EO_OP_ERR_NO_OP_PRINT(file, line, op, klass) \