emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 7e85311a911: Allow equal user-defined hash table tests with diffe


From: Mattias Engdegård
Subject: master 7e85311a911: Allow equal user-defined hash table tests with different names
Date: Wed, 31 Jan 2024 06:53:18 -0500 (EST)

branch: master
commit 7e85311a9113a4720ec9d7b06188646fc7bdae0b
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Allow equal user-defined hash table tests with different names
    
    Hash tables using different user-defined tests defined identically
    sometimes ended up using the wrong test (bug#68668).
    
    * src/fns.c (get_hash_table_user_test): Take test name into account
    when matching the test object.
    * test/src/fns-tests.el (fns--define-hash-table-test): New.
---
 src/fns.c             |  5 ++++-
 test/src/fns-tests.el | 10 ++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/fns.c b/src/fns.c
index e4fa8157000..1262e3e749e 100644
--- a/src/fns.c
+++ b/src/fns.c
@@ -5374,6 +5374,8 @@ mark_fns (void)
     }
 }
 
+/* Find the hash_table_test object correponding to the (bare) symbol TEST,
+   creating one if none existed.  */
 static struct hash_table_test *
 get_hash_table_user_test (Lisp_Object test)
 {
@@ -5384,7 +5386,8 @@ get_hash_table_user_test (Lisp_Object test)
   Lisp_Object equal_fn = XCAR (prop);
   Lisp_Object hash_fn = XCAR (XCDR (prop));
   struct hash_table_user_test *ut = hash_table_user_tests;
-  while (ut && !(EQ (equal_fn, ut->test.user_cmp_function)
+  while (ut && !(BASE_EQ (test, ut->test.name)
+                && EQ (equal_fn, ut->test.user_cmp_function)
                 && EQ (hash_fn, ut->test.user_hash_function)))
     ut = ut->next;
   if (!ut)
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index 3893b8b0320..7437c07f156 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1097,6 +1097,16 @@
   (should (= (sxhash-equal (record 'a (make-string 10 ?a)))
             (sxhash-equal (record 'a (make-string 10 ?a))))))
 
+(ert-deftest fns--define-hash-table-test ()
+  ;; Check that we can have two differently-named tests using the
+  ;; same functions (bug#68668).
+  (define-hash-table-test 'fns-tests--1 'my-cmp 'my-hash)
+  (define-hash-table-test 'fns-tests--2 'my-cmp 'my-hash)
+  (let ((h1 (make-hash-table :test 'fns-tests--1))
+        (h2 (make-hash-table :test 'fns-tests--2)))
+    (should (eq (hash-table-test h1) 'fns-tests--1))
+    (should (eq (hash-table-test h2) 'fns-tests--2))))
+
 (ert-deftest test-secure-hash ()
   (should (equal (secure-hash 'md5    "foobar")
                  "3858f62230ac3c915f300c664312c63f"))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]