mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-24 14:36:13 +01:00
gstrfuncs: Fix regression in types accepted by g_str_equal()
The new macro form of `g_str_equal()` had stricter type checking than the original function form. That would be nice, except it causes new compiler warnings in third party projects, which counts as an API break for us, so unfortunately we can’t do it. Add some tests to prevent regressions on this again. Signed-off-by: Philip Withnall <pwithnall@endlessos.org> Fixes: #2809
This commit is contained in:
parent
054b96fd09
commit
bcd364afef
@ -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 ((v1), (v2)) == 0)
|
||||
#define g_str_equal(v1, v2) (strcmp ((gconstpointer) (v1), (gconstpointer) (v2)) == 0)
|
||||
|
||||
GLIB_AVAILABLE_IN_ALL
|
||||
guint g_str_hash (gconstpointer v);
|
||||
|
@ -2178,6 +2178,31 @@ test_transliteration (void)
|
||||
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 */
|
||||
static 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/test-is-to-digit", test_is_to_digit);
|
||||
g_test_add_func ("/strfuncs/transliteration", test_transliteration);
|
||||
g_test_add_func ("/strfuncs/str-equal", test_str_equal);
|
||||
|
||||
return g_test_run();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user