]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't use volatile modifier in glib API when targetting >= 2.68
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 19 Feb 2021 13:22:20 +0000 (14:22 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 19 Feb 2021 13:22:20 +0000 (14:22 +0100)
See https://gitlab.gnome.org/GNOME/glib/merge_requests/1719

codegen/valaccodebasemodule.vala
codegen/valagobjectmodule.vala
codegen/valatyperegisterfunction.vala
vapi/glib-2.0.vapi

index 9ed7d38164d7e6fda7b777eb89ac5f9f0f61fbc8..2b8132ee52fd39b238ac1629d0cd9f9c05860745 100644 (file)
@@ -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);
 
index 54b1d4401175587fef734fe81265446bbbddae3f..30d7eace6e821771bafa8e610d1f22b9798251bd 100644 (file)
@@ -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"));
index eac326312e32fa2cb5090f4467d46d1f8acfb562..4a779aeb52f15c77506ab2d8b753270ce2f888dd 100644 (file)
@@ -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");
index 30864b302bf0bce9757db4ec160de0cd3477834e..b5e9af9ba0de5a12110674bab458b1533e294893 100644 (file)
@@ -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;
        }