unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* bug#39634: All keyowrds hash to the same value
@ 2020-02-16 18:20 Rob Browning
  2020-02-20 16:19 ` Ludovic Courtès
  0 siblings, 1 reply; 8+ messages in thread
From: Rob Browning @ 2020-02-16 18:20 UTC (permalink / raw)
  To: 39634

[-- Attachment #1: Type: text/plain, Size: 184 bytes --]


(hash #:x most-postive-fixnum) hashes to the same value for all keyowrds
in at least 2.2 and 3.0.  Here's one potential fix for 3.0, and I'd be
happy to adjust it for 2.2 if needed.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Implement-hashing-for-keywords-i.e.-hash-x.patch --]
[-- Type: text/x-diff, Size: 1651 bytes --]

From b380102564aad053f22586eb404e99c82635a3b0 Mon Sep 17 00:00:00 2001
From: Rob Browning <rlb@defaultvalue.org>
Date: Sun, 16 Feb 2020 12:12:08 -0600
Subject: [PATCH 1/1] Implement hashing for keywords, i.e. (hash #:x ...)

Add keyword handling to (hash ...).  Previously it would just return the
same value for all keywords.

* libguile/hash.c (scm_raw_ihash): Add scm_tc7_keyword case.

* libguile/keywords.h (SCM_I_KEYWORD_HASH): New macro.
---
 libguile/hash.c     | 3 +++
 libguile/keywords.h | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/libguile/hash.c b/libguile/hash.c
index d6e93dae0..c51a794c9 100644
--- a/libguile/hash.c
+++ b/libguile/hash.c
@@ -35,6 +35,7 @@
 #include "chars.h"
 #include "foreign.h"
 #include "gsubr.h"
+#include "keywords.h"
 #include "numbers.h"
 #include "pairs.h"
 #include "ports.h"
@@ -307,6 +308,8 @@ scm_raw_ihash (SCM obj, size_t depth)
       return scm_i_string_hash (obj);
     case scm_tc7_symbol:
       return scm_i_symbol_hash (obj);
+    case scm_tc7_keyword:
+      return SCM_I_KEYWORD_HASH (obj);
     case scm_tc7_pointer:
       return scm_raw_ihashq ((uintptr_t) SCM_POINTER_VALUE (obj));
     case scm_tc7_wvect:
diff --git a/libguile/keywords.h b/libguile/keywords.h
index c8f480869..cb8598d8b 100644
--- a/libguile/keywords.h
+++ b/libguile/keywords.h
@@ -60,6 +60,8 @@ SCM_API void
 scm_c_bind_keyword_arguments (const char *subr, SCM rest,
                               scm_t_keyword_arguments_flags flags, ...);
 
+#define SCM_I_KEYWORD_HASH(x) scm_i_symbol_hash (SCM_CELL_OBJECT_1 (x))
+
 SCM_INTERNAL void scm_init_keywords (void);
 
 #endif  /* SCM_KEYWORDS_H */
-- 
2.24.1


[-- Attachment #3: Type: text/plain, Size: 198 bytes --]


-- 
Rob Browning
rlb @defaultvalue.org and @debian.org
GPG as of 2011-07-10 E6A9 DA3C C9FD 1FF8 C676 D2C4 C0F0 39E9 ED1B 597A
GPG as of 2002-11-03 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-03-06 16:19 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-16 18:20 bug#39634: All keyowrds hash to the same value Rob Browning
2020-02-20 16:19 ` Ludovic Courtès
2020-02-25 20:56   ` Andy Wingo
2020-02-25 22:13     ` lloda
2020-02-26 21:02     ` Ludovic Courtès
2020-03-06 14:42     ` Ludovic Courtès
2020-03-06 15:43       ` Andy Wingo
2020-03-06 16:19         ` Ludovic Courtès

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).