]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Implementing GLib.Source.prepare/check is optional since 2.36
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 26 May 2021 16:39:20 +0000 (18:39 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 22 Jul 2021 08:57:32 +0000 (10:57 +0200)
codegen/valaccodemethodcallmodule.vala
tests/objects/gsource.vala
vapi/glib-2.0.vapi

index 3b4d03b2497bb998ceebd489dd9867b31bc1ce4f..7154c18df2c8b31ab1fbd59666199d47dda4d008 100644 (file)
@@ -206,10 +206,27 @@ public class Vala.CCodeMethodCallModule : CCodeAssignmentModule {
                                // g_source_new
 
                                string class_prefix = get_ccode_lower_case_name (current_class);
+                               string prepare_func = "NULL";
+                               string check_func = "NULL";
+                               foreach (Method impl in current_class.get_methods ()) {
+                                       if (!impl.overrides) {
+                                               continue;
+                                       }
+                                       switch (impl.name) {
+                                       case "prepare":
+                                               prepare_func = "%s_real_prepare".printf (class_prefix);
+                                               break;
+                                       case "check":
+                                               check_func = "%s_real_check".printf (class_prefix);
+                                               break;
+                                       default:
+                                               break;
+                                       }
+                               }
 
                                var funcs = new CCodeDeclaration ("const GSourceFuncs");
                                funcs.modifiers = CCodeModifiers.STATIC;
-                               funcs.add_declarator (new CCodeVariableDeclarator ("_source_funcs", new CCodeConstant ("{ %s_real_prepare, %s_real_check, %s_real_dispatch, %s_finalize}".printf (class_prefix, class_prefix, class_prefix, class_prefix))));
+                               funcs.add_declarator (new CCodeVariableDeclarator ("_source_funcs", new CCodeConstant ("{ %s, %s, %s_real_dispatch, %s_finalize}".printf (prepare_func, check_func, class_prefix, class_prefix))));
                                ccode.add_statement (funcs);
 
                                ccall.add_argument (new CCodeCastExpression (new CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, new CCodeIdentifier ("_source_funcs")), "GSourceFuncs *"));
index cb2543979352b908e25ce67c4fa486229b291b38..c2185b9a760257af204f8b5d9585394546d809f2 100644 (file)
@@ -13,6 +13,13 @@ class FooSource : Source {
        }
 }
 
+class ManamSource : Source {
+       public override bool dispatch (SourceFunc? callback) {
+               return false;
+       }
+}
+
 void main () {
        var foo = new FooSource ();
+       var manam = new ManamSource ();
 }
index a81812741b85e1eabe63f540417000ed42f9f9da..4d8b298f4e7787dfe15c96abc2336a654e667d93 100644 (file)
@@ -2077,8 +2077,13 @@ namespace GLib {
                [CCode (cname = "G_SOURCE_REMOVE")]
                public const bool REMOVE;
 
+#if VALA_0_18
+               protected virtual bool prepare (out int timeout_);
+               protected virtual bool check ();
+#else
                protected abstract bool prepare (out int timeout_);
                protected abstract bool check ();
+#endif
                protected abstract bool dispatch (SourceFunc? _callback);
        }
 
@@ -2096,10 +2101,10 @@ namespace GLib {
 
        [CCode (has_type_id = false)]
        public struct SourceFuncs {
-               public SourcePrepareFunc prepare;
-               public SourceCheckFunc check;
+               public SourcePrepareFunc? prepare;
+               public SourceCheckFunc? check;
                public SourceDispatchFunc dispatch;
-               public SourceFinalizeFunc finalize;
+               public SourceFinalizeFunc? finalize;
        }
 
        [CCode (has_target = false)]