]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Perform required cast while assigning and passing function pointers
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 5 Feb 2023 18:33:15 +0000 (19:33 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 5 Feb 2023 19:05:26 +0000 (20:05 +0100)
Found by -Wincompatible-function-pointer-types

See https://gitlab.gnome.org/GNOME/vala/issues/1408

codegen/valaccodememberaccessmodule.vala
tests/delegates/params-array-with-throws.c-expected
tests/delegates/params-array.c-expected
tests/delegates/variadic.c-expected

index 77437775281573bb9e428707aa5ad7483a1b8591..29d0251428b5b8def61b3aadd24d4b7a25c26ce4 100644 (file)
@@ -90,6 +90,12 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                set_cvalue (expr, new CCodeIdentifier (get_ccode_name (m)));
                        }
 
+                       delegate_type = expr.target_type as DelegateType;
+                       if (delegate_type != null) {
+                               generate_type_declaration (delegate_type, cfile);
+                               set_cvalue (expr, new CCodeCastExpression (get_cvalue (expr), get_ccode_name (delegate_type.delegate_symbol)));
+                       }
+
                        set_delegate_target_destroy_notify (expr, new CCodeConstant ("NULL"));
                        if (m.binding == MemberBinding.STATIC) {
                                set_delegate_target (expr, new CCodeConstant ("NULL"));
index f3734d7f97df3d913534feb0d2089c5e75ec81e6..7c35f290f47c1dd6b22a22be3232c0e8bcf0b0ac 100644 (file)
@@ -173,7 +173,7 @@ _vala_main (void)
        GError* _inner_error0_ = NULL;
        {
                FooFunc func = NULL;
-               func = foo;
+               func = (FooFunc) foo;
                func (&_inner_error0_, "foo", "bar", "manam", NULL);
                if (G_UNLIKELY (_inner_error0_ != NULL)) {
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
@@ -183,7 +183,7 @@ _vala_main (void)
        }
        {
                FooFunc func = NULL;
-               func = bar;
+               func = (FooFunc) bar;
                {
                        FooFunc _tmp0_;
                        _tmp0_ = func;
index 339c072a0b6551bb92c7342c8f89b3f5c0af3645..b41164b6eeccd0f3d82a235e8968f64614bb8d59 100644 (file)
@@ -349,12 +349,12 @@ _vala_main (void)
 {
        {
                FooFunc func = NULL;
-               func = foo;
+               func = (FooFunc) foo;
                func ("foo", "bar", "manam", NULL);
        }
        {
                BarFunc func = NULL;
-               func = bar;
+               func = (BarFunc) bar;
                func (23, 42, 4711, NULL);
        }
        {
@@ -362,7 +362,7 @@ _vala_main (void)
                GValue* _tmp0_ = NULL;
                GValue* _tmp1_ = NULL;
                GValue* _tmp2_ = NULL;
-               func = manam;
+               func = (ManamFunc) manam;
                _tmp0_ = g_new0 (GValue, 1);
                g_value_init (_tmp0_, G_TYPE_STRING);
                g_value_set_string (_tmp0_, "foo");
@@ -382,7 +382,7 @@ _vala_main (void)
                GValue* _tmp3_ = NULL;
                GValue* _tmp4_ = NULL;
                GValue* _tmp5_ = NULL;
-               func = manam_owned;
+               func = (ManamOwnedFunc) manam_owned;
                _tmp3_ = g_new0 (GValue, 1);
                g_value_init (_tmp3_, G_TYPE_STRING);
                g_value_set_string (_tmp3_, "foo");
@@ -399,7 +399,7 @@ _vala_main (void)
                GVariant* _tmp6_;
                GVariant* _tmp7_;
                GVariant* _tmp8_;
-               func = minim;
+               func = (MinimFunc) minim;
                _tmp6_ = _variant_new1 ("foo");
                _tmp7_ = _variant_new2 (4711);
                _tmp8_ = _variant_new3 (3.1415);
index 7df1cf3ff38ad794adf95c8b807de424daf48b80..cb3a55b50284de4f0e6f50f31c073dccbf94b20b 100644 (file)
@@ -151,13 +151,13 @@ _vala_main (void)
        GError* _inner_error0_ = NULL;
        {
                FooFunc func = NULL;
-               func = foo;
+               func = (FooFunc) foo;
                func ("foo", 42, "bar", NULL);
        }
        {
                FooFunc func = NULL;
                BarFunc f = NULL;
-               func = foo;
+               func = (FooFunc) foo;
                f = func;
        }
        {
@@ -168,7 +168,7 @@ _vala_main (void)
        }
        {
                BazFunc func = NULL;
-               func = baz;
+               func = (BazFunc) baz;
                func ("baz", &_inner_error0_, 23, "bar", NULL);
                if (G_UNLIKELY (_inner_error0_ != NULL)) {
                        g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
@@ -178,7 +178,7 @@ _vala_main (void)
        }
        {
                BazFunc func = NULL;
-               func = baz_fail;
+               func = (BazFunc) baz_fail;
                {
                        BazFunc _tmp0_;
                        _tmp0_ = func;
@@ -210,7 +210,7 @@ _vala_main (void)
                }
        }
        {
-               mamam (foo);
+               mamam ((FooFunc) foo);
        }
        {
                mamam ((FooFunc) foo);