[gobject-introspection] Try harder to preserve c:type
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] Try harder to preserve c:type
- Date: Sat, 13 Aug 2011 17:39:53 +0000 (UTC)
commit 81abc2eb63317003a11d1484e84698a37e8ec035
Author: Johan Dahlin <johan gnome org>
Date: Sat Aug 13 14:36:53 2011 -0300
Try harder to preserve c:type
When we replace a type using annotation we should keep
the ctype of the original type.
giscanner/maintransformer.py | 6 ++-
tests/scanner/Annotation-1.0-expected.gir | 30 ++++++----
tests/scanner/Foo-1.0-expected.gir | 4 +-
tests/scanner/Regress-1.0-expected.gir | 84 ++++++++++++++--------------
tests/scanner/annotation.c | 11 ++++
tests/scanner/annotation.h | 1 +
6 files changed, 79 insertions(+), 57 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 1d26bf1..a86c722 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -297,6 +297,10 @@ usage is void (*_gtk_reserved1)(void);"""
text = type_str
message.warn_node(parent, "%s: Unknown type: %r" %
(text, result.ctype), positions=position)
+ # If we replace a node with a new type (such as an annotated) we
+ # might lose the ctype from the original node.
+ if type_node is not None:
+ result.ctype = type_node.ctype
return result
def _get_position(self, func, param):
@@ -944,7 +948,7 @@ method or constructor of some type."""
# A quick hack here...in the future we should catch C signature/GI signature
# mismatches in a general way in finaltransformer
- if first.type.ctype is not None and first.type.ctype.count('*') != 1:
+ if first.type.ctype is not None and first.type.ctype.count('*') > 1:
return False
if not func.is_method:
diff --git a/tests/scanner/Annotation-1.0-expected.gir b/tests/scanner/Annotation-1.0-expected.gir
index c544702..10f5e74 100644
--- a/tests/scanner/Annotation-1.0-expected.gir
+++ b/tests/scanner/Annotation-1.0-expected.gir
@@ -54,14 +54,14 @@ and/or use gtk-doc annotations. -->
<return-value transfer-ownership="container">
<doc xml:whitespace="preserve">list of strings</doc>
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
<parameters>
<parameter name="in" transfer-ownership="none">
<doc xml:whitespace="preserve">list of strings</doc>
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</parameter>
</parameters>
@@ -238,8 +238,8 @@ objects.</doc>
<return-value transfer-ownership="full">
<doc xml:whitespace="preserve">hash table</doc>
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="GObject.Object"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="GObject.Object" c:type="GHashTable*"/>
</type>
</return-value>
</method>
@@ -250,7 +250,7 @@ intentionally similar example to gtk_container_get_children</doc>
<return-value transfer-ownership="container">
<doc xml:whitespace="preserve">list of objects</doc>
<type name="GLib.SList" c:type="GSList*">
- <type name="Object"/>
+ <type name="Object" c:type="GSList*"/>
</type>
</return-value>
</method>
@@ -260,7 +260,7 @@ each string needs to be freed.</doc>
<return-value transfer-ownership="full">
<doc xml:whitespace="preserve">list of strings</doc>
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
</method>
@@ -410,7 +410,7 @@ each string needs to be freed.</doc>
<parameter name="data" transfer-ownership="none">
<doc xml:whitespace="preserve">The data</doc>
<array length="1" zero-terminated="0" c:type="gchar*">
- <type name="gint8"/>
+ <type name="gint8" c:type="gchar*"/>
</array>
</parameter>
<parameter name="length" transfer-ownership="none">
@@ -429,7 +429,7 @@ type.</doc>
<parameter name="data" transfer-ownership="none">
<doc xml:whitespace="preserve">The data</doc>
<array length="1" zero-terminated="0" c:type="gpointer">
- <type name="guint8"/>
+ <type name="guint8" c:type="gpointer"/>
</array>
</parameter>
<parameter name="length" transfer-ownership="none">
@@ -677,7 +677,7 @@ detection, and fixing it via annotations.</doc>
<function name="get_source_file" c:identifier="annotation_get_source_file">
<return-value transfer-ownership="full">
<doc xml:whitespace="preserve">Source file</doc>
- <type name="filename"/>
+ <type name="filename" c:type="char*"/>
</return-value>
</function>
<function name="init" c:identifier="annotation_init">
@@ -725,7 +725,7 @@ detection, and fixing it via annotations.</doc>
<parameter name="array" transfer-ownership="none">
<doc xml:whitespace="preserve">the array</doc>
<array name="GLib.PtrArray" c:type="GPtrArray*">
- <type name="GLib.Value"/>
+ <type name="GLib.Value" c:type="GPtrArray*"/>
</array>
</parameter>
</parameters>
@@ -747,6 +747,12 @@ detection, and fixing it via annotations.</doc>
</parameter>
</parameters>
</function>
+ <function name="return_filename" c:identifier="annotation_return_filename">
+ <return-value transfer-ownership="full">
+ <doc xml:whitespace="preserve">An annotated filename</doc>
+ <type name="filename" c:type="gchar*"/>
+ </return-value>
+ </function>
<function name="set_source_file" c:identifier="annotation_set_source_file">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
@@ -754,7 +760,7 @@ detection, and fixing it via annotations.</doc>
<parameters>
<parameter name="fname" transfer-ownership="none">
<doc xml:whitespace="preserve">Source file</doc>
- <type name="filename"/>
+ <type name="filename" c:type="char*"/>
</parameter>
</parameters>
</function>
@@ -776,7 +782,7 @@ detection, and fixing it via annotations.</doc>
</parameter>
<parameter name="properties" transfer-ownership="none">
<array length="0" zero-terminated="0" c:type="gchar*">
- <type name="utf8"/>
+ <type name="utf8" c:type="gchar*"/>
</array>
</parameter>
</parameters>
diff --git a/tests/scanner/Foo-1.0-expected.gir b/tests/scanner/Foo-1.0-expected.gir
index 1772b56..f18ed56 100644
--- a/tests/scanner/Foo-1.0-expected.gir
+++ b/tests/scanner/Foo-1.0-expected.gir
@@ -355,7 +355,7 @@ and/or use gtk-doc annotations. -->
uses a C sugar return type.</doc>
<return-value transfer-ownership="none">
<doc xml:whitespace="preserve">The global #FooSubobject</doc>
- <type name="Subobject"/>
+ <type name="Subobject" c:type="FooObject*"/>
</return-value>
</function>
<function name="static_meth" c:identifier="foo_object_static_meth">
@@ -1086,7 +1086,7 @@ exposed to language bindings.</doc>
<function name="test_array" c:identifier="foo_test_array">
<return-value transfer-ownership="container">
<array name="GLib.Array" c:type="GArray*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GArray*"/>
</array>
</return-value>
</function>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index 02e56fd..e44ab2e 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -154,7 +154,7 @@ use it should be.</doc>
</parameter>
<parameter name="path" transfer-ownership="none">
<doc xml:whitespace="preserve">Path to file</doc>
- <type name="filename"/>
+ <type name="filename" c:type="char*"/>
</parameter>
</parameters>
</callback>
@@ -1135,7 +1135,7 @@ TpAccount::status-changed</doc>
</field>
<field name="array2" writable="1">
<array c:type="gpointer*">
- <type name="TestObj"/>
+ <type name="TestObj" c:type="gpointer*"/>
</array>
</field>
<field name="field" writable="1">
@@ -1143,12 +1143,12 @@ TpAccount::status-changed</doc>
</field>
<field name="list" writable="1">
<type name="GLib.List" c:type="GList*">
- <type name="TestObj"/>
+ <type name="TestObj" c:type="GList*"/>
</type>
</field>
<field name="garray" writable="1">
<array name="GLib.PtrArray" c:type="GPtrArray*">
- <type name="TestObj"/>
+ <type name="TestObj" c:type="GPtrArray*"/>
</array>
</field>
</record>
@@ -1902,7 +1902,7 @@ call and can be released on return.</doc>
<return-value transfer-ownership="full">
<doc xml:whitespace="preserve">list of strings</doc>
<type name="GLib.SList" c:type="GSList*">
- <type name="filename"/>
+ <type name="filename" c:type="GSList*"/>
</type>
</return-value>
</function>
@@ -1920,8 +1920,8 @@ call and can be released on return.</doc>
c:identifier="regress_test_ghash_container_return">
<return-value transfer-ownership="container">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</return-value>
</function>
@@ -1929,8 +1929,8 @@ call and can be released on return.</doc>
c:identifier="regress_test_ghash_everything_return">
<return-value transfer-ownership="full">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</return-value>
</function>
@@ -1938,7 +1938,7 @@ call and can be released on return.</doc>
c:identifier="regress_test_ghash_nested_everything_return">
<doc xml:whitespace="preserve">Specify nested parameterized types directly with the (type ) annotation.</doc>
<return-value transfer-ownership="full">
- <type name="GLib.HashTable">
+ <type name="GLib.HashTable" c:type="GHashTable*">
<type name="utf8"/>
<type name="GLib.HashTable">
<type name="utf8"/>
@@ -1953,8 +1953,8 @@ call and can be released on return.</doc>
element-type annotation.</doc>
<return-value transfer-ownership="full">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="GLib.HashTable">
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="GLib.HashTable" c:type="GHashTable*">
<type name="utf8"/>
<type name="utf8"/>
</type>
@@ -1969,8 +1969,8 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</parameter>
</parameters>
@@ -1983,8 +1983,8 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</parameter>
</parameters>
@@ -1993,8 +1993,8 @@ element-type annotation.</doc>
c:identifier="regress_test_ghash_nothing_return">
<return-value transfer-ownership="none">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</return-value>
</function>
@@ -2002,8 +2002,8 @@ element-type annotation.</doc>
c:identifier="regress_test_ghash_nothing_return2">
<return-value transfer-ownership="none">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</return-value>
</function>
@@ -2015,8 +2015,8 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none" allow-none="1">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</parameter>
</parameters>
@@ -2033,8 +2033,8 @@ element-type annotation.</doc>
transfer-ownership="full"
allow-none="1">
<type name="GLib.HashTable" c:type="GHashTable**">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable**"/>
+ <type name="utf8" c:type="GHashTable**"/>
</type>
</parameter>
</parameters>
@@ -2043,8 +2043,8 @@ element-type annotation.</doc>
c:identifier="regress_test_ghash_null_return">
<return-value transfer-ownership="none">
<type name="GLib.HashTable" c:type="GHashTable*">
- <type name="utf8"/>
- <type name="utf8"/>
+ <type name="utf8" c:type="GHashTable*"/>
+ <type name="utf8" c:type="GHashTable*"/>
</type>
</return-value>
</function>
@@ -2052,7 +2052,7 @@ element-type annotation.</doc>
c:identifier="regress_test_glist_container_return">
<return-value transfer-ownership="container">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
</function>
@@ -2060,7 +2060,7 @@ element-type annotation.</doc>
c:identifier="regress_test_glist_everything_return">
<return-value transfer-ownership="full">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
</function>
@@ -2072,7 +2072,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</parameter>
</parameters>
@@ -2085,7 +2085,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</parameter>
</parameters>
@@ -2094,7 +2094,7 @@ element-type annotation.</doc>
c:identifier="regress_test_glist_nothing_return">
<return-value transfer-ownership="none">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
</function>
@@ -2102,7 +2102,7 @@ element-type annotation.</doc>
c:identifier="regress_test_glist_nothing_return2">
<return-value transfer-ownership="none">
<type name="GLib.List" c:type="GList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GList*"/>
</type>
</return-value>
</function>
@@ -2114,7 +2114,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none" allow-none="1">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</parameter>
</parameters>
@@ -2131,7 +2131,7 @@ element-type annotation.</doc>
transfer-ownership="full"
allow-none="1">
<type name="GLib.SList" c:type="GSList**">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList**"/>
</type>
</parameter>
</parameters>
@@ -2140,7 +2140,7 @@ element-type annotation.</doc>
c:identifier="regress_test_gslist_container_return">
<return-value transfer-ownership="container">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</return-value>
</function>
@@ -2148,7 +2148,7 @@ element-type annotation.</doc>
c:identifier="regress_test_gslist_everything_return">
<return-value transfer-ownership="full">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</return-value>
</function>
@@ -2160,7 +2160,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</parameter>
</parameters>
@@ -2173,7 +2173,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</parameter>
</parameters>
@@ -2182,7 +2182,7 @@ element-type annotation.</doc>
c:identifier="regress_test_gslist_nothing_return">
<return-value transfer-ownership="none">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</return-value>
</function>
@@ -2190,7 +2190,7 @@ element-type annotation.</doc>
c:identifier="regress_test_gslist_nothing_return2">
<return-value transfer-ownership="none">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</return-value>
</function>
@@ -2202,7 +2202,7 @@ element-type annotation.</doc>
<parameters>
<parameter name="in" transfer-ownership="none" allow-none="1">
<type name="GLib.SList" c:type="GSList*">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList*"/>
</type>
</parameter>
</parameters>
@@ -2219,7 +2219,7 @@ element-type annotation.</doc>
transfer-ownership="full"
allow-none="1">
<type name="GLib.SList" c:type="GSList**">
- <type name="utf8"/>
+ <type name="utf8" c:type="GSList**"/>
</type>
</parameter>
</parameters>
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index 29036b3..07e5a34 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -811,3 +811,14 @@ void
annotation_space_after_comment_bug631690 (void)
{
}
+
+/**
+ * annotation_return_filename
+ *
+ * Returns: (type filename): An annotated filename
+ */
+gchar*
+annotation_return_filename (void)
+{
+ return "a utf-8 filename";
+}
diff --git a/tests/scanner/annotation.h b/tests/scanner/annotation.h
index e4c5de6..c7de0f1 100644
--- a/tests/scanner/annotation.h
+++ b/tests/scanner/annotation.h
@@ -167,6 +167,7 @@ GObject * annotation_test_parsing_bug630862 (void);
void annotation_space_after_comment_bug631690 (void);
+gchar* annotation_return_filename (void);
#endif /* __ANNOTATION_OBJECT_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]