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