summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Morgado <aleksander@lanedo.com>2012-09-25 14:41:37 +0200
committerAleksander Morgado <aleksander@lanedo.com>2012-09-26 09:45:42 +0200
commitc4a85b1f960247d2f614975d182049d010b36eb3 (patch)
treee48d589aaece8aaa8680fcffd61c74432163e6c7
parenta336eca159f3c8c9b7f2f65c05c9adefb2617322 (diff)
qmi-codegen: don't issue the array element clear function on 'Input' arrays
When an array is required to be passed in an input TLV, the user who created it is responsible for freeing it. Therefore, we should not dump the static array element clear function in these cases, or these unused methods will end up breaking the compilation.
-rw-r--r--build-aux/qmi-codegen/Container.py4
-rw-r--r--build-aux/qmi-codegen/Field.py6
-rw-r--r--build-aux/qmi-codegen/VariableArray.py20
-rw-r--r--build-aux/qmi-codegen/VariableFactory.py8
-rw-r--r--build-aux/qmi-codegen/VariableSequence.py6
-rw-r--r--build-aux/qmi-codegen/VariableStruct.py5
6 files changed, 32 insertions, 17 deletions
diff --git a/build-aux/qmi-codegen/Container.py b/build-aux/qmi-codegen/Container.py
index 4b9e2f9..c9c5785 100644
--- a/build-aux/qmi-codegen/Container.py
+++ b/build-aux/qmi-codegen/Container.py
@@ -88,9 +88,9 @@ class Container:
if field_dictionary['type'] == 'TLV':
if field_dictionary['format'] == 'struct' and \
field_dictionary['name'] == 'Result':
- self.fields.append(FieldResult(self.fullname, field_dictionary, common_objects_dictionary))
+ self.fields.append(FieldResult(self.fullname, field_dictionary, common_objects_dictionary, container_type))
else:
- self.fields.append(Field(self.fullname, field_dictionary, common_objects_dictionary))
+ self.fields.append(Field(self.fullname, field_dictionary, common_objects_dictionary, container_type))
"""
diff --git a/build-aux/qmi-codegen/Field.py b/build-aux/qmi-codegen/Field.py
index 2a5758a..751725d 100644
--- a/build-aux/qmi-codegen/Field.py
+++ b/build-aux/qmi-codegen/Field.py
@@ -32,7 +32,7 @@ class Field:
"""
Constructor
"""
- def __init__(self, prefix, dictionary, common_objects_dictionary):
+ def __init__(self, prefix, dictionary, common_objects_dictionary, container_type):
# The field prefix, usually the name of the Container,
# e.g. "Qmi Message Ctl Something Output"
self.prefix = prefix
@@ -44,13 +44,15 @@ class Field:
self.mandatory = dictionary['mandatory']
# The type, which must always be "TLV"
self.type = dictionary['type']
+ # The container type, which must be either "Input" or "Output"
+ self.container_type = container_type
# Create the composed full name (prefix + name),
# e.g. "Qmi Message Ctl Something Output Result"
self.fullname = dictionary['fullname'] if 'fullname' in dictionary else self.prefix + ' ' + self.name
# Create our variable object
- self.variable = VariableFactory.create_variable(dictionary, self.fullname)
+ self.variable = VariableFactory.create_variable(dictionary, self.fullname, self.container_type)
# Create the variable name within the Container
self.variable_name = 'arg_' + string.lower(utils.build_underscore_name(self.name))
diff --git a/build-aux/qmi-codegen/VariableArray.py b/build-aux/qmi-codegen/VariableArray.py
index 47ff6ff..f5bc65f 100644
--- a/build-aux/qmi-codegen/VariableArray.py
+++ b/build-aux/qmi-codegen/VariableArray.py
@@ -31,7 +31,7 @@ class VariableArray(Variable):
"""
Constructor
"""
- def __init__(self, dictionary, array_element_type):
+ def __init__(self, dictionary, array_element_type, container_type):
# Call the parent constructor
Variable.__init__(self, dictionary)
@@ -44,11 +44,16 @@ class VariableArray(Variable):
# The array and its contents need to get disposed
self.needs_dispose = True
+ # We need to know whether the variable comes in an Input container or in
+ # an Output container, as we should not dump the element clear() helper method
+ # if the variable is from an Input container.
+ self.container_type = container_type
+
# Load variable type of this array
if 'name' in dictionary['array-element']:
- self.array_element = VariableFactory.create_variable(dictionary['array-element'], array_element_type + ' ' + dictionary['array-element']['name'])
+ self.array_element = VariableFactory.create_variable(dictionary['array-element'], array_element_type + ' ' + dictionary['array-element']['name'], self.container_type)
else:
- self.array_element = VariableFactory.create_variable(dictionary['array-element'], '')
+ self.array_element = VariableFactory.create_variable(dictionary['array-element'], '', self.container_type)
# Load variable type for the array size prefix
if 'size-prefix-format' in dictionary:
@@ -56,7 +61,7 @@ class VariableArray(Variable):
if dictionary['size-prefix-format'] not in [ 'guint8', 'guint16', 'guint32' ]:
raise ValueError('Invalid size prefix format (%s): not guint8 or guint16 or guint32' % dictionary['size-prefix-format'])
default_array_size = { 'format' : dictionary['size-prefix-format'] }
- self.array_size_element = VariableFactory.create_variable(default_array_size, '')
+ self.array_size_element = VariableFactory.create_variable(default_array_size, '', self.container_type)
elif 'fixed-size' in dictionary:
# fixed-size arrays have no size element, obviously
self.fixed_size = dictionary['fixed-size']
@@ -65,7 +70,7 @@ class VariableArray(Variable):
else:
# Default to 'guint8' if no explicit array size given
default_array_size = { 'format' : 'guint8' }
- self.array_size_element = VariableFactory.create_variable(default_array_size, '')
+ self.array_size_element = VariableFactory.create_variable(default_array_size, '', self.container_type)
"""
@@ -97,6 +102,11 @@ class VariableArray(Variable):
if self.array_element.needs_dispose == False:
return
+ # No need for the clear func if we were not the ones who created
+ # the array
+ if self.container_type == "Input":
+ return
+
translations = { 'element_format' : self.array_element.public_format,
'underscore' : self.clear_func_name(),
'dispose_contents' : self.array_element.build_dispose(' ', '(*p)') }
diff --git a/build-aux/qmi-codegen/VariableFactory.py b/build-aux/qmi-codegen/VariableFactory.py
index e1d5c95..48b1541 100644
--- a/build-aux/qmi-codegen/VariableFactory.py
+++ b/build-aux/qmi-codegen/VariableFactory.py
@@ -30,16 +30,16 @@ from VariableArray import VariableArray
Helps in the creation of Variable objects based on the specific 'format' found
in the given dictionary
"""
-def create_variable(dictionary, new_type_name):
+def create_variable(dictionary, new_type_name, container_type):
if utils.format_is_integer(dictionary['format']):
return VariableInteger(dictionary)
elif dictionary['format'] == 'string':
return VariableString(dictionary)
elif dictionary['format'] == 'struct':
- return VariableStruct(dictionary, new_type_name)
+ return VariableStruct(dictionary, new_type_name, container_type)
elif dictionary['format'] == 'sequence':
- return VariableSequence(dictionary, new_type_name)
+ return VariableSequence(dictionary, new_type_name, container_type)
elif dictionary['format'] == 'array':
- return VariableArray(dictionary, new_type_name)
+ return VariableArray(dictionary, new_type_name, container_type)
else:
raise RuntimeError('Unexpected field format \'%s\'' % dictionary['format'])
diff --git a/build-aux/qmi-codegen/VariableSequence.py b/build-aux/qmi-codegen/VariableSequence.py
index 79fff5c..6e6777a 100644
--- a/build-aux/qmi-codegen/VariableSequence.py
+++ b/build-aux/qmi-codegen/VariableSequence.py
@@ -31,17 +31,19 @@ class VariableSequence(Variable):
"""
Constructor
"""
- def __init__(self, dictionary, sequence_type_name):
+ def __init__(self, dictionary, sequence_type_name, container_type):
# Call the parent constructor
Variable.__init__(self, dictionary)
+ self.container_type = container_type
+
# Load members of this sequence
self.members = []
for member_dictionary in dictionary['contents']:
member = {}
member['name'] = utils.build_underscore_name(member_dictionary['name'])
- member['object'] = VariableFactory.create_variable(member_dictionary, sequence_type_name + ' ' + member['name'])
+ member['object'] = VariableFactory.create_variable(member_dictionary, sequence_type_name + ' ' + member['name'], self.container_type)
self.members.append(member)
# TODO: do we need this?
diff --git a/build-aux/qmi-codegen/VariableStruct.py b/build-aux/qmi-codegen/VariableStruct.py
index b5aed87..5b582b2 100644
--- a/build-aux/qmi-codegen/VariableStruct.py
+++ b/build-aux/qmi-codegen/VariableStruct.py
@@ -31,7 +31,7 @@ class VariableStruct(Variable):
"""
Constructor
"""
- def __init__(self, dictionary, struct_type_name):
+ def __init__(self, dictionary, struct_type_name, container_type):
# Call the parent constructor
Variable.__init__(self, dictionary)
@@ -40,13 +40,14 @@ class VariableStruct(Variable):
# struct type name
self.public_format = utils.build_camelcase_name(struct_type_name)
self.private_format = self.public_format
+ self.container_type = container_type
# Load members of this struct
self.members = []
for member_dictionary in dictionary['contents']:
member = {}
member['name'] = utils.build_underscore_name(member_dictionary['name'])
- member['object'] = VariableFactory.create_variable(member_dictionary, struct_type_name + ' ' + member['name'])
+ member['object'] = VariableFactory.create_variable(member_dictionary, struct_type_name + ' ' + member['name'], self.container_type)
self.members.append(member)
# We'll need to dispose if at least one of the members needs it