aboutsummaryrefslogtreecommitdiffstats
path: root/build-aux
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux')
-rw-r--r--build-aux/qmi-codegen/Variable.py12
-rw-r--r--build-aux/qmi-codegen/VariableString.py44
-rw-r--r--build-aux/qmi-codegen/VariableStruct.py3
3 files changed, 53 insertions, 6 deletions
diff --git a/build-aux/qmi-codegen/Variable.py b/build-aux/qmi-codegen/Variable.py
index d3691a3..6b534d7 100644
--- a/build-aux/qmi-codegen/Variable.py
+++ b/build-aux/qmi-codegen/Variable.py
@@ -16,6 +16,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2012 Lanedo GmbH
+# Copyright (C) 2012-2015 Aleksander Morgado <aleksander@aleksander.es>
#
import string
@@ -54,6 +55,11 @@ class Variable:
else:
raise ValueError("Invalid endian value %s" % endian)
+ """
+ Initially all variables are flagged as not being public
+ """
+ self.public = False
+
"""
Emits the code to declare specific new types required by the variable.
"""
@@ -150,3 +156,9 @@ class Variable:
"""
def add_sections(self, sections):
pass
+
+ """
+ Flag as being public
+ """
+ def flag_public(self):
+ self.public = True
diff --git a/build-aux/qmi-codegen/VariableString.py b/build-aux/qmi-codegen/VariableString.py
index b58a7d2..01452f5 100644
--- a/build-aux/qmi-codegen/VariableString.py
+++ b/build-aux/qmi-codegen/VariableString.py
@@ -16,6 +16,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2012 Lanedo GmbH
+# Copyright (C) 2012-2015 Aleksander Morgado <aleksander@aleksander.es>
#
import string
@@ -83,10 +84,24 @@ class VariableString(Variable):
if self.is_fixed_size:
translations['fixed_size'] = self.fixed_size
- template = (
- '${lp}if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, ${fixed_size}, &${variable_name}[0], ${error}))\n'
- '${lp} goto ${tlv_out};\n'
- '${lp}${variable_name}[${fixed_size}] = \'\\0\';\n')
+
+ # Fixed sized strings exposed in public fields will need to be
+ # explicitly allocated in heap
+ if self.public:
+ translations['fixed_size_plus_one'] = int(self.fixed_size) + 1
+ template = (
+ '${lp}${variable_name} = g_malloc (${fixed_size_plus_one});\n'
+ '${lp}if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, ${fixed_size}, &${variable_name}[0], ${error})) {\n'
+ '${lp} g_free (${variable_name});\n'
+ '${lp} ${variable_name} = NULL;\n'
+ '${lp} goto ${tlv_out};\n'
+ '${lp}}\n'
+ '${lp}${variable_name}[${fixed_size}] = \'\\0\';\n')
+ else:
+ template = (
+ '${lp}if (!qmi_message_tlv_read_fixed_size_string (message, init_offset, &offset, ${fixed_size}, &${variable_name}[0], ${error}))\n'
+ '${lp} goto ${tlv_out};\n'
+ '${lp}${variable_name}[${fixed_size}] = \'\\0\';\n')
else:
translations['n_size_prefix_bytes'] = self.n_size_prefix_bytes
translations['max_size'] = self.max_size if self.max_size != '' else '0'
@@ -158,7 +173,13 @@ class VariableString(Variable):
translations = { 'lp' : line_prefix,
'name' : variable_name }
- if self.is_fixed_size:
+ if public:
+ # Fixed sized strings given in public structs are given as pointers,
+ # instead of as fixed-sized arrays directly in the struct.
+ template = (
+ '${lp}gchar *${name};\n')
+ self.is_public = True
+ elif self.is_fixed_size:
translations['fixed_size_plus_one'] = int(self.fixed_size) + 1
template = (
'${lp}gchar ${name}[${fixed_size_plus_one}];\n')
@@ -309,7 +330,7 @@ class VariableString(Variable):
"""
def build_dispose(self, line_prefix, variable_name):
# Fixed-size strings don't need dispose
- if self.is_fixed_size:
+ if self.is_fixed_size and not self.public:
return ''
translations = { 'lp' : line_prefix,
@@ -318,3 +339,14 @@ class VariableString(Variable):
template = (
'${lp}g_free (${variable_name});\n')
return string.Template(template).substitute(translations)
+
+
+ """
+ Flag as being public
+ """
+ def flag_public(self):
+ # Call the parent method
+ Variable.flag_public(self)
+ # Fixed-sized strings will need dispose if they are in the public header
+ if self.is_fixed_size:
+ self.needs_dispose = True
diff --git a/build-aux/qmi-codegen/VariableStruct.py b/build-aux/qmi-codegen/VariableStruct.py
index 445af71..78e6752 100644
--- a/build-aux/qmi-codegen/VariableStruct.py
+++ b/build-aux/qmi-codegen/VariableStruct.py
@@ -16,6 +16,7 @@
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright (C) 2012 Lanedo GmbH
+# Copyright (C) 2012-2015 Aleksander Morgado <aleksander@aleksander.es>
#
import string
@@ -48,6 +49,8 @@ class VariableStruct(Variable):
member = {}
member['name'] = utils.build_underscore_name(member_dictionary['name'])
member['object'] = VariableFactory.create_variable(member_dictionary, struct_type_name + ' ' + member['name'], self.container_type)
+ # Specify that the variable will be defined in the public header
+ member['object'].flag_public()
self.members.append(member)
# We'll need to dispose if at least one of the members needs it