eo2: fix eo2 custom constructors

This commit is contained in:
Jérémy Zurcher 2013-08-01 09:47:21 +02:00 committed by Tom Hacohen
parent ebc90200a6
commit bbab74320a
2 changed files with 77 additions and 2 deletions

View File

@ -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.

View File

@ -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) \