Bug 556433 – assume direction = out for int * parameters
authorJohan Bilien <jobi@via.ecp.fr>
Wed, 15 Oct 2008 17:47:08 +0000 (17:47 +0000)
committerJohan Bilien <jobi@src.gnome.org>
Wed, 15 Oct 2008 17:47:08 +0000 (17:47 +0000)
2008-10-15  Johan Bilien  <jobi@via.ecp.fr>

Bug 556433 – assume direction = out for int * parameters

* giscanner/ast.py: define a list of types for which, if passed as
reference, we assume a default direction of 'out'
* giscanner/transformer.py: if a type has type pointer to one of the
previously defined types, and no direction is set, assume out.
* tests/scanner/drawable.[ch]: added tests for guessed direction=out

svn path=/trunk/; revision=710

ChangeLog
giscanner/ast.py
giscanner/transformer.py
tests/scanner/drawable-1.0-expected.gir
tests/scanner/drawable.c
tests/scanner/drawable.h

index dff9e69..e4b16a8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-15  Johan Bilien  <jobi@via.ecp.fr>
+
+       Bug 556433 – assume direction = out for int * parameters
+
+       * giscanner/ast.py: define a list of types for which, if passed as
+       reference, we assume a default direction of 'out'
+       * giscanner/transformer.py: if a type has type pointer to one of the
+       previously defined types, and no direction is set, assume out.
+       * tests/scanner/drawable.[ch]: added tests for guessed direction=out
+
 2008-10-15  Johan Bilien  <jobi@via.ecp.fr>
 
        * tests/scanner/annotation.c: fixed a few copy-paste errors
index 3d2c76c..8ee6f7a 100644 (file)
@@ -123,6 +123,10 @@ default_array_types = {}
 default_array_types['uint8*'] = TYPE_UINT8
 default_array_types['char**'] = TYPE_STRING
 
+# These types, when seen by reference, are interpreted as out parameters
+default_out_types = (TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG,
+                     TYPE_FLOAT, TYPE_DOUBLE)
+
 
 def type_name_from_ctype(ctype):
     return type_names.get(ctype, ctype)
index 9418195..c1609aa 100644 (file)
@@ -25,7 +25,8 @@ from giscanner.ast import (Callback, Enum, Function, Namespace, Member,
                            Parameter, Return, Array, Struct, Field,
                            Type, Alias, Interface, Class, Node, Union,
                            List, Map, Varargs, Constant, type_name_from_ctype,
-                           type_names, default_array_types, TYPE_STRING)
+                           type_names, default_array_types, default_out_types,
+                           TYPE_STRING)
 from giscanner.config import DATADIR
 from .glibast import GLibBoxed
 from giscanner.sourcescanner import (
@@ -402,6 +403,15 @@ class Transformer(object):
             else:
                 options['transfer'] = ['full']
 
+        # deduce direction for some types passed by reference
+        if (not ('out' in options or
+                 'in' in options or
+                 'inout' in options or
+                 'in-out' in options) and
+            source_type.type == CTYPE_POINTER and
+            type_name_from_ctype(resolved_type_name) in default_out_types):
+            options['out'] = []
+
         return Type(resolved_type_name, ctype)
 
     def _handle_generic_param_options(self, param, options):
index 4dd1904..54ba700 100644 (file)
           </parameter>
         </parameters>
       </method>
+      <method name="get_origin" c:identifier="test_drawable_get_origin">
+        <return-value>
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="x" direction="out">
+            <type name="int" c:type="int*"/>
+          </parameter>
+          <parameter name="y" direction="out">
+            <type name="int" c:type="int*"/>
+          </parameter>
+        </parameters>
+      </method>
+      <method name="get_size" c:identifier="test_drawable_get_size">
+        <return-value>
+          <type name="none" c:type="void"/>
+        </return-value>
+        <parameters>
+          <parameter name="width" direction="out">
+            <type name="uint" c:type="guint*"/>
+          </parameter>
+          <parameter name="height" direction="out">
+            <type name="uint" c:type="guint*"/>
+          </parameter>
+        </parameters>
+      </method>
       <field name="parent_instance">
         <type name="GObject.Object" c:type="GObject"/>
       </field>
index 7dbd5fc..2f0d562 100644 (file)
@@ -19,3 +19,17 @@ test_drawable_do_foo (TestDrawable *drawable, int x)
 {
   
 }
+
+void
+test_drawable_get_origin (TestDrawable *drawable, int *x, int *y)
+{
+  *x = 0;
+  *y = 0;
+}
+
+void
+test_drawable_get_size (TestDrawable *drawable, guint *width, guint *height)
+{
+  *width = 42;
+  *height = 42;
+}
index dac51fb..c4db66b 100644 (file)
@@ -19,6 +19,8 @@ struct _TestDrawableClass
 GType test_drawable_get_type (void) G_GNUC_CONST;
 
 void test_drawable_do_foo (TestDrawable *drawable, int x);
+void test_drawable_get_origin (TestDrawable *drawable, int *x, int *y);
+void test_drawable_get_size (TestDrawable *drawable, guint *width, guint *height);
 
 struct _TestPixmapObjectClass
 {