[vala] Fix GType declaration for structs



commit 79b4d15b1ed7b2810639c831f321ca3c4dd47464
Author: Levi Bard <taktaktaktaktaktaktaktaktaktak gmail com>
Date:   Wed Apr 15 23:02:15 2009 +0200

    Fix GType declaration for structs
    
    Fixes bug 578162.
---
 gobject/valaccodestructmodule.vala |   10 ++++++++++
 gobject/valagtypemodule.vala       |   13 +++++--------
 2 files changed, 15 insertions(+), 8 deletions(-)

diff --git a/gobject/valaccodestructmodule.vala b/gobject/valaccodestructmodule.vala
index d1cfe5e..7a61de8 100644
--- a/gobject/valaccodestructmodule.vala
+++ b/gobject/valaccodestructmodule.vala
@@ -34,6 +34,16 @@ internal class Vala.CCodeStructModule : CCodeBaseModule {
 			return;
 		}
 
+		if (st.has_type_id) {
+			decl_space.add_type_declaration (new CCodeNewline ());
+			var macro = "(%s_get_type ())".printf (st.get_lower_case_cname (null));
+			decl_space.add_type_declaration (new CCodeMacroReplacement (st.get_type_id (), macro));
+
+			var type_fun = new StructRegisterFunction (st, context);
+			type_fun.init_from_type (false);
+			decl_space.add_type_member_declaration (type_fun.get_declaration ());
+		}
+
 		var instance_struct = new CCodeStruct ("_%s".printf (st.get_cname ()));
 
 		foreach (Field f in st.get_fields ()) {
diff --git a/gobject/valagtypemodule.vala b/gobject/valagtypemodule.vala
index 8b6be98..7a7acbb 100644
--- a/gobject/valagtypemodule.vala
+++ b/gobject/valagtypemodule.vala
@@ -1760,13 +1760,10 @@ internal class Vala.GTypeModule : GErrorModule {
 	public override void visit_struct (Struct st) {
 		base.visit_struct (st);
 
-		source_declarations.add_type_declaration (new CCodeNewline ());
-		var macro = "(%s_get_type ())".printf (st.get_lower_case_cname (null));
-		source_declarations.add_type_declaration (new CCodeMacroReplacement (st.get_type_id (), macro));
-
-		var type_fun = new StructRegisterFunction (st, context);
-		type_fun.init_from_type (false);
-		source_declarations.add_type_member_declaration (type_fun.get_declaration ());
-		source_type_member_definition.append (type_fun.get_definition ());
+		if (st.has_type_id) {
+			var type_fun = new StructRegisterFunction (st, context);
+			type_fun.init_from_type (false);
+			source_type_member_definition.append (type_fun.get_definition ());
+		}
 	}
 }



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