Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorColin Walters <walters@verbum.org>2009-02-19 17:16:17 (GMT)
committer Colin Walters <walters@verbum.org>2009-03-16 18:05:23 (GMT)
commit6531a094d73703c0c16777bdc82252688d1c7d51 (patch)
treeddcb4921fc322d27381e90060f2e2776f4dfada7
parent90526643ceb248c56e40f5b6755c3cbb91c3857c (diff)
Bug 565147 - Add (type) annotation to override the C type definition
We previously supported (type) on signals only, extend it to all cases. This is useful for a few cases where libraries use a superclass like GtkWidget* for C convenience, where the actual type is a subclass.
-rw-r--r--giscanner/annotationparser.py7
-rw-r--r--tests/scanner/annotation-1.0-expected.gir15
-rw-r--r--tests/scanner/annotation-1.0-expected.tgir15
-rw-r--r--tests/scanner/annotation.c20
-rw-r--r--tests/scanner/annotation.h3
-rw-r--r--tests/scanner/foo-1.0-expected.gir8
-rw-r--r--tests/scanner/foo-1.0-expected.tgir5
-rw-r--r--tests/scanner/foo.c14
-rw-r--r--tests/scanner/foo.h2
9 files changed, 88 insertions, 1 deletions
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index f32486c..e94afa3 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -416,6 +416,7 @@ class AnnotationApplier(object):
# We're only attempting to name the signal parameters if
# the number of parameter tags (@foo) is the same or greater
# than the number of signal parameters
+ resolve = self._transformer.resolve_param_type
if block and len(block.tags) > len(signal.parameters):
names = block.tags.items()
else:
@@ -427,7 +428,7 @@ class AnnotationApplier(object):
options = getattr(tag, 'options', {})
param_type = options.get(OPT_TYPE)
if param_type:
- param.type.name = param_type.one()
+ param.type.name = resolve(param_type.one())
else:
tag = None
self._parse_param(signal, param, tag)
@@ -489,6 +490,10 @@ class AnnotationApplier(object):
node.transfer = self._extract_transfer(parent, node, options)
if OPT_ALLOW_NONE in options:
node.allow_none = True
+ param_type = options.get(OPT_TYPE)
+ if param_type:
+ resolve = self._transformer.resolve_param_type
+ node.type.name = resolve(param_type.one())
assert node.transfer is not None
if tag is not None and tag.comment is not None:
diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir
index 1af7271..c37d2d4 100644
--- a/tests/scanner/annotation-1.0-expected.gir
+++ b/tests/scanner/annotation-1.0-expected.gir
@@ -493,6 +493,11 @@ known by GObject as it&apos;s only marked as G_TYPE_POINTER">
</array>
</field>
</record>
+ <function name="get_source_file" c:identifier="annotation_get_source_file">
+ <return-value transfer-ownership="full" doc="Source file">
+ <type name="filename" c:type="char*"/>
+ </return-value>
+ </function>
<function name="init" c:identifier="annotation_init">
<return-value transfer-ownership="none">
<type name="none" c:type="void"/>
@@ -529,6 +534,16 @@ known by GObject as it&apos;s only marked as G_TYPE_POINTER">
</parameter>
</parameters>
</function>
+ <function name="set_source_file" c:identifier="annotation_set_source_file">
+ <return-value transfer-ownership="none">
+ <type name="none" c:type="void"/>
+ </return-value>
+ <parameters>
+ <parameter name="fname" transfer-ownership="none" doc="Source file">
+ <type name="filename" c:type="char*"/>
+ </parameter>
+ </parameters>
+ </function>
<function name="string_zero_terminated"
c:identifier="annotation_string_zero_terminated">
<return-value transfer-ownership="none" doc="The return value">
diff --git a/tests/scanner/annotation-1.0-expected.tgir b/tests/scanner/annotation-1.0-expected.tgir
index 2a1426b..99c3d26 100644
--- a/tests/scanner/annotation-1.0-expected.tgir
+++ b/tests/scanner/annotation-1.0-expected.tgir
@@ -368,6 +368,11 @@
</array>
</field>
</record>
+ <function name="get_source_file" c:identifier="annotation_get_source_file">
+ <return-value transfer-ownership="full">
+ <type name="filename"/>
+ </return-value>
+ </function>
<function name="init" c:identifier="annotation_init">
<return-value transfer-ownership="none">
<type name="none"/>
@@ -395,6 +400,16 @@
</parameter>
</parameters>
</function>
+ <function name="set_source_file" c:identifier="annotation_set_source_file">
+ <return-value transfer-ownership="none">
+ <type name="none"/>
+ </return-value>
+ <parameters>
+ <parameter name="fname" transfer-ownership="none">
+ <type name="filename"/>
+ </parameter>
+ </parameters>
+ </function>
<function name="string_zero_terminated" c:identifier="annotation_string_zero_terminated">
<return-value transfer-ownership="none">
<array zero-terminated="1">
diff --git a/tests/scanner/annotation.c b/tests/scanner/annotation.c
index 41508e2..3dcc6be 100644
--- a/tests/scanner/annotation.c
+++ b/tests/scanner/annotation.c
@@ -575,4 +575,24 @@ annotation_object_extra_annos (AnnotationObject *object)
{
}
+/**
+ * annotation_get_source_file:
+ *
+ * Return value: (type filename): Source file
+ */
+char *
+annotation_get_source_file (void)
+{
+}
+
+/**
+ * annotation_set_source_file:
+ * @fname: (type filename): Source file
+ *
+ */
+void
+annotation_set_source_file (const char *fname)
+{
+}
+
char backslash_parsing_tester_2 = '\\';
diff --git a/tests/scanner/annotation.h b/tests/scanner/annotation.h
index 79a686d..102b571 100644
--- a/tests/scanner/annotation.h
+++ b/tests/scanner/annotation.h
@@ -115,6 +115,9 @@ void annotation_string_zero_terminated_out (char ***out);
void annotation_object_extra_annos (AnnotationObject *object);
+char * annotation_get_source_file (void);
+void annotation_set_source_file (const char *fname);
+
/**
* AnnotationStruct:
*
diff --git a/tests/scanner/foo-1.0-expected.gir b/tests/scanner/foo-1.0-expected.gir
index 086170e..59efffd 100644
--- a/tests/scanner/foo-1.0-expected.gir
+++ b/tests/scanner/foo-1.0-expected.gir
@@ -290,6 +290,14 @@ and/or use gtk-doc annotations. -->
<type name="int" c:type="int"/>
</return-value>
</function>
+ <function name="get_default"
+ c:identifier="foo_object_get_default"
+ doc="This function is intended to match clutter_stage_get_default which
+uses a C sugar return type.">
+ <return-value transfer-ownership="full" doc="The global #FooSubobject">
+ <type name="Subobject" c:type="FooObject*"/>
+ </return-value>
+ </function>
<virtual-method name="virtual_method" invoker="virtual_method">
<return-value transfer-ownership="none">
<type name="boolean" c:type="gboolean"/>
diff --git a/tests/scanner/foo-1.0-expected.tgir b/tests/scanner/foo-1.0-expected.tgir
index 1d82b6a..e834876 100644
--- a/tests/scanner/foo-1.0-expected.tgir
+++ b/tests/scanner/foo-1.0-expected.tgir
@@ -206,6 +206,11 @@
<type name="int"/>
</return-value>
</function>
+ <function name="get_default" c:identifier="foo_object_get_default">
+ <return-value transfer-ownership="full">
+ <type name="Subobject"/>
+ </return-value>
+ </function>
<method name="external_type" c:identifier="foo_object_external_type">
<return-value transfer-ownership="full">
<type name="utility.Object"/>
diff --git a/tests/scanner/foo.c b/tests/scanner/foo.c
index 8a9283d..6cb1f3f 100644
--- a/tests/scanner/foo.c
+++ b/tests/scanner/foo.c
@@ -269,6 +269,20 @@ foo_subobject_init (FooSubobject *object)
}
+/**
+ * foo_object_get_default:
+ *
+ * This function is intended to match clutter_stage_get_default which
+ * uses a C sugar return type.
+ *
+ * Return value: (type FooSubobject): The global #FooSubobject
+ */
+FooObject *
+foo_object_get_default ()
+{
+ return NULL;
+}
+
int foo_init (void)
{
return FOO_SUCCESS_INT;
diff --git a/tests/scanner/foo.h b/tests/scanner/foo.h
index 02f3cfe..e9d00dd 100644
--- a/tests/scanner/foo.h
+++ b/tests/scanner/foo.h
@@ -135,6 +135,8 @@ struct _FooSubobjectClass
GType foo_subobject_get_type (void) G_GNUC_CONST;
FooSubobject* foo_subobject_new ();
+FooObject * foo_object_get_default ();
+
GType foo_buffer_get_type (void);
void foo_buffer_some_method (FooBuffer *buffer);