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



commit faddfe33c36ddf8e5b5497b39850c33f2a763542
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 b6114dc..e641d9b 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 5dde7d3..5837a37 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 4eb2251..723baa8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
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]