]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't uncoditionally null check callback_func for GLib.Closure
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 24 Jan 2022 09:17:46 +0000 (10:17 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 24 Jan 2022 09:17:46 +0000 (10:17 +0100)
Found by -Werror=address with GCC 12

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

codegen/valaccodemethodcallmodule.vala
tests/delegates/gclosure-conversion.c-expected
tests/delegates/gclosure-conversion.vala
vala/valacastexpression.vala
vala/valamemberaccess.vala

index 1e0b3ad9580270c72766ebb9a8f072bfdcd47b2d..d7827741b99fe23d4744513e29774d8632f06e4b 100644 (file)
@@ -437,7 +437,12 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                                                        closure_new.add_argument (new CCodeCastExpression (cexpr, "GCallback"));
                                                                        closure_new.add_argument (delegate_target);
                                                                        closure_new.add_argument (new CCodeCastExpression (delegate_target_destroy_notify, "GClosureNotify"));
-                                                                       cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeConstant ("NULL")), new CCodeConstant ("NULL"), closure_new);
+                                                                       //TODO Use get_non_null (arg.target_value)
+                                                                       if (arg.is_non_null ()) {
+                                                                               cexpr = closure_new;
+                                                                       } else {
+                                                                               cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeConstant ("NULL")), new CCodeConstant ("NULL"), closure_new);
+                                                                       }
                                                                } else {
                                                                        // Override previously given target/destroy only if it was NULL
                                                                        // TODO https://gitlab.gnome.org/GNOME/vala/issues/59
index 991bb6f150d3301091ca38e2829d6c2a329e437d..916299d7c6d647721e8d9033bc18f780621afdfb 100644 (file)
@@ -431,6 +431,9 @@ _vala_main (void)
        Foo* _tmp0_;
        Bar* bar = NULL;
        Bar* _tmp1_;
+       GBindingTransformFunc transform_to_func = NULL;
+       gpointer transform_to_func_target;
+       GDestroyNotify transform_to_func_target_destroy_notify;
        gint _tmp2_;
        gint _tmp3_;
        const gchar* _tmp4_;
@@ -439,7 +442,10 @@ _vala_main (void)
        foo = _tmp0_;
        _tmp1_ = bar_new ();
        bar = _tmp1_;
-       g_object_bind_property_with_closures (G_TYPE_CHECK_INSTANCE_CAST (foo, G_TYPE_OBJECT, GObject), "foo", G_TYPE_CHECK_INSTANCE_CAST (bar, G_TYPE_OBJECT, GObject), "bar", G_BINDING_BIDIRECTIONAL, (GClosure*) ((((GBindingTransformFunc) to_int) == NULL) ? NULL : g_cclosure_new ((GCallback) ((GBindingTransformFunc) to_int), NULL, (GClosureNotify) NULL)), (GClosure*) ((((GBindingTransformFunc) to_string) == NULL) ? NULL : g_cclosure_new ((GCallback) ((GBindingTransformFunc) to_string), NULL, (GClosureNotify) NULL)));
+       transform_to_func = (GBindingTransformFunc) to_int;
+       transform_to_func_target = NULL;
+       transform_to_func_target_destroy_notify = NULL;
+       g_object_bind_property_with_closures (G_TYPE_CHECK_INSTANCE_CAST (foo, G_TYPE_OBJECT, GObject), "foo", G_TYPE_CHECK_INSTANCE_CAST (bar, G_TYPE_OBJECT, GObject), "bar", G_BINDING_BIDIRECTIONAL, (GClosure*) ((transform_to_func == NULL) ? NULL : g_cclosure_new ((GCallback) transform_to_func, transform_to_func_target, (GClosureNotify) NULL)), (GClosure*) g_cclosure_new ((GCallback) ((GBindingTransformFunc) to_string), NULL, (GClosureNotify) NULL));
        foo_set_foo (foo, "42");
        _tmp2_ = bar_get_bar (bar);
        _tmp3_ = _tmp2_;
@@ -448,6 +454,10 @@ _vala_main (void)
        _tmp4_ = foo_get_foo (foo);
        _tmp5_ = _tmp4_;
        _vala_assert (g_strcmp0 (_tmp5_, "23") == 0, "foo.foo == \"23\"");
+       (transform_to_func_target_destroy_notify == NULL) ? NULL : (transform_to_func_target_destroy_notify (transform_to_func_target), NULL);
+       transform_to_func = NULL;
+       transform_to_func_target = NULL;
+       transform_to_func_target_destroy_notify = NULL;
        _g_object_unref0 (bar);
        _g_object_unref0 (foo);
 }
index 7df324a3a8227cc1040aaae6d6eea0e3b6759d0f..e8c8b6e1636f46b65312a608e75f13cd8d326a86 100644 (file)
@@ -20,8 +20,10 @@ void main () {
        var foo = new Foo ();
        var bar = new Bar ();
 
+       BindingTransformFunc transform_to_func = (BindingTransformFunc) to_int;
+
        foo.bind_property ("foo", bar, "bar", BindingFlags.BIDIRECTIONAL,
-               (BindingTransformFunc) to_int, (BindingTransformFunc) to_string);
+               transform_to_func, (BindingTransformFunc) to_string);
 
        foo.foo = "42";
        assert (bar.bar == 42);
index 5d0783e41d95a4bf8568a510226d0fa769d0b503..95a708fecb947a8ad4a8f56355160b9edd1944e9 100644 (file)
@@ -132,6 +132,10 @@ public class Vala.CastExpression : Expression {
                }
        }
 
+       public override bool is_non_null () {
+               return is_non_null_cast || (!is_silent_cast && inner.is_non_null ());
+       }
+
        public override void get_error_types (Collection<DataType> collection, SourceReference? source_reference = null) {
                inner.get_error_types (collection, source_reference);
        }
index 12154b0f601e667db5944002d5d603ed20cc5350..d27a4266a0aaf5d868367dc411827b88213282a6 100644 (file)
@@ -199,10 +199,13 @@ public class Vala.MemberAccess : Expression {
        public override bool is_non_null () {
                unowned Constant? c = symbol_reference as Constant;
                unowned LocalVariable? l = symbol_reference as LocalVariable;
+               unowned Method? m = symbol_reference as Method;
                if (c != null) {
                        return (c is EnumValue || !c.type_reference.nullable);
                } else if (l != null) {
                        return (l.variable_type is ArrayType && ((ArrayType) l.variable_type).inline_allocated);
+               } else if (m != null) {
+                       return (m.binding == MemberBinding.STATIC || prototype_access);
                } else {
                        return false;
                }