aboutsummaryrefslogtreecommitdiffstats
path: root/src/alloc.c
diff options
context:
space:
mode:
authorPaul Eggert2011-05-30 23:05:00 -0700
committerPaul Eggert2011-05-30 23:05:00 -0700
commit0de4bb688da4961269edab53dc0e0d5a30c01a44 (patch)
tree10e3c4d22f03496bf5b8fc4a41ee04cfcc52e33d /src/alloc.c
parentb9627cfb1d5b5b0914525a19cd9edb06f91a1665 (diff)
downloademacs-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/alloc.c')
-rw-r--r--src/alloc.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/alloc.c b/src/alloc.c
index e627af6c071..8fcc6f91df9 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -157,7 +157,7 @@ struct emacs_globals globals;
157 157
158/* Number of bytes of consing done since the last gc. */ 158/* Number of bytes of consing done since the last gc. */
159 159
160int consing_since_gc; 160EMACS_INT consing_since_gc;
161 161
162/* Similar minimum, computed from Vgc_cons_percentage. */ 162/* Similar minimum, computed from Vgc_cons_percentage. */
163 163
@@ -2788,6 +2788,11 @@ allocate_vectorlike (EMACS_INT len)
2788{ 2788{
2789 struct Lisp_Vector *p; 2789 struct Lisp_Vector *p;
2790 size_t nbytes; 2790 size_t nbytes;
2791 int header_size = offsetof (struct Lisp_Vector, contents);
2792 int word_size = sizeof p->contents[0];
2793
2794 if ((SIZE_MAX - header_size) / word_size < len)
2795 memory_full ();
2791 2796
2792 MALLOC_BLOCK_INPUT; 2797 MALLOC_BLOCK_INPUT;
2793 2798
@@ -2801,8 +2806,7 @@ allocate_vectorlike (EMACS_INT len)
2801 /* This gets triggered by code which I haven't bothered to fix. --Stef */ 2806 /* This gets triggered by code which I haven't bothered to fix. --Stef */
2802 /* eassert (!handling_signal); */ 2807 /* eassert (!handling_signal); */
2803 2808
2804 nbytes = (offsetof (struct Lisp_Vector, contents) 2809 nbytes = header_size + len * word_size;
2805 + len * sizeof p->contents[0]);
2806 p = (struct Lisp_Vector *) lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE); 2810 p = (struct Lisp_Vector *) lisp_malloc (nbytes, MEM_TYPE_VECTORLIKE);
2807 2811
2808#ifdef DOUG_LEA_MALLOC 2812#ifdef DOUG_LEA_MALLOC