[glib] gatomic: statically assert that our assumptions hold
- From: Simon McVittie <smcv src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] gatomic: statically assert that our assumptions hold
- Date: Wed, 23 Jul 2014 08:28:04 +0000 (UTC)
commit 7269d75321b9d2a967a59fb35f243397f577eb41
Author: Simon McVittie <simon mcvittie collabora co uk>
Date: Sun Jul 20 12:39:24 2014 +0100
gatomic: statically assert that our assumptions hold
This code assumes that int is exactly 4 bytes, and that pointers
are either 4 or 8 bytes, on platforms with __ATOMIC_SEQ_CST.
In practice this is going to be true.
Bug: https://bugzilla.gnome.org/show_bug.cgi?id=730932
glib/gatomic.h | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
---
diff --git a/glib/gatomic.h b/glib/gatomic.h
index 9d04b1d..056a517 100644
--- a/glib/gatomic.h
+++ b/glib/gatomic.h
@@ -87,6 +87,9 @@ G_END_DECLS
/* We prefer the new C11-style atomic extension of GCC if available */
#if defined(__ATOMIC_SEQ_CST) && !defined(__clang__)
+/* We use __atomic_load_4, so we rely on this being true */
+G_STATIC_ASSERT (sizeof (gint) == 4);
+
#define g_atomic_int_get(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
@@ -116,6 +119,9 @@ G_END_DECLS
#else /* GLIB_SIZEOF_VOID_P == 8 */
+/* Assume that if GLIB_SIZEOF_VOID_P is not 8, it must be 4 */
+G_STATIC_ASSERT (sizeof (gpointer) == 4);
+
#define g_atomic_pointer_get(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]