[vala/staging: 2/3] codegen: Don't use volatile modifier in glib API when targetting >= 2.68




commit 4ca8ff86f9ee1da8b7718b7b70eaca9ab40f6337
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Feb 19 14:22:20 2021 +0100

    codegen: Don't use volatile modifier in glib API when targetting >= 2.68
    
    See https://gitlab.gnome.org/GNOME/glib/merge_requests/1719

 codegen/valaccodebasemodule.vala      | 12 +++++++--
 codegen/valagobjectmodule.vala        |  6 ++++-
 codegen/valatyperegisterfunction.vala |  6 ++++-
 vapi/glib-2.0.vapi                    | 49 +++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 9ed7d3816..2b8132ee5 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -4430,7 +4430,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        push_function (fun);
 
                        var once_enter_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_once_init_enter"));
-                       once_enter_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+                       if (context.require_glib_version (2, 68)) {
+                               once_enter_call.add_argument (new CCodeConstant ("(gsize*) re"));
+                       } else {
+                               once_enter_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+                       }
                        ccode.open_if (once_enter_call);
 
                        var regex_new_call = new CCodeFunctionCall (new CCodeIdentifier ("g_regex_new"));
@@ -4441,7 +4445,11 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        ccode.add_assignment (new CCodeIdentifier ("GRegex* val"), regex_new_call);
 
                        var once_leave_call = new CCodeFunctionCall (new CCodeIdentifier 
("g_once_init_leave"));
-                       once_leave_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+                       if (context.require_glib_version (2, 68)) {
+                               once_leave_call.add_argument (new CCodeConstant ("(gsize*) re"));
+                       } else {
+                               once_leave_call.add_argument (new CCodeConstant ("(volatile gsize*) re"));
+                       }
                        once_leave_call.add_argument (new CCodeConstant ("(gsize) val"));
                        ccode.add_expression (once_leave_call);
 
diff --git a/codegen/valagobjectmodule.vala b/codegen/valagobjectmodule.vala
index 54b1d4401..30d7eace6 100644
--- a/codegen/valagobjectmodule.vala
+++ b/codegen/valagobjectmodule.vala
@@ -515,7 +515,11 @@ public class Vala.GObjectModule : GTypeModule {
 
                                var once_lock = new CCodeDeclaration("gsize");
                                once_lock.add_declarator (new CCodeVariableDeclarator (singleton_once_name, 
new CCodeConstant ("0")));
-                               once_lock.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
+                               if (context.require_glib_version (2, 68)) {
+                                       once_lock.modifiers = CCodeModifiers.STATIC;
+                               } else {
+                                       once_lock.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
+                               }
                                ccode.add_statement (once_lock);
 
                                var once_init = new CCodeFunctionCall (new CCodeIdentifier 
("g_once_init_enter"));
diff --git a/codegen/valatyperegisterfunction.vala b/codegen/valatyperegisterfunction.vala
index eac326312..4a779aeb5 100644
--- a/codegen/valatyperegisterfunction.vala
+++ b/codegen/valatyperegisterfunction.vala
@@ -50,7 +50,11 @@ public abstract class Vala.TypeRegisterFunction {
                if (!plugin) {
                        cdecl = new CCodeDeclaration ("gsize");
                        cdecl.add_declarator (new CCodeVariableDeclarator (type_id_name + "__volatile", new 
CCodeConstant ("0")));
-                       cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
+                       if (context.require_glib_version (2, 68)) {
+                               cdecl.modifiers = CCodeModifiers.STATIC;
+                       } else {
+                               cdecl.modifiers = CCodeModifiers.STATIC | CCodeModifiers.VOLATILE;
+                       }
                        type_block.add_statement (cdecl);
                } else {
                        cdecl = new CCodeDeclaration ("GType");
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 30864b302..b5e9af9ba 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -1829,6 +1829,47 @@ namespace GLib {
 
        /* Atomic Operations */
 
+#if GLIB_2_68
+       [Version (since = "2.4")]
+       namespace AtomicInt {
+               public static int get (ref int atomic);
+               public static void set (ref int atomic, int newval);
+               [Version (since = "2.30")]
+               public static int add (ref int atomic, int val);
+               [Version (deprecated_since = "2.30", replacement = "add")]
+               public static int exchange_and_add (ref int atomic, int val);
+               public static bool compare_and_exchange (ref int atomic, int oldval, int newval);
+               public static void inc (ref int atomic);
+               public static bool dec_and_test (ref int atomic);
+       }
+
+       [Version (since = "2.4")]
+       namespace AtomicUint {
+               [CCode (cname = "g_atomic_int_get")]
+               public static uint get (ref uint atomic);
+               [CCode (cname = "g_atomic_int_set")]
+               public static void set (ref uint atomic, uint newval);
+               [Version (since = "2.30")]
+               [CCode (cname = "g_atomic_int_add")]
+               public static uint add (ref uint atomic, uint val);
+               [Version (deprecated_since = "2.30", replacement = "add")]
+               [CCode (cname = "g_atomic_int_exchange_and_add")]
+               public static uint exchange_and_add (ref uint atomic, uint val);
+               [CCode (cname = "g_atomic_int_compare_and_exchange")]
+               public static bool compare_and_exchange (ref uint atomic, uint oldval, uint newval);
+               [CCode (cname = "g_atomic_int_inc")]
+               public static void inc (ref uint atomic);
+               [CCode (cname = "g_atomic_int_dec_and_test")]
+               public static bool dec_and_test (ref uint atomic);
+       }
+
+       [Version (since = "2.4")]
+       namespace AtomicPointer {
+               public static void* get (void** atomic);
+               public static void set (void** atomic, void* newval);
+               public static bool compare_and_exchange (void** atomic, void* oldval, void* newval);
+       }
+#else
        [Version (since = "2.4")]
        namespace AtomicInt {
                public static int get ([CCode (type = "volatile gint *")] ref int atomic);
@@ -1868,6 +1909,7 @@ namespace GLib {
                public static void set ([CCode (type = "volatile gpointer *")] void** atomic, void* newval);
                public static bool compare_and_exchange ([CCode (type = "volatile gpointer *")] void** 
atomic, void* oldval, void* newval);
        }
+#endif
 
        /* The Main Event Loop */
 
@@ -2307,10 +2349,17 @@ namespace GLib {
        public struct Once<G> {
                [CCode (cname = "g_once")]
                public unowned G once (OnceFunc<G> function);
+#if GLIB_2_68
+               [Version (since = "2.14")]
+               public static bool init_enter (size_t *value);
+               [Version (since = "2.14")]
+               public static void init_leave (size_t *value, size_t set_value);
+#else
                [Version (since = "2.14")]
                public static bool init_enter ([CCode (type="volatile gsize *")] size_t *value);
                [Version (since = "2.14")]
                public static void init_leave ([CCode (type="volatile gsize *")] size_t *value, size_t 
set_value);
+#endif
                public OnceStatus status;
        }
 


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