[vala] codegen: Fix definition of fields when array length cname is specified



commit 0a67ba6c93a371c2d6350d8f0d7bcddfea2d9d18
Author: Luca Bruno <lucabru src gnome org>
Date:   Sun May 29 19:05:00 2011 +0200

    codegen: Fix definition of fields when array length cname is specified
    
    Fixes bug 588203.

 codegen/valaccodestructmodule.vala |    8 +++++++-
 codegen/valagtypemodule.vala       |   16 ++++++++++++++--
 tests/Makefile.am                  |    1 +
 tests/objects/bug588203.vala       |    9 +++++++++
 4 files changed, 31 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index b038472..a1abbbf 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -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 ()) {
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 73a1259..239f3a3 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -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 ()) {
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b4026c4..2d70b43 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -74,6 +74,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
index 0000000..e3c251e
--- /dev/null
+++ b/tests/objects/bug588203.vala
@@ -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];
+}



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