Bug 584453 - Handle char ** correctly (and const variation)
authorColin Walters <walters@verbum.org>
Thu, 4 Jun 2009 17:51:26 +0000 (13:51 -0400)
committerColin Walters <walters@verbum.org>
Tue, 9 Jun 2009 15:49:07 +0000 (11:49 -0400)
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
gir/everything.c
gir/everything.h
giscanner/annotationparser.py
giscanner/transformer.py
tests/scanner/annotation-1.0-expected.gir
tests/scanner/annotation-1.0-expected.tgir

index aaacee5..2a96e2b 100644 (file)
@@ -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"/>
index 341f849..e01a3a9 100644 (file)
@@ -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.
index 583ccda..59a7a10 100644 (file)
@@ -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 */
index 5458ee1..8c901a2 100644 (file)
@@ -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):
index c084606..88cbc15 100644 (file)
@@ -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
 
index c4e0fa0..46a3006 100644 (file)
@@ -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>
index 46af2ec..0041cda 100644 (file)
           <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>
         <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>
       </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>
       </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>
         <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>