* You must use this macro if you want thread safety in class creation.
*/
#define EO_DEFINE_CLASS(class_get_func_name, class_desc, parent_class, ...) \
- EO_DEFINE_CLASS_STATIC(class_get_func_name, 0, class_desc, parent_class, __VA_ARGS__)
-
-/**
- * @def EO_DEFINE_CLASS_STATIC(class_get_func_name, id, class_desc, parent_class, ...)
- * *** DO NOT USE UNLESS YOU REALLY KNOW WHAT YOU ARE DOING ***
- * @param id a positive number to serve as the id of the class. 0 means dynamic. See eo_class_new() for details.
- * @param class_get_func_name the name of the wanted class_get function name.
- * @param class_desc the class description.
- * @param parent_class The parent class for the function. Look at eo_class_new() for more information.
- * @param ... List of etxensions. Look at eo_class_new() for more information.
- *
- * This macro should only be used if you know what you are doing and you want
- * to create a class with a static id.
- * Use #EO_DEFINE_CLASS instead.
- *
- * @see #EO_DEFINE_CLASS
- */
-#define EO_DEFINE_CLASS_STATIC(class_get_func_name, id, class_desc, parent_class, ...) \
EAPI const Eo_Class * \
class_get_func_name(void) \
{ \
} \
eina_lock_release(&_eo_class_creation_lock); \
(void) parent_class; \
- _my_class = eo_class_new(class_desc, id, parent_class, __VA_ARGS__); \
+ _my_class = eo_class_new(class_desc, parent_class, __VA_ARGS__); \
eina_lock_release(&_my_lock); \
\
eina_lock_take(&_eo_class_creation_lock); \
/**
* @brief Create a new class.
* @param desc the class description to create the class with.
- * @param id a positive number to serve as the id of the class. 0 means dynamic allocation. The number of static Ids is limited and regular users should not use static ids.
* @param parent the class to inherit from.
* @param ... A NULL terminated list of extensions (interfaces, mixins and the classes of any composite objects).
* @return The new class's handle on success, or NULL otherwise.
*
* @see #EO_DEFINE_CLASS
*/
-EAPI const Eo_Class *eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *parent, ...);
+EAPI const Eo_Class *eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...);
/**
* @brief Check if an object "is a" klass.
typedef void (*eo_base_data_free_func)(void *);
/**
- * @def EO_BASE_CLASS_ID
- * #EO_BASE_CLASS 's class id.
- */
-#define EO_BASE_CLASS_ID 1
-
-/**
- * @def EO_BASE_BASE_ID
+ * @var EO_BASE_BASE_ID
* #EO_BASE_CLASS 's base id.
*/
-#define EO_BASE_BASE_ID EO_BASE_CLASS_ID // FIXME: Awful hack.
+extern EAPI Eo_Op EO_BASE_BASE_ID;
enum {
EO_BASE_SUB_ID_CONSTRUCTOR,
#include "config.h"
/* The last id that should be reserved for statically allocated classes. */
-#define EO_STATIC_IDS_LAST 10
+#define EO_CLASS_IDS_FIRST 1
#define EO_OP_IDS_FIRST 1
/* Used inside the class_get functions of classes, see #EO_DEFINE_CLASS */
/* DEVCHECK */
static Eina_Bool
-_eo_class_check_op_descs(const Eo_Class *klass, Eo_Class_Id id)
+_eo_class_check_op_descs(const Eo_Class *klass)
{
const Eo_Class_Description *desc = klass->desc;
const Eo_Op_Description *itr;
if (desc->ops.count > 0)
{
- if (((id == 0) || (id > EO_STATIC_IDS_LAST)) && !desc->ops.base_op_id)
+ if (!desc->ops.base_op_id)
{
ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
desc->name);
}
EAPI const Eo_Class *
-eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *parent, ...)
+eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...)
{
Eo_Class *klass;
va_list p_list;
return NULL;
}
- if (id > EO_STATIC_IDS_LAST)
- {
- ERR("Tried creating a class with the static id %d while the maximum static id is %d. Aborting.", id, EO_STATIC_IDS_LAST);
- return NULL;
- }
-
va_start(p_list, parent);
EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
EO_ALIGN_SIZE(klass->parent->desc->data_size);
}
- if (!_eo_class_check_op_descs(klass, id))
+ if (!_eo_class_check_op_descs(klass))
{
goto cleanup;
}
eina_lock_take(&_eo_class_creation_lock);
- if (id == 0)
- {
- klass->class_id = ++_eo_classes_last_id;
- }
- else
- {
-#ifndef NDEBUG
- if (_eo_classes && _eo_classes[id - 1])
- {
- ERR("A class with id %d was already defined (%s). Aborting.", id,
- _eo_classes[id - 1]->desc->name);
- eina_lock_release(&_eo_class_creation_lock);
- goto cleanup;
- }
-#endif
- klass->class_id = id;
- }
-
+ klass->class_id = ++_eo_classes_last_id;
{
/* FIXME: Handle errors. */
eina_init();
_eo_classes = NULL;
- _eo_classes_last_id = EO_STATIC_IDS_LAST;
+ _eo_classes_last_id = EO_CLASS_IDS_FIRST - 1;
_eo_ops_last_id = EO_OP_IDS_FIRST;
_eo_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_LIGHTBLUE);
if (_eo_log_dom < 0)
#include "config.h"
+EAPI Eo_Op EO_BASE_BASE_ID = 0;
+
static int event_freeze_count = 0;
typedef struct
EO_VERSION,
"Eo Base",
EO_CLASS_TYPE_REGULAR_NO_INSTANT,
- EO_CLASS_DESCRIPTION_OPS(NULL, op_desc, EO_BASE_SUB_ID_LAST),
+ EO_CLASS_DESCRIPTION_OPS(&EO_BASE_BASE_ID, op_desc, EO_BASE_SUB_ID_LAST),
event_desc,
sizeof(Private_Data),
_class_constructor,
NULL
};
-EO_DEFINE_CLASS_STATIC(eo_base_class_get, EO_BASE_CLASS_ID, &class_desc, NULL, NULL)
+EO_DEFINE_CLASS(eo_base_class_get, &class_desc, NULL, NULL)
NULL
};
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.ops.base_op_id = &TMP_BASE_ID;
class_desc.ops.descs = NULL;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.ops.descs = op_desc;
class_desc.ops.count = TEST_SUB_ID_LAST + 1;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.ops.count = 0;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.ops.count = TEST_SUB_ID_LAST;
class_desc.ops.descs = op_desc_wrong;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.ops.descs = op_desc;
class_desc.name = NULL;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.name = "Simple";
- klass = eo_class_new(NULL, 0, NULL, NULL);
+ klass = eo_class_new(NULL, NULL, NULL);
fail_if(klass);
/* Should create a class. */
- klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
(void) klass;
NULL
};
- klass_mixin = eo_class_new(&class_desc_mixin, 0, NULL, NULL);
+ klass_mixin = eo_class_new(&class_desc_mixin, NULL, NULL);
fail_if(!klass_mixin);
- klass_simple = eo_class_new(&class_desc_simple, 0, EO_BASE_CLASS, NULL);
+ klass_simple = eo_class_new(&class_desc_simple, EO_BASE_CLASS, NULL);
fail_if(!klass_simple);
- klass = eo_class_new(&class_desc, 0, klass_simple, NULL);
+ klass = eo_class_new(&class_desc, klass_simple, NULL);
fail_if(klass);
class_desc.type = EO_CLASS_TYPE_REGULAR;
- klass = eo_class_new(&class_desc, 0, klass_mixin, NULL);
+ klass = eo_class_new(&class_desc, klass_mixin, NULL);
fail_if(klass);
(void) klass;
NULL
};
- klass_mixin = eo_class_new(&class_desc_mixin, 0, NULL, NULL);
+ klass_mixin = eo_class_new(&class_desc_mixin, NULL, NULL);
fail_if(!klass_mixin);
- klass_mixin2 = eo_class_new(&class_desc_mixin2, 0, klass_mixin, NULL);
+ klass_mixin2 = eo_class_new(&class_desc_mixin2, klass_mixin, NULL);
fail_if(!klass_mixin2);
- klass_mixin3 = eo_class_new(&class_desc_mixin3, 0, klass_mixin, NULL);
+ klass_mixin3 = eo_class_new(&class_desc_mixin3, klass_mixin, NULL);
fail_if(!klass_mixin3);
- klass = eo_class_new(&class_desc_simple, 0, EO_BASE_CLASS, klass_mixin, klass_mixin2, NULL);
+ klass = eo_class_new(&class_desc_simple, EO_BASE_CLASS, klass_mixin, klass_mixin2, NULL);
fail_if(klass);
- klass = eo_class_new(&class_desc_simple, 0, EO_BASE_CLASS, klass_mixin2, klass_mixin, NULL);
+ klass = eo_class_new(&class_desc_simple, EO_BASE_CLASS, klass_mixin2, klass_mixin, NULL);
fail_if(!klass);
- klass = eo_class_new(&class_desc_simple, 0, EO_BASE_CLASS, klass_mixin2, klass_mixin3, NULL);
+ klass = eo_class_new(&class_desc_simple, EO_BASE_CLASS, klass_mixin2, klass_mixin3, NULL);
fail_if(!klass);
eo_shutdown();
NULL
};
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(klass);
class_desc.data_size = 0;
class_desc.class_constructor = _stub_class_constructor;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(!klass);
class_desc.class_constructor = NULL;
class_desc.class_destructor = _stub_class_constructor;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(!klass);
class_desc.class_destructor = NULL;
- klass = eo_class_new(&class_desc, 0, NULL, NULL);
+ klass = eo_class_new(&class_desc, NULL, NULL);
fail_if(!klass);
eo_shutdown();
NULL
};
- klass = eo_class_new(&class_desc, 0, SIMPLE_CLASS, NULL);
+ klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
fail_if(!klass);
/* Add class checks here... */
NULL
};
- const Eo_Class *klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
Eo *obj = eo_add(klass, NULL);
eo_unref(obj);
class_desc.data_size = 0;
- klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
obj = eo_add(klass, NULL);
NULL
};
- iface = eo_class_new(&class_desc, 0, NULL, NULL);
+ iface = eo_class_new(&class_desc, NULL, NULL);
fail_if(!iface);
}
NULL
};
- mixin = eo_class_new(&class_desc, 0, NULL, NULL);
+ mixin = eo_class_new(&class_desc, NULL, NULL);
fail_if(!mixin);
}
NULL
};
- klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, iface, mixin, NULL);
+ klass = eo_class_new(&class_desc, EO_BASE_CLASS, iface, mixin, NULL);
fail_if(!klass);
}
}
END_TEST
-START_TEST(eo_static_classes)
-{
- eo_init();
-
- static const Eo_Op_Description op_desc[] = {
- EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
- EO_OP_DESCRIPTION_SENTINEL
- };
-
- /* Usually should be const, not const only for the test... */
- static Eo_Class_Description class_desc = {
- EO_VERSION,
- "Simple2",
- EO_CLASS_TYPE_REGULAR,
- EO_CLASS_DESCRIPTION_OPS(NULL, op_desc, 1),
- NULL,
- 0,
- NULL,
- NULL
- };
-
- const Eo_Class *klass = eo_class_new(&class_desc, 1, EO_BASE_CLASS, NULL);
- fail_if(klass);
-
- klass = eo_class_new(&class_desc, 1000, EO_BASE_CLASS, NULL);
- fail_if(klass);
-
- klass = eo_class_new(&class_desc, 2, EO_BASE_CLASS, NULL);
- fail_if(!klass);
-
- eo_shutdown();
-}
-END_TEST
-
static Eina_Bool _man_should_con = EINA_TRUE;
static Eina_Bool _man_should_des = EINA_TRUE;
NULL
};
- const Eo_Class *klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
Eo *obj = eo_add(klass, NULL);
eo_unref(obj);
_man_should_des = EINA_FALSE;
- klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
obj = eo_add(klass, NULL);
eo_manual_free(obj);
_man_should_con = EINA_FALSE;
- klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
+ klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
fail_if(!klass);
obj = eo_add(klass, NULL);
NULL
};
- const Eo_Class *klass = eo_class_new(&class_desc, 0, SIMPLE_CLASS, NULL);
+ const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
fail_if(!klass);
Eo *obj = eo_add(klass, NULL);
eo_class_do((Eo_Class *) buf, NULL);
eo_class_do_super((Eo_Class *) buf, EO_NOOP);
- fail_if(eo_class_new(NULL, 0, (Eo_Class *) buf), NULL);
+ fail_if(eo_class_new(NULL, (Eo_Class *) buf), NULL);
eo_xref(obj, (Eo *) buf);
eo_xunref(obj, (Eo *) buf);
NULL
};
- const Eo_Class *klass = eo_class_new(&class_desc, 0, SIMPLE_CLASS, NULL);
+ const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
fail_if(!klass);
Eo *obj = eo_add(klass, NULL);
tcase_add_test(tc, eo_magic_checks);
tcase_add_test(tc, eo_data_fetch);
tcase_add_test(tc, eo_man_free);
- tcase_add_test(tc, eo_static_classes);
tcase_add_test(tc, eo_composite_tests);
tcase_add_test(tc, eo_isa_tests);
tcase_add_test(tc, eo_multiple_do);