summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Dahlin <johan@gnome.org>2010-05-27 00:08:20 -0300
committerJohan Dahlin <johan@gnome.org>2010-05-27 00:09:55 -0300
commite77f99fba5fce4dd0d4810707aa1aeac2ba0fb50 (patch)
treea837d6e79a57c2f085f42a8794dc535afc6d51a7
parent666bb8d76a648011a49f14b6db4558e256c8e31b (diff)
downloadgobject-introspection-e77f99fba5fce4dd0d4810707aa1aeac2ba0fb50.tar.gz
[scanner] Element-type annotation for GArray types
Add support for (element-type) annotations for G*Array types. https://bugzilla.gnome.org/show_bug.cgi?id=619545
-rw-r--r--giscanner/annotationparser.py17
-rw-r--r--tests/scanner/annotation-1.0-expected.gir12
-rw-r--r--tests/scanner/annotation-1.0-expected.tgir12
-rw-r--r--tests/scanner/annotation.c9
-rw-r--r--tests/scanner/annotation.h3
5 files changed, 49 insertions, 4 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index b1d4ea00..180de6be 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -647,15 +647,20 @@ class AnnotationApplier(object):
return True
return False
+ def _is_array_type(self, node):
+ if node.type.name in ['GLib.Array', 'GLib.PtrArray',
+ 'GLib.ByteArray']:
+ return True
+ if node.type.ctype in ['GArray*', 'GPtrArray*', 'GByteArray*']:
+ return True
+ return False
+
def _extract_container_type(self, parent, node, options):
has_element_type = OPT_ELEMENT_TYPE in options
has_array = OPT_ARRAY in options
if not has_array:
- has_array = \
- node.type.name in ['GLib.Array', 'GLib.PtrArray',
- 'GLib.ByteArray'] or \
- node.type.ctype in ['GArray*', 'GPtrArray*', 'GByteArray*']
+ has_array = self._is_array_type(node)
# FIXME: This is a hack :-(
if (not isinstance(node, Field) and
@@ -781,6 +786,10 @@ class AnnotationApplier(object):
node.type.ctype,
self._resolve(element_type[0]),
self._resolve(element_type[1]))
+ elif self._is_array_type(node):
+ container_type = Array(node.type.name,
+ node.type.ctype,
+ self._resolve(element_type[0]))
else:
print 'FIXME: unhandled element-type container:', node
return container_type
diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir
index 035b32e1..25216d1a 100644
--- a/tests/scanner/annotation-1.0-expected.gir
+++ b/tests/scanner/annotation-1.0-expected.gir
@@ -607,6 +607,18 @@ detection, and fixing it via annotations.">
</parameter>
</parameters>
</function>
+ <function name="ptr_array" c:identifier="annotation_ptr_array">
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="array" transfer-ownership="none" doc="the array">
+ <array name="GLib.PtrArray" c:type="GPtrArray*">
+ <type name="GLib.Value"/>
+ </array>
+ </parameter>
+ </parameters>
+ </function>
<function name="return_array" c:identifier="annotation_return_array">
<return-value transfer-ownership="full" doc="The return value">
<array length="0" c:type="char**">
diff --git a/tests/scanner/annotation-1.0-expected.tgir b/tests/scanner/annotation-1.0-expected.tgir
index 3b37cf2b..aafd0701 100644
--- a/tests/scanner/annotation-1.0-expected.tgir
+++ b/tests/scanner/annotation-1.0-expected.tgir
@@ -440,6 +440,18 @@
</parameter>
</parameters>
</function>
+ <function name="ptr_array" c:identifier="annotation_ptr_array">
+ <return-value transfer-ownership="none">
+ <type name="none"/>
+ </return-value>
+ <parameters>
+ <parameter name="array" transfer-ownership="none">
+ <array>
+ <type name="GLib.Value"/>
+ </array>
+ </parameter>
+ </parameters>
+ </function>
<function name="return_array" c:identifier="annotation_return_array">
<return-value transfer-ownership="full">
<array length="0">
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index fb025b97..e1376e4c 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -673,4 +673,13 @@ annotation_set_source_file (const char *fname)
{
}
+/**
+ * annotation_ptr_array:
+ * @array: (element-type GLib.Value): the array
+ */
+void
+annotation_ptr_array (GPtrArray *array)
+{
+}
+
char backslash_parsing_tester_2 = '\\';
diff --git a/tests/scanner/annotation.h b/tests/scanner/annotation.h
index 798594b1..0f47d22e 100644
--- a/tests/scanner/annotation.h
+++ b/tests/scanner/annotation.h
@@ -149,4 +149,7 @@ struct AnnotationStruct
AnnotationObject *objects[10];
};
+void annotation_ptr_array (GPtrArray *array);
+
#endif /* __ANNOTATION_OBJECT_H__ */
+