summaryrefslogtreecommitdiff
path: root/giscanner
diff options
context:
space:
mode:
authorGiovanni Campagna <gcampagna@src.gnome.org>2011-07-02 15:31:38 +0200
committerGiovanni Campagna <gcampagna@src.gnome.org>2011-08-18 15:15:04 +0200
commit8a4e168dec871fca394f1bc24f80f9a6abb8ceec (patch)
tree58e1a594ef66fb78bf76814aabbfe8dd0cafd626 /giscanner
parente9b0c8013dd15d643e46dd6e763585d5fe1b5b45 (diff)
downloadgobject-introspection-8a4e168dec871fca394f1bc24f80f9a6abb8ceec.tar.gz
Forbid GPtrArrays holding non-pointer types
It should be safe for bindings to assume that GPtrArrays hold only pointers (or values as big as it), so there is no need to go through hoops for converting smaller integers when marshalling. Libraries that need arrays of integers should use GArray. https://bugzilla.gnome.org/show_bug.cgi?id=652753
Diffstat (limited to 'giscanner')
-rw-r--r--giscanner/ast.py4
-rw-r--r--giscanner/maintransformer.py14
2 files changed, 18 insertions, 0 deletions
diff --git a/giscanner/ast.py b/giscanner/ast.py
index 373daa9f..d2975afc 100644
--- a/giscanner/ast.py
+++ b/giscanner/ast.py
@@ -222,6 +222,10 @@ GIR_TYPES = [TYPE_NONE, TYPE_ANY]
GIR_TYPES.extend(BASIC_GIR_TYPES)
GIR_TYPES.extend([TYPE_STRING, TYPE_FILENAME, TYPE_VALIST])
+# These are the only basic types that are guaranteed to
+# be as big as a pointer (and thus are allowed in GPtrArray)
+POINTER_TYPES = [TYPE_ANY, TYPE_INTPTR, TYPE_UINTPTR]
+
INTROSPECTABLE_BASIC = list(GIR_TYPES)
for v in [TYPE_NONE, TYPE_ANY,
TYPE_LONG_LONG, TYPE_LONG_ULONG,
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 79004199..c89424fd 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -318,6 +318,18 @@ usage is void (*_gtk_reserved1)(void);"""
return block.position
+ def _check_array_element_type(self, array, options):
+ # GPtrArrays are allowed to contain non basic types
+ # (except enums and flags) or basic types that are
+ # as big as a gpointer
+ if array.array_type == ast.Array.GLIB_PTRARRAY and \
+ ((array.element_type in ast.BASIC_GIR_TYPES \
+ and not array.element_type in ast.POINTER_TYPES) or \
+ isinstance(array.element_type, ast.Enum) or \
+ isinstance(array.element_type, ast.Bitfield)):
+ message.warn("invalid (element-type) for a GPtrArray, "
+ "must be a pointer", options.position)
+
def _apply_annotations_array(self, parent, node, options):
array_opt = options.get(OPT_ARRAY)
if array_opt:
@@ -368,6 +380,7 @@ usage is void (*_gtk_reserved1)(void);"""
except ValueError:
# Already warned in annotationparser.py
return
+ self._check_array_element_type(container_type, options)
node.type = container_type
def _apply_annotations_element_type(self, parent, node, options):
@@ -409,6 +422,7 @@ usage is void (*_gtk_reserved1)(void);"""
return
node.type.element_type = self._resolve(element_type_opt.one(),
node.type, node, parent)
+ self._check_array_element_type(node.type, options)
else:
message.warn_node(parent,
"Unknown container %r for element-type annotation" % (node.type, ))