From 50dfb465658a5c1705cac51a31f145fee8b6b168 Mon Sep 17 00:00:00 2001 From: Dieter Verfaillie Date: Sun, 1 Mar 2015 21:36:12 +0100 Subject: scanner: allow (array zero-terminated) instead of (array zero-terminated=1) What we already had: - (array zero-terminated=1) > array which is NULL terminated - (array zero-terminated=0) > array which is not NULL terminated - (array) > array which is not NULL terminated - (array zero-terminated=X) > array which is not NULL terminated where X can be anything What this patch adds: - (array zero-terminated) > array which is NULL terminated https://bugzilla.gnome.org/show_bug.cgi?id=657754 --- giscanner/annotationparser.py | 7 ++++++- giscanner/maintransformer.py | 10 +++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) (limited to 'giscanner') diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index afeca9ce..907039c4 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -652,7 +652,7 @@ class GtkDocAnnotatable(object): return for option, value in options.items(): - if option in [OPT_ARRAY_ZERO_TERMINATED, OPT_ARRAY_FIXED_SIZE]: + if option == OPT_ARRAY_FIXED_SIZE: try: int(value) except (TypeError, ValueError): @@ -663,6 +663,11 @@ class GtkDocAnnotatable(object): warn('invalid "%s" annotation option "%s" value "%s", must be an integer' % (ann_name, option, value), position) + elif option == OPT_ARRAY_ZERO_TERMINATED: + if value is not None and value not in ['0', '1']: + warn('invalid "%s" annotation option "%s" value "%s", must be 0 or 1' % + (ann_name, option, value), + position) elif option == OPT_ARRAY_LENGTH: if value is None: warn('"%s" annotation option "length" needs a value' % (ann_name, ), diff --git a/giscanner/maintransformer.py b/giscanner/maintransformer.py index 4326374f..df598adf 100644 --- a/giscanner/maintransformer.py +++ b/giscanner/maintransformer.py @@ -386,10 +386,14 @@ class MainTransformer(object): array_options = annotations.get(ANN_ARRAY) container_type = ast.Array(array_type, element_type_node, ctype=node.type.ctype, is_const=node.type.is_const) - if OPT_ARRAY_ZERO_TERMINATED in array_options: - container_type.zeroterminated = array_options.get(OPT_ARRAY_ZERO_TERMINATED) == '1' - else: + if array_options.get(OPT_ARRAY_ZERO_TERMINATED, '0') == '0': container_type.zeroterminated = False + else: + if (OPT_ARRAY_ZERO_TERMINATED in array_options + or array_options.get(OPT_ARRAY_ZERO_TERMINATED) == '1'): + container_type.zeroterminated = True + else: + container_type.zeroterminated = False length = array_options.get(OPT_ARRAY_LENGTH) if length: -- cgit v1.2.1