aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-04-27 22:15:35 -0700
committerPaul Eggert2011-04-27 22:15:35 -0700
commit2f30ecd05f7e5b9f78f256f75677530c501e5a6d (patch)
treea7466caa2d9a8a4b6ffb76e785edac70950caa5e /src
parent2a866e7b9881176980c0a4acb998e1625aabf87f (diff)
downloademacs-2f30ecd05f7e5b9f78f256f75677530c501e5a6d.tar.gz
emacs-2f30ecd05f7e5b9f78f256f75677530c501e5a6d.zip
* lread.c (hash_string): Use size_t, not int, for hash computation.
Normally we prefer signed values; but hashing is special, because it's better to use unsigned division on hash table sizes so that the remainder is nonnegative. Also, size_t is the natural width for hashing into memory. The previous code used 'int', which doesn't retain enough info to hash well into very large tables. (oblookup, oblookup_last_bucket_number, Funintern): Likewise.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog8
-rw-r--r--src/lread.c20
2 files changed, 18 insertions, 10 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 52b7f323cd3..2bda5ffa46f 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,5 +1,13 @@
12011-04-28 Paul Eggert <eggert@cs.ucla.edu> 12011-04-28 Paul Eggert <eggert@cs.ucla.edu>
2 2
3 * lread.c (hash_string): Use size_t, not int, for hash computation.
4 Normally we prefer signed values; but hashing is special, because
5 it's better to use unsigned division on hash table sizes so that
6 the remainder is nonnegative. Also, size_t is the natural width
7 for hashing into memory. The previous code used 'int', which doesn't
8 retain enough info to hash well into very large tables.
9 (oblookup, oblookup_last_bucket_number, Funintern): Likewise.
10
3 * dbusbind.c: Don't possibly lose pointer info when converting. 11 * dbusbind.c: Don't possibly lose pointer info when converting.
4 (xd_remove_watch, Fdbus_init_bus, xd_read_queued_messages): 12 (xd_remove_watch, Fdbus_init_bus, xd_read_queued_messages):
5 Use XPNTR rather than XHASH, so that the high-order bits of 13 Use XPNTR rather than XHASH, so that the high-order bits of
diff --git a/src/lread.c b/src/lread.c
index 7ffc98b254f..2c8c3acd56a 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -3611,9 +3611,9 @@ static Lisp_Object initial_obarray;
3611 3611
3612/* oblookup stores the bucket number here, for the sake of Funintern. */ 3612/* oblookup stores the bucket number here, for the sake of Funintern. */
3613 3613
3614static int oblookup_last_bucket_number; 3614static size_t oblookup_last_bucket_number;
3615 3615
3616static int hash_string (const char *ptr, int len); 3616static size_t hash_string (const char *ptr, size_t len);
3617 3617
3618/* Get an error if OBARRAY is not an obarray. 3618/* Get an error if OBARRAY is not an obarray.
3619 If it is one, return it. */ 3619 If it is one, return it. */
@@ -3755,7 +3755,7 @@ OBARRAY defaults to the value of the variable `obarray'. */)
3755 (Lisp_Object name, Lisp_Object obarray) 3755 (Lisp_Object name, Lisp_Object obarray)
3756{ 3756{
3757 register Lisp_Object string, tem; 3757 register Lisp_Object string, tem;
3758 int hash; 3758 size_t hash;
3759 3759
3760 if (NILP (obarray)) obarray = Vobarray; 3760 if (NILP (obarray)) obarray = Vobarray;
3761 obarray = check_obarray (obarray); 3761 obarray = check_obarray (obarray);
@@ -3824,8 +3824,8 @@ OBARRAY defaults to the value of the variable `obarray'. */)
3824Lisp_Object 3824Lisp_Object
3825oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_INT size_byte) 3825oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_INT size_byte)
3826{ 3826{
3827 int hash; 3827 size_t hash;
3828 int obsize; 3828 size_t obsize;
3829 register Lisp_Object tail; 3829 register Lisp_Object tail;
3830 Lisp_Object bucket, tem; 3830 Lisp_Object bucket, tem;
3831 3831
@@ -3858,21 +3858,21 @@ oblookup (Lisp_Object obarray, register const char *ptr, EMACS_INT size, EMACS_I
3858 return tem; 3858 return tem;
3859} 3859}
3860 3860
3861static int 3861static size_t
3862hash_string (const char *ptr, int len) 3862hash_string (const char *ptr, size_t len)
3863{ 3863{
3864 register const char *p = ptr; 3864 register const char *p = ptr;
3865 register const char *end = p + len; 3865 register const char *end = p + len;
3866 register unsigned char c; 3866 register unsigned char c;
3867 register int hash = 0; 3867 register size_t hash = 0;
3868 3868
3869 while (p != end) 3869 while (p != end)
3870 { 3870 {
3871 c = *p++; 3871 c = *p++;
3872 if (c >= 0140) c -= 40; 3872 if (c >= 0140) c -= 40;
3873 hash = ((hash<<3) + (hash>>28) + c); 3873 hash = (hash << 3) + (hash >> (CHAR_BIT * sizeof hash - 4)) + c;
3874 } 3874 }
3875 return hash & 07777777777; 3875 return hash;
3876} 3876}
3877 3877
3878void 3878void