summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--giscanner/maintransformer.py3
-rw-r--r--tests/scanner/Regress-1.0-C-expected/Regress.test_return_allow_none.page30
-rw-r--r--tests/scanner/Regress-1.0-C-expected/Regress.test_return_nullable.page30
-rw-r--r--tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_allow_none.page32
-rw-r--r--tests/scanner/Regress-1.0-Gjs-expected/Regress.test_return_nullable.page32
-rw-r--r--tests/scanner/Regress-1.0-Python-expected/Regress.test_return_allow_none.page32
-rw-r--r--tests/scanner/Regress-1.0-Python-expected/Regress.test_return_nullable.page32
-rw-r--r--tests/scanner/Regress-1.0-expected.gir14
-rw-r--r--tests/scanner/Regress-1.0-sections-expected.txt2
-rw-r--r--tests/scanner/regress.c24
-rw-r--r--tests/scanner/regress.h7
11 files changed, 236 insertions, 2 deletions
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 8954fa70..da904cfd 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 00000000..f39dcf2a
--- /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 00000000..098f8d42
--- /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 00000000..c682230e
--- /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 00000000..e6f2a3c5
--- /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 00000000..708af8f6
--- /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 00000000..cda2b1d2
--- /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 a7589ef9..55586c4f 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 68d28dd6..335bfec7 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 43708e9f..537d7d66 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 7cc705fa..ba0b5626 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);