From fd2ab4b80d94071c65de999f519b5b1e91421a02 Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Mon, 5 Feb 2024 08:37:09 +0100 Subject: [PATCH] Imported Upstream version 2.74.3 --- NEWS | 12 ++++++++++++ glib/ghash.h | 2 +- glib/tests/cxx.cpp | 23 +++++++++++++++++++++++ meson.build | 2 +- 4 files changed, 37 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 1787d3a..8200935 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,15 @@ +Overview of changes in GLib 2.74.3 +================================== + +* Fix regression in type checking `g_str_equal()` from C++ projects (#2820) + +* Bugs fixed: + - #2820 g_str_equal: New macro version breaks compilation in C++ projects + (Philip Withnall) + - !3096 Backport !3094 “gstrfuncs: Fix regression in C++ types accepted by + g_str_equal()” to glib-2-74 + + Overview of changes in GLib 2.74.2 ================================== diff --git a/glib/ghash.h b/glib/ghash.h index 6a37415..396148d 100644 --- a/glib/ghash.h +++ b/glib/ghash.h @@ -162,7 +162,7 @@ gboolean g_str_equal (gconstpointer v1, gconstpointer v2); /* Macro for optimization in the case it is not used as callback function */ -#define g_str_equal(v1, v2) (strcmp ((gconstpointer) (v1), (gconstpointer) (v2)) == 0) +#define g_str_equal(v1, v2) (strcmp ((const char *) (v1), (const char *) (v2)) == 0) GLIB_AVAILABLE_IN_ALL guint g_str_hash (gconstpointer v); diff --git a/glib/tests/cxx.cpp b/glib/tests/cxx.cpp index 6ac6079..300777d 100644 --- a/glib/tests/cxx.cpp +++ b/glib/tests/cxx.cpp @@ -192,6 +192,28 @@ test_steal_pointer (void) g_assert_null (ptr); } +static void +test_str_equal (void) +{ + const char *str_a = "a"; + char *str_b = g_strdup ("b"); + gconstpointer str_a_ptr = str_a, str_b_ptr = str_b; + const unsigned char *str_c = (const unsigned char *) "c"; + + g_test_summary ("Test typechecking and casting of arguments to g_str_equal() macro in C++"); + g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2820"); + + /* We don’t actually care what the comparisons do at runtime. What we’re + * checking here is that the types don’t emit warnings at compile time. */ + g_assert_true (g_str_equal ("a", str_a)); + g_assert_false (g_str_equal ("a", str_b)); + g_assert_true (g_str_equal (str_a, str_a_ptr)); + g_assert_false (g_str_equal (str_a_ptr, str_b_ptr)); + g_assert_false (g_str_equal (str_c, str_b)); + + g_free (str_b); +} + int main (int argc, char *argv[]) { @@ -211,6 +233,7 @@ main (int argc, char *argv[]) g_test_add_func ("/C++/inlined-not-inlined-functions", test_inline_no_inline_macros); g_test_add_func ("/C++/clear-pointer", test_clear_pointer); g_test_add_func ("/C++/steal-pointer", test_steal_pointer); + g_test_add_func ("/C++/str-equal", test_str_equal); return g_test_run (); } diff --git a/meson.build b/meson.build index c497380..6ea8841 100644 --- a/meson.build +++ b/meson.build @@ -1,5 +1,5 @@ project('glib', 'c', - version : '2.74.2', + version : '2.74.3', # NOTE: See the policy in docs/meson-version.md before changing the Meson dependency meson_version : '>= 0.60.0', default_options : [ -- 2.7.4