[glib/wip/smcv/armel-atomic-pointer-get] gatomic: Make fallback g_atomic_pointer_get type-safe
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/smcv/armel-atomic-pointer-get] gatomic: Make fallback g_atomic_pointer_get type-safe
- Date: Sun, 14 Feb 2021 23:39:12 +0000 (UTC)
commit d2b4ba55cb24c0bb5b408329497fac6721f751b2
Author: Simon McVittie <smcv collabora com>
Date: Sun Feb 14 23:26:58 2021 +0000
gatomic: Make fallback g_atomic_pointer_get type-safe
Since !1715, g_atomic_pointer_get (&x) has usually returned the type of
x, rather than a generic pointer, in C++ code (where x is any pointer,
or any pointer-sized integer such as guintptr). glib/tests/cxx.cpp
asserts that this is the case.
However, this was only implemented for the lock-free fast-path, not
for the slow path used in platforms with an ARMv5 baseline (and
therefore no atomic instructions) such as Debian armel.
Signed-off-by: Simon McVittie <smcv collabora com>
glib/gatomic.h | 14 ++++++++++++++
1 file changed, 14 insertions(+)
---
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 3b84a5049..16e0c7298 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -423,10 +423,24 @@ G_END_DECLS
#define g_atomic_int_dec_and_test(atomic) \
(g_atomic_int_dec_and_test ((gint *) (atomic)))
+#if defined(glib_typeof)
+ /* The (void *) cast in the middle *looks* redundant, because
+ * g_atomic_pointer_get returns void * already, but it's to silence
+ * -Werror=bad-function-cast when we're doing something like:
+ * guintptr a, b; ...; a = g_atomic_pointer_get (&b);
+ * which would otherwise be assigning the void * result of
+ * g_atomic_pointer_get directly to the pointer-sized but
+ * non-pointer-typed result. */
+#define g_atomic_pointer_get(atomic) \
+ (glib_typeof (*(atomic))) (void *) ((g_atomic_pointer_get) ((void *) atomic))
+#else /* !defined(glib_typeof) */
#define g_atomic_pointer_get(atomic) \
(g_atomic_pointer_get (atomic))
+#endif
+
#define g_atomic_pointer_set(atomic, newval) \
(g_atomic_pointer_set ((atomic), (gpointer) (newval)))
+
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
(g_atomic_pointer_compare_and_exchange ((atomic), (gpointer) (oldval), (gpointer) (newval)))
#define g_atomic_pointer_add(atomic, val) \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]