]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix equal function for SimpleType structs with only static fields
authorLuca Bruno <lucabru@src.gnome.org>
Wed, 31 Aug 2011 13:37:04 +0000 (15:37 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Wed, 31 Aug 2011 14:01:39 +0000 (16:01 +0200)
The function produced wrong results if the struct had static fields but
no instance fields.

Fixes bug 657813.

codegen/valaccodebasemodule.vala

index c9d141739e8c973e73d838b1d7d70081923fd7e8..f8897980b80a9c16cdb3d5dc3786adb535874cde 100644 (file)
@@ -2487,12 +2487,15 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        ccode.close ();
                }
 
+               bool has_instance_fields = false;
                foreach (Field f in st.get_fields ()) {
                        if (f.binding != MemberBinding.INSTANCE) {
                                // we only compare instance fields
                                continue;
                        }
 
+                       has_instance_fields = true;
+
                        CCodeExpression cexp; // if (cexp) return FALSE;
                        var s1 = (CCodeExpression) new CCodeMemberAccess.pointer (new CCodeIdentifier ("s1"), f.name); // s1->f
                        var s2 = (CCodeExpression) new CCodeMemberAccess.pointer (new CCodeIdentifier ("s2"), f.name); // s2->f
@@ -2520,7 +2523,7 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        ccode.close ();
                }
 
-               if (st.get_fields().size == 0) {
+               if (!has_instance_fields) {
                        // either opaque structure or simple type
                        if (st.is_simple_type ()) {
                                var cexp = new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s1")), new CCodeUnaryExpression (CCodeUnaryOperator.POINTER_INDIRECTION, new CCodeIdentifier ("s2")));