]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Fix support for public fields on GLib.Source subclasses
authorOle André Vadla Ravnås <oleavr@gmail.com>
Sat, 22 May 2021 21:37:28 +0000 (23:37 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 22 May 2021 21:48:02 +0000 (23:48 +0200)
codegen/valagtypemodule.vala
tests/objects/gsource.vala

index 5930fcc74132647a8134e0ea2e7f89c931bc579f..a54b32619b2e798abb6a4a8538e2eef31f24e07d 100644 (file)
@@ -89,7 +89,7 @@ public class Vala.GTypeModule : GErrorModule {
                        decl_space.add_type_declaration (new CCodeNewline ());
                }
 
-               if (cl.is_compact && cl.base_class != null) {
+               if (!(!cl.is_compact || cl.base_class == null || compact_class_has_instance_struct_member (cl))) {
                        decl_space.add_type_declaration (new CCodeTypeDefinition (get_ccode_name (cl.base_class), new CCodeVariableDeclarator (get_ccode_name (cl))));
                } else {
                        decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (get_ccode_name (cl)), new CCodeVariableDeclarator (get_ccode_name (cl))));
@@ -339,8 +339,7 @@ public class Vala.GTypeModule : GErrorModule {
                        instance_struct.add_field ("int", "dummy");
                }
 
-               if (!cl.is_compact || cl.base_class == null) {
-                       // derived compact classes do not have a struct
+               if (!cl.is_compact || cl.base_class == null || compact_class_has_instance_struct_member (cl)) {
                        decl_space.add_type_definition (instance_struct);
                }
 
index cb2543979352b908e25ce67c4fa486229b291b38..753d2c4d97517e973b81f57f56e33ada95ecc1ff 100644 (file)
@@ -13,6 +13,28 @@ class FooSource : Source {
        }
 }
 
+class BarSource : Source {
+       public int custom_timeout;
+
+       public BarSource (int timeout) {
+               custom_timeout = timeout;
+       }
+
+       public override bool prepare (out int timeout) {
+               timeout = custom_timeout;
+               return false;
+       }
+
+       public override bool check () {
+               return false;
+       }
+
+       public override bool dispatch (SourceFunc? callback) {
+               return false;
+       }
+}
+
 void main () {
        var foo = new FooSource ();
+       var bar = new BarSource (1000);
 }