After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 530605 - [PATCH] implement struct comparison
[PATCH] implement struct comparison
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Structs
0.3.x
Other All
: High normal
: 1.0
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2008-04-29 18:47 UTC by Marc-Andre Lureau
Modified: 2010-01-07 20:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
accept recusive nullable struct fields (856 bytes, patch)
2009-10-09 10:34 UTC, Marc-Andre Lureau
committed Details | Review
fix (1.53 KB, patch)
2009-10-09 10:34 UTC, Marc-Andre Lureau
rejected Details | Review
Bug 530605 - invalid operands to binary == (7.89 KB, patch)
2009-10-26 01:21 UTC, Marc-Andre Lureau
none Details | Review

Description Marc-Andre Lureau 2008-04-29 18:47:07 UTC
using GLib;

struct A {
	int a;
    int cmp (A? other) {
		if (this == other)
			return 1;
		return 0;
	}
}
Comment 1 Jürg Billeter 2008-05-02 21:06:37 UTC
Confirming.
Comment 2 Levi Bard 2009-04-01 20:18:17 UTC
This appears to be fixed as of 0.6.0.
Comment 3 Jürg Billeter 2009-07-27 13:24:38 UTC
No, it's not fixed yet.
Comment 4 Marc-Andre Lureau 2009-10-09 10:34:18 UTC
Created attachment 145112 [details] [review]
accept recusive nullable struct fields
Comment 5 Marc-Andre Lureau 2009-10-09 10:34:57 UTC
Created attachment 145113 [details] [review]
fix
Comment 6 Marc-Andre Lureau 2009-10-26 01:21:22 UTC
Created attachment 146235 [details] [review]
Bug 530605 - invalid operands to binary ==

That should make this kind of test work.

struct Test {
       Test? a;
       Test* b;
       void test() {
              bool aa = (&this != b);
              bool bb = (this != a);
       }
}

static void main() {
       Test t = new Test();
       Test* tp = &t;
       Test? tn = t;

       bool a = tn == t;
       bool b = t == tn;
}

codegen: implement struct_cmp
Comment 7 Marc-Andre Lureau 2009-10-26 10:08:45 UTC
Review of attachment 146235 [details] [review]:

::: codegen/valaccodebasemodule.vala
@@ +2326,3 @@
+		var right_type_as_struct = right_type.data_type as Struct;
+		var left_type_as_struct = left_type.data_type as Struct;
+	private void make_comparable_cexpression(DataType left_type, ref CCodeExpression cleft, DataType right_type, ref CCodeExpression cright) {

I guess we should keep the FIXME to check if cleft/cright are NULL before INDIRECTION

@@ +2401,3 @@
+				ccall.add_argument (s2);
+				cexp = ccall;
+			} else {

What about arrays? do we compare content or reference?
Comment 8 Jürg Billeter 2010-01-07 20:05:19 UTC
commit a04d18379da5c4cd4f4e860f68cad6647e20b4a0
Author: Jürg Billeter <j@bitron.ch>
Date:   Fri Oct 9 12:29:00 2009 +0200

    Support struct comparison
    
    Based on patch by Marc-André Lureau, fixes bug 530605.