diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-08-01 09:47:21 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-09-17 22:37:00 +0200 |
commit | 77b6a43f34e01740209694ccdab663de63d22cbb (patch) | |
tree | 6d260f9d02ba6fb22c9454bd0228bc55b1c838be | |
parent | b66c222b87e6ababe77f735192c8dbc4b3c1ad43 (diff) | |
download | efl-77b6a43f34e01740209694ccdab663de63d22cbb.tar.gz |
fix eo2 custom constructors
-rw-r--r-- | src/lib/eo/Eo.h | 20 | ||||
-rw-r--r-- | 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 91a9954508..05301032f4 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -933,7 +933,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; \ }) /** @@ -951,6 +957,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. @@ -965,6 +981,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 the parent of an object diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c index 381d411a67..da2130a49a 100644 --- a/src/lib/eo/eo.c +++ b/src/lib/eo/eo.c @@ -445,7 +445,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)) { @@ -610,6 +609,64 @@ _eo2_class_funcs_set(const _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) \ |