summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-01-09 14:43:26 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-01-09 14:43:26 +0100
commit03008c95f532c30c7c737d50cb04863f554f4b21 (patch)
treed4ff397eb3579898abc63547524a86f64bb217bf
parent890469314cee7b6a2d9ee2ffa9d69b071e36f371 (diff)
eo2: do not allow ill formed class creation
eo_class_new() returns NULL on error in _eo2_class_funcs_set(). it covers: NULL API func, API redefined, dich func override, overriding non-existing fct.
-rw-r--r--src/lib/eo/eo.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 3dee6dfd9e..df1f8c7152 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -96,7 +96,7 @@ _dich_func_get(const _Eo_Class *klass, Eo_Op op)
96 return &chain1->funcs[DICH_CHAIN_LAST(op)]; 96 return &chain1->funcs[DICH_CHAIN_LAST(op)];
97} 97}
98 98
99static inline void 99static inline Eina_Bool
100_dich_func_set(_Eo_Class *klass, Eo_Op op, eo_op_func_type func) 100_dich_func_set(_Eo_Class *klass, Eo_Op op, eo_op_func_type func)
101{ 101{
102 op_type_funcs *fsrc; 102 op_type_funcs *fsrc;
@@ -108,12 +108,15 @@ _dich_func_set(_Eo_Class *klass, Eo_Op op, eo_op_func_type func)
108 { 108 {
109 const _Eo_Class *op_kls = _eo_op_class_get(op); 109 const _Eo_Class *op_kls = _eo_op_class_get(op);
110 const char *op_name = _eo_op_id_name_get(op, op_kls->desc->version); 110 const char *op_name = _eo_op_id_name_get(op, op_kls->desc->version);
111 ERR("Already set function for op %d (%s:'%s'). Overriding %p with %p.", 111 ERR("Class '%s': Overriding func %p for op %d (%s:'%s') with %p.",
112 op, op_kls->desc->name, op_name, fsrc->func, func); 112 klass->desc->name, fsrc->func, op, op_kls->desc->name, op_name, func);
113 return EINA_FALSE;
113 } 114 }
114 115
115 fsrc->func = func; 116 fsrc->func = func;
116 fsrc->src = klass; 117 fsrc->src = klass;
118
119 return EINA_TRUE;
117} 120}
118 121
119static inline void 122static inline void
@@ -692,28 +695,29 @@ _eo2_class_funcs_set(_Eo_Class *klass)
692 op_id = klass->base_id; 695 op_id = klass->base_id;
693 op_descs = klass->desc->ops.descs2; 696 op_descs = klass->desc->ops.descs2;
694 697
695 qsort((void*)op_descs, klass->desc->ops.count, sizeof(Eo2_Op_Description), eo2_api_funcs_cmp);
696
697 DBG("Set functions for class '%s':%p", klass->desc->name, klass); 698 DBG("Set functions for class '%s':%p", klass->desc->name, klass);
698 699
699 if (!op_descs) return EINA_TRUE; 700 if (!op_descs) return EINA_TRUE;
700 701
702 qsort((void*)op_descs, klass->desc->ops.count, sizeof(Eo2_Op_Description), eo2_api_funcs_cmp);
703
701 last_api_func = NULL; 704 last_api_func = NULL;
702 for (op_desc = op_descs; op_desc->op_type != EO_OP_TYPE_INVALID; op_desc++) 705 for (op_desc = op_descs; op_desc->op_type != EO_OP_TYPE_INVALID; op_desc++)
703 { 706 {
704 if(op_desc->api_func == NULL) 707 if(op_desc->api_func == NULL)
705 { 708 {
706 ERR("Ignore %d NULL->%p '%s'. Can't set implementation for NULL API.", 709 ERR("Class '%s': NULL API not allowed (%d NULL->%p '%s').",
707 op_desc->op, op_desc->func, op_desc->doc); 710 klass->desc->name, op_desc->op, op_desc->func, op_desc->doc);
708 continue; 711 return EINA_FALSE;
709 } 712 }
710 713
711 if (op_desc->op == EO_NOOP) 714 if (op_desc->op == EO_NOOP)
712 { 715 {
713 if (op_desc->api_func == last_api_func) 716 if (op_desc->api_func == last_api_func)
714 { 717 {
715 ERR("API already defined %d %p->%p '%s'. Expect undefined behaviour.", 718 ERR("Class '%s': API previously defined (%d %p->%p '%s').",
716 op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc); 719 klass->desc->name, op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc);
720 return EINA_FALSE;
717 } 721 }
718 op_desc->op = op_id; 722 op_desc->op = op_id;
719 op_id++; 723 op_id++;
@@ -724,9 +728,9 @@ _eo2_class_funcs_set(_Eo_Class *klass)
724 728
725 if (api_desc == NULL) 729 if (api_desc == NULL)
726 { 730 {
727 ERR("Ignore override %p->%p. Can't find api func description in class hierarchy.", 731 ERR("Class '%s': Can't find api func description in class hierarchy (%p->%p).",
728 op_desc->api_func, op_desc->func); 732 klass->desc->name, op_desc->api_func, op_desc->func);
729 continue; 733 return EINA_FALSE;
730 } 734 }
731 735
732 op_desc->op = api_desc->op; 736 op_desc->op = api_desc->op;
@@ -735,7 +739,9 @@ _eo2_class_funcs_set(_Eo_Class *klass)
735 739
736 DBG(" %4d %p->%p '%s'", op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc); 740 DBG(" %4d %p->%p '%s'", op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc);
737 741
738 _dich_func_set(klass, op_desc->op, op_desc->func); 742 if (!_dich_func_set(klass, op_desc->op, op_desc->func))
743 return EINA_FALSE;
744
739 last_api_func = op_desc->api_func; 745 last_api_func = op_desc->api_func;
740 } 746 }
741 747