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