Bug 566419 – Element type of arrays not properly handled in all cases
authorJohan Dahlin <jdahlin@async.com.br>
Mon, 12 Jan 2009 20:54:11 +0000 (20:54 +0000)
committerJohan Dahlin <johan@src.gnome.org>
Mon, 12 Jan 2009 20:54:11 +0000 (20:54 +0000)
2009-01-12  Johan Dahlin  <jdahlin@async.com.br>

        Bug 566419 – Element type of arrays not properly handled in all cases

        * giscanner/annotationparser.py:
        * tests/scanner/annotation-1.0-expected.gir:
        * tests/scanner/annotation-1.0-expected.tgir:
        * tests/scanner/annotation.c (annotation_object_set_data),
        (annotation_object_set_data2), (annotation_object_set_data3):
        * tests/scanner/annotation.h:

        Based on patch by Andreas Rottmann

svn path=/trunk/; revision=1019

ChangeLog
giscanner/annotationparser.py
tests/scanner/annotation-1.0-expected.gir
tests/scanner/annotation-1.0-expected.tgir
tests/scanner/annotation.c
tests/scanner/annotation.h

index 0e134e8..56eedfa 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2009-01-12  Johan Dahlin  <jdahlin@async.com.br>
 
+        Bug 566419 – Element type of arrays not properly handled in all cases
+       
+       * giscanner/annotationparser.py:
+       * tests/scanner/annotation-1.0-expected.gir:
+       * tests/scanner/annotation-1.0-expected.tgir:
+       * tests/scanner/annotation.c (annotation_object_set_data),
+       (annotation_object_set_data2), (annotation_object_set_data3):
+       * tests/scanner/annotation.h:
+
+       Based on patch by Andreas Rottmann
+
+2009-01-12  Johan Dahlin  <jdahlin@async.com.br>
+
        Bug 566560 – giscanner.transformer.SkipError
 
        * giscanner/transformer.py:
index 630508a..89d4b33 100644 (file)
@@ -329,7 +329,7 @@ class AnnotationApplier(object):
             parent, node, options)
         if container_type is not None:
             node.type = container_type
-        if not node.direction:
+        if node.direction is None:
             node.direction = self._guess_direction(node)
         node.transfer = self._extract_transfer(parent, node, options)
         if 'allow-none' in options:
@@ -383,18 +383,34 @@ class AnnotationApplier(object):
     def _parse_array(self, parent, node, options):
         array_opt = options.get('array')
         if array_opt:
-            values = array_opt.all()
+            array_values = array_opt.all()
         else:
