[vala/wip/gsource: 2/2] codegen: Implementing GLib.Source.prepare/check is optional since 2.36




commit 2d70cc9bb60b54030e74e898e2d9560da11bb1ed
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed May 26 18:39:20 2021 +0200

    codegen: Implementing GLib.Source.prepare/check is optional since 2.36

 codegen/valaccodemethodcallmodule.vala | 20 ++++++++++++++++++--
 tests/objects/gsource.vala             |  7 +++++++
 vapi/glib-2.0.vapi                     | 10 +++++-----
 3 files changed, 30 insertions(+), 7 deletions(-)
---
diff --git a/codegen/valaccodemethodcallmodule.vala b/codegen/valaccodemethodcallmodule.vala
index bbd08e00f..9390e868d 100644
--- a/codegen/valaccodemethodcallmodule.vala
+++ b/codegen/valaccodemethodcallmodule.vala
@@ -188,10 +188,26 @@ 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 *"));
diff --git a/tests/objects/gsource.vala b/tests/objects/gsource.vala
index 753d2c4d9..e1f4f07a3 100644
--- a/tests/objects/gsource.vala
+++ b/tests/objects/gsource.vala
@@ -34,7 +34,14 @@ class BarSource : Source {
        }
 }
 
+class ManamSource : Source {
+       public override bool dispatch (SourceFunc? callback) {
+               return false;
+       }
+}
+
 void main () {
        var foo = new FooSource ();
        var bar = new BarSource (1000);
+       var manam = new ManamSource ();
 }
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 2a1456028..075069ce8 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -2119,8 +2119,8 @@ namespace GLib {
                [CCode (cname = "G_SOURCE_REMOVE")]
                public const bool REMOVE;
 
-               protected abstract bool prepare (out int timeout_);
-               protected abstract bool check ();
+               protected virtual bool prepare (out int timeout_);
+               protected virtual bool check ();
                protected abstract bool dispatch (SourceFunc? _callback);
        }
 
@@ -2138,10 +2138,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)]


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