Merge branch '2809-str-equal-api-break' into 'main'

gstrfuncs: Fix regression in types accepted by g_str_equal()

Closes #2809

See merge request GNOME/glib!3082
This commit is contained in:
Marco Trevisan 2022-11-22 16:08:58 +00:00
commit 8aef5fc099
2 changed files with 27 additions and 1 deletions

View File

@ -162,7 +162,7 @@ gboolean g_str_equal (gconstpointer v1,
gconstpointer v2); gconstpointer v2);
/* Macro for optimization in the case it is not used as callback function */ /* Macro for optimization in the case it is not used as callback function */
#define g_str_equal(v1, v2) (strcmp ((v1), (v2)) == 0) #define g_str_equal(v1, v2) (strcmp ((gconstpointer) (v1), (gconstpointer) (v2)) == 0)
GLIB_AVAILABLE_IN_ALL GLIB_AVAILABLE_IN_ALL
guint g_str_hash (gconstpointer v); guint g_str_hash (gconstpointer v);

View File

@ -2178,6 +2178,31 @@ test_transliteration (void)
g_free (out); g_free (out);
} }
static void
test_str_equal (void)
{
const guchar *unsigned_a = (const guchar *) "a";
g_test_summary ("Test macro and function forms of g_str_equal()");
/* Test function form. */
g_assert_true ((g_str_equal) ("a", "a"));
g_assert_false ((g_str_equal) ("a", "b"));
/* Test macro form. */
g_assert_true (g_str_equal ("a", "a"));
g_assert_false (g_str_equal ("a", "b"));
/* As g_str_equal() is defined for use with GHashTable, it takes gconstpointer
* arguments, so can historically accept unsigned arguments. We need to
* continue to support that. */
g_assert_true ((g_str_equal) (unsigned_a, "a"));
g_assert_false ((g_str_equal) (unsigned_a, "b"));
g_assert_true (g_str_equal (unsigned_a, "a"));
g_assert_false (g_str_equal (unsigned_a, "b"));
}
/* Testing g_strv_contains() function with various cases */ /* Testing g_strv_contains() function with various cases */
static void static void
test_strv_contains (void) test_strv_contains (void)
@ -2676,6 +2701,7 @@ main (int argc,
g_test_add_func ("/strfuncs/strv-length", test_strv_length); g_test_add_func ("/strfuncs/strv-length", test_strv_length);
g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit); g_test_add_func ("/strfuncs/test-is-to-digit", test_is_to_digit);
g_test_add_func ("/strfuncs/transliteration", test_transliteration); g_test_add_func ("/strfuncs/transliteration", test_transliteration);
g_test_add_func ("/strfuncs/str-equal", test_str_equal);
return g_test_run(); return g_test_run();
} }