[libvirt] [PATCH] esx: Fix dynamic dispatch for types with more than one level of inheritance

Matthias Bolte matthias.bolte at googlemail.com
Sat Oct 6 16:32:09 UTC 2012


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 |   36 ++++++++++++++++++++++++------------
 src/esx/esx_vi_types.c      |   12 ++++++++----
 2 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index c4bbb03..af4e7e8 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 d2c71c7..c5ddb51 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)
-- 
1.7.4.1




More information about the libvir-list mailing list