[vala/0.52] codegen: Don't uncoditionally null check callback_func for GLib.Closure



commit 0c9b9a80a05d566f1021f7b3ecd7748a20df274c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Jan 24 10:17:46 2022 +0100

    codegen: Don't uncoditionally null check callback_func for GLib.Closure
    
    Found by -Werror=address with GCC 12
    
    See https://gitlab.gnome.org/GNOME/vala/issues/1282

 codegen/valaccodemethodcallmodule.vala   | 7 ++++++-
 tests/delegates/gclosure-conversion.vala | 4 +++-
 vala/valacastexpression.vala             | 4 ++++
 vala/valamemberaccess.vala               | 3 +++
 4 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index 8fa45ed37..3098daa6f 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -460,7 +460,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
diff --git a/tests/delegates/gclosure-conversion.vala b/tests/delegates/gclosure-conversion.vala
index 7df324a3a..e8c8b6e16 100644
--- a/tests/delegates/gclosure-conversion.vala
+++ b/tests/delegates/gclosure-conversion.vala
@@ -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);
diff --git a/vala/valacastexpression.vala b/vala/valacastexpression.vala
index 1d1dbb0f2..bc8441ac9 100644
--- a/vala/valacastexpression.vala
+++ b/vala/valacastexpression.vala
@@ -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);
        }
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index a56b7cf78..35c5bdc98 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -194,10 +194,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;
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]