[gobject-introspection] Bug 584453 - Handle char ** correctly (and const variation)
- From: Colin Walters <walters src gnome org>
- To: svn-commits-list gnome org
- Subject: [gobject-introspection] Bug 584453 - Handle char ** correctly (and const variation)
- Date: Tue, 9 Jun 2009 13:54:14 -0400 (EDT)
commit b23ca1ec2afeed3c5ab914c996c1dd73870ecab6
Author: Colin Walters <walters verbum org>
Date: Thu Jun 4 13:51:26 2009 -0400
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.
---
gir/Everything-1.0-expected.gir | 21 ++++++++++++++++++++-
gir/everything.c | 21 +++++++++++++++++++++
gir/everything.h | 1 +
giscanner/annotationparser.py | 5 ++---
giscanner/transformer.py | 6 +++---
tests/scanner/annotation-1.0-expected.gir | 10 +++++-----
tests/scanner/annotation-1.0-expected.tgir | 10 +++++-----
7 files changed, 57 insertions(+), 17 deletions(-)
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.">
</parameter>
</parameters>
</function>
- <function name="test_strv_out" c:identifier="test_strv_out">
+ <function name="test_strv_out"
+ c:identifier="test_strv_out"
+ doc="No annotations here. We want the default to Do The Right Thing.">
+ <return-value transfer-ownership="full">
+ <array c:type="char**">
+ <type name="utf8"/>
+ </array>
+ </return-value>
+ </function>
+ <function name="test_strv_out_c"
+ c:identifier="test_strv_out_c"
+ doc="No annotations here. We want the default to Do The Right Thing.">
+ <return-value transfer-ownership="none">
+ <array c:type="char**">
+ <type name="utf8"/>
+ </array>
+ </return-value>
+ </function>
+ <function name="test_strv_out_container"
+ c:identifier="test_strv_out_container">
<return-value transfer-ownership="container">
<array c:type="char**">
<type name="utf8"/>
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)
{
@@ -439,6 +444,22 @@ int test_array_int_in_take (int n_ints, int *ints)
}
/**
+ * 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.
* Returns: (array length=len) (transfer full): a new array of integers.
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">
</parameter>
<parameter name="argv"
direction="inout"
- transfer-ownership="none"
+ transfer-ownership="full"
doc="Argument vector">
<array length="1" c:type="char***">
<type name="utf8"/>
@@ -574,7 +574,7 @@ detection, and fixing it via annotations.">
</parameter>
<parameter name="argv"
direction="inout"
- transfer-ownership="none"
+ transfer-ownership="full"
doc="The arguments.">
<array length="0" c:type="char***">
<type name="utf8"/>
@@ -583,7 +583,7 @@ detection, and fixing it via annotations.">
</parameters>
</function>
<function name="return_array" c:identifier="annotation_return_array">
- <return-value transfer-ownership="none" doc="The return value">
+ <return-value transfer-ownership="full" doc="The return value">
<array length="0" c:type="char**">
<type name="utf8"/>
</array>
@@ -609,7 +609,7 @@ detection, and fixing it via annotations.">
</function>
<function name="string_zero_terminated"
c:identifier="annotation_string_zero_terminated">
- <return-value transfer-ownership="none" doc="The return value">
+ <return-value transfer-ownership="full" doc="The return value">
<array c:type="char**">
<type name="utf8"/>
</array>
@@ -621,7 +621,7 @@ detection, and fixing it via annotations.">
<type name="none" c:type="void"/>
</return-value>
<parameters>
- <parameter name="out" direction="inout" transfer-ownership="none">
+ <parameter name="out" direction="inout" transfer-ownership="full">
<array c:type="char***">
<type name="utf8"/>
</array>
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 @@
<parameter name="argc" transfer-ownership="full" direction="inout">
<type name="int"/>
</parameter>
- <parameter name="argv" transfer-ownership="none" direction="inout">
+ <parameter name="argv" transfer-ownership="full" direction="inout">
<array length="1" zero-terminated="1">
<type name="utf8"/>
</array>
@@ -423,7 +423,7 @@
<parameter name="argc" transfer-ownership="full" direction="inout">
<type name="int"/>
</parameter>
- <parameter name="argv" transfer-ownership="none" direction="inout">
+ <parameter name="argv" transfer-ownership="full" direction="inout">
<array length="0" zero-terminated="1">
<type name="utf8"/>
</array>
@@ -431,7 +431,7 @@
</parameters>
</function>
<function name="return_array" c:identifier="annotation_return_array">
- <return-value transfer-ownership="none">
+ <return-value transfer-ownership="full">
<array length="0" zero-terminated="1">
<type name="utf8"/>
</array>
@@ -453,7 +453,7 @@
</parameters>
</function>
<function name="string_zero_terminated" c:identifier="annotation_string_zero_terminated">
- <return-value transfer-ownership="none">
+ <return-value transfer-ownership="full">
<array zero-terminated="1">
<type name="utf8"/>
</array>
@@ -464,7 +464,7 @@
<type name="none"/>
</return-value>
<parameters>
- <parameter name="out" transfer-ownership="none" direction="inout">
+ <parameter name="out" transfer-ownership="full" direction="inout">
<array zero-terminated="1">
<type name="utf8"/>
</array>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]