diff options
| author | Paul Eggert | 2011-05-30 23:05:00 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-05-30 23:05:00 -0700 |
| commit | 0de4bb688da4961269edab53dc0e0d5a30c01a44 (patch) | |
| tree | 10e3c4d22f03496bf5b8fc4a41ee04cfcc52e33d /src/lisp.h | |
| parent | b9627cfb1d5b5b0914525a19cd9edb06f91a1665 (diff) | |
| download | emacs-0de4bb688da4961269edab53dc0e0d5a30c01a44.tar.gz emacs-0de4bb688da4961269edab53dc0e0d5a30c01a44.zip | |
Remove arbitrary limit of 2**31 entries in hash tables.
* category.c (hash_get_category_set): Use 'EMACS_UINT' and 'EMACS_INT'
for hashes and hash indexes, instead of 'unsigned' and 'int'.
* ccl.c (ccl_driver): Likewise.
* charset.c (Fdefine_charset_internal): Likewise.
* charset.h (struct charset.hash_index): Likewise.
* composite.c (get_composition_id, gstring_lookup_cache):
(composition_gstring_put_cache): Likewise.
* composite.h (struct composition.hash_index): Likewise.
* dispextern.h (struct image.hash): Likewise.
* fns.c (next_almost_prime, larger_vector, cmpfn_eql):
(cmpfn_equal, cmpfn_user_defined, hashfn_eq, hashfn_eql):
(hashfn_equal, hashfn_user_defined, make_hash_table):
(maybe_resize_hash_table, hash_lookup, hash_put):
(hash_remove_from_table, hash_clear, sweep_weak_table, SXHASH_COMBINE):
(sxhash_string, sxhash_list, sxhash_vector, sxhash_bool_vector):
(Fsxhash, Fgethash, Fputhash, Fmaphash): Likewise.
* image.c (make_image, search_image_cache, lookup_image):
(xpm_put_color_table_h): Likewise.
* lisp.h (struct Lisp_Hash_Table): Likewise, for 'count', 'cmpfn',
and 'hashfn' members.
* minibuf.c (Ftry_completion, Fall_completions, Ftest_completion):
Likewise.
* print.c (print): Likewise.
* alloc.c (allocate_vectorlike): Check for overflow in vector size
calculations.
* ccl.c (ccl_driver): Check for overflow when converting EMACS_INT
to int.
* fns.c, image.c: Remove unnecessary static decls that would otherwise
need to be updated by these changes.
* fns.c (make_hash_table, maybe_resize_hash_table): Check for integer
overflow with large hash tables.
(make_hash_table, maybe_resize_hash_table, Fmake_hash_table):
Prefer the faster XFLOAT_DATA to XFLOATINT where either will do.
(SXHASH_REDUCE): New macro.
(sxhash_string, sxhash_list, sxhash_vector, sxhash_bool_vector):
Use it instead of discarding useful hash info with large hash values.
(sxhash_float): New function.
(sxhash): Use it. No more need for "& INTMASK" due to above changes.
* lisp.h (FIXNUM_BITS): New macro, useful for SXHASH_REDUCE etc.
(MOST_NEGATIVE_FIXNUM, MOST_POSITIVE_FIXNUM, INTMASK): Rewrite
to use FIXNUM_BITS, as this simplifies things.
(next_almost_prime, larger_vector, sxhash, hash_lookup, hash_put):
Adjust signatures to match updated version of code.
(consing_since_gc): Now EMACS_INT, since a single hash table can
use more than INT_MAX bytes.
Diffstat (limited to 'src/lisp.h')
| -rw-r--r-- | src/lisp.h | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/lisp.h b/src/lisp.h index 8a504e8eb86..6e61d0b8bd3 100644 --- a/src/lisp.h +++ b/src/lisp.h | |||
| @@ -525,23 +525,21 @@ extern Lisp_Object make_number (EMACS_INT); | |||
| 525 | 525 | ||
| 526 | #define EQ(x, y) (XHASH (x) == XHASH (y)) | 526 | #define EQ(x, y) (XHASH (x) == XHASH (y)) |
| 527 | 527 | ||
| 528 | /* Largest and smallest representable fixnum values. These are the C | 528 | /* Number of bits in a fixnum, including the sign bit. */ |
| 529 | values. */ | ||
| 530 | |||
| 531 | #ifdef USE_2_TAGS_FOR_INTS | 529 | #ifdef USE_2_TAGS_FOR_INTS |
| 532 | # define MOST_NEGATIVE_FIXNUM - ((EMACS_INT) 1 << VALBITS) | 530 | # define FIXNUM_BITS (VALBITS + 1) |
| 533 | # define MOST_POSITIVE_FIXNUM (((EMACS_INT) 1 << VALBITS) - 1) | ||
| 534 | /* Mask indicating the significant bits of a Lisp_Int. | ||
| 535 | I.e. (x & INTMASK) == XUINT (make_number (x)). */ | ||
| 536 | # define INTMASK ((((EMACS_INT) 1) << (VALBITS + 1)) - 1) | ||
| 537 | #else | 531 | #else |
| 538 | # define MOST_NEGATIVE_FIXNUM - ((EMACS_INT) 1 << (VALBITS - 1)) | 532 | # define FIXNUM_BITS VALBITS |
| 539 | # define MOST_POSITIVE_FIXNUM (((EMACS_INT) 1 << (VALBITS - 1)) - 1) | ||
| 540 | /* Mask indicating the significant bits of a Lisp_Int. | ||
| 541 | I.e. (x & INTMASK) == XUINT (make_number (x)). */ | ||
| 542 | # define INTMASK ((((EMACS_INT) 1) << VALBITS) - 1) | ||
| 543 | #endif | 533 | #endif |
| 544 | 534 | ||
| 535 | /* Mask indicating the significant bits of a fixnum. */ | ||
| 536 | #define INTMASK (((EMACS_INT) 1 << FIXNUM_BITS) - 1) | ||
| 537 | |||
| 538 | /* Largest and smallest representable fixnum values. These are the C | ||
| 539 | values. */ | ||
| 540 | #define MOST_POSITIVE_FIXNUM (INTMASK / 2) | ||
| 541 | #define MOST_NEGATIVE_FIXNUM (-1 - MOST_POSITIVE_FIXNUM) | ||
| 542 | |||
| 545 | /* Value is non-zero if I doesn't fit into a Lisp fixnum. It is | 543 | /* Value is non-zero if I doesn't fit into a Lisp fixnum. It is |
| 546 | written this way so that it also works if I is of unsigned | 544 | written this way so that it also works if I is of unsigned |
| 547 | type or if I is a NaN. */ | 545 | type or if I is a NaN. */ |
| @@ -1179,7 +1177,7 @@ struct Lisp_Hash_Table | |||
| 1179 | a special way (e.g. because of weakness). */ | 1177 | a special way (e.g. because of weakness). */ |
| 1180 | 1178 | ||
| 1181 | /* Number of key/value entries in the table. */ | 1179 | /* Number of key/value entries in the table. */ |
| 1182 | unsigned int count; | 1180 | EMACS_INT count; |
| 1183 | 1181 | ||
| 1184 | /* Vector of keys and values. The key of item I is found at index | 1182 | /* Vector of keys and values. The key of item I is found at index |
| 1185 | 2 * I, the value is found at index 2 * I + 1. | 1183 | 2 * I, the value is found at index 2 * I + 1. |
| @@ -1191,11 +1189,12 @@ struct Lisp_Hash_Table | |||
| 1191 | struct Lisp_Hash_Table *next_weak; | 1189 | struct Lisp_Hash_Table *next_weak; |
| 1192 | 1190 | ||
| 1193 | /* C function to compare two keys. */ | 1191 | /* C function to compare two keys. */ |
| 1194 | int (* cmpfn) (struct Lisp_Hash_Table *, Lisp_Object, | 1192 | int (*cmpfn) (struct Lisp_Hash_Table *, |
| 1195 | unsigned, Lisp_Object, unsigned); | 1193 | Lisp_Object, EMACS_UINT, |
| 1194 | Lisp_Object, EMACS_UINT); | ||
| 1196 | 1195 | ||
| 1197 | /* C function to compute hash code. */ | 1196 | /* C function to compute hash code. */ |
| 1198 | unsigned (* hashfn) (struct Lisp_Hash_Table *, Lisp_Object); | 1197 | EMACS_UINT (*hashfn) (struct Lisp_Hash_Table *, Lisp_Object); |
| 1199 | }; | 1198 | }; |
| 1200 | 1199 | ||
| 1201 | 1200 | ||
| @@ -2093,7 +2092,7 @@ extern Lisp_Object Vascii_canon_table; | |||
| 2093 | 2092 | ||
| 2094 | /* Number of bytes of structure consed since last GC. */ | 2093 | /* Number of bytes of structure consed since last GC. */ |
| 2095 | 2094 | ||
| 2096 | extern int consing_since_gc; | 2095 | extern EMACS_INT consing_since_gc; |
| 2097 | 2096 | ||
| 2098 | extern EMACS_INT gc_relative_threshold; | 2097 | extern EMACS_INT gc_relative_threshold; |
| 2099 | 2098 | ||
| @@ -2468,19 +2467,19 @@ extern void syms_of_syntax (void); | |||
| 2468 | 2467 | ||
| 2469 | /* Defined in fns.c */ | 2468 | /* Defined in fns.c */ |
| 2470 | extern Lisp_Object QCrehash_size, QCrehash_threshold; | 2469 | extern Lisp_Object QCrehash_size, QCrehash_threshold; |
| 2471 | extern int next_almost_prime (int); | 2470 | extern EMACS_INT next_almost_prime (EMACS_INT); |
| 2472 | extern Lisp_Object larger_vector (Lisp_Object, int, Lisp_Object); | 2471 | extern Lisp_Object larger_vector (Lisp_Object, EMACS_INT, Lisp_Object); |
| 2473 | extern void sweep_weak_hash_tables (void); | 2472 | extern void sweep_weak_hash_tables (void); |
| 2474 | extern Lisp_Object Qcursor_in_echo_area; | 2473 | extern Lisp_Object Qcursor_in_echo_area; |
| 2475 | extern Lisp_Object Qstring_lessp; | 2474 | extern Lisp_Object Qstring_lessp; |
| 2476 | extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql; | 2475 | extern Lisp_Object QCsize, QCtest, QCweakness, Qequal, Qeq, Qeql; |
| 2477 | unsigned sxhash (Lisp_Object, int); | 2476 | EMACS_UINT sxhash (Lisp_Object, int); |
| 2478 | Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object, | 2477 | Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object, |
| 2479 | Lisp_Object, Lisp_Object, Lisp_Object, | 2478 | Lisp_Object, Lisp_Object, Lisp_Object, |
| 2480 | Lisp_Object); | 2479 | Lisp_Object); |
| 2481 | int hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, unsigned *); | 2480 | EMACS_INT hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); |
| 2482 | int hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, | 2481 | EMACS_INT hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, |
| 2483 | unsigned); | 2482 | EMACS_UINT); |
| 2484 | void init_weak_hash_tables (void); | 2483 | void init_weak_hash_tables (void); |
| 2485 | extern void init_fns (void); | 2484 | extern void init_fns (void); |
| 2486 | EXFUN (Fmake_hash_table, MANY); | 2485 | EXFUN (Fmake_hash_table, MANY); |