Eo: Made an hot-path check compile out when not in debug mode.
[profile/ivi/eobj.git] / lib / eo.c
1 #include <Eina.h>
2
3 #include "Eo.h"
4 #include "eo_private.h"
5
6 #include "config.h"
7
8 typedef size_t Eo_Class_Id;
9
10 /* Used inside the class_get functions of classes, see #EO_DEFINE_CLASS */
11 EAPI Eina_Lock _eo_class_creation_lock;
12 int _eo_log_dom = -1;
13
14 static Eo_Class **_eo_classes;
15 static Eo_Class_Id _eo_classes_last_id;
16 static Eina_Bool _eo_init_count = 0;
17
18 static void _eo_constructor(Eo *obj, const Eo_Class *klass);
19 static void _eo_destructor(Eo *obj, const Eo_Class *klass);
20 static inline Eina_Bool _eo_error_get(const Eo *obj);
21 static inline void _eo_error_unset(Eo *obj);
22 static inline void *_eo_data_get(const Eo *obj, const Eo_Class *klass);
23 static inline Eo *_eo_ref(Eo *obj);
24 static inline void _eo_unref(Eo *obj);
25
26 typedef struct
27 {
28    Eo_Op op;
29    const Eo_Class **kls_itr;
30 } Eo_Kls_Itr;
31
32 struct _Eo {
33      EINA_MAGIC
34      Eo *parent;
35      const Eo_Class *klass;
36      int refcount;
37 #ifndef NDEBUG
38      Eina_Inlist *xrefs;
39 #endif
40
41      Eina_List *composite_objects;
42
43      Eo_Kls_Itr mro_itr;
44
45      Eina_Bool del:1;
46      Eina_Bool construct_error:1;
47      Eina_Bool manual_free:1;
48 };
49
50 /* Start of Dich */
51 /* Dich search, split to 0xff 0xff 0xffff */
52
53 #define DICH_CHAIN1_MASK (0xffff)
54 #define DICH_CHAIN_LAST_MASK (0xffff)
55 #define DICH_CHAIN1(x) (((x) >> 16) & DICH_CHAIN1_MASK)
56 #define DICH_CHAIN_LAST(x) ((x) & DICH_CHAIN_LAST_MASK)
57
58 #define OP_CLASS_OFFSET 16
59 #define OP_CLASS_OFFSET_GET(x) (((x) >> OP_CLASS_OFFSET) & 0xffff)
60 #define OP_CLASS_GET(op) ({ \
61       Eo_Class_Id tmp = OP_CLASS_OFFSET_GET(op); \
62       ID_CLASS_GET(tmp); \
63       })
64 #define OP_SUB_ID_GET(op) ((op) & 0xffff)
65
66 #define ID_CLASS_GET(id) ({ \
67       (Eo_Class *) ((id <= _eo_classes_last_id) && (id > 0)) ? \
68       (_eo_classes[id - 1]) : NULL; \
69       })
70
71 #define EO_ALIGN_SIZE(size) \
72         ((size) + (sizeof(void *) - ((size) % sizeof(void *))))
73
74 /* Structure of Eo_Op is:
75  * 16bit: class
76  * 16bit: op.
77  */
78
79 typedef struct _Dich_Chain1 Dich_Chain1;
80
81 typedef struct
82 {
83    eo_op_func_type func;
84    const Eo_Class *src;
85 } op_type_funcs;
86
87 struct _Dich_Chain1
88 {
89    op_type_funcs *funcs;
90 };
91
92 typedef struct
93 {
94      EINA_INLIST;
95      const Eo_Class *klass;
96 } Eo_Extension_Node;
97
98 typedef struct
99 {
100      const Eo_Class *klass;
101      size_t offset;
102 } Eo_Extension_Data_Offset;
103
104 struct _Eo_Class
105 {
106    EINA_MAGIC
107    Eo_Class_Id class_id;
108    const Eo_Class *parent;
109    const Eo_Class_Description *desc;
110    Dich_Chain1 *chain; /**< The size is class_id */
111    Eina_Inlist *extensions;
112
113    Eo_Extension_Data_Offset *extn_data_off;
114    size_t extn_data_size;
115
116    const Eo_Class **mro;
117    Eo_Kls_Itr mro_itr;
118
119    size_t data_offset; /* < Offset of the data within object data. */
120
121    Eina_Bool constructed : 1;
122 };
123
124 static inline void
125 _dich_chain_alloc(Dich_Chain1 *chain1, size_t num_ops)
126 {
127    if (!chain1->funcs)
128      {
129         chain1->funcs = calloc(num_ops, sizeof(*(chain1->funcs)));
130      }
131 }
132
133 static inline void
134 _dich_copy_all(Eo_Class *dst, const Eo_Class *src)
135 {
136    if (!src->chain) return;
137
138    if (!dst->chain)
139      {
140         dst->chain = calloc(dst->class_id, sizeof(*dst->chain));
141      }
142
143    Eo_Class_Id i;
144    const Dich_Chain1 *sc1 = src->chain;
145    Dich_Chain1 *dc1 = dst->chain;
146    for (i = 0 ; i < src->class_id ; i++, sc1++, dc1++)
147      {
148         if (sc1->funcs)
149           {
150              size_t j;
151              const Eo_Class *op_klass = ID_CLASS_GET(i + 1);
152              /* Can be NULL because of future static classes. */
153              if (!op_klass)
154                 continue;
155
156              size_t num_ops = op_klass->desc->ops.count;
157              _dich_chain_alloc(dc1, num_ops);
158
159              const op_type_funcs *sf = sc1->funcs;
160              op_type_funcs *df = dc1->funcs;
161              for (j = 0 ; j < num_ops ; j++, df++, sf++)
162                {
163                   if (sf->func)
164                     {
165                        memcpy(df, sf, sizeof(*df));
166                     }
167                }
168           }
169      }
170 }
171
172 static inline const op_type_funcs *
173 _dich_func_get(const Eo_Class *klass, Eo_Op op)
174 {
175    if (!klass->chain) return NULL;
176
177    size_t idx1 = DICH_CHAIN1(op) - 1;
178    if (idx1 >= klass->class_id) return NULL;
179    const Dich_Chain1 *chain1 = &klass->chain[idx1];
180    if (!chain1->funcs) return NULL;
181
182    size_t idxl = DICH_CHAIN_LAST(op);
183    /* num_ops is calculated from the class. */
184    const Eo_Class *op_klass = ID_CLASS_GET(idx1 + 1);
185    if (!op_klass || (idxl >= op_klass->desc->ops.count))
186       return NULL;
187
188    return &chain1->funcs[idxl];
189 }
190
191 static inline void
192 _dich_func_set(Eo_Class *klass, Eo_Op op, eo_op_func_type func)
193 {
194    const Eo_Class *op_klass = OP_CLASS_GET(op);
195    size_t num_ops;
196
197    /* Verify op is valid. */
198    if (op_klass)
199      {
200         /* num_ops is calculated from the class. */
201         num_ops = op_klass->desc->ops.count;
202         if (DICH_CHAIN_LAST(op) >= num_ops)
203           {
204              ERR("OP %x is too big for the domain '%s', expected value < %x.",
205                    op, op_klass->desc->name, op_klass->desc->ops.count);
206              return;
207           }
208      }
209    else
210      {
211         ERR("OP %x is from an illegal class.", op);
212         return;
213      }
214
215    if (!klass->chain)
216      {
217         klass->chain = calloc(klass->class_id, sizeof(*klass->chain));
218      }
219
220    size_t idx1 = DICH_CHAIN1(op) - 1;
221    Dich_Chain1 *chain1 = &klass->chain[idx1];
222    _dich_chain_alloc(chain1, num_ops);
223    chain1->funcs[DICH_CHAIN_LAST(op)].func = func;
224    chain1->funcs[DICH_CHAIN_LAST(op)].src = klass;
225 }
226
227 static inline void
228 _dich_func_clean_all(Eo_Class *klass)
229 {
230    size_t i;
231    Dich_Chain1 *chain1 = klass->chain;
232
233    if (!chain1)
234       return;
235
236    for (i = 0 ; i < klass->class_id ; i++, chain1++)
237      {
238         if (chain1->funcs)
239            free(chain1->funcs);
240      }
241    free(klass->chain);
242    klass->chain = NULL;
243 }
244
245 /* END OF DICH */
246
247 static const Eo_Op_Description noop_desc =
248         EO_OP_DESCRIPTION(EO_NOOP, "", "No operation.");
249
250 static const Eo_Op_Description *
251 _eo_op_id_desc_get(Eo_Op op)
252 {
253    const Eo_Class *klass = OP_CLASS_GET(op);
254    Eo_Op sub_id = OP_SUB_ID_GET(op);
255
256    if (op == EO_NOOP)
257       return &noop_desc;
258
259    if (klass && (sub_id < klass->desc->ops.count))
260       return klass->desc->ops.descs + sub_id;
261
262    return NULL;
263 }
264
265 static const char *
266 _eo_op_id_name_get(Eo_Op op)
267 {
268    const Eo_Op_Description *desc = _eo_op_id_desc_get(op);
269    return (desc) ? desc->name : NULL;
270 }
271
272 static inline void
273 _eo_kls_itr_init(const Eo_Class *obj_klass, Eo_Kls_Itr *cur, Eo_Op op, Eo_Kls_Itr *prev_state)
274 {
275    prev_state->op = cur->op;
276    prev_state->kls_itr = cur->kls_itr;
277
278    /* If we are in a constructor/destructor or we changed an op - init. */
279    if ((op == EO_NOOP) || (cur->op != op))
280      {
281         cur->op = op;
282         cur->kls_itr = obj_klass->mro;
283      }
284 }
285
286 static inline void
287 _eo_kls_itr_end(Eo_Kls_Itr *cur, Eo_Kls_Itr *prev_state)
288 {
289    if (cur->op != prev_state->op)
290      {
291         cur->op = prev_state->op;
292         cur->kls_itr = prev_state->kls_itr;
293      }
294 }
295
296 static inline const Eo_Class *
297 _eo_kls_itr_get(Eo_Kls_Itr *cur)
298 {
299    return (cur->kls_itr) ? *(cur->kls_itr) : NULL;
300 }
301
302 static inline const Eo_Class *
303 _eo_kls_itr_next(Eo_Kls_Itr *cur, Eo_Op op)
304 {
305    if (cur->op != op)
306      {
307         Eo_Op node_op = cur->op;
308         ERR("Called with op %d ('%s') while expecting: %d ('%s'). This probaly means you called eo_*_super functions from a wrong place.",
309               op, _eo_op_id_name_get(op),
310               node_op, _eo_op_id_name_get(node_op));
311         return NULL;
312      }
313
314    const Eo_Class **kls_itr = cur->kls_itr;
315    if (*kls_itr)
316      {
317         if (op != EO_NOOP)
318           {
319              const op_type_funcs *fsrc = _dich_func_get(*kls_itr, op);
320
321              while (*kls_itr && (*(kls_itr++) != fsrc->src))
322                 ;
323           }
324         else
325           {
326              kls_itr++;
327           }
328
329         cur->kls_itr = kls_itr;
330         return *kls_itr;
331      }
332    else
333      {
334         return NULL;
335      }
336 }
337
338 static inline Eina_Bool
339 _eo_kls_itr_reached_end(const Eo_Kls_Itr *cur)
340 {
341    const Eo_Class **kls_itr = cur->kls_itr;
342    return !(*kls_itr && *(kls_itr + 1));
343 }
344
345 static inline const op_type_funcs *
346 _eo_kls_itr_func_get(const Eo_Class *klass, Eo_Kls_Itr *mro_itr, Eo_Op op, Eo_Kls_Itr *prev_state)
347 {
348    _eo_kls_itr_init(klass, mro_itr, op, prev_state);
349    klass = _eo_kls_itr_get(mro_itr);
350    if (klass)
351      {
352         const op_type_funcs *func = _dich_func_get(klass, op);
353
354         if (func && func->func)
355           {
356              return func;
357           }
358      }
359
360    return NULL;
361 }
362
363 #define _EO_OP_ERR_NO_OP_PRINT(op, klass) \
364    do \
365       { \
366          const Eo_Class *op_klass = OP_CLASS_GET(op); \
367          const char *_dom_name = (op_klass) ? op_klass->desc->name : NULL; \
368          ERR("Can't find func for op %x ('%s' of domain '%s') for class '%s'. Aborting.", \
369                op, _eo_op_id_name_get(op), _dom_name, \
370                (klass) ? klass->desc->name : NULL); \
371       } \
372    while (0)
373
374 static Eina_Bool
375 _eo_op_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, va_list *p_list)
376 {
377    Eina_Bool ret = EINA_FALSE;
378
379    const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
380
381    if (op_desc)
382      {
383         if (op_desc->op_type == EO_OP_TYPE_CLASS)
384           {
385              ERR("Tried calling a class op '%s' (%d) from a non-class context.", (op_desc) ? op_desc->name : NULL, op);
386              return EINA_FALSE;
387           }
388         else if ((op_type == EO_OP_TYPE_CONST) &&
389               (op_desc->op_type != EO_OP_TYPE_CONST))
390           {
391              ERR("Tried calling non-const or non-existant op '%s' (%d) from a const (query) function.", (op_desc) ? op_desc->name : NULL, op);
392              return EINA_FALSE;
393           }
394      }
395
396    Eo_Kls_Itr prev_state;
397
398      {
399         const op_type_funcs *func =
400            _eo_kls_itr_func_get(obj->klass, &obj->mro_itr, op, &prev_state);
401         if (func)
402           {
403              func->func(obj, _eo_data_get(obj, func->src), p_list);
404              ret = EINA_TRUE;
405              goto end;
406           }
407      }
408
409    /* Try composite objects */
410      {
411         Eina_List *itr;
412         Eo *emb_obj;
413         EINA_LIST_FOREACH(obj->composite_objects, itr, emb_obj)
414           {
415              if (_eo_op_internal(emb_obj, op_type, op, p_list))
416                {
417                   ret = EINA_TRUE;
418                   goto end;
419                }
420           }
421      }
422
423 end:
424    _eo_kls_itr_end(&obj->mro_itr, &prev_state);
425    return ret;
426 }
427
428 EAPI Eina_Bool
429 eo_do_internal(Eo *obj, Eo_Op_Type op_type, ...)
430 {
431    Eina_Bool ret = EINA_TRUE;
432    Eo_Op op = EO_NOOP;
433    va_list p_list;
434
435    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
436
437    _eo_ref(obj);
438
439    va_start(p_list, op_type);
440
441    op = va_arg(p_list, Eo_Op);
442    while (op)
443      {
444         if (!_eo_op_internal(obj, op_type, op, &p_list))
445           {
446              _EO_OP_ERR_NO_OP_PRINT(op, obj->klass);
447              ret = EINA_FALSE;
448              break;
449           }
450         op = va_arg(p_list, Eo_Op);
451      }
452
453    va_end(p_list);
454
455    _eo_unref(obj);
456    return ret;
457 }
458
459 EAPI Eina_Bool
460 eo_do_super_internal(Eo *obj, Eo_Op_Type op_type, Eo_Op op, ...)
461 {
462    const Eo_Class *nklass;
463    Eina_Bool ret = EINA_TRUE;
464    va_list p_list;
465    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
466
467    /* Advance the kls itr. */
468    nklass = _eo_kls_itr_next(&obj->mro_itr, op);
469
470    if (obj->mro_itr.op != op)
471       return EINA_FALSE;
472
473    va_start(p_list, op);
474    if (!_eo_op_internal(obj, op_type, op, &p_list))
475      {
476         _EO_OP_ERR_NO_OP_PRINT(op, nklass);
477         ret = EINA_FALSE;
478      }
479    va_end(p_list);
480
481    return ret;
482 }
483
484 static Eina_Bool
485 _eo_class_op_internal(Eo_Class *klass, Eo_Op op, va_list *p_list)
486 {
487    Eina_Bool ret = EINA_FALSE;
488
489    const Eo_Op_Description *op_desc = _eo_op_id_desc_get(op);
490
491    if (op_desc)
492      {
493         if (op_desc->op_type != EO_OP_TYPE_CLASS)
494           {
495              ERR("Tried calling an instant op '%s' (%d) from a class context.", (op_desc) ? op_desc->name : NULL, op);
496              return EINA_FALSE;
497           }
498      }
499
500    Eo_Kls_Itr prev_state;
501
502      {
503         const op_type_funcs *func =
504            _eo_kls_itr_func_get(klass, &klass->mro_itr, op, &prev_state);
505         if (func)
506           {
507              ((eo_op_func_type_class) func->func)(klass, p_list);
508              ret = EINA_TRUE;
509              goto end;
510           }
511      }
512
513 end:
514    _eo_kls_itr_end(&klass->mro_itr, &prev_state);
515    return ret;
516 }
517
518 EAPI Eina_Bool
519 eo_class_do_internal(const Eo_Class *klass, ...)
520 {
521    Eina_Bool ret = EINA_TRUE;
522    Eo_Op op = EO_NOOP;
523    va_list p_list;
524
525    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
526
527    va_start(p_list, klass);
528
529    op = va_arg(p_list, Eo_Op);
530    while (op)
531      {
532         if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list))
533           {
534              _EO_OP_ERR_NO_OP_PRINT(op, klass);
535              ret = EINA_FALSE;
536              break;
537           }
538         op = va_arg(p_list, Eo_Op);
539      }
540
541    va_end(p_list);
542
543    return ret;
544 }
545
546 EAPI Eina_Bool
547 eo_class_do_super_internal(const Eo_Class *klass, Eo_Op op, ...)
548 {
549    const Eo_Class *nklass;
550    Eina_Bool ret = EINA_TRUE;
551    va_list p_list;
552    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, EINA_FALSE);
553
554    /* Advance the kls itr. */
555    nklass = _eo_kls_itr_next(&((Eo_Class *) klass)->mro_itr, op);
556
557    if (klass->mro_itr.op != op)
558       return EINA_FALSE;
559
560    va_start(p_list, op);
561    if (!_eo_class_op_internal((Eo_Class *) klass, op, &p_list))
562      {
563         _EO_OP_ERR_NO_OP_PRINT(op, nklass);
564         ret = EINA_FALSE;
565      }
566    va_end(p_list);
567
568    return ret;
569 }
570
571 EAPI const Eo_Class *
572 eo_class_get(const Eo *obj)
573 {
574    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, EINA_FALSE);
575
576    return obj->klass;
577 }
578
579 EAPI const char *
580 eo_class_name_get(const Eo_Class *klass)
581 {
582    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
583
584    return klass->desc->name;
585 }
586
587 static void
588 _eo_class_base_op_init(Eo_Class *klass)
589 {
590    const Eo_Class_Description *desc = klass->desc;
591    if (!desc || !desc->ops.base_op_id)
592       return;
593
594    /* FIXME: Depends on values defined above! */
595    *(desc->ops.base_op_id) = klass->class_id << OP_CLASS_OFFSET;
596 }
597
598 #ifndef NDEBUG
599 static Eina_Bool
600 _eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find)
601 {
602    const Eo_Class **itr;
603    for (itr = klass->mro ; *itr ; itr++)
604      {
605         if (*itr == find)
606           {
607              return EINA_TRUE;
608           }
609      }
610
611    return EINA_FALSE;
612 }
613 #endif
614
615 static Eina_List *
616 _eo_class_mro_add(Eina_List *mro, const Eo_Class *klass)
617 {
618    Eina_List *extn_pos = NULL;
619    Eina_Bool check_consistency = !mro;
620    if (!klass)
621       return mro;
622
623    mro = eina_list_append(mro, klass);
624
625    /* Recursively add extenions. */
626      {
627         Eo_Extension_Node *extn;
628         EINA_INLIST_FOREACH(klass->extensions, extn)
629           {
630              mro = _eo_class_mro_add(mro, extn->klass);
631              /* Not possible: if (!mro) return NULL; */
632
633              if (check_consistency)
634                {
635                   extn_pos = eina_list_append(extn_pos, eina_list_last(mro));
636                }
637           }
638      }
639
640    /* Check if we can create a consistent mro. We only do it for the class
641     * we are working on (i.e no parents). */
642    if (check_consistency)
643      {
644         Eo_Extension_Node *extn;
645
646         Eina_List *itr = extn_pos;
647         EINA_INLIST_FOREACH(klass->extensions, extn)
648           {
649              /* Get the first one after the extension. */
650              Eina_List *extn_list = eina_list_next(eina_list_data_get(itr));
651
652              /* If we found the extension again. */
653              if (eina_list_data_find_list(extn_list, extn->klass))
654                {
655                   eina_list_free(mro);
656                   ERR("Cannot create a consistent method resolution order for class '%s' because of '%s'.", klass->desc->name, extn->klass->desc->name);
657                   return NULL;
658                }
659
660              itr = eina_list_next(itr);
661           }
662      }
663
664
665    mro = _eo_class_mro_add(mro, klass->parent);
666
667    return mro;
668 }
669
670 static Eina_Bool
671 _eo_class_mro_init(Eo_Class *klass)
672 {
673    Eina_List *mro = NULL;
674
675    DBG("Started creating MRO for class '%s'", klass->desc->name);
676    mro = _eo_class_mro_add(mro, klass);
677
678    if (!mro)
679       return EINA_FALSE;
680
681    /* Remove duplicates and make them the right order. */
682      {
683         Eina_List *itr1, *itr2, *itr2n;
684
685         itr1 = eina_list_last(mro);
686         while (itr1)
687           {
688              itr2 = eina_list_prev(itr1);
689
690              while (itr2)
691                {
692                   itr2n = eina_list_prev(itr2);
693
694                   if (eina_list_data_get(itr1) == eina_list_data_get(itr2))
695                     {
696                        mro = eina_list_remove_list(mro, itr2);
697                     }
698
699                   itr2 = itr2n;
700                }
701
702              itr1 = eina_list_prev(itr1);
703           }
704      }
705
706    /* Copy the mro and free the list. */
707      {
708         const Eo_Class *kls_itr;
709         const Eo_Class **mro_itr;
710         klass->mro = calloc(sizeof(*klass->mro), eina_list_count(mro) + 1);
711
712         mro_itr = klass->mro;
713
714         EINA_LIST_FREE(mro, kls_itr)
715           {
716              *(mro_itr++) = kls_itr;
717
718              DBG("Added '%s' to MRO", kls_itr->desc->name);
719           }
720         *(mro_itr) = NULL;
721      }
722
723    DBG("Finished creating MRO for class '%s'", klass->desc->name);
724
725    return EINA_TRUE;
726 }
727
728 static void
729 _eo_class_constructor(Eo_Class *klass)
730 {
731    if (klass->constructed)
732       return;
733
734    klass->constructed = EINA_TRUE;
735
736    if (klass->desc->class_constructor)
737       klass->desc->class_constructor(klass);
738 }
739
740 EAPI void
741 eo_class_funcs_set(Eo_Class *klass, const Eo_Op_Func_Description *func_descs)
742 {
743    EO_MAGIC_RETURN(klass, EO_CLASS_EINA_MAGIC);
744
745    const Eo_Op_Func_Description *itr;
746    itr = func_descs;
747    if (itr)
748      {
749         for ( ; itr->op != 0 ; itr++)
750           {
751              const Eo_Op_Description *op_desc = _eo_op_id_desc_get(itr->op);
752
753              if (EINA_LIKELY(!op_desc || (itr->op_type == op_desc->op_type)))
754                {
755                   _dich_func_set(klass, itr->op, itr->func);
756                }
757              else
758                {
759                   ERR("Set function's op type (%d) is different than the one in the op description (%d) for op '%s' in class '%s'.", itr->op_type, op_desc->op_type, op_desc->name, klass->desc->name);
760                }
761           }
762      }
763 }
764
765 static void
766 eo_class_free(Eo_Class *klass)
767 {
768    if (klass->constructed)
769      {
770         if (klass->desc->class_destructor)
771            klass->desc->class_destructor(klass);
772
773         _dich_func_clean_all(klass);
774      }
775
776      {
777         Eina_Inlist *itrn;
778         Eo_Extension_Node *extn = NULL;
779         EINA_INLIST_FOREACH_SAFE(klass->extensions, itrn, extn)
780           {
781              free(extn);
782           }
783      }
784
785    if (klass->mro)
786       free(klass->mro);
787
788    if (klass->extn_data_off)
789       free(klass->extn_data_off);
790
791    free(klass);
792 }
793
794 /* DEVCHECK */
795 static Eina_Bool
796 _eo_class_check_op_descs(const Eo_Class *klass)
797 {
798    const Eo_Class_Description *desc = klass->desc;
799    const Eo_Op_Description *itr;
800    size_t i;
801
802    if (desc->ops.count > 0)
803      {
804         if (!desc->ops.base_op_id)
805           {
806              ERR("Class '%s' has a non-zero ops count, but base_id is NULL.",
807                    desc->name);
808              return EINA_FALSE;
809           }
810
811         if (!desc->ops.descs)
812           {
813              ERR("Class '%s' has a non-zero ops count, but there are no descs.",
814                    desc->name);
815              return EINA_FALSE;
816           }
817      }
818
819    itr = desc->ops.descs;
820    for (i = 0 ; i < desc->ops.count ; i++, itr++)
821      {
822         if (itr->sub_op != i)
823           {
824              if (itr->name)
825                {
826                   ERR("Wrong order in Ops description for class '%s'. Expected %d and got %d", desc->name, i, itr->sub_op);
827                }
828              else
829                {
830                   ERR("Found too few Ops description for class '%s'. Expected %d descriptions, but found %d.", desc->name, desc->ops.count, i);
831                }
832              return EINA_FALSE;
833           }
834      }
835
836    if (itr && itr->name)
837      {
838         ERR("Found extra Ops description for class '%s'. Expected %d descriptions, but found more.", desc->name, desc->ops.count);
839         return EINA_FALSE;
840      }
841
842    return EINA_TRUE;
843 }
844
845 EAPI const Eo_Class *
846 eo_class_new(const Eo_Class_Description *desc, const Eo_Class *parent, ...)
847 {
848    Eo_Class *klass;
849    va_list p_list;
850
851    if (parent && !EINA_MAGIC_CHECK(parent, EO_CLASS_EINA_MAGIC))
852      {
853         EINA_MAGIC_FAIL(parent, EO_CLASS_EINA_MAGIC);
854         return NULL;
855      }
856
857    va_start(p_list, parent);
858
859    EINA_SAFETY_ON_NULL_RETURN_VAL(desc, NULL);
860    EINA_SAFETY_ON_NULL_RETURN_VAL(desc->name, NULL);
861
862    /* Check restrictions on Interface types. */
863    if (desc->type == EO_CLASS_TYPE_INTERFACE)
864      {
865         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->constructor, NULL);
866         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->destructor, NULL);
867         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_constructor, NULL);
868         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->class_destructor, NULL);
869         EINA_SAFETY_ON_FALSE_RETURN_VAL(!desc->data_size, NULL);
870      }
871
872    klass = calloc(1, sizeof(Eo_Class));
873    klass->parent = parent;
874
875    /* Handle class extensions */
876      {
877         Eo_Class *extn = NULL;
878
879         extn = va_arg(p_list, Eo_Class *);
880         while (extn)
881           {
882              switch (extn->desc->type)
883                {
884                 case EO_CLASS_TYPE_REGULAR:
885                 case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
886                    /* Use it like an interface. */
887                 case EO_CLASS_TYPE_INTERFACE:
888                    break;
889                 case EO_CLASS_TYPE_MIXIN:
890                      {
891                         Eo_Extension_Node *node = calloc(1, sizeof(*node));
892                         node->klass = extn;
893                         klass->extensions =
894                            eina_inlist_append(klass->extensions,
895                                  EINA_INLIST_GET(node));
896                      }
897                    break;
898                }
899
900              extn = va_arg(p_list, Eo_Class *);
901           }
902      }
903
904    klass->desc = desc;
905
906    /* Handle the inheritance */
907    if (klass->parent)
908      {
909         /* Verify the inheritance is allowed. */
910         switch (klass->desc->type)
911           {
912            case EO_CLASS_TYPE_REGULAR:
913            case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
914               if ((klass->parent->desc->type != EO_CLASS_TYPE_REGULAR) &&
915                     (klass->parent->desc->type != EO_CLASS_TYPE_REGULAR_NO_INSTANT))
916                 {
917                    ERR("Regular classes ('%s') aren't allowed to inherit from non-regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
918                    goto cleanup;
919                 }
920               break;
921            case EO_CLASS_TYPE_INTERFACE:
922            case EO_CLASS_TYPE_MIXIN:
923               if ((klass->parent->desc->type != EO_CLASS_TYPE_INTERFACE) &&
924                     (klass->parent->desc->type != EO_CLASS_TYPE_MIXIN))
925                 {
926                    ERR("Non-regular classes ('%s') aren't allowed to inherit from regular classes ('%s').", klass->desc->name, klass->parent->desc->name);
927                    goto cleanup;
928                 }
929               break;
930           }
931
932
933         /* Update the current offset. */
934         /* FIXME: Make sure this alignment is enough. */
935         klass->data_offset = klass->parent->data_offset +
936            EO_ALIGN_SIZE(klass->parent->desc->data_size);
937      }
938
939    if (!_eo_class_check_op_descs(klass))
940      {
941         goto cleanup;
942      }
943
944    if (!_eo_class_mro_init(klass))
945      {
946         goto cleanup;
947      }
948
949    /* create MIXIN offset table. */
950      {
951         const Eo_Class **mro_itr = klass->mro;
952         Eo_Extension_Data_Offset *extn_data_itr;
953         size_t extn_num = 0;
954         size_t extn_data_off = klass->data_offset +
955            EO_ALIGN_SIZE(klass->desc->data_size);
956
957         /* FIXME: Make faster... */
958         while (*mro_itr)
959           {
960              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
961                    ((*mro_itr)->desc->data_size > 0))
962                {
963                   extn_num++;
964                }
965              mro_itr++;
966           }
967
968         klass->extn_data_off = calloc(extn_num + 1,
969               sizeof(*klass->extn_data_off));
970
971         extn_data_itr = klass->extn_data_off;
972         mro_itr = klass->mro;
973         while (*mro_itr)
974           {
975              if (((*mro_itr)->desc->type == EO_CLASS_TYPE_MIXIN) &&
976                    ((*mro_itr)->desc->data_size > 0))
977                {
978                   extn_data_itr->klass = *mro_itr;
979                   extn_data_itr->offset = extn_data_off;
980
981                   extn_data_off += EO_ALIGN_SIZE(extn_data_itr->klass->desc->data_size);
982                   extn_data_itr++;
983                }
984              mro_itr++;
985           }
986
987         klass->extn_data_size = extn_data_off;
988      }
989
990    eina_lock_take(&_eo_class_creation_lock);
991    klass->class_id = ++_eo_classes_last_id;
992      {
993         /* FIXME: Handle errors. */
994         Eo_Class **tmp;
995         tmp = realloc(_eo_classes, _eo_classes_last_id * sizeof(*_eo_classes));
996         _eo_classes = tmp;
997         _eo_classes[klass->class_id - 1] = klass;
998      }
999    eina_lock_release(&_eo_class_creation_lock);
1000
1001    EINA_MAGIC_SET(klass, EO_CLASS_EINA_MAGIC);
1002
1003    /* Flatten the function array */
1004      {
1005         const Eo_Class **mro_itr = klass->mro;
1006         for (  ; *mro_itr ; mro_itr++)
1007            ;
1008
1009         for ( mro_itr-- ; mro_itr >= klass->mro ; mro_itr--)
1010           {
1011              _dich_copy_all(klass, *mro_itr);
1012           }
1013      }
1014
1015    _eo_class_base_op_init(klass);
1016
1017    _eo_class_constructor(klass);
1018
1019    va_end(p_list);
1020
1021    return klass;
1022
1023 cleanup:
1024    eo_class_free(klass);
1025    return NULL;
1026 }
1027
1028 EAPI Eo *
1029 eo_add(const Eo_Class *klass, Eo *parent)
1030 {
1031    EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
1032
1033    if (parent) EO_MAGIC_RETURN_VAL(parent, EO_EINA_MAGIC, NULL);
1034
1035    if (EINA_UNLIKELY(klass->desc->type != EO_CLASS_TYPE_REGULAR))
1036      {
1037         ERR("Class '%s' is not instantiate-able. Aborting.", klass->desc->name);
1038         return NULL;
1039      }
1040
1041    Eo *obj = calloc(1, EO_ALIGN_SIZE(sizeof(*obj)) +
1042          (klass->data_offset + EO_ALIGN_SIZE(klass->desc->data_size)) +
1043          klass->extn_data_size);
1044    obj->klass = klass;
1045    obj->parent = parent;
1046
1047    obj->refcount++;
1048
1049    Eo_Kls_Itr prev_state;
1050
1051    _eo_kls_itr_init(klass, &obj->mro_itr, EO_NOOP, &prev_state);
1052    _eo_error_unset(obj);
1053
1054    EINA_MAGIC_SET(obj, EO_EINA_MAGIC);
1055    _eo_ref(obj);
1056    _eo_constructor(obj, klass);
1057
1058    if (EINA_UNLIKELY(_eo_error_get(obj)))
1059      {
1060         ERR("Type '%s' - One of the object constructors have failed.", klass->desc->name);
1061         goto fail;
1062      }
1063
1064    if (EINA_UNLIKELY(!_eo_kls_itr_reached_end(&obj->mro_itr)))
1065      {
1066         ERR("Type '%s' - Not all of the object constructors have been executed.", klass->desc->name);
1067         goto fail;
1068      }
1069    _eo_kls_itr_end(&obj->mro_itr, &prev_state);
1070    _eo_unref(obj);
1071
1072    return obj;
1073
1074 fail:
1075    _eo_kls_itr_end(&obj->mro_itr, &prev_state);
1076    /* Unref twice, once for the ref above, and once for the basic object ref. */
1077    _eo_unref(obj);
1078    _eo_unref(obj);
1079    return NULL;
1080 }
1081
1082 typedef struct
1083 {
1084    EINA_INLIST;
1085    const Eo *ref_obj;
1086    const char *file;
1087    int line;
1088 } Eo_Xref_Node;
1089
1090 EAPI Eo *
1091 eo_xref_internal(Eo *obj, const Eo *ref_obj, const char *file, int line)
1092 {
1093    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
1094
1095    _eo_ref(obj);
1096
1097 #ifndef NDEBUG
1098    Eo_Xref_Node *xref = calloc(1, sizeof(*xref));
1099    xref->ref_obj = ref_obj;
1100    xref->file = file;
1101    xref->line = line;
1102
1103    /* FIXME: Make it sorted. */
1104    obj->xrefs = eina_inlist_prepend(obj->xrefs, EINA_INLIST_GET(xref));
1105 #else
1106    (void) ref_obj;
1107    (void) file;
1108    (void) line;
1109 #endif
1110
1111    return obj;
1112 }
1113
1114 EAPI void
1115 eo_xunref(Eo *obj, const Eo *ref_obj)
1116 {
1117    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1118 #ifndef NDEBUG
1119    Eo_Xref_Node *xref = NULL;
1120    EINA_INLIST_FOREACH(obj->xrefs, xref)
1121      {
1122         if (xref->ref_obj == ref_obj)
1123            break;
1124      }
1125
1126    if (xref)
1127      {
1128         obj->xrefs = eina_inlist_remove(obj->xrefs, EINA_INLIST_GET(xref));
1129         free(xref);
1130      }
1131    else
1132      {
1133         ERR("ref_obj (%p) does not reference obj (%p). Aborting unref.", ref_obj, obj);
1134         return;
1135      }
1136 #else
1137    (void) ref_obj;
1138 #endif
1139    _eo_unref(obj);
1140 }
1141
1142 static inline Eo *
1143 _eo_ref(Eo *obj)
1144 {
1145    obj->refcount++;
1146    return obj;
1147 }
1148
1149 EAPI Eo *
1150 eo_ref(const Eo *_obj)
1151 {
1152    Eo *obj = (Eo *) _obj;
1153    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, obj);
1154
1155    return _eo_ref(obj);
1156 }
1157
1158 static void
1159 _eo_del_internal(Eo *obj)
1160 {
1161    if (obj->del)
1162       return;
1163    /* We need that for the event callbacks that may ref/unref. */
1164    obj->refcount++;
1165
1166    eo_do(obj, eo_event_callback_call(EO_EV_DEL, NULL, NULL));
1167    obj->del = EINA_TRUE;
1168
1169    const Eo_Class *klass = eo_class_get(obj);
1170    Eo_Kls_Itr prev_state;
1171
1172    _eo_kls_itr_init(klass, &obj->mro_itr, EO_NOOP, &prev_state);
1173    _eo_error_unset(obj);
1174    _eo_destructor(obj, klass);
1175    if (_eo_error_get(obj))
1176      {
1177         ERR("Type '%s' - One of the object destructors have failed.", klass->desc->name);
1178      }
1179
1180    if (!_eo_kls_itr_reached_end(&obj->mro_itr))
1181      {
1182         ERR("Type '%s' - Not all of the object destructors have been executed.", klass->desc->name);
1183      }
1184    _eo_kls_itr_end(&obj->mro_itr, &prev_state);
1185    /*FIXME: add eo_class_unref(klass) ? - just to clear the caches. */
1186
1187    Eina_List *itr, *itr_n;
1188    Eo *emb_obj;
1189    EINA_LIST_FOREACH_SAFE(obj->composite_objects, itr, itr_n, emb_obj)
1190      {
1191         eo_composite_object_detach(obj, emb_obj);
1192      }
1193
1194    obj->refcount--;
1195 }
1196
1197 static inline void
1198 _eo_free(Eo *obj)
1199 {
1200    EINA_MAGIC_SET(obj, EO_DELETED_EINA_MAGIC);
1201    free(obj);
1202 }
1203
1204 static inline void
1205 _eo_unref(Eo *obj)
1206 {
1207    if (--(obj->refcount) == 0)
1208      {
1209         _eo_del_internal(obj);
1210
1211 #ifndef NDEBUG
1212         /* If for some reason it's not empty, clear it. */
1213         while (obj->xrefs)
1214           {
1215              WRN("obj->xrefs is not empty, possibly a bug, please report. - An error will be reported for each xref in the stack.");
1216              Eina_Inlist *nitr = obj->xrefs->next;
1217              free(EINA_INLIST_CONTAINER_GET(obj->xrefs, Eo_Xref_Node));
1218              obj->xrefs = nitr;
1219           }
1220 #endif
1221
1222         if (!obj->manual_free) _eo_free(obj);
1223      }
1224 }
1225
1226 EAPI void
1227 eo_unref(const Eo *_obj)
1228 {
1229    Eo *obj = (Eo *) _obj;
1230    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1231
1232    _eo_unref(obj);
1233 }
1234
1235 EAPI int
1236 eo_ref_get(const Eo *obj)
1237 {
1238    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, 0);
1239
1240    return obj->refcount;
1241 }
1242
1243 EAPI void
1244 eo_del(Eo *obj)
1245 {
1246    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1247
1248    _eo_del_internal(obj);
1249    _eo_unref(obj);
1250 }
1251
1252 EAPI Eo *
1253 eo_parent_get(const Eo *obj)
1254 {
1255    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1256
1257    return obj->parent;
1258 }
1259
1260 EAPI void
1261 eo_error_set_internal(const Eo *obj, const char *file, int line)
1262 {
1263    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1264
1265    ERR("Error with obj '%p' at %s:%d", obj, file, line);
1266
1267    ((Eo *) obj)->construct_error = EINA_TRUE;
1268 }
1269
1270 static inline void
1271 _eo_error_unset(Eo *obj)
1272 {
1273    obj->construct_error = EINA_FALSE;
1274 }
1275
1276 /**
1277  * @internal
1278  * @brief Check if there was an error when constructing, destructing or calling a function of the object.
1279  * @param obj the object to work on.
1280  * @return @c EINA_TRUE if there was an error.
1281  */
1282 static inline Eina_Bool
1283 _eo_error_get(const Eo *obj)
1284 {
1285    return obj->construct_error;
1286 }
1287
1288 static inline void
1289 _eo_constructor_default(Eo *obj)
1290 {
1291    eo_constructor_super(obj);
1292 }
1293
1294 static inline void
1295 _eo_destructor_default(Eo *obj)
1296 {
1297    eo_destructor_super(obj);
1298 }
1299
1300 static void
1301 _eo_constructor(Eo *obj, const Eo_Class *klass)
1302 {
1303    if (!klass)
1304       return;
1305
1306    if (klass->desc->constructor)
1307       klass->desc->constructor(obj, _eo_data_get(obj, klass));
1308    else
1309       _eo_constructor_default(obj);
1310 }
1311
1312 static void
1313 _eo_destructor(Eo *obj, const Eo_Class *klass)
1314 {
1315    if (!klass)
1316       return;
1317
1318    if (klass->desc->destructor)
1319       klass->desc->destructor(obj, _eo_data_get(obj, klass));
1320    else
1321       _eo_destructor_default(obj);
1322 }
1323
1324 EAPI void
1325 eo_constructor_super(Eo *obj)
1326 {
1327    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1328
1329    _eo_constructor(obj, _eo_kls_itr_next(&obj->mro_itr, EO_NOOP));
1330 }
1331
1332 EAPI void
1333 eo_destructor_super(Eo *obj)
1334 {
1335    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1336
1337    _eo_destructor(obj, _eo_kls_itr_next(&obj->mro_itr, EO_NOOP));
1338 }
1339
1340 static inline void *
1341 _eo_data_get(const Eo *obj, const Eo_Class *klass)
1342 {
1343    if (EINA_LIKELY(klass->desc->data_size > 0))
1344      {
1345         if (EINA_UNLIKELY(klass->desc->type == EO_CLASS_TYPE_MIXIN))
1346           {
1347              Eo_Extension_Data_Offset *doff_itr =
1348                 eo_class_get(obj)->extn_data_off;
1349
1350              if (!doff_itr)
1351                 return NULL;
1352
1353              while (doff_itr->klass)
1354                {
1355                   if (doff_itr->klass == klass)
1356                      return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1357                            doff_itr->offset;
1358                   doff_itr++;
1359                }
1360           }
1361         else
1362           {
1363           return ((char *) obj) + EO_ALIGN_SIZE(sizeof(*obj)) +
1364              klass->data_offset;
1365           }
1366      }
1367
1368    return NULL;
1369 }
1370
1371 EAPI void *
1372 eo_data_get(const Eo *obj, const Eo_Class *klass)
1373 {
1374    void *ret;
1375    EO_MAGIC_RETURN_VAL(obj, EO_EINA_MAGIC, NULL);
1376
1377 #ifndef NDEBUG
1378    if (!_eo_class_mro_has(obj->klass, klass))
1379      {
1380         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);
1381         return NULL;
1382      }
1383 #endif
1384
1385    ret = _eo_data_get(obj, klass);
1386
1387 #ifndef NDEBUG
1388    if (!ret && (klass->desc->data_size == 0))
1389      {
1390         ERR("Tried getting data of class '%s', but it has none..", klass->desc->name);
1391      }
1392 #endif
1393
1394    return ret;
1395 }
1396
1397 EAPI Eina_Bool
1398 eo_init(void)
1399 {
1400    const char *log_dom = "eo";
1401    if (_eo_init_count++ > 0)
1402       return EINA_TRUE;
1403
1404    eina_init();
1405
1406    _eo_classes = NULL;
1407    _eo_classes_last_id = 0;
1408    _eo_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_LIGHTBLUE);
1409    if (_eo_log_dom < 0)
1410      {
1411         EINA_LOG_ERR("Could not register log domain: %s", log_dom);
1412         return EINA_FALSE;
1413      }
1414
1415    if (!eina_lock_new(&_eo_class_creation_lock))
1416      {
1417         EINA_LOG_ERR("Could not init lock.");
1418         return EINA_FALSE;
1419      }
1420
1421    eina_magic_string_static_set(EO_EINA_MAGIC, EO_EINA_MAGIC_STR);
1422    eina_magic_string_static_set(EO_DELETED_EINA_MAGIC,
1423          EO_DELETED_EINA_MAGIC_STR);
1424    eina_magic_string_static_set(EO_CLASS_EINA_MAGIC,
1425          EO_CLASS_EINA_MAGIC_STR);
1426
1427    return EINA_TRUE;
1428 }
1429
1430 EAPI Eina_Bool
1431 eo_shutdown(void)
1432 {
1433    size_t i;
1434    Eo_Class **cls_itr = _eo_classes;
1435
1436    if (--_eo_init_count > 0)
1437       return EINA_TRUE;
1438
1439    for (i = 0 ; i < _eo_classes_last_id ; i++, cls_itr++)
1440      {
1441         if (*cls_itr)
1442            eo_class_free(*cls_itr);
1443      }
1444
1445    if (_eo_classes)
1446       free(_eo_classes);
1447
1448    eina_lock_free(&_eo_class_creation_lock);
1449
1450    eina_log_domain_unregister(_eo_log_dom);
1451    _eo_log_dom = -1;
1452
1453    eina_shutdown();
1454    return EINA_TRUE;
1455 }
1456
1457 EAPI void
1458 eo_composite_object_attach(Eo *obj, Eo *emb_obj)
1459 {
1460    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1461    EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
1462
1463    eo_xref(emb_obj, obj);
1464    obj->composite_objects = eina_list_prepend(obj->composite_objects, emb_obj);
1465 }
1466
1467 EAPI void
1468 eo_composite_object_detach(Eo *obj, Eo *emb_obj)
1469 {
1470    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1471    EO_MAGIC_RETURN(emb_obj, EO_EINA_MAGIC);
1472
1473    obj->composite_objects = eina_list_remove(obj->composite_objects, emb_obj);
1474    eo_xunref(emb_obj, obj);
1475 }
1476
1477 EAPI Eina_Bool
1478 eo_composite_is(const Eo *emb_obj)
1479 {
1480    if (!EINA_MAGIC_CHECK(emb_obj, EO_EINA_MAGIC))
1481      {
1482         EINA_MAGIC_FAIL(emb_obj, EO_EINA_MAGIC);
1483         return EINA_FALSE;
1484      }
1485
1486    Eo *obj = eo_parent_get(emb_obj);
1487    Eina_List *itr;
1488    Eo *tmp;
1489
1490    if (!obj)
1491       return EINA_FALSE;
1492
1493    EINA_LIST_FOREACH(obj->composite_objects, itr, tmp)
1494      {
1495         if (tmp == emb_obj)
1496            return EINA_TRUE;
1497      }
1498
1499    return EINA_FALSE;
1500 }
1501
1502 EAPI void
1503 eo_manual_free_set(Eo *obj, Eina_Bool manual_free)
1504 {
1505    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1506    obj->manual_free = manual_free;
1507 }
1508
1509 EAPI void
1510 eo_manual_free(Eo *obj)
1511 {
1512    EO_MAGIC_RETURN(obj, EO_EINA_MAGIC);
1513
1514    if (EINA_FALSE == obj->manual_free)
1515      {
1516         ERR("Tried to free manually the object %p while the option has not been set; see eo_manual_free_set for more information.", obj);
1517         return;
1518      }
1519
1520    if (0 != obj->refcount)
1521      {
1522         ERR("Tried deleting the object %p while still referenced(%d).", obj, eo_ref_get(obj));
1523         return;
1524      }
1525
1526    _eo_free(obj);
1527 }
1528