[vala] GType: Support virtual signals in interfaces



commit 72815fed8f55b91c137e778156e13ba1a9e64d45
Author: Luca Bruno <lucabru src gnome org>
Date:   Mon May 16 15:51:29 2011 +0200

    GType: Support virtual signals in interfaces
    
    Fixes bug 642809.

 codegen/valagsignalmodule.vala |    8 ++++++--
 codegen/valagtypemodule.vala   |    6 ++++++
 tests/Makefile.am              |    1 +
 tests/objects/bug642809.vala   |   11 +++++++++++
 4 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valagsignalmodule.vala b/codegen/valagsignalmodule.vala
index 27d0c58..1bde964 100644
--- a/codegen/valagsignalmodule.vala
+++ b/codegen/valagsignalmodule.vala
@@ -336,7 +336,6 @@ public class Vala.GSignalModule : GObjectModule {
 
 	public override CCodeFunctionCall get_signal_creation (Signal sig, TypeSymbol type) {	
 		var csignew = new CCodeFunctionCall (new CCodeIdentifier ("g_signal_new"));
-		var cl = sig.parent_symbol as Class;
 		csignew.add_argument (new CCodeConstant ("\"%s\"".printf (sig.get_cname ())));
 		csignew.add_argument (new CCodeIdentifier (type.get_type_id ()));
 		string[] flags = new string[0];
@@ -369,7 +368,12 @@ public class Vala.GSignalModule : GObjectModule {
 			csignew.add_argument (new CCodeConstant ("0"));
 		} else {
 			var struct_offset = new CCodeFunctionCall (new CCodeIdentifier ("G_STRUCT_OFFSET"));
-			struct_offset.add_argument (new CCodeIdentifier ("%sClass".printf (cl.get_cname ())));
+			if (type is Class) {
+				struct_offset.add_argument (new CCodeIdentifier ("%sClass".printf (type.get_cname ())));
+			} else {
+				// interface
+				struct_offset.add_argument (new CCodeIdentifier (((Interface) type).get_type_cname ()));
+			}
 			struct_offset.add_argument (new CCodeIdentifier (sig.default_handler.vfunc_name));
 			csignew.add_argument (struct_offset);
 		}
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index b84bd15..e5eb298 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -1861,6 +1861,12 @@ public class Vala.GTypeModule : GErrorModule {
 			generate_virtual_method_declaration (m, decl_space, type_struct);
 		}
 
+		foreach (Signal sig in iface.get_signals ()) {
+			if (sig.default_handler != null) {
+				generate_virtual_method_declaration (sig.default_handler, decl_space, type_struct);
+			}
+		}
+
 		foreach (Property prop in iface.get_properties ()) {
 			if (!prop.is_abstract && !prop.is_virtual) {
 				continue;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 95cb9ea..3169591 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -78,6 +78,7 @@ TESTS = \
 	objects/bug620706.vala \
 	objects/bug624594.vala \
 	objects/bug628639.vala \
+	objects/bug642809.vala \
 	errors/errors.vala \
 	errors/bug567181.vala \
 	errors/bug579101.vala \
diff --git a/tests/objects/bug642809.vala b/tests/objects/bug642809.vala
new file mode 100644
index 0000000..91ba53e
--- /dev/null
+++ b/tests/objects/bug642809.vala
@@ -0,0 +1,11 @@
+interface Foo : Object {
+	public virtual signal void virtual_signal () { }
+}
+
+class Bar : Object, Foo {
+}
+
+void main () {
+	var bar = new Bar ();
+	bar.virtual_signal ();
+}



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