[gobject-introspection] Disallow non byte types for GByteArrays
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Disallow non byte types for GByteArrays
- Date: Thu, 18 Aug 2011 13:15:37 +0000 (UTC)
commit 4c90020f97be3b7a65287a80784b0e453a729fcc
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sat Jul 2 16:04:17 2011 +0200
Disallow non byte types for GByteArrays
Similarly to GPtrArrays, GByteArrays can only contain bytes. Emit
a warning if an inconsistent (element-type) is placed, and ensure
that the default is guint8 if nothing is added. This way bindings
can support GByteArrays without special casing them.
https://bugzilla.gnome.org/show_bug.cgi?id=652753
giscanner/maintransformer.py | 16 ++++++++++++++--
tests/gimarshallingtests.c | 2 +-
2 files changed, 15 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index c89424f..dafdcad 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -249,6 +249,9 @@ usage is void (*_gtk_reserved1)(void);"""
elif has_element_type:
self._apply_annotations_element_type(parent, node, options)
+ if isinstance(node.type, ast.Array):
+ self._check_array_element_type(node.type, options)
+
def _resolve(self, type_str, type_node=None, node=None, parent=None):
def grab_one(type_str, resolver, top_combiner, combiner):
"""Return a complete type, and the trailing string part after it.
@@ -330,6 +333,17 @@ usage is void (*_gtk_reserved1)(void);"""
message.warn("invalid (element-type) for a GPtrArray, "
"must be a pointer", options.position)
+ # GByteArrays have (element-type) guint8 by default
+ if array.array_type == ast.Array.GLIB_BYTEARRAY:
+ if array.element_type == ast.TYPE_ANY:
+ array.element_type = ast.TYPE_UINT8
+ elif not array.element_type in [ast.TYPE_UINT8,
+ ast.TYPE_INT8,
+ ast.TYPE_CHAR]:
+ message.warn("invalid (element-type) for a GByteArray, "
+ "must be one of guint8, gint8 or gchar",
+ options.position)
+
def _apply_annotations_array(self, parent, node, options):
array_opt = options.get(OPT_ARRAY)
if array_opt:
@@ -380,7 +394,6 @@ 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):
@@ -422,7 +435,6 @@ 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, ))
diff --git a/tests/gimarshallingtests.c b/tests/gimarshallingtests.c
index 279831b..e830081 100644
--- a/tests/gimarshallingtests.c
+++ b/tests/gimarshallingtests.c
@@ -2009,7 +2009,7 @@ gi_marshalling_tests_bytearray_full_return (void)
/**
* gi_marshalling_tests_bytearray_none_in:
- * @array_: (element-type gint) (transfer none):
+ * @array_: (element-type gint8) (transfer none):
*/
void
gi_marshalling_tests_bytearray_none_in (GByteArray *array_)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]