]> 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>
Wed, 16 Feb 2022 17:31:49 +0000 (18:31 +0100)
Found by -Werror=address with GCC 12

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

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

index 548e63b754bf3ac35c55f0e00ff418abe40bc748..34452d80aaad5c064e9f4be9340b7bfadadffdfb 100644 (file)
@@ -449,7 +449,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 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 de5aa5db3f95c15981e371e68bd43ff403351449..cad4a68e8f5e97df00da6bd8f9a371554f0c6e72 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 114735bc4219d657056e6f3ebfa8a066cae9254a..f15c094ede94cc111f4e4fd1a48046fb9c445a5f 100644 (file)
@@ -193,10 +193,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;
                }