mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-24 21:16:15 +01:00
Merge branch '1041-atomic-bad-function-cast' into 'master'
Allow g_atomic_pointer_get() to be used by projects which enable -Wbad-function-cast Closes #1041 See merge request GNOME/glib!166
This commit is contained in:
commit
51065370a0
@ -3407,6 +3407,7 @@ AC_ARG_ENABLE(compile-warnings,
|
||||
AS_IF([test "x$enable_compile_warnings" != xno], [
|
||||
CC_CHECK_FLAGS_APPEND([GLIB_WARN_CFLAGS], [CFLAGS], [\
|
||||
-Wall -Wstrict-prototypes -Wduplicated-branches -Wmisleading-indentation \
|
||||
-Wno-bad-function-cast \
|
||||
-Werror=declaration-after-statement \
|
||||
-Werror=missing-prototypes -Werror=implicit-function-declaration \
|
||||
-Werror=pointer-arith -Werror=init-self -Werror=format-security \
|
||||
|
@ -109,7 +109,8 @@ G_END_DECLS
|
||||
#define g_atomic_pointer_get(atomic) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
(gpointer) __atomic_load_8 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
guint64 gapg_temp = __atomic_load_8 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
(gpointer) gapg_temp; \
|
||||
}))
|
||||
#define g_atomic_pointer_set(atomic, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
@ -127,7 +128,8 @@ G_END_DECLS
|
||||
#define g_atomic_pointer_get(atomic) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
(gpointer) __atomic_load_4 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
guint32 gapg_temp = __atomic_load_4 ((atomic), __ATOMIC_SEQ_CST); \
|
||||
(gpointer) gapg_temp; \
|
||||
}))
|
||||
#define g_atomic_pointer_set(atomic, newval) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
@ -186,7 +188,7 @@ G_END_DECLS
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
|
||||
(void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1); \
|
||||
(gboolean) __sync_bool_compare_and_swap ((atomic), (oldval), (newval)); \
|
||||
__sync_bool_compare_and_swap ((atomic), (oldval), (newval)) ? TRUE : FALSE; \
|
||||
}))
|
||||
#define g_atomic_int_add(atomic, val) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
@ -217,7 +219,7 @@ G_END_DECLS
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
|
||||
(void) (0 ? (gpointer) *(atomic) : NULL); \
|
||||
(gboolean) __sync_bool_compare_and_swap ((atomic), (oldval), (newval)); \
|
||||
__sync_bool_compare_and_swap ((atomic), (oldval), (newval)) ? TRUE : FALSE; \
|
||||
}))
|
||||
#define g_atomic_pointer_add(atomic, val) \
|
||||
(G_GNUC_EXTENSION ({ \
|
||||
|
@ -11,6 +11,11 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
/* We want the g_atomic_pointer_get() macros to work when compiling third party
|
||||
* projects with -Wbad-function-cast.
|
||||
* See https://gitlab.gnome.org/GNOME/glib/issues/1041. */
|
||||
#pragma GCC diagnostic error "-Wbad-function-cast"
|
||||
|
||||
static void
|
||||
test_types (void)
|
||||
{
|
||||
@ -191,7 +196,8 @@ G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
g_assert (ip == 0);
|
||||
|
||||
g_atomic_pointer_set (&gs, 0);
|
||||
gs2 = (gsize) g_atomic_pointer_get (&gs);
|
||||
vp = g_atomic_pointer_get (&gs);
|
||||
gs2 = (gsize) vp;
|
||||
g_assert (gs2 == 0);
|
||||
res = g_atomic_pointer_compare_and_exchange (&gs, 0, 0);
|
||||
g_assert (res);
|
||||
|
@ -333,6 +333,9 @@ if cc.get_id() == 'gcc' or cc.get_id() == 'clang'
|
||||
'-Wmisleading-indentation',
|
||||
'-Wstrict-prototypes',
|
||||
'-Wunused',
|
||||
# Due to pervasive use of things like GPOINTER_TO_UINT(), we do not support
|
||||
# building with -Wbad-function-cast.
|
||||
'-Wno-bad-function-cast',
|
||||
'-Werror=declaration-after-statement',
|
||||
'-Werror=format=2',
|
||||
'-Werror=format-security',
|
||||
|
Loading…
Reference in New Issue
Block a user