From: Paul Eggert Date: Tue, 19 Jul 2011 06:07:07 +0000 (-0700) Subject: Use ptrdiff_t for hash table indexes. X-Git-Tag: emacs-pretest-24.0.90~104^2~152^2~136 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=d3411f89d34bd1009cae738f917abf477be09882;p=emacs.git Use ptrdiff_t for hash table indexes. * category.c (hash_get_category_set): * ccl.c (ccl_driver): * charset.h (struct charset.hash_index, CHECK_CHARSET_GET_ID): * coding.c (coding_system_charset_list, detect_coding_system): * coding.h (struct coding_system.id): * composite.c (get_composition_id, gstring_lookup_cache): * fns.c (hash_lookup, hash_put, Fgethash, Fputhash): * image.c (xpm_get_color_table_h): * lisp.h (hash_lookup, hash_put): * minibuf.c (Ftest_completion): Use ptrdiff_t for hash table indexes, not int (which is too narrow, on 64-bit hosts) or EMACS_INT (which is too wide, on 32-bit --with-wide-int hosts). --- diff --git a/src/ChangeLog b/src/ChangeLog index 4a9e03d5da0..cf75596f422 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,20 @@ 2011-07-19 Paul Eggert + Use ptrdiff_t for hash table indexes. + * category.c (hash_get_category_set): + * ccl.c (ccl_driver): + * charset.h (struct charset.hash_index, CHECK_CHARSET_GET_ID): + * coding.c (coding_system_charset_list, detect_coding_system): + * coding.h (struct coding_system.id): + * composite.c (get_composition_id, gstring_lookup_cache): + * fns.c (hash_lookup, hash_put, Fgethash, Fputhash): + * image.c (xpm_get_color_table_h): + * lisp.h (hash_lookup, hash_put): + * minibuf.c (Ftest_completion): + Use ptrdiff_t for hash table indexes, not int (which is too + narrow, on 64-bit hosts) or EMACS_INT (which is too wide, on + 32-bit --with-wide-int hosts). + * charset.c (Fdefine_charset_internal): Check for integer overflow. Add a FIXME comment about memory leaks. (syms_of_charset): Don't assume xmalloc returns. diff --git a/src/category.c b/src/category.c index 08eadb04730..a822bb654b0 100644 --- a/src/category.c +++ b/src/category.c @@ -67,7 +67,7 @@ static Lisp_Object hash_get_category_set (Lisp_Object table, Lisp_Object category_set) { struct Lisp_Hash_Table *h; - EMACS_INT i; + ptrdiff_t i; EMACS_UINT hash; if (NILP (XCHAR_TABLE (table)->extras[1])) diff --git a/src/ccl.c b/src/ccl.c index 9cfcbfe8703..087c0feb4ab 100644 --- a/src/ccl.c +++ b/src/ccl.c @@ -1303,7 +1303,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size case CCL_LookupIntConstTbl: { - EMACS_INT eop; + ptrdiff_t eop; struct Lisp_Hash_Table *h; GET_CCL_RANGE (eop, ccl_prog, ic++, 0, (VECTORP (Vtranslation_hash_table_vector) @@ -1329,7 +1329,7 @@ ccl_driver (struct ccl_program *ccl, int *source, int *destination, int src_size case CCL_LookupCharConstTbl: { - EMACS_INT eop; + ptrdiff_t eop; struct Lisp_Hash_Table *h; GET_CCL_RANGE (eop, ccl_prog, ic++, 0, (VECTORP (Vtranslation_hash_table_vector) diff --git a/src/charset.h b/src/charset.h index c2a52a38e7e..be02bc0feae 100644 --- a/src/charset.h +++ b/src/charset.h @@ -148,7 +148,7 @@ struct charset int id; /* Index to Vcharset_hash_table. */ - EMACS_INT hash_index; + ptrdiff_t hash_index; /* Dimension of the charset: 1, 2, 3, or 4. */ int dimension; @@ -341,7 +341,7 @@ extern int emacs_mule_charset[256]; number of the charset. Otherwise, signal an error. */ #define CHECK_CHARSET_GET_ID(x, id) \ do { \ - int idx; \ + ptrdiff_t idx; \ \ if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0) \ wrong_type_argument (Qcharsetp, (x)); \ diff --git a/src/coding.c b/src/coding.c index 65c8a767c2b..73a4bbc5e25 100644 --- a/src/coding.c +++ b/src/coding.c @@ -5838,7 +5838,7 @@ coding_charset_list (struct coding_system *coding) Lisp_Object coding_system_charset_list (Lisp_Object coding_system) { - int id; + ptrdiff_t id; Lisp_Object attrs, charset_list; CHECK_CODING_SYSTEM_GET_ID (coding_system, id); @@ -8076,7 +8076,7 @@ detect_coding_system (const unsigned char *src, Lisp_Object attrs, eol_type; Lisp_Object val = Qnil; struct coding_system coding; - int id; + ptrdiff_t id; struct coding_detection_info detect_info; enum coding_category base_category; int null_byte_found = 0, eight_bit_found = 0; diff --git a/src/coding.h b/src/coding.h index 85e153dcc3a..fdf9b762e75 100644 --- a/src/coding.h +++ b/src/coding.h @@ -415,7 +415,7 @@ struct coding_system setup_coding_system. At the early stage of building time, this value is -1 in the array coding_categories to indicate that no coding-system of that category is yet defined. */ - int id; + ptrdiff_t id; /* Flag bits of the coding system. The meaning of each bit is common to all types of coding systems. */ diff --git a/src/composite.c b/src/composite.c index d402d5ad0c4..43041f7b381 100644 --- a/src/composite.c +++ b/src/composite.c @@ -179,7 +179,7 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, Lisp_Object id, length, components, key, *key_contents; int glyph_len; struct Lisp_Hash_Table *hash_table = XHASH_TABLE (composition_hash_table); - EMACS_INT hash_index; + ptrdiff_t hash_index; EMACS_UINT hash_code; struct composition *cmp; EMACS_INT i; @@ -656,7 +656,7 @@ static Lisp_Object gstring_lookup_cache (Lisp_Object header) { struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); - EMACS_INT i = hash_lookup (h, header, NULL); + ptrdiff_t i = hash_lookup (h, header, NULL); return (i >= 0 ? HASH_VALUE (h, i) : Qnil); } diff --git a/src/fns.c b/src/fns.c index 9c9d19fe26a..fdaffe947ac 100644 --- a/src/fns.c +++ b/src/fns.c @@ -3787,11 +3787,11 @@ maybe_resize_hash_table (struct Lisp_Hash_Table *h) the hash code of KEY. Value is the index of the entry in H matching KEY, or -1 if not found. */ -EMACS_INT +ptrdiff_t hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash) { EMACS_UINT hash_code; - EMACS_INT start_of_bucket; + ptrdiff_t start_of_bucket; Lisp_Object idx; hash_code = h->hashfn (h, key); @@ -3821,11 +3821,11 @@ hash_lookup (struct Lisp_Hash_Table *h, Lisp_Object key, EMACS_UINT *hash) HASH is a previously computed hash code of KEY. Value is the index of the entry in H matching KEY. */ -EMACS_INT +ptrdiff_t hash_put (struct Lisp_Hash_Table *h, Lisp_Object key, Lisp_Object value, EMACS_UINT hash) { - EMACS_INT start_of_bucket, i; + ptrdiff_t start_of_bucket, i; xassert ((hash & ~INTMASK) == 0); @@ -4482,7 +4482,7 @@ If KEY is not found, return DFLT which defaults to nil. */) (Lisp_Object key, Lisp_Object table, Lisp_Object dflt) { struct Lisp_Hash_Table *h = check_hash_table (table); - EMACS_INT i = hash_lookup (h, key, NULL); + ptrdiff_t i = hash_lookup (h, key, NULL); return i >= 0 ? HASH_VALUE (h, i) : dflt; } @@ -4494,7 +4494,7 @@ VALUE. In any case, return VALUE. */) (Lisp_Object key, Lisp_Object value, Lisp_Object table) { struct Lisp_Hash_Table *h = check_hash_table (table); - EMACS_INT i; + ptrdiff_t i; EMACS_UINT hash; i = hash_lookup (h, key, &hash); diff --git a/src/image.c b/src/image.c index 3a58be5d85e..974c525c4e6 100644 --- a/src/image.c +++ b/src/image.c @@ -3807,8 +3807,8 @@ xpm_get_color_table_h (Lisp_Object color_table, int chars_len) { struct Lisp_Hash_Table *table = XHASH_TABLE (color_table); - int i = hash_lookup (table, make_unibyte_string (chars_start, chars_len), - NULL); + ptrdiff_t i = + hash_lookup (table, make_unibyte_string (chars_start, chars_len), NULL); return i >= 0 ? HASH_VALUE (table, i) : Qnil; } diff --git a/src/lisp.h b/src/lisp.h index 1e141dbb5d0..2d326043614 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -2562,8 +2562,8 @@ EMACS_UINT sxhash (Lisp_Object, int); Lisp_Object make_hash_table (Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object, Lisp_Object); -EMACS_INT hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); -EMACS_INT hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, +ptrdiff_t hash_lookup (struct Lisp_Hash_Table *, Lisp_Object, EMACS_UINT *); +ptrdiff_t hash_put (struct Lisp_Hash_Table *, Lisp_Object, Lisp_Object, EMACS_UINT); void init_weak_hash_tables (void); extern void init_fns (void); diff --git a/src/minibuf.c b/src/minibuf.c index cf37c337be4..951bf028c38 100644 --- a/src/minibuf.c +++ b/src/minibuf.c @@ -1713,7 +1713,7 @@ the values STRING, PREDICATE and `lambda'. */) (Lisp_Object string, Lisp_Object collection, Lisp_Object predicate) { Lisp_Object regexps, tail, tem = Qnil; - EMACS_INT i = 0; + ptrdiff_t i = 0; CHECK_STRING (string);