[libvirt] [PATCH] esx: Fix generator for string return values

Distinguish between strings as parameters (const char *) and strings as return values (char **). --- src/esx/esx_vi_generator.py | 19 +++++++++++++------ src/esx/esx_vi_methods.c | 22 ++++++++++++---------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py index be96a03..f9e8e11 100755 --- a/src/esx/esx_vi_generator.py +++ b/src/esx/esx_vi_generator.py @@ -52,9 +52,10 @@ class Parameter: "SessionManager" : "sessionManager", "VirtualDiskManager" : "virtualDiskManager" } - def __init__(self, type, name, occurrence): + def __init__(self, type, name, occurrence, is_return_value = False): self.type = type self.occurrence = occurrence + self.is_return_value = is_return_value if ':' in name and name.startswith("_this"): self.name, self.autobind_type = name.split(":") @@ -96,7 +97,7 @@ class Parameter: def generate_return(self, offset = 0, end_of_line = ";"): if self.occurrence == OCCURRENCE__IGNORED: - raise ValueError("invalid function parameteroccurrence value '%s'" % self.occurrence) + raise ValueError("invalid function parameter occurrence value '%s'" % self.occurrence) else: string = " " string += " " * offset @@ -130,7 +131,10 @@ class Parameter: if self.type == "String" and \ self.occurrence not in [OCCURRENCE__REQUIRED_LIST, OCCURRENCE__OPTIONAL_LIST]: - return "const char *" + if self.is_return_value: + return "char *" + else: + return "const char *" elif self.is_enum(): return "esxVI_%s " % self.type else: @@ -227,9 +231,11 @@ class Method: source += "),\n" if self.returns is None: - source += " void, None,\n" + source += " void, /* nothing */, None,\n" + elif self.returns.type == "String": + source += " String, Value, %s,\n" % self.returns.get_occurrence_short_enum() else: - source += " %s, %s,\n" % (self.returns.type, self.returns.get_occurrence_short_enum()) + source += " %s, /* nothing */, %s,\n" % (self.returns.type, self.returns.get_occurrence_short_enum()) source += "{\n" @@ -1054,7 +1060,8 @@ def parse_method(block): report_error("line %d: invalid block header" % (number)) else: returns = Parameter(type = header_items[3], name = "output", - occurrence = header_items[4]) + occurrence = header_items[4], + is_return_value = True) parameters = [] diff --git a/src/esx/esx_vi_methods.c b/src/esx/esx_vi_methods.c index a00561f..5967088 100644 --- a/src/esx/esx_vi_methods.c +++ b/src/esx/esx_vi_methods.c @@ -67,34 +67,34 @@ -#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__None(_type) \ +#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__None(_type, _suffix) \ /* nothing */ -#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type) \ - if (esxVI_##_type##_Deserialize(response->node, output) < 0) { \ +#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredItem(_type, _suffix) \ + if (esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \ goto cleanup; \ } -#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type) \ +#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__RequiredList(_type, _suffix) \ if (esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ goto cleanup; \ } -#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type) \ +#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalItem(_type, _suffix) \ if (response->node != NULL && \ - esxVI_##_type##_Deserialize(response->node, output) < 0) { \ + esxVI_##_type##_Deserialize##_suffix(response->node, output) < 0) { \ goto cleanup; \ } -#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type) \ +#define ESX_VI__METHOD__DESERIALIZE_OUTPUT__OptionalList(_type, _suffix) \ if (response->node != NULL && \ esxVI_##_type##_DeserializeList(response->node, output) < 0) { \ goto cleanup; \ @@ -103,7 +103,8 @@ #define ESX_VI__METHOD(_name, _this_from_service, _parameters, _output_type, \ - _occurrence, _validate, _serialize) \ + _deserialize_suffix, _occurrence, _validate, \ + _serialize) \ int \ esxVI_##_name _parameters \ { \ @@ -139,7 +140,8 @@ goto cleanup; \ } \ \ - ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence(_output_type) \ + ESX_VI__METHOD__DESERIALIZE_OUTPUT__##_occurrence \ + (_output_type, _deserialize_suffix) \ \ result = 0; \ \ @@ -296,7 +298,7 @@ ESX_VI__METHOD(ValidateMigration, /* special _this */, esxVI_ManagedObjectReference *pool, /* optional */ esxVI_ManagedObjectReference *host, /* optional */ esxVI_Event **output), /* optional, list */ - Event, OptionalList, + Event, /* nothing */, OptionalList, { ESX_VI__METHOD__PARAMETER__REQUIRE(vm) }, -- 1.7.0.4

On 08/29/2010 05:00 PM, Matthias Bolte wrote:
Distinguish between strings as parameters (const char *) and strings as return values (char **).
Here, you mention char**,
if self.type == "String" and \ self.occurrence not in [OCCURRENCE__REQUIRED_LIST, OCCURRENCE__OPTIONAL_LIST]: - return "const char *" + if self.is_return_value: + return "char *"
But here, it is only char*. Which is it? Other than that, I'm not very good with python (yet), so while I didn't spot anything glaringly wrong, I'm probably not the best reviewer. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2010/8/30 Eric Blake <eblake@redhat.com>:
On 08/29/2010 05:00 PM, Matthias Bolte wrote:
Distinguish between strings as parameters (const char *) and strings as return values (char **).
Here, you mention char**,
if self.type == "String" and \ self.occurrence not in [OCCURRENCE__REQUIRED_LIST, OCCURRENCE__OPTIONAL_LIST]: - return "const char *" + if self.is_return_value: + return "char *"
But here, it is only char*. Which is it?
That's a bit tricky. In case Parameter.get_type_string() is called from Parameter.generate_return() then string += "%s*%s)%s" % (self.get_type_string(), self.name, end_of_line) in line 104 adds the second *. I attached v2 where this is simplified. Matthias

On 09/01/2010 09:32 AM, Matthias Bolte wrote:
That's a bit tricky. In case Parameter.get_type_string() is called from Parameter.generate_return() then
string += "%s*%s)%s" % (self.get_type_string(), self.name, end_of_line)
in line 104 adds the second *.
I attached v2 where this is simplified.
Yes, it's much easier to see in v2. ACK, if you trust my minimal python reviewing skills. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

2010/9/1 Eric Blake <eblake@redhat.com>:
On 09/01/2010 09:32 AM, Matthias Bolte wrote:
That's a bit tricky. In case Parameter.get_type_string() is called from Parameter.generate_return() then
string += "%s*%s)%s" % (self.get_type_string(), self.name, end_of_line)
in line 104 adds the second *.
I attached v2 where this is simplified.
Yes, it's much easier to see in v2. ACK, if you trust my minimal python reviewing skills.
Well, your first review already improved the patch :) Thanks, pushed v2. Matthias
participants (2)
-
Eric Blake
-
Matthias Bolte