From: Matthias Bolte Date: Sat, 6 Oct 2012 16:30:45 +0000 (+0200) Subject: esx: Fix dynamic dispatch for types with more than one level of inheritance X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=69037428d74cd04485621269e1042b893d7ed50b;p=libvirt.git esx: Fix dynamic dispatch for types with more than one level of inheritance Traverse the whole inheritance hierarchy for dynamic dispatch as it is already done for the dynamic cast. Also make AnyType cast errors more verbose. Reported by Ata Bohra. --- diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py index 6ddd10cc97..2883ac0d97 100755 --- a/src/esx/esx_vi_generator.py +++ b/src/esx/esx_vi_generator.py @@ -484,6 +484,26 @@ class Object(Type): return members + def generate_dispatch(self, suffix, is_first=True): + source = "" + + if self.extended_by is not None: + if not is_first: + source += "\n" + + source += " /* %s */\n" % self.name + + for extended_by in self.extended_by: + source += " ESX_VI__TEMPLATE__DISPATCH__%s(%s)\n" \ + % (suffix, extended_by) + + for extended_by in self.extended_by: + source += objects_by_name[extended_by] \ + .generate_dispatch(suffix, False) + + return source + + def generate_free_code(self, add_banner=False): source = "" @@ -835,9 +855,7 @@ class Object(Type): source += "ESX_VI__TEMPLATE__DYNAMIC_DEEP_COPY(%s,\n" % self.name source += "{\n" - for extended_by in self.extended_by: - source += " ESX_VI__TEMPLATE__DISPATCH__DEEP_COPY(%s)\n" \ - % extended_by + source += self.generate_dispatch('DEEP_COPY') source += "},\n" source += "{\n" @@ -863,9 +881,7 @@ class Object(Type): % self.name source += "{\n" - for extended_by in self.extended_by: - source += " ESX_VI__TEMPLATE__DISPATCH__CAST_FROM_ANY_TYPE(%s)\n" \ - % extended_by + source += self.generate_dispatch('CAST_FROM_ANY_TYPE') source += "})\n\n" @@ -895,9 +911,7 @@ class Object(Type): source += "ESX_VI__TEMPLATE__DYNAMIC_SERIALIZE(%s,\n" % self.name source += "{\n" - for extended_by in self.extended_by: - source += " ESX_VI__TEMPLATE__DISPATCH__SERIALIZE(%s)\n" \ - % extended_by + source += self.generate_dispatch('SERIALIZE') source += "},\n" source += "{\n" @@ -933,9 +947,7 @@ class Object(Type): % self.name source += "{\n" - for extended_by in self.extended_by: - source += " ESX_VI__TEMPLATE__DISPATCH__DESERIALIZE(%s)\n" \ - % extended_by + source += self.generate_dispatch('DESERIALIZE') source += "},\n" source += "{\n" diff --git a/src/esx/esx_vi_types.c b/src/esx/esx_vi_types.c index d2c71c7ed8..c5ddb51734 100644 --- a/src/esx/esx_vi_types.c +++ b/src/esx/esx_vi_types.c @@ -212,8 +212,10 @@ { \ if (anyType->type != esxVI_Type_##_type) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - _("Call to %s for unexpected type '%s'"), \ - __FUNCTION__, anyType->other); \ + _("Call to %s for unexpected type '%s', " \ + "expected '%s'"), \ + __FUNCTION__, anyType->other, \ + esxVI_Type_ToString(esxVI_Type_##_type)); \ return -1; \ } \ }, /* nothing */) @@ -225,8 +227,10 @@ { \ if (anyType->type != esxVI_Type_##_type) { \ virReportError(VIR_ERR_INTERNAL_ERROR, \ - _("Call to %s for unexpected type '%s'"), \ - __FUNCTION__, anyType->other); \ + _("Call to %s for unexpected type '%s', " \ + "expected '%s'"), \ + __FUNCTION__, anyType->other, \ + esxVI_Type_ToString(esxVI_Type_##_type)); \ return -1; \ } \ }, Value)