From f889275a2864cb4d34385619dfae59c88d907b2a Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Oct 2022 10:23:09 +0100 Subject: [PATCH 1/3] Revert "Add tests for hash collisions in simple cases" This reverts commit e02db8ea22d545749ecaf3be9d342cc565bc143a. We can't guarantee a lack of hash collisions if we go back to the 2.74.0 hashing implementation. Signed-off-by: Simon McVittie --- glib/tests/hash.c | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/glib/tests/hash.c b/glib/tests/hash.c index 604dcc049..32d357979 100644 --- a/glib/tests/hash.c +++ b/glib/tests/hash.c @@ -459,19 +459,6 @@ int64_hash_test (void) g_hash_table_destroy (h); } -static void -int64_hash_collision_test (void) -{ - gint64 m; - gint64 n; - - g_test_summary ("Check int64 Hash collisions caused by ignoring high word"); - - m = 722; - n = ((gint64) 2003 << 32) + 722; - g_assert_cmpuint (g_int64_hash (&m), !=, g_int64_hash (&n)); -} - static void double_hash_test (void) { @@ -501,27 +488,6 @@ double_hash_test (void) g_hash_table_destroy (h); } -static void -double_hash_collision_test (void) -{ - gdouble m; - gdouble n; - - g_test_summary ("Check double Hash collisions caused by int conversion " \ - "and by numbers larger than 2^64-1 (G_MAXUINT64)"); - g_test_bug ("https://gitlab.gnome.org/GNOME/glib/-/issues/2771"); - - /* Equal when directly converted to integers */ - m = 0.1; - n = 0.2; - g_assert_cmpuint (g_double_hash (&m), !=, g_double_hash (&n)); - - /* Numbers larger than 2^64-1 (G_MAXUINT64) */ - m = 1e100; - n = 1e200; - g_assert_cmpuint (g_double_hash (&m), !=, g_double_hash (&n)); -} - static void string_free (gpointer data) { @@ -1749,9 +1715,7 @@ main (int argc, char *argv[]) g_test_add_func ("/hash/direct2", direct_hash_test2); g_test_add_func ("/hash/int", int_hash_test); g_test_add_func ("/hash/int64", int64_hash_test); - g_test_add_func ("/hash/int64/collisions", int64_hash_collision_test); g_test_add_func ("/hash/double", double_hash_test); - g_test_add_func ("/hash/double/collisions", double_hash_collision_test); g_test_add_func ("/hash/string", string_hash_test); g_test_add_func ("/hash/set", set_hash_test); g_test_add_func ("/hash/set-ref", set_ref_hash_test); From c8e9eaf9a39d99e9648470af9c004820d2509cd2 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Oct 2022 10:23:18 +0100 Subject: [PATCH 2/3] Revert "Optional optimization for `g_int64_hash`" This reverts commit c1af4b2b886bd77d6d8857cf3f677edbc0d34a61, which caused a regression on big-endian architectures (all 64-bit integers would hash to zero). Partially resolves #2787 Signed-off-by: Simon McVittie --- glib/ghash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/ghash.c b/glib/ghash.c index 0e6ba4882..59fd421d9 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -2494,7 +2494,7 @@ g_int64_equal (gconstpointer v1, guint g_int64_hash (gconstpointer v) { - return (guint) ((const guint) (*(guint64 *) v >> 32)) ^ (*(const guint *) v); + return (guint) *(const gint64*) v; } /** From 53178b084c3c46842f227b6cea6a1e84694161a7 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Fri, 21 Oct 2022 10:23:37 +0100 Subject: [PATCH 3/3] Revert "Optimize g_double_hash implementation" This reverts commit dd1f4f709ea8cad1a1d6184ee0883be128fb81d8. which caused a regression on big-endian architectures (all doubles would hash to zero). Partially resolves #2787 Signed-off-by: Simon McVittie --- glib/ghash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glib/ghash.c b/glib/ghash.c index 59fd421d9..463242ecd 100644 --- a/glib/ghash.c +++ b/glib/ghash.c @@ -2535,5 +2535,5 @@ g_double_equal (gconstpointer v1, guint g_double_hash (gconstpointer v) { - return (guint) ((const guint) (*(guint64 *) v >> 32)) ^ (*(const guint *) v); + return (guint) *(const gdouble*) v; }