summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-01-08 11:13:34 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-01-08 11:13:34 +0100
commitd8408ea079b94c37414278a30f783040780c48ab (patch)
treefdedd376416aafb1254757de630145b7b767fe31
parent7831150d7d155317c7fe5ca19a0ccc4aac0ab371 (diff)
eo2: improve _eo2_class_funcs_set() errors support
as op descs are sorted, we can't output fct indexes in error msgs, but as they are sorted using api_fct as key, we can detect multiple usage of the same api_fct which leads to an unpredictable call to whatever is returned by _eo2_api_op_id_get()->_eo2_api_desc_get(). it is still possible to instanciate an object of a not well defined class.
-rw-r--r--src/lib/eo/eo.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/lib/eo/eo.c b/src/lib/eo/eo.c
index 148be51f88..fe4e6acf11 100644
--- a/src/lib/eo/eo.c
+++ b/src/lib/eo/eo.c
@@ -681,25 +681,37 @@ EAPI void
681_eo2_class_funcs_set(_Eo_Class *klass) 681_eo2_class_funcs_set(_Eo_Class *klass)
682{ 682{
683 int op_id; 683 int op_id;
684 const void *last_api_func;
684 const Eo2_Op_Description *api_desc; 685 const Eo2_Op_Description *api_desc;
685 Eo2_Op_Description *op_desc; 686 Eo2_Op_Description *op_desc;
686 Eo2_Op_Description *op_descs; 687 Eo2_Op_Description *op_descs;
687 688
689 op_id = klass->base_id;
688 op_descs = klass->desc->ops.descs2; 690 op_descs = klass->desc->ops.descs2;
689 691
690 qsort((void*)op_descs, klass->desc->ops.count, sizeof(Eo2_Op_Description), eo2_api_funcs_cmp); 692 qsort((void*)op_descs, klass->desc->ops.count, sizeof(Eo2_Op_Description), eo2_api_funcs_cmp);
691 693
692 op_id = klass->base_id; 694 DBG("Set functions for class '%s':%p", klass->desc->name, klass);
693 DBG("Set functions for class '%s' %p", klass->desc->name, klass); 695
694 if (!op_descs) return; 696 if (!op_descs) return;
697
698 last_api_func = NULL;
695 for (op_desc = op_descs; op_desc->op_type != EO_OP_TYPE_INVALID; op_desc++) 699 for (op_desc = op_descs; op_desc->op_type != EO_OP_TYPE_INVALID; op_desc++)
696 { 700 {
697 if(op_desc->api_func == NULL) 701 if(op_desc->api_func == NULL)
698 ERR("Setting implementation for NULL API. Class '%s', Func index: %lu", 702 {
699 klass->desc->name, (unsigned long) (op_desc - op_descs)); 703 ERR("Ignore %d NULL->%p '%s'. Can't set implementation for NULL API.",
704 op_desc->op, op_desc->func, op_desc->doc);
705 continue;
706 }
700 707
701 if (op_desc->op == EO_NOOP) 708 if (op_desc->op == EO_NOOP)
702 { 709 {
710 if (op_desc->api_func == last_api_func)
711 {
712 ERR("API already defined %d %p->%p '%s'. Expect undefined behaviour.",
713 op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc);
714 }
703 op_desc->op = op_id; 715 op_desc->op = op_id;
704 op_id++; 716 op_id++;
705 } 717 }
@@ -708,20 +720,20 @@ _eo2_class_funcs_set(_Eo_Class *klass)
708 api_desc = _eo2_api_desc_get(op_desc->api_func, klass->parent, klass->extensions); 720 api_desc = _eo2_api_desc_get(op_desc->api_func, klass->parent, klass->extensions);
709 721
710 if (api_desc == NULL) 722 if (api_desc == NULL)
711 ERR("Can't find api func %p description in class hierarchy. Class '%s', Func index: %lu", 723 {
712 op_desc->api_func, klass->desc->name, (unsigned long) (op_desc - op_descs)); 724 ERR("Ignore override %p->%p. Can't find api func description in class hierarchy.",
725 op_desc->api_func, op_desc->func);
726 continue;
727 }
713 728
714 op_desc->op = api_desc->op; 729 op_desc->op = api_desc->op;
715 op_desc->doc = api_desc->doc; 730 op_desc->doc = api_desc->doc;
716
717 if (op_desc->op == EO_NOOP)
718 ERR("API func %p, not found in direct parent '%s'. Class '%s', Func index: %lu",
719 op_desc->api_func, klass->parent->desc->name,
720 klass->desc->name, (unsigned long) (op_desc - op_descs));
721 } 731 }
722 732
723 DBG(" %4d %p %p %s", op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc); 733 DBG(" %4d %p->%p '%s'", op_desc->op, op_desc->api_func, op_desc->func, op_desc->doc);
734
724 _dich_func_set(klass, op_desc->op, op_desc->func); 735 _dich_func_set(klass, op_desc->op, op_desc->func);
736 last_api_func = op_desc->api_func;
725 } 737 }
726} 738}
727 739