]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Use get_value_*_function() in GSignalModule.generate_marshaller()
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 12 Apr 2020 09:02:29 +0000 (11:02 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 20 Apr 2020 19:43:27 +0000 (21:43 +0200)
This makes sure to pick up the intended function like the generated ones
for fundamental classes.

Fixes https://gitlab.gnome.org/GNOME/vala/issues/468

codegen/valaccodebasemodule.vala
codegen/valagsignalmodule.vala
tests/Makefile.am
tests/objects/signals-fundamental-return.vala [new file with mode: 0644]
tests/objects/signals-gobject-return.vala [new file with mode: 0644]

index 3719a23b68769a09e5c1c8d69be9c6e07bd87440..af7378a1dbc51d39cd6b2a6ace4c6341a93c2306 100644 (file)
@@ -708,7 +708,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                }
        }
 
-       CCodeIdentifier get_value_getter_function (DataType type_reference) {
+       public CCodeIdentifier get_value_getter_function (DataType type_reference) {
                var array_type = type_reference as ArrayType;
                if (type_reference.data_type != null) {
                        return new CCodeIdentifier (get_ccode_get_value_function (type_reference.data_type));
index f87a4e0dc81fcec362830ee8be44cff8cc456a77..5c37c8ee6a7c9f3816cb0067065988871431d674 100644 (file)
@@ -261,27 +261,14 @@ public class Vala.GSignalModule : GObjectModule {
                fc.add_argument (new CCodeIdentifier ("data1"));
                i = 1;
                foreach (Parameter p in params) {
-                       string get_value_function;
+                       CCodeFunctionCall inner_fc;
                        if (p.direction != ParameterDirection.IN) {
-                               get_value_function = "g_value_get_pointer";
-                       } else if (p.variable_type is ArrayType) {
-                               if (((ArrayType) p.variable_type).element_type.data_type == string_type.data_type) {
-                                       get_value_function = "g_value_get_boxed";
-                               } else {
-                                       get_value_function = "g_value_get_pointer";
-                               }
-                       } else if (p.variable_type is DelegateType) {
-                               get_value_function = "g_value_get_pointer";
-                       } else if (p.variable_type is PointerType || p.variable_type is GenericType) {
-                               get_value_function = "g_value_get_pointer";
-                       } else if (p.variable_type is ErrorType) {
-                               get_value_function = "g_value_get_pointer";
+                               inner_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                        } else if (p.variable_type is ValueType && p.variable_type.nullable) {
-                               get_value_function = "g_value_get_pointer";
+                               inner_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                        } else {
-                               get_value_function = get_ccode_get_value_function (p.variable_type.data_type);
+                               inner_fc = new CCodeFunctionCall (get_value_getter_function (p.variable_type));
                        }
-                       var inner_fc = new CCodeFunctionCall (new CCodeIdentifier (get_value_function));
                        inner_fc.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
                        fc.add_argument (inner_fc);
                        i++;
@@ -298,12 +285,12 @@ public class Vala.GSignalModule : GObjectModule {
                        } else if (p.variable_type is DelegateType) {
                                unowned DelegateType delegate_type = (DelegateType) p.variable_type;
                                if (delegate_type.delegate_symbol.has_target) {
-                                       inner_fc = new CCodeFunctionCall (new CCodeIdentifier (get_value_function));
+                                       inner_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                                        inner_fc.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
                                        fc.add_argument (inner_fc);
                                        i++;
                                        if (delegate_type.is_disposable ()) {
-                                               inner_fc = new CCodeFunctionCall (new CCodeIdentifier (get_value_function));
+                                               inner_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_get_pointer"));
                                                inner_fc.add_argument (new CCodeBinaryExpression (CCodeBinaryOperator.PLUS, new CCodeIdentifier ("param_values"), new CCodeIdentifier (i.to_string ())));
                                                fc.add_argument (inner_fc);
                                                i++;
@@ -317,24 +304,14 @@ public class Vala.GSignalModule : GObjectModule {
                        ccode.add_assignment (new CCodeIdentifier ("v_return"), fc);
 
                        CCodeFunctionCall set_fc;
-                       if (return_type is ArrayType) {
-                               if (((ArrayType) return_type).element_type.data_type == string_type.data_type) {
-                                       set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_boxed"));
-                               } else {
+                       if (return_type is ValueType) {
+                               if (return_type.nullable) {
                                        set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
+                               } else {
+                                       set_fc = new CCodeFunctionCall (get_value_setter_function (return_type));
                                }
-                       } else if (return_type is GenericType) {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
-                       } else if (return_type is ErrorType) {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
-                       } else if (return_type.data_type == string_type.data_type) {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_string"));
-                       } else if (return_type.data_type is Class || return_type.data_type is Interface) {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_take_object"));
-                       } else if (return_type is ValueType && return_type.nullable) {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier ("g_value_set_pointer"));
                        } else {
-                               set_fc = new CCodeFunctionCall (new CCodeIdentifier (get_ccode_set_value_function (return_type.data_type)));
+                               set_fc = new CCodeFunctionCall (get_value_taker_function (return_type));
                        }
                        set_fc.add_argument (new CCodeIdentifier ("return_value"));
                        set_fc.add_argument (new CCodeIdentifier ("v_return"));
index 18aeab85414cccbad95aaaee0fd076952f1a3ba6..fc848e2011f03d8168f2c9e2e1b1f51695c5c6ee 100644 (file)
@@ -392,6 +392,8 @@ TESTS = \
        objects/signals-enum-marshal.vala \
        objects/signals-delegate.vala \
        objects/signals-delegate-parameter.vala \
+       objects/signals-fundamental-return.vala \
+       objects/signals-gobject-return.vala \
        objects/signals-lambda-delegate.vala \
        objects/singleton.vala \
        objects/test-025.vala \
diff --git a/tests/objects/signals-fundamental-return.vala b/tests/objects/signals-fundamental-return.vala
new file mode 100644 (file)
index 0000000..d73ed03
--- /dev/null
@@ -0,0 +1,28 @@
+class Maman {
+}
+
+interface IBar : Maman {
+}
+
+class Bar : Maman, IBar {
+}
+
+class Foo {
+       public signal Foo on_foo ();
+       public signal IBar on_bar ();
+}
+
+void main () {
+       var foo = new Foo ();
+       foo.on_foo.connect (() => {
+               return new Foo ();
+       });
+       foo.on_bar.connect (() => {
+               return new Bar ();
+       });
+
+       var bar = foo.on_foo ();
+       assert (bar is Foo);
+       var bar2 = foo.on_bar ();
+       assert (bar2 is IBar);
+}
diff --git a/tests/objects/signals-gobject-return.vala b/tests/objects/signals-gobject-return.vala
new file mode 100644 (file)
index 0000000..71f20df
--- /dev/null
@@ -0,0 +1,22 @@
+interface IBar : Object {
+}
+
+class Foo : Object, IBar {
+       public signal Foo on_foo ();
+       public signal IBar on_bar ();
+}
+
+void main () {
+       var foo = new Foo ();
+       foo.on_foo.connect (() => {
+               return new Foo ();
+       });
+       foo.on_bar.connect (() => {
+               return new Foo ();
+       });
+
+       var bar = foo.on_foo ();
+       assert (bar is Foo);
+       var bar2 = foo.on_bar ();
+       assert (bar2 is IBar);
+}