[gobject-introspection] [annotationparser] Allow param less closures



commit 818333247787bb1cf51b0fb13276114de9f9bfa2
Author: Johan Dahlin <johan gnome org>
Date:   Fri Sep 24 13:50:17 2010 -0300

    [annotationparser] Allow param less closures
    
    Allow closures without annotations to avoid having
    to duplicate the parameter name.

 giscanner/annotationparser.py |    6 +++++-
 giscanner/maintransformer.py  |    2 +-
 tests/scanner/annotation.h    |    2 +-
 tests/warn/Makefile.am        |    1 +
 tests/warn/invalid-closure.h  |    8 ++++++++
 5 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py
index 075f227..f2bc1d4 100644
--- a/giscanner/annotationparser.py
+++ b/giscanner/annotationparser.py
@@ -207,7 +207,11 @@ class DocTag(object):
             elif option == OPT_ATTRIBUTE:
                 self._validate_option('attribute', value, n_params=2)
             elif option == OPT_CLOSURE:
-                self._validate_option('closure', value, n_params=1)
+                if value is not None and value.length() > 1:
+                    message.warn(
+                        'closure takes at maximium 1 value, %d given' % (
+                        value.length()), self.position)
+                    continue
             elif option == OPT_DESTROY:
                 self._validate_option('destroy', value, n_params=1)
             elif option == OPT_ELEMENT_TYPE:
diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py
index 0407bbc..e45ff79 100644
--- a/giscanner/maintransformer.py
+++ b/giscanner/maintransformer.py
@@ -600,7 +600,7 @@ usage is void (*_gtk_reserved1)(void);"""
                     # since we don't have a way right now to flag this callback a destroy.
                     destroy_param.scope = ast.PARAM_SCOPE_NOTIFIED
             closure = options.get(OPT_CLOSURE)
-            if closure:
+            if closure and closure.length() == 1:
                 param.closure_name = self._get_validate_parameter_name(parent,
                                                                        closure.one(),
                                                                        param)
diff --git a/tests/scanner/annotation.h b/tests/scanner/annotation.h
index 559ea70..e4f2906 100644
--- a/tests/scanner/annotation.h
+++ b/tests/scanner/annotation.h
@@ -23,7 +23,7 @@ typedef GList* (*AnnotationListCallback) (GList *in);
 
 /**
  * AnnotationNotifyFunc:
- * @data: (closure data): The user data
+ * @data: (closure): The user data
  *
  * This is a callback with a 'closure' argument that is not named
  * 'user_data' and hence has to be annotated.
diff --git a/tests/warn/Makefile.am b/tests/warn/Makefile.am
index db006e5..3cd44b0 100644
--- a/tests/warn/Makefile.am
+++ b/tests/warn/Makefile.am
@@ -5,6 +5,7 @@ TESTS = \
 	callback-missing-scope.h \
 	return-gobject.h \
 	invalid-array.h \
+	invalid-closure.h \
 	invalid-element-type.h \
 	invalid-option.h \
 	invalid-out.h \
diff --git a/tests/warn/invalid-closure.h b/tests/warn/invalid-closure.h
new file mode 100644
index 0000000..fcaf093
--- /dev/null
+++ b/tests/warn/invalid-closure.h
@@ -0,0 +1,8 @@
+
+/**
+ * test_invalid_closure:
+ * @param: (closure a b):
+ */
+void test_invalid_closure(int param);
+
+// EXPECT:4: Warning: Test: closure takes at maximium 1 value, 2 given



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]