]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix definition of fields when array length cname is specified
authorLuca Bruno <lucabru@src.gnome.org>
Sun, 29 May 2011 17:05:00 +0000 (19:05 +0200)
committerJürg Billeter <j@bitron.ch>
Tue, 31 May 2011 19:04:07 +0000 (21:04 +0200)
Fixes bug 588203.

codegen/valaccodestructmodule.vala
codegen/valagtypemodule.vala
tests/Makefile.am
tests/objects/bug588203.vala [new file with mode: 0644]

index b6114dcbfae5e1ecc8d8b84a661a89a3fc58a029..e641d9bba7acc118097b1ccf5b2c87511a8b9609 100644 (file)
@@ -79,7 +79,13 @@ public abstract class Vala.CCodeStructModule : CCodeBaseModule {
                                                var len_type = int_type.copy ();
 
                                                for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                       instance_struct.add_field (len_type.get_cname (), get_array_length_cname (f.name, dim));
+                                                       string length_cname;
+                                                       if (f.has_array_length_cname) {
+                                                               length_cname = f.get_array_length_cname ();
+                                                       } else {
+                                                               length_cname = get_array_length_cname (f.name, dim);
+                                                       }
+                                                       instance_struct.add_field (len_type.get_cname (), length_cname);
                                                }
 
                                                if (array_type.rank == 1 && f.is_internal_symbol ()) {
index 5dde7d3702068481a22c85b198e0c5d65d6fa5ad..5837a37b3b3e31a016821f6c2a79a4dd08e7db58 100644 (file)
@@ -321,7 +321,13 @@ public class Vala.GTypeModule : GErrorModule {
                                                        var len_type = int_type.copy ();
 
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               instance_struct.add_field (len_type.get_cname (), get_array_length_cname (f.name, dim));
+                                                               string length_cname;
+                                                               if (f.has_array_length_cname) {
+                                                                       length_cname = f.get_array_length_cname ();
+                                                               } else {
+                                                                       length_cname = get_array_length_cname (f.name, dim);
+                                                               }
+                                                               instance_struct.add_field (len_type.get_cname (), length_cname);
                                                        }
 
                                                        if (array_type.rank == 1 && f.is_internal_symbol ()) {
@@ -421,7 +427,13 @@ public class Vala.GTypeModule : GErrorModule {
 
                                                if (!array_type.fixed_length) {
                                                        for (int dim = 1; dim <= array_type.rank; dim++) {
-                                                               instance_priv_struct.add_field (len_type.get_cname (), get_array_length_cname (f.name, dim));
+                                                               string length_cname;
+                                                               if (f.has_array_length_cname) {
+                                                                       length_cname = f.get_array_length_cname ();
+                                                               } else {
+                                                                       length_cname = get_array_length_cname (f.name, dim);
+                                                               }
+                                                               instance_priv_struct.add_field (len_type.get_cname (), length_cname);
                                                        }
 
                                                        if (array_type.rank == 1 && f.is_internal_symbol ()) {
index 4eb2251ea91a88b8c8588c21e20f532e151e7857..723baa8a029fae4fde2ccd0e8a870ac3d50f674d 100644 (file)
@@ -70,6 +70,7 @@ TESTS = \
        objects/test-029.vala \
        objects/test-034.vala \
        objects/bug566909.vala \
+       objects/bug588203.vala \
        objects/bug593260.vala \
        objects/bug596621.vala \
        objects/bug597155.vala \
diff --git a/tests/objects/bug588203.vala b/tests/objects/bug588203.vala
new file mode 100644 (file)
index 0000000..e3c251e
--- /dev/null
@@ -0,0 +1,9 @@
+public class Foo {
+       [CCode (array_length_cname = "length")]
+       public int[] bar;
+}
+
+void main () {
+       var foo = new Foo ();
+       foo.bar = new int[10];
+}