Re: hash table allocation failure

Eric Blake <[email protected]>
Newsgroups gmane.comp.gnu.m4.patches
Message-ID <[email protected]>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Eric Blake on 6/20/2009 3:19 PM:
> According to Eric Blake on 6/15/2009 9:25 PM:
>> Thanks to Jim's recent work on the gnulib hash module, I audited the code
>> for cases where allocation failure could cause assertion failures instead
>> of expected xalloc_die behavior
> 
> Now that gnulib memory handling bugs are fixed, I'm committing this followup:

And taking a leaf from gnulib, it is more readable to write hash routines
like this:

- --
Don't work too hard, make some time for fun as well!

Eric Blake             [email protected]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpEPlIACgkQ84KuGfSFAYCKxwCfVPpjwvlaqNiHqwTdX9Xw9tMh
cQgAn2vhuenMVS4YkHcKIKG19oi5HlTW
=bEpP
-----END PGP SIGNATURE-----

_______________________________________________
M4-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/m4-patches
m4.patch426 (text/plain, 3.6 KB)
From 891a0fd44d0666fc0576071ec9866cb2b87490eb Mon Sep 17 00:00:00 2001
From: Eric Blake <[email protected]>
Date: Thu, 25 Jun 2009 12:08:25 -0600
Subject: [PATCH] Use bitrotate for hashing.

* gnulib: Update to latest.
* m4/gnulib-cache.m4: Import bitrotate module.
* src/symtab.c (hash): Use it.

Signed-off-by: Eric Blake <[email protected]>
---
 ChangeLog          |    5 +++++
 gnulib             |    2 +-
 m4/gnulib-cache.m4 |    3 ++-
 src/symtab.c       |    3 ++-
 4 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4dac1a0..69321da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-06-25  Eric Blake  <[email protected]>

+	Use bitrotate for hashing.
+	* gnulib: Update to latest.
+	* m4/gnulib-cache.m4: Import bitrotate module.
+	* src/symtab.c (hash): Use it.
+
 	Fix description of limits on diversions.
 	* doc/m4.texinfo (Diversions): Fix grammar.  Be less pessimistic
 	about limitations.
diff --git a/gnulib b/gnulib
index 12f78b4..836f397 160000
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 12f78b4faa14cd2da952f865979843dee79fcf93
+Subproject commit 836f3974faad2f3de7bafd46719b77d6632a4c96
diff --git a/m4/gnulib-cache.m4 b/m4/gnulib-cache.m4
index d3e4d73..3db1a44 100644
--- a/m4/gnulib-cache.m4
+++ b/m4/gnulib-cache.m4
@@ -15,7 +15,7 @@


 # Specification in the form of a command-line invocation:
-#   gnulib-tool --import --dir=. --local-dir=local --lib=libm4 --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen assert autobuild avltree-oset binary-io clean-temp cloexec close-stream closein config-h dirname error execute fdl-1.3 fflush filenamecat flexmember fopen fopen-safer freadptr freadseek fseeko gendocs getopt git-version-gen gnumakefile gnupload gpl-3.0 hash intprops maintainer-makefile memchr2 memcmp2 memmem mkstemp obstack obstack-printf-posix pipe progname quote regex rename snprintf-posix stdbool stdint stdlib-safer strtod strtol unlocked-io vasnprintf-posix verror version-etc version-etc-fsf wait-process xalloc xmemdup0 xprintf xvasprintf-posix
+#   gnulib-tool --import --dir=. --local-dir=local --lib=libm4 --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=build-aux --with-tests --no-libtool --macro-prefix=M4 announce-gen assert autobuild avltree-oset binary-io bitrotate clean-temp cloexec close-stream closein config-h dirname error execute fdl-1.3 fflush filenamecat flexmember fopen fopen-safer freadptr freadseek fseeko gendocs getopt git-version-gen gnumakefile gnupload gpl-3.0 hash intprops maintainer-makefile memchr2 memcmp2 memmem mkstemp obstack obstack-printf-posix pipe progname quote regex rename snprintf-posix stdbool stdint stdlib-safer strtod strtol unlocked-io vasnprintf-posix verror version-etc version-etc-fsf wait-process xalloc xmemdup0 xprintf xvasprintf-posix

 # Specification in the form of a few gnulib-tool.m4 macro invocations:
 gl_LOCAL_DIR([local])
@@ -25,6 +25,7 @@ gl_MODULES([
   autobuild
   avltree-oset
   binary-io
+  bitrotate
   clean-temp
   cloexec
   close-stream
diff --git a/src/symtab.c b/src/symtab.c
index 338bf17..dd9eb67 100644
--- a/src/symtab.c
+++ b/src/symtab.c
@@ -33,6 +33,7 @@

 #include "m4.h"

+#include "bitrotate.h"
 #include "hash.h"

 #ifdef DEBUG_SYM
@@ -112,7 +113,7 @@ hash (const char *s, size_t len)
   /* This algorithm was originally borrowed from GNU Emacs, but has
      been modified to allow embedded NUL.  */
   while (len--)
-    val = (val << 7) + (val >> (sizeof val * CHAR_BIT - 7)) + to_uchar (*s++);
+    val = rotl_sz (val, 7) + to_uchar (*s++);
   return val;
 }

-- 
1.6.3.3.334.g916e1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.