~ chicken-core (chicken-5) 0d8e29fe20d21d81329934ed62f6ff777820d8d1
commit 0d8e29fe20d21d81329934ed62f6ff777820d8d1
Author: Peter Bex <address@hidden>
AuthorDate: Sun Mar 4 18:32:08 2012 +0100
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Fri Mar 16 08:26:43 2012 +0100
Don't allow random numbers for hash tables to have all zeroes as lower bits; especially for small hashes this produces values that are more predictable than neccessary. Also hide hash-default-randomization in srfi-69
Signed-off-by: felix <felix@call-with-current-continuation.org>
diff --git a/eval.scm b/eval.scm
index cea7e13c..52e19f26 100644
--- a/eval.scm
+++ b/eval.scm
@@ -45,6 +45,8 @@
#ifndef C_BINARY_VERSION
# define C_BINARY_VERSION 0
#endif
+
+#define C_rnd_fix() (C_fix(rand()))
<#
(include "common-declarations.scm")
@@ -111,7 +113,7 @@
(let ([cache-s #f]
[cache-h #f]
;; NOTE: All low-level hash tables share the same randomization factor
- [rand (##core#inline "C_random_fixnum" most-positive-fixnum)] )
+ [rand (##core#inline "C_rnd_fix")] )
(lambda (s n)
(if (eq? s cache-s)
(##core#inline "C_fixnum_modulo" cache-h n)
diff --git a/runtime.c b/runtime.c
index 8c60abc3..ef8cf8e7 100644
--- a/runtime.c
+++ b/runtime.c
@@ -886,7 +886,7 @@ C_regparm C_SYMBOL_TABLE *C_new_symbol_table(char *name, unsigned int size)
stp->name = name;
stp->size = size;
stp->next = symbol_table_list;
- stp->rand = C_unfix(C_random_fixnum(C_fix(size)));
+ stp->rand = rand();
if((stp->table = (C_word *)C_malloc(size * sizeof(C_word))) == NULL)
return NULL;
diff --git a/srfi-69.scm b/srfi-69.scm
index 03e1620c..99025a21 100644
--- a/srfi-69.scm
+++ b/srfi-69.scm
@@ -30,11 +30,13 @@
*eq?-hash *eqv?-hash *equal?-hash
*make-hash-table
*hash-table-copy *hash-table-merge! *hash-table-update!/default
- *hash-table-for-each *hash-table-fold
+ *hash-table-for-each *hash-table-fold hash-default-randomization
hash-table-canonical-length hash-table-rehash! hash-table-check-resize! ) )
(include "common-declarations.scm")
+(foreign-declare "#define C_rnd_fix() (C_fix(rand()))")
+
(register-feature! 'srfi-69)
@@ -105,8 +107,7 @@
(define-constant unknown-immediate-hash-value 262)
(define-constant hash-default-bound 536870912)
-(define hash-default-randomization
- (##core#inline "C_random_fixnum" hash-default-bound))
+(define hash-default-randomization (##core#inline "C_rnd_fix"))
;; Force Hash to Bounded Fixnum:
@@ -414,7 +415,7 @@
string-hash string-hash-ci number-hash))
;; Don't add unneccessary bounds checks for procedures known to be
;; well-behaved (these are not user-*created* functions)
- (let ((randomization (##core#inline "C_random_fixnum" most-positive-fixnum)))
+ (let ((randomization (##core#inline "C_rnd_fix")))
(if (memq user-function (list string-hash string-hash-ci))
;; String functions have differing signatures; treat them specially
(lambda (object bound)
Trap