summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKhem Raj <raj.khem@gmail.com>2022-04-01 07:41:14 -0700
committerRichard Purdie <richard.purdie@linuxfoundation.org>2022-04-03 10:40:31 +0100
commit1459f495ba40595912da7060d6a83244b424d8de (patch)
treeb4ea3f52b0b961a2d51d1db8b803de522a0c0c52
parent2a02a178af98cc528a90ad87aacc3d99ebd81abc (diff)
downloadpoky-1459f495ba40595912da7060d6a83244b424d8de.tar.gz
glib-2.0: Backport patches C++ variant of g_atomic_int_compare_and_exchange()
This fixes a regression when glib-2.0 was used with clang. (From OE-Core rev: a963f71e882e11c8e41dadf77944de408ad12acb) Signed-off-by: Khem Raj <raj.khem@gmail.com> Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/recipes-core/glib-2.0/glib-2.0/0001-tests-Add-C-tests-for-typechecking-with-atomic-compa.patch64
-rw-r--r--meta/recipes-core/glib-2.0/glib-2.0/0002-gatomic-Add-a-C-variant-of-g_atomic_int_compare_and_.patch70
-rw-r--r--meta/recipes-core/glib-2.0/glib-2.0_2.72.0.bb2
3 files changed, 136 insertions, 0 deletions
diff --git a/meta/recipes-core/glib-2.0/glib-2.0/0001-tests-Add-C-tests-for-typechecking-with-atomic-compa.patch b/meta/recipes-core/glib-2.0/glib-2.0/0001-tests-Add-C-tests-for-typechecking-with-atomic-compa.patch
new file mode 100644
index 0000000000..4842f462e1
--- /dev/null
+++ b/meta/recipes-core/glib-2.0/glib-2.0/0001-tests-Add-C-tests-for-typechecking-with-atomic-compa.patch
@@ -0,0 +1,64 @@
1From 44b4bcd56d7ac2bd8ebf00e9fa433ad897d68216 Mon Sep 17 00:00:00 2001
2From: Philip Withnall <pwithnall@endlessos.org>
3Date: Fri, 1 Apr 2022 13:44:45 +0100
4Subject: [PATCH 1/2] tests: Add C++ tests for typechecking with atomic compare
5 and exchanges
6
7Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
8
9Helps: #2625
10Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2578]
11Signed-off-by: Khem Raj <raj.khem@gmail.com>
12---
13 glib/tests/cxx.cpp | 28 ++++++++++++++++++++++++++++
14 1 file changed, 28 insertions(+)
15
16diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp
17index be0a6bfa1..7d7f27c91 100644
18--- a/glib/tests/cxx.cpp
19+++ b/glib/tests/cxx.cpp
20@@ -53,6 +53,32 @@ test_typeof (void)
21 #endif
22 }
23
24+static void
25+test_atomic_pointer_compare_and_exchange (void)
26+{
27+ const gchar *str1 = "str1";
28+ const gchar *str2 = "str2";
29+ const gchar *atomic_string = str1;
30+
31+ g_test_message ("Test that g_atomic_pointer_compare_and_exchange() with a "
32+ "non-void* pointer doesn’t have any compiler warnings in C++ mode");
33+
34+ g_assert_true (g_atomic_pointer_compare_and_exchange (&atomic_string, str1, str2));
35+ g_assert_true (atomic_string == str2);
36+}
37+
38+static void
39+test_atomic_int_compare_and_exchange (void)
40+{
41+ gint atomic_int = 5;
42+
43+ g_test_message ("Test that g_atomic_int_compare_and_exchange() doesn’t have "
44+ "any compiler warnings in C++ mode");
45+
46+ g_assert_true (g_atomic_int_compare_and_exchange (&atomic_int, 5, 50));
47+ g_assert_cmpint (atomic_int, ==, 50);
48+}
49+
50 int
51 main (int argc, char *argv[])
52 {
53@@ -63,6 +89,8 @@ main (int argc, char *argv[])
54 #endif
55
56 g_test_add_func ("/C++/typeof", test_typeof);
57+ g_test_add_func ("/C++/atomic-pointer-compare-and-exchange", test_atomic_pointer_compare_and_exchange);
58+ g_test_add_func ("/C++/atomic-int-compare-and-exchange", test_atomic_int_compare_and_exchange);
59
60 return g_test_run ();
61 }
62--
632.35.1
64
diff --git a/meta/recipes-core/glib-2.0/glib-2.0/0002-gatomic-Add-a-C-variant-of-g_atomic_int_compare_and_.patch b/meta/recipes-core/glib-2.0/glib-2.0/0002-gatomic-Add-a-C-variant-of-g_atomic_int_compare_and_.patch
new file mode 100644
index 0000000000..a07f94672f
--- /dev/null
+++ b/meta/recipes-core/glib-2.0/glib-2.0/0002-gatomic-Add-a-C-variant-of-g_atomic_int_compare_and_.patch
@@ -0,0 +1,70 @@
1From 2668390454bc0efe52a262eb2faa4a2bd5a062e2 Mon Sep 17 00:00:00 2001
2From: Philip Withnall <pwithnall@endlessos.org>
3Date: Fri, 1 Apr 2022 13:47:19 +0100
4Subject: [PATCH 2/2] gatomic: Add a C++ variant of
5 g_atomic_int_compare_and_exchange()
6MIME-Version: 1.0
7Content-Type: text/plain; charset=UTF-8
8Content-Transfer-Encoding: 8bit
9
10The C++ variant implements type safety differently, to avoid warnings
11from C++ compilers about:
12```
13../../../gnome-commander-1.14.2/src/intviewer/searcher.cc:303:5: error: cannot initialize a parameter of type 'gint *' (aka 'int *') with an rvalue of type 'void *'
14 g_atomic_int_compare_and_exchange ((gint*)&src->priv->progress_value, oldval, (gint)d);
15 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16/mnt/b/yoe/master/build/tmp/work/cortexa72-yoe-linux/gnome-commander/1.14.2-r0/recipe-sysroot/usr/include/glib-2.0/glib/gatomic.h:160:44: note: expanded from macro 'g_atomic_int_compare_and_exchange'
17 __atomic_compare_exchange_n ((atomic), (void *) (&(gaicae_oldval)), (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
18 ^~~~~~~~~~~~~~~~~~~~~~~~~~~
19```
20
21This complements the existing C++ variant for
22`g_atomic_pointer_compare_and_exchange()`, and fixes a regression on C++
23from https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2114.
24
25With the addition of the unit tests in the previous commit, this is
26effectively tested by the FreeBSD and macOS CI jobs, as they use
27`clang++` in C++ mode. `g++` doesn’t seem to emit a warning about this.
28
29Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
30
31Fixes: #2625
32Upstream-Status: Submitted [https://gitlab.gnome.org/GNOME/glib/-/merge_requests/2578]
33Signed-off-by: Khem Raj <raj.khem@gmail.com>
34---
35 glib/gatomic.h | 12 ++++++++++++
36 1 file changed, 12 insertions(+)
37
38diff --git a/glib/gatomic.h b/glib/gatomic.h
39index 5eba1dbc7..8b2b880c8 100644
40--- a/glib/gatomic.h
41+++ b/glib/gatomic.h
42@@ -152,6 +152,17 @@ G_END_DECLS
43 (void) (0 ? *(atomic) ^ *(atomic) : 1); \
44 __atomic_fetch_sub ((atomic), 1, __ATOMIC_SEQ_CST) == 1; \
45 }))
46+#if defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L
47+/* See comments below about equivalent g_atomic_pointer_compare_and_exchange()
48+ * shenanigans for type-safety when compiling in C++ mode. */
49+#define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
50+ (G_GNUC_EXTENSION ({ \
51+ glib_typeof (*(atomic)) gaicae_oldval = (oldval); \
52+ G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
53+ (void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1); \
54+ __atomic_compare_exchange_n ((atomic), &gaicae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
55+ }))
56+#else /* if !(defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L) */
57 #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
58 (G_GNUC_EXTENSION ({ \
59 gint gaicae_oldval = (oldval); \
60@@ -159,6 +170,7 @@ G_END_DECLS
61 (void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1); \
62 __atomic_compare_exchange_n ((atomic), (void *) (&(gaicae_oldval)), (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
63 }))
64+#endif /* defined(glib_typeof) */
65 #define g_atomic_int_add(atomic, val) \
66 (G_GNUC_EXTENSION ({ \
67 G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
68--
692.35.1
70
diff --git a/meta/recipes-core/glib-2.0/glib-2.0_2.72.0.bb b/meta/recipes-core/glib-2.0/glib-2.0_2.72.0.bb
index 8b7016ec0f..62479e3c3f 100644
--- a/meta/recipes-core/glib-2.0/glib-2.0_2.72.0.bb
+++ b/meta/recipes-core/glib-2.0/glib-2.0_2.72.0.bb
@@ -16,6 +16,8 @@ SRC_URI = "${GNOME_MIRROR}/glib/${SHRT_VER}/glib-${PV}.tar.xz \
16 file://0001-Do-not-write-bindir-into-pkg-config-files.patch \ 16 file://0001-Do-not-write-bindir-into-pkg-config-files.patch \
17 file://0001-meson-Run-atomics-test-on-clang-as-well.patch \ 17 file://0001-meson-Run-atomics-test-on-clang-as-well.patch \
18 file://0001-gio-tests-resources.c-comment-out-a-build-host-only-.patch \ 18 file://0001-gio-tests-resources.c-comment-out-a-build-host-only-.patch \
19 file://0001-tests-Add-C-tests-for-typechecking-with-atomic-compa.patch \
20 file://0002-gatomic-Add-a-C-variant-of-g_atomic_int_compare_and_.patch \
19 " 21 "
20SRC_URI:append:class-native = " file://relocate-modules.patch" 22SRC_URI:append:class-native = " file://relocate-modules.patch"
21 23