From: Johan Bilien Date: Wed, 15 Oct 2008 17:47:08 +0000 (+0000) Subject: Bug 556433 – assume direction = out for int * parameters X-Git-Tag: GOBJECT_INTROSPECTION_0_6_0~139 X-Git-Url: http://git.roojs.org/?a=commitdiff_plain;h=a658109407ab33222584b93ae00aaf135807a456;p=gnome.gobject-introspection Bug 556433 – assume direction = out for int * parameters 2008-10-15 Johan Bilien 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 --- diff --git a/ChangeLog b/ChangeLog index dff9e69..e4b16a8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-10-15 Johan Bilien + + 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 * tests/scanner/annotation.c: fixed a few copy-paste errors diff --git a/giscanner/ast.py b/giscanner/ast.py index 3d2c76c..8ee6f7a 100644 --- a/giscanner/ast.py +++ b/giscanner/ast.py @@ -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) diff --git a/giscanner/transformer.py b/giscanner/transformer.py index 9418195..c1609aa 100644 --- a/giscanner/transformer.py +++ b/giscanner/transformer.py @@ -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): diff --git a/tests/scanner/drawable-1.0-expected.gir b/tests/scanner/drawable-1.0-expected.gir index 4dd1904..54ba700 100644 --- a/tests/scanner/drawable-1.0-expected.gir +++ b/tests/scanner/drawable-1.0-expected.gir @@ -22,6 +22,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/scanner/drawable.c b/tests/scanner/drawable.c index 7dbd5fc..2f0d562 100644 --- a/tests/scanner/drawable.c +++ b/tests/scanner/drawable.c @@ -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; +} diff --git a/tests/scanner/drawable.h b/tests/scanner/drawable.h index dac51fb..c4db66b 100644 --- a/tests/scanner/drawable.h +++ b/tests/scanner/drawable.h @@ -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 {