Eo: Added debug-mode check for eo_data_get.

SVN revision: 70625
This commit is contained in:
Tom Hacohen 2012-05-02 13:59:18 +00:00
parent 241bb1b7e5
commit 742f987798
2 changed files with 50 additions and 2 deletions

View File

@ -486,6 +486,21 @@ _eo_class_base_op_init(Eo_Class *klass)
*(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
}
static Eina_Bool
_eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find)
{
const Eo_Class **itr;
for (itr = klass->mro ; *itr ; itr++)
{
if (*itr == find)
{
return EINA_TRUE;
}
}
return EINA_FALSE;
}
static Eina_List *
_eo_class_mro_add(Eina_List *mro, const Eo_Class *klass)
{
@ -1189,8 +1204,13 @@ eo_data_get(const Eo *obj, const Eo_Class *klass)
{
EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
/* FIXME: Add a check that this is of the right klass and we don't seg.
* Probably just return NULL. */
#ifndef NDEBUG
if (!_eo_class_mro_has(obj->klass, klass))
{
ERR("Tried getting data of class '%s' from object of class '%s', but the former is not a direct inheritance of the latter.", klass->desc->name, obj->klass->desc->name);
return NULL;
}
#endif
if (EINA_LIKELY(klass->desc->data_size > 0))
{
if (EINA_UNLIKELY(klass->desc->type == EO_CLASS_TYPE_MIXIN))

View File

@ -19,6 +19,33 @@ START_TEST(eo_simple)
}
END_TEST
START_TEST(eo_data_fetch)
{
eo_init();
static const Eo_Class_Description class_desc = {
"Simple2",
EO_CLASS_TYPE_REGULAR,
EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
NULL,
10,
NULL,
NULL,
NULL,
NULL
};
const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
Eo *obj = eo_add(klass, NULL);
fail_if(!obj);
fail_if(eo_data_get(obj, SIMPLE_CLASS));
eo_shutdown();
}
END_TEST
START_TEST(eo_refs)
{
eo_init();
@ -353,4 +380,5 @@ void eo_test_general(TCase *tc)
tcase_add_test(tc, eo_weak_reference);
tcase_add_test(tc, eo_refs);
tcase_add_test(tc, eo_magic_checks);
tcase_add_test(tc, eo_data_fetch);
}