]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
esx: Fix dynamic dispatch for types with more than one level of inheritance
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 6 Oct 2012 16:30:45 +0000 (18:30 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 9 Oct 2012 21:02:39 +0000 (23:02 +0200)
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.

src/esx/esx_vi_generator.py
src/esx/esx_vi_types.c

index 6ddd10cc971cf3d4a5fb49a1fb527a33bb82432d..2883ac0d97cd248c86a4afc8173a03975b4b99fd 100755 (executable)
@@ -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"
index d2c71c7ed849f12bc5b134d4a9d8309f98fd8469..c5ddb517343e6eba756e5a84937650bfaa0c28f4 100644 (file)
     {                                                                         \
         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 */)
     {                                                                         \
         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)