summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2019-01-07 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2019-01-07 11:19:30 +0100
commitd020c524bad9a9e26b124b85a356d3858b03cab7 (patch)
treeedede2442f1152cf6825c0093d07cc72284fa072 /giscanner
parent58e97dc13e33fc4fdfe83090fbde8ecc40662386 (diff)
downloadgobject-introspection-d020c524bad9a9e26b124b85a356d3858b03cab7.tar.gz
scanner: Flatten multi-dimensional arrays fields
Provide partial support for multi-dimensional arrays by representing them as flattened one dimensional array with size that is equal to product of sizes in each dimension. Previously only the first dimension would be actually used. This should be sufficient to ensure that those fields have layout compatible with C, without using nested array types that are currently unsupported by vapigen Issue #255.
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/transformer.py27
1 files changed, 17 insertions, 10 deletions
diff --git a/giscanner/transformer.py b/giscanner/transformer.py
index e2294a63..9911de70 100644
--- a/giscanner/transformer.py
+++ b/giscanner/transformer.py
@@ -551,25 +551,32 @@ raise ValueError."""
# Special handling for fields; we don't have annotations on them
# to apply later, yet.
if source_type.type == CTYPE_ARRAY:
+ # Determine flattened array size and its element type.
+ flattened_size = 1
+ while source_type.type == CTYPE_ARRAY:
+ for child in source_type.child_list:
+ if flattened_size is not None:
+ flattened_size *= child.const_int
+ break
+ else:
+ flattened_size = None
+ source_type = source_type.base_type
+
# If the array contains anonymous unions, like in the GValue
# struct, we need to handle this specially. This is necessary
# to be able to properly calculate the size of the compound
# type (e.g. GValue) that contains this array, see
# <https://bugzilla.gnome.org/show_bug.cgi?id=657040>.
- if (source_type.base_type.type == CTYPE_UNION
- and source_type.base_type.name is None):
- synthesized_type = self._synthesize_union_type(symbol, parent_symbol)
- ftype = ast.Array(None, synthesized_type)
+ if source_type.type == CTYPE_UNION and source_type.name is None:
+ element_type = self._synthesize_union_type(symbol, parent_symbol)
else:
ctype = self._create_source_type(source_type)
complete_ctype = self._create_complete_source_type(source_type)
- from_ctype = self.create_type_from_ctype_string(ctype,
- complete_ctype=complete_ctype)
- ftype = ast.Array(None, from_ctype)
- child_list = list(symbol.base_type.child_list)
+ element_type = self.create_type_from_ctype_string(ctype,
+ complete_ctype=complete_ctype)
+ ftype = ast.Array(None, element_type)
ftype.zeroterminated = False
- if child_list:
- ftype.size = child_list[0].const_int
+ ftype.size = flattened_size
else:
ftype = self._create_type_from_base(symbol.base_type)
# ast.Fields are assumed to be read-write