[gobject-introspection] scanner: Warn and ignore return annotations when there is no return value
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gobject-introspection] scanner: Warn and ignore return annotations when there is no return value
- Date: Sun, 4 Oct 2015 21:35:20 +0000 (UTC)
commit 09c466f0184e74ba6f279f103ad3be3a7e1f2a06
Author: Garrett Regier <garrett regier riftio com>
Date: Mon Jul 6 18:54:23 2015 -0700
scanner: Warn and ignore return annotations when there is no return value
Otherwise the .gir can contain invalid data which would
likely cause a crash at runtime.
https://bugzilla.gnome.org/show_bug.cgi?id=752044
Signed-off-by: Garrett Regier <garrett regier riftio com>
giscanner/codegen.py | 9 +++++----
giscanner/maintransformer.py | 7 ++++++-
tests/warn/Makefile.am | 1 +
tests/warn/invalid-return.h | 19 +++++++++++++++++++
4 files changed, 31 insertions(+), 5 deletions(-)
---
diff --git a/giscanner/codegen.py b/giscanner/codegen.py
index ff1a435..0d4a8d8 100644
--- a/giscanner/codegen.py
+++ b/giscanner/codegen.py
@@ -108,10 +108,11 @@ class CCodeGenerator(object):
self._write_annotation_transfer(param)
self.out_c.write(":\n")
self.out_c.write(' *\n')
- self.out_c.write(' * Undocumented.\n')
- self.out_c.write(' *\n')
- self.out_c.write(' * Returns:')
- self._write_annotation_transfer(func.retval)
+ self.out_c.write(' * Undocumented.')
+ if func.retval.type != ast.TYPE_NONE:
+ self.out_c.write('\n *\n')
+ self.out_c.write(' * Returns: ')
+ self._write_annotation_transfer(func.retval)
self.out_c.write('\n */')
@contextmanager
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 872395a..bb79a5b 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -784,6 +784,12 @@ class MainTransformer(object):
tag = block.tags.get(TAG_RETURNS)
else:
tag = None
+
+ if tag is not None and return_.type == ast.TYPE_NONE:
+ message.warn('%s: invalid return annotation' % (block.name,),
+ tag.position)
+ tag = None
+
self._apply_annotations_param_ret_common(parent, return_, tag)
def _apply_annotations_params(self, parent, params, block):
@@ -871,7 +877,6 @@ class MainTransformer(object):
if block:
self._apply_annotations_annotated(signal, block)
-
# We're only attempting to name the signal parameters if
# the number of parameters (@foo) is the same or greater
# than the number of signal parameters
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index fb7e989..5f47df0 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -14,6 +14,7 @@ TESTS = \
invalid-option.h \
invalid-optional.h \
invalid-out.h \
+ invalid-return.h \
invalid-transfer.h \
missing-element-type.h \
return-gobject.h \
diff --git a/tests/warn/invalid-return.h b/tests/warn/invalid-return.h
new file mode 100644
index 0000000..c033b76
--- /dev/null
+++ b/tests/warn/invalid-return.h
@@ -0,0 +1,19 @@
+#include "common.h"
+
+/**
+ * TestInvalidReturnCallback:
+ *
+ * Returns:
+ */
+typedef void (*TestInvalidReturnCallback) (void);
+
+// EXPECT:6: Warning: Test: TestInvalidReturnCallback: invalid return annotation
+
+/**
+ * test_invalid_return:
+ *
+ * Returns:
+ */
+void test_invalid_return (void);
+
+// EXPECT:15: Warning: Test: test_invalid_return: invalid return annotation
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]