gobject-introspection r710 - in trunk: . giscanner tests/scanner



Author: jobi
Date: Wed Oct 15 17:47:08 2008
New Revision: 710
URL: http://svn.gnome.org/viewvc/gobject-introspection?rev=710&view=rev

Log:

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



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

Modified: trunk/giscanner/ast.py
==============================================================================
--- trunk/giscanner/ast.py	(original)
+++ trunk/giscanner/ast.py	Wed Oct 15 17:47:08 2008
@@ -123,6 +123,10 @@
 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)

Modified: trunk/giscanner/transformer.py
==============================================================================
--- trunk/giscanner/transformer.py	(original)
+++ trunk/giscanner/transformer.py	Wed Oct 15 17:47:08 2008
@@ -25,7 +25,8 @@
                            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 @@
             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):

Modified: trunk/tests/scanner/drawable-1.0-expected.gir
==============================================================================
--- trunk/tests/scanner/drawable-1.0-expected.gir	(original)
+++ trunk/tests/scanner/drawable-1.0-expected.gir	Wed Oct 15 17:47:08 2008
@@ -22,6 +22,32 @@
           </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>

Modified: trunk/tests/scanner/drawable.c
==============================================================================
--- trunk/tests/scanner/drawable.c	(original)
+++ trunk/tests/scanner/drawable.c	Wed Oct 15 17:47:08 2008
@@ -19,3 +19,17 @@
 {
   
 }
+
+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;
+}

Modified: trunk/tests/scanner/drawable.h
==============================================================================
--- trunk/tests/scanner/drawable.h	(original)
+++ trunk/tests/scanner/drawable.h	Wed Oct 15 17:47:08 2008
@@ -19,6 +19,8 @@
 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
 {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]