From: Colin Walters Date: Thu, 4 Jun 2009 17:51:26 +0000 (-0400) Subject: Bug 584453 - Handle char ** correctly (and const variation) X-Git-Tag: GOBJECT_INTROSPECTION_0_6_3~19 X-Git-Url: http://git.roojs.org/?a=commitdiff_plain;h=b23ca1ec2afeed3c5ab914c996c1dd73870ecab6;p=gnome.gobject-introspection Bug 584453 - Handle char ** correctly (and const variation) This patch fixes our default handling of char **. We add Return node types as a case where we test for array handling. Remove the hardcoded assumption of array = "no transfer", just use the separate Parameter/Return cases. This change causes inout char ** to be transfer="full", but that seems more correct. --- diff --git a/gir/Everything-1.0-expected.gir b/gir/Everything-1.0-expected.gir index aaacee5..2a96e2b 100644 --- a/gir/Everything-1.0-expected.gir +++ b/gir/Everything-1.0-expected.gir @@ -1083,7 +1083,26 @@ call and can be released on return."> - + + + + + + + + + + + + + + + diff --git a/gir/everything.c b/gir/everything.c index 341f849..e01a3a9 100644 --- a/gir/everything.c +++ b/gir/everything.c @@ -377,6 +377,11 @@ test_array_gtype_in (int n_types, GType *types) return g_string_free (string, FALSE); } +/** + * test_strv_out: + * + * No annotations here. We want the default to Do The Right Thing. + */ char ** test_strv_out (void) { @@ -438,6 +443,22 @@ int test_array_int_in_take (int n_ints, int *ints) return sum; } +/** + * test_strv_out_c: + * + * No annotations here. We want the default to Do The Right Thing. + */ +const char * const* +test_strv_out_c (void) +{ + static char **ret = NULL; + + if (ret == NULL) + ret = test_strv_out (); + + return (const char * const *) ret; +} + /** * test_array_int_full_out: * @len: length of the returned array. diff --git a/gir/everything.h b/gir/everything.h index 583ccda..59a7a10 100644 --- a/gir/everything.h +++ b/gir/everything.h @@ -45,6 +45,7 @@ gint64 test_array_gint64_in (int n_ints, gint64 *ints); char *test_array_gtype_in (int n_types, GType *types); char **test_strv_out_container (void); char **test_strv_out (void); +const char * const * test_strv_out_c (void); void test_strv_outarg (char ***retp); /* transfer tests */ diff --git a/giscanner/annotationparser.py b/giscanner/annotationparser.py index 5458ee1..8c901a2 100644 --- a/giscanner/annotationparser.py +++ b/giscanner/annotationparser.py @@ -560,6 +560,7 @@ class AnnotationApplier(object): if (not isinstance(node, Field) and (not has_element_type and (node.direction is None + or isinstance(node, Return) or node.direction == PARAM_DIRECTION_IN))): if self._guess_array(node): has_array = True @@ -588,6 +589,7 @@ class AnnotationApplier(object): container_type = Array(node.type.ctype, element_type_name) + container_type.is_const = node.type.is_const if OPT_ARRAY_ZERO_TERMINATED in array_values: container_type.zeroterminated = array_values.get( OPT_ARRAY_ZERO_TERMINATED) == '1' @@ -724,12 +726,9 @@ class AnnotationApplier(object): if node.transfer is not None: return node.transfer - if isinstance(node.type, Array): - return PARAM_TRANSFER_NONE # Anything with 'const' gets none if node.type.is_const: return PARAM_TRANSFER_NONE - elif node.type.name in [TYPE_NONE, TYPE_ANY]: return PARAM_TRANSFER_NONE elif isinstance(node.type, Varargs): diff --git a/giscanner/transformer.py b/giscanner/transformer.py index c084606..88cbc15 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -475,9 +475,9 @@ class Transformer(object): rettype.derefed_canonical = self._canonicalize_ctype(derefed_ctype) canontype = type_name_from_ctype(ctype) - if ((canontype == TYPE_STRING or - source_type.type == CTYPE_POINTER) and - source_type.base_type.type_qualifier & TYPE_QUALIFIER_CONST): + # Is it a const char * or a const gpointer? + if ((canontype == TYPE_STRING or source_type.type == CTYPE_POINTER) and + (source_type.base_type.type_qualifier & TYPE_QUALIFIER_CONST)): rettype.is_const = True return rettype diff --git a/tests/scanner/annotation-1.0-expected.gir b/tests/scanner/annotation-1.0-expected.gir index c4e0fa0..46a3006 100644 --- a/tests/scanner/annotation-1.0-expected.gir +++ b/tests/scanner/annotation-1.0-expected.gir @@ -344,7 +344,7 @@ intentionally similar example to gtk_container_get_children"> @@ -574,7 +574,7 @@ detection, and fixing it via annotations."> @@ -583,7 +583,7 @@ detection, and fixing it via annotations."> - + @@ -609,7 +609,7 @@ detection, and fixing it via annotations."> - + @@ -621,7 +621,7 @@ detection, and fixing it via annotations."> - + diff --git a/tests/scanner/annotation-1.0-expected.tgir b/tests/scanner/annotation-1.0-expected.tgir index 46af2ec..0041cda 100644 --- a/tests/scanner/annotation-1.0-expected.tgir +++ b/tests/scanner/annotation-1.0-expected.tgir @@ -254,7 +254,7 @@ - + @@ -423,7 +423,7 @@ - + @@ -431,7 +431,7 @@ - + @@ -453,7 +453,7 @@ - + @@ -464,7 +464,7 @@ - +