From 818333247787bb1cf51b0fb13276114de9f9bfa2 Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 24 Sep 2010 13:50:17 -0300 Subject: [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(-) create mode 100644 tests/warn/invalid-closure.h diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index 075f227d..f2bc1d4b 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 0407bbc5..e45ff795 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 559ea705..e4f29065 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 db006e57..3cd44b00 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 00000000..fcaf0937 --- /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 -- cgit v1.2.1