From 26e0f72a6bb214f1f53326c7b2325715afe43fb6 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Fri, 22 Apr 2011 09:19:36 +0300 Subject: Add 32/64 bit consistency in hashing. --- ChangeLog | 6 ++++++ array.c | 8 +++++++- test/ChangeLog | 4 ++++ test/arraysort.ok | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index ffe1ad5c..51302224 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Apr 22 09:18:16 2011 Arnold D. Robbins + + * array.c (awk_hash): Force results into 32 bits for consistency + across platforms. Keeps the test suite happy. This may turn out + to be a bad idea in the long run. + Mon Apr 18 10:18:26 2011 John Haque * array.c (assoc_list): New function to construct, and optionally diff --git a/array.c b/array.c index 15053bb0..3d7ff2fa 100644 --- a/array.c +++ b/array.c @@ -427,9 +427,15 @@ awk_hash(const char *s, size_t len, unsigned long hsize, size_t *code) * Even more speed: * #define HASHC h = *s++ + 65599 * h * Because 65599 = pow(2, 6) + pow(2, 16) - 1 we multiply by shifts + * + * 4/2011: Force the results to 32 bits, to get the same + * result on both 32- and 64-bit systems. This may be a + * bad idea. */ #define HASHC htmp = (h << 6); \ - h = *s++ + htmp + (htmp << 10) - h + h = *s++ + htmp + (htmp << 10) - h ; \ + htmp &= 0xFFFFFFFF; \ + h &= 0xFFFFFFFF; unsigned long htmp; diff --git a/test/ChangeLog b/test/ChangeLog index 89aa4d11..3081a53c 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,7 @@ +Fri Apr 22 09:19:06 2011 Arnold D. Robbins + + * arraysort.ok: Updated. + Mon Apr 18 10:22:28 2011 John Haque * arraysort.awk, arraysort.ok, sort1.awk, sort1.ok: Updated. diff --git a/test/arraysort.ok b/test/arraysort.ok index 23d7c44a..70af0e01 100644 --- a/test/arraysort.ok +++ b/test/arraysort.ok @@ -34,9 +34,9 @@ y 1 | 3| 3| |0|0| |1|1| +| 4 | 4 | |2|2| |3|3| -| 4 | 4 | --asc ind str-- | 3| 3| | 4 | 4 | -- cgit v1.2.3