[gobject-introspection] scanner: Fix allow-none on return values
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] scanner: Fix allow-none on return values
- Date: Wed, 30 Sep 2015 03:58:58 +0000 (UTC)
commit cd2a5a7bb85db1e823833dd6082da5aa9ad19d0b
Author: Garrett Regier <garrett regier riftio com>
Date: Mon Jul 6 11:45:33 2015 -0700
scanner: Fix allow-none on return values
The optional annotation was being applied which
is invalid for return values.
https://bugzilla.gnome.org/show_bug.cgi?id=752029
Signed-off-by: Garrett Regier <garrett regier riftio com>
giscanner/maintransformer.py | 3 +-
.../Regress.test_return_allow_none.page | 30 ++++++++++++++++++
.../Regress.test_return_nullable.page | 30 ++++++++++++++++++
.../Regress.test_return_allow_none.page | 32 ++++++++++++++++++++
.../Regress.test_return_nullable.page | 32 ++++++++++++++++++++
.../Regress.test_return_allow_none.page | 32 ++++++++++++++++++++
.../Regress.test_return_nullable.page | 32 ++++++++++++++++++++
tests/scanner/Regress-1.0-expected.gir | 14 ++++++++-
tests/scanner/Regress-1.0-sections-expected.txt | 2 +
tests/scanner/regress.c | 24 +++++++++++++++
tests/scanner/regress.h | 7 ++++
11 files changed, 236 insertions(+), 2 deletions(-)
---
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 8954fa7..da904cf 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -653,7 +653,8 @@ class MainTransformer(object):
node.optional = True
if ANN_ALLOW_NONE in annotations:
- if node.direction == ast.PARAM_DIRECTION_OUT:
+ if (node.direction == ast.PARAM_DIRECTION_OUT and
+ not isinstance(node, ast.Return)):
node.optional = True
else:
node.nullable = True
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.test_return_allow_none.page
b/tests/scanner/Regress-1.0-C-expected/Regress.test_return_allow_none.page
new file mode 100644
index 0000000..f39dcf2
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.test_return_allow_none.page
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_allow_none"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>char*</api:type>
+ </api:returns>
+ <api:name>regress_test_return_allow_none</api:name>
+ </api:function>
+ </info>
+ <title>regress_test_return_allow_none</title>
+ <synopsis><code mime="text/x-csrc">
+char* regress_test_return_allow_none (void);
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-C-expected/Regress.test_return_nullable.page
b/tests/scanner/Regress-1.0-C-expected/Regress.test_return_nullable.page
new file mode 100644
index 0000000..098f8d4
--- /dev/null
+++ b/tests/scanner/Regress-1.0-C-expected/Regress.test_return_nullable.page
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_nullable"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>char*</api:type>
+ </api:returns>
+ <api:name>regress_test_return_nullable</api:name>
+ </api:function>
+ </info>
+ <title>regress_test_return_nullable</title>
+ <synopsis><code mime="text/x-csrc">
+char* regress_test_return_nullable (void);
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_allow_none.page
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_allow_none.page
new file mode 100644
index 0000000..c682230
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_allow_none.page
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_allow_none"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>String</api:type>
+ </api:returns>
+ <api:name>regress_test_return_allow_none</api:name>
+ </api:function>
+ </info>
+ <title>Regress.test_return_allow_none</title>
+ <synopsis><code mime="text/x-gjs">
+function test_return_allow_none(): String {
+ // Gjs wrapper for regress_test_return_allow_none()
+}
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_nullable.page
b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_nullable.page
new file mode 100644
index 0000000..e6f2a3c
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_nullable.page
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_nullable"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>String</api:type>
+ </api:returns>
+ <api:name>regress_test_return_nullable</api:name>
+ </api:function>
+ </info>
+ <title>Regress.test_return_nullable</title>
+ <synopsis><code mime="text/x-gjs">
+function test_return_nullable(): String {
+ // Gjs wrapper for regress_test_return_nullable()
+}
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_allow_none.page
b/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_allow_none.page
new file mode 100644
index 0000000..708af8f
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_allow_none.page
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_allow_none"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>unicode</api:type>
+ </api:returns>
+ <api:name>regress_test_return_allow_none</api:name>
+ </api:function>
+ </info>
+ <title>Regress.test_return_allow_none</title>
+ <synopsis><code mime="text/x-python">
+ returns(unicode)
+def test_return_allow_none():
+ # Python wrapper for regress_test_return_allow_none()
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+{formatter.format(node, node.retval.doc)}
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_nullable.page
b/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_nullable.page
new file mode 100644
index 0000000..cda2b1d
--- /dev/null
+++ b/tests/scanner/Regress-1.0-Python-expected/Regress.test_return_nullable.page
@@ -0,0 +1,32 @@
+<?xml version="1.0"?>
+<page id="Regress.test_return_nullable"
+ type="topic"
+ style="function"
+ xmlns="http://projectmallard.org/1.0/"
+ xmlns:api="http://projectmallard.org/experimental/api/"
+ xmlns:ui="http://projectmallard.org/1.0/ui/">
+ <info>
+ <link xref="index" group="function" type="guide"/>
+ <api:function>
+ <api:returns>
+ <api:type>unicode</api:type>
+ </api:returns>
+ <api:name>regress_test_return_nullable</api:name>
+ </api:function>
+ </info>
+ <title>Regress.test_return_nullable</title>
+ <synopsis><code mime="text/x-python">
+ returns(unicode)
+def test_return_nullable():
+ # Python wrapper for regress_test_return_nullable()
+ </code></synopsis>
+
+
+<terms>
+<item>
+<title><code>Returns</code></title>
+{formatter.format(node, node.retval.doc)}
+</item>
+</terms>
+
+</page>
diff --git a/tests/scanner/Regress-1.0-expected.gir b/tests/scanner/Regress-1.0-expected.gir
index a7589ef..55586c4 100644
--- a/tests/scanner/Regress-1.0-expected.gir
+++ b/tests/scanner/Regress-1.0-expected.gir
@@ -5716,7 +5716,7 @@ element-type annotation.</doc>
</function>
<function name="test_ghash_null_return"
c:identifier="regress_test_ghash_null_return">
- <return-value transfer-ownership="none">
+ <return-value transfer-ownership="none" nullable="1">
<type name="GLib.HashTable" c:type="const GHashTable*">
<type name="utf8"/>
<type name="utf8"/>
@@ -6182,6 +6182,18 @@ What we're testing here is that the scanner ignores the @a nested inside XML.</d
</parameter>
</parameters>
</function>
+ <function name="test_return_allow_none"
+ c:identifier="regress_test_return_allow_none">
+ <return-value transfer-ownership="full" nullable="1">
+ <type name="utf8" c:type="char*"/>
+ </return-value>
+ </function>
+ <function name="test_return_nullable"
+ c:identifier="regress_test_return_nullable">
+ <return-value transfer-ownership="full" nullable="1">
+ <type name="utf8" c:type="char*"/>
+ </return-value>
+ </function>
<function name="test_short" c:identifier="regress_test_short">
<return-value transfer-ownership="none">
<type name="gshort" c:type="gshort"/>
diff --git a/tests/scanner/Regress-1.0-sections-expected.txt b/tests/scanner/Regress-1.0-sections-expected.txt
index 68d28dd..335bfec 100644
--- a/tests/scanner/Regress-1.0-sections-expected.txt
+++ b/tests/scanner/Regress-1.0-sections-expected.txt
@@ -157,6 +157,8 @@ regress_test_multiline_doc_comments
regress_test_nested_parameter
regress_test_null_gerror_callback
regress_test_owned_gerror_callback
+regress_test_return_allow_none
+regress_test_return_nullable
regress_test_short
regress_test_simple_boxed_a_const_return
regress_test_simple_callback
diff --git a/tests/scanner/regress.c b/tests/scanner/regress.c
index 43708e9..537d7d6 100644
--- a/tests/scanner/regress.c
+++ b/tests/scanner/regress.c
@@ -25,6 +25,30 @@ regress_set_abort_on_error (gboolean in)
abort_on_error = in;
}
+/* return annotations */
+
+/**
+ * regress_test_return_allow_none:
+ *
+ * Returns: (allow-none):
+ */
+char *
+regress_test_return_allow_none (void)
+{
+ return NULL;
+}
+
+/**
+ * regress_test_return_nullable:
+ *
+ * Returns: (nullable):
+ */
+char *
+regress_test_return_nullable (void)
+{
+ return NULL;
+}
+
/* basic types */
gboolean
regress_test_boolean (gboolean in)
diff --git a/tests/scanner/regress.h b/tests/scanner/regress.h
index 7cc705f..ba0b562 100644
--- a/tests/scanner/regress.h
+++ b/tests/scanner/regress.h
@@ -15,6 +15,13 @@
_GI_TEST_EXTERN
void regress_set_abort_on_error (gboolean abort_on_error);
+/* return annotations */
+_GI_TEST_EXTERN
+char *regress_test_return_allow_none (void);
+
+_GI_TEST_EXTERN
+char *regress_test_return_nullable (void);
+
/* basic types */
_GI_TEST_EXTERN
gboolean regress_test_boolean (gboolean in);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]