-            values = {}
-        container_type = Array(node.type.ctype, node.type.name)
-        if 'zero-terminated' in values:
-            container_type.zeroterminated = values.get(
+            array_values = {}
+
+        element_type = options.get('element-type')
+        if element_type is not None:
+            element_type_name = element_type.one()
+        else:
+            element_type_name = node.type.name
+
+        container_type = Array(node.type.ctype,
+                               element_type_name)
+        if 'zero-terminated' in array_values:
+            container_type.zeroterminated = array_values.get(
                 'zero-terminated') == '1'
-        length = values.get('length')
+        length = array_values.get('length')
         if length is not None:
             param_index = parent.get_parameter_index(length)
             container_type.length_param_index = param_index
-        container_type.size = values.get('fized-size')
+            # For in parameters we're incorrectly deferring
+            # char/unsigned char to utf8 when a length annotation
+            # is specified.
+            if (isinstance(node, Parameter) and
+                node.type.name == 'utf8' and
+                self._guess_direction(node) == PARAM_DIRECTION_IN):
+                # FIXME: unsigned char/guchar should be uint8
+                container_type.element_type = 'int8'
+        container_type.size = array_values.get('fized-size')
         return container_type
 
     def _parse_element_type(self, parent, node, options):
index a0c2a68..0391559 100644 (file)
           </parameter>
         </parameters>
       </method>
+      <method name="set_data" c:identifier="annotation_object_set_data">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" c:type="guchar*">
+              <type name="uint8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size_t" c:type="gsize"/>
+          </parameter>
+        </parameters>
+      </method>
+      <method name="set_data2" c:identifier="annotation_object_set_data2">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" c:type="gchar*">
+              <type name="int8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size_t" c:type="gsize"/>
+          </parameter>
+        </parameters>
+      </method>
+      <method name="set_data3" c:identifier="annotation_object_set_data3">
+        <return-value transfer-ownership="none">
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" c:type="gpointer">
+              <type name="uint8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size_t" c:type="gsize"/>
+          </parameter>
+        </parameters>
+      </method>
       <method name="do_not_use"
               c:identifier="annotation_object_do_not_use"
               deprecated="Use annotation_object_create_object() instead."
index 0a654d5..bb160fc 100644 (file)
           </parameter>
         </parameters>
       </method>
+      <method name="set_data" c:identifier="annotation_object_set_data">
+        <return-value transfer-ownership="none">
+          <type name="none"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" zero-terminated="1">
+              <type name="uint8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size"/>
+          </parameter>
+        </parameters>
+      </method>
+      <method name="set_data2" c:identifier="annotation_object_set_data2">
+        <return-value transfer-ownership="none">
+          <type name="none"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" zero-terminated="1">
+              <type name="int8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size"/>
+          </parameter>
+        </parameters>
+      </method>
+      <method name="set_data3" c:identifier="annotation_object_set_data3">
+        <return-value transfer-ownership="none">
+          <type name="none"/>
+        </return-value>
+        <parameters>
+          <parameter name="data" transfer-ownership="none">
+            <array length="2" zero-terminated="1">
+              <type name="uint8"/>
+            </array>
+          </parameter>
+          <parameter name="length" transfer-ownership="none">
+            <type name="size"/>
+          </parameter>
+        </parameters>
+      </method>
       <method name="do_not_use" c:identifier="annotation_object_do_not_use" deprecated="1">
         <return-value transfer-ownership="full">
           <type name="GObject.Object"/>
index 8fa6d8e..8239400 100644 (file)
@@ -324,6 +324,55 @@ annotation_object_foreach (AnnotationObject *object,
 }
 
 /**
+ * annotation_object_set_data:
+ * @object: a #AnnotationObject
+ * @data: (array length=length): The data
+ * @length: Length of the data
+ *
+ * Test taking a guchar * with a length.
+ **/
+void
+annotation_object_set_data (AnnotationObject *object,
+                            const guchar *data,
+                            gsize length)
+{
+  
+}
+
+/**
+ * annotation_object_set_data2:
+ * @object: a #AnnotationObject
+ * @data: (array length=length): The data
+ * @length: Length of the data
+ *
+ * Test taking a gchar * with a length.
+ **/
+void
+annotation_object_set_data2 (AnnotationObject *object,
+                             const gchar *data,
+                             gsize length)
+{
+  
+}
+
+/**
+ * annotation_object_set_data3:
+ * @object: a #AnnotationObject
+ * @data: (array length=length) (element-type uint8): The data
+ * @length: Length of the data
+ *
+ * Test taking a gchar * with a length, overriding the array element
+ * type.
+ **/
+void
+annotation_object_set_data3 (AnnotationObject *object,
+                             gpointer data,
+                             gsize length)
+{
+  
+}
+
+/**
  * annotation_object_allow_none:
  * @object: a #GObject
  * @somearg: (allow-none):
index ddafeb6..d53cd90 100644 (file)
@@ -83,6 +83,16 @@ void     annotation_object_foreach      (AnnotationObject *object,
                                          AnnotationForeachFunc func,
                                          gpointer user_data);
 
+void     annotation_object_set_data     (AnnotationObject *object,
+                                         const guchar     *data,
+                                         gsize             length);
+void     annotation_object_set_data2    (AnnotationObject *object,
+                                         const gchar      *data,
+                                         gsize             length);
+void     annotation_object_set_data3    (AnnotationObject *object,
+                                         gpointer          data,
+                                         gsize             length);
+
 GObject* annotation_object_do_not_use   (AnnotationObject *object);
 
 void     annotation_init                (int              *argc,