diff options
Diffstat (limited to 'src/composite.c')
| -rw-r--r-- | src/composite.c | 67 |
1 files changed, 36 insertions, 31 deletions
diff --git a/src/composite.c b/src/composite.c index 3308a028042..2a3fbe29552 100644 --- a/src/composite.c +++ b/src/composite.c | |||
| @@ -142,10 +142,10 @@ Lisp_Object Qcomposition; | |||
| 142 | struct composition **composition_table; | 142 | struct composition **composition_table; |
| 143 | 143 | ||
| 144 | /* The current size of `composition_table'. */ | 144 | /* The current size of `composition_table'. */ |
| 145 | static int composition_table_size; | 145 | static ptrdiff_t composition_table_size; |
| 146 | 146 | ||
| 147 | /* Number of compositions currently made. */ | 147 | /* Number of compositions currently made. */ |
| 148 | int n_compositions; | 148 | ptrdiff_t n_compositions; |
| 149 | 149 | ||
| 150 | /* Hash table for compositions. The key is COMPONENTS-VEC of | 150 | /* Hash table for compositions. The key is COMPONENTS-VEC of |
| 151 | `composition' property. The value is the corresponding | 151 | `composition' property. The value is the corresponding |
| @@ -172,19 +172,30 @@ Lisp_Object composition_temp; | |||
| 172 | 172 | ||
| 173 | If the composition is invalid, return -1. */ | 173 | If the composition is invalid, return -1. */ |
| 174 | 174 | ||
| 175 | int | 175 | ptrdiff_t |
| 176 | get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, | 176 | get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, |
| 177 | Lisp_Object prop, Lisp_Object string) | 177 | Lisp_Object prop, Lisp_Object string) |
| 178 | { | 178 | { |
| 179 | Lisp_Object id, length, components, key, *key_contents; | 179 | Lisp_Object id, length, components, key, *key_contents; |
| 180 | int glyph_len; | 180 | ptrdiff_t glyph_len; |
| 181 | struct Lisp_Hash_Table *hash_table = XHASH_TABLE (composition_hash_table); | 181 | struct Lisp_Hash_Table *hash_table = XHASH_TABLE (composition_hash_table); |
| 182 | EMACS_INT hash_index; | 182 | ptrdiff_t hash_index; |
| 183 | EMACS_UINT hash_code; | 183 | EMACS_UINT hash_code; |
| 184 | enum composition_method method; | ||
| 184 | struct composition *cmp; | 185 | struct composition *cmp; |
| 185 | EMACS_INT i; | 186 | EMACS_INT i; |
| 186 | int ch; | 187 | int ch; |
| 187 | 188 | ||
| 189 | /* Maximum length of a string of glyphs. XftGlyphExtents limits | ||
| 190 | this to INT_MAX, and Emacs limits it further. Divide INT_MAX - 1 | ||
| 191 | by 2 because x_produce_glyphs computes glyph_len * 2 + 1. Divide | ||
| 192 | the size by MAX_MULTIBYTE_LENGTH because encode_terminal_code | ||
| 193 | multiplies glyph_len by MAX_MULTIBYTE_LENGTH. */ | ||
| 194 | enum { | ||
| 195 | GLYPH_LEN_MAX = min ((INT_MAX - 1) / 2, | ||
| 196 | min (PTRDIFF_MAX, SIZE_MAX) / MAX_MULTIBYTE_LENGTH) | ||
| 197 | }; | ||
| 198 | |||
| 188 | /* PROP should be | 199 | /* PROP should be |
| 189 | Form-A: ((LENGTH . COMPONENTS) . MODIFICATION-FUNC) | 200 | Form-A: ((LENGTH . COMPONENTS) . MODIFICATION-FUNC) |
| 190 | or | 201 | or |
| @@ -258,21 +269,9 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, | |||
| 258 | /* This composition is a new one. We must register it. */ | 269 | /* This composition is a new one. We must register it. */ |
| 259 | 270 | ||
| 260 | /* Check if we have sufficient memory to store this information. */ | 271 | /* Check if we have sufficient memory to store this information. */ |
| 261 | if (composition_table_size == 0) | 272 | if (composition_table_size <= n_compositions) |
| 262 | { | 273 | composition_table = xpalloc (composition_table, &composition_table_size, |
| 263 | composition_table_size = 256; | 274 | 1, -1, sizeof *composition_table); |
| 264 | composition_table | ||
| 265 | = (struct composition **) xmalloc (sizeof (composition_table[0]) | ||
| 266 | * composition_table_size); | ||
| 267 | } | ||
| 268 | else if (composition_table_size <= n_compositions) | ||
| 269 | { | ||
| 270 | composition_table_size += 256; | ||
| 271 | composition_table | ||
| 272 | = (struct composition **) xrealloc (composition_table, | ||
| 273 | sizeof (composition_table[0]) | ||
| 274 | * composition_table_size); | ||
| 275 | } | ||
| 276 | 275 | ||
| 277 | key_contents = XVECTOR (key)->contents; | 276 | key_contents = XVECTOR (key)->contents; |
| 278 | 277 | ||
| @@ -316,20 +315,26 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars, | |||
| 316 | /* Register the composition in composition_hash_table. */ | 315 | /* Register the composition in composition_hash_table. */ |
| 317 | hash_index = hash_put (hash_table, key, id, hash_code); | 316 | hash_index = hash_put (hash_table, key, id, hash_code); |
| 318 | 317 | ||
| 318 | method = (NILP (components) | ||
| 319 | ? COMPOSITION_RELATIVE | ||
| 320 | : ((INTEGERP (components) || STRINGP (components)) | ||
| 321 | ? COMPOSITION_WITH_ALTCHARS | ||
| 322 | : COMPOSITION_WITH_RULE_ALTCHARS)); | ||
| 323 | |||
| 324 | glyph_len = (method == COMPOSITION_WITH_RULE_ALTCHARS | ||
| 325 | ? (ASIZE (key) + 1) / 2 | ||
| 326 | : ASIZE (key)); | ||
| 327 | |||
| 328 | if (GLYPH_LEN_MAX < glyph_len) | ||
| 329 | memory_full (SIZE_MAX); | ||
| 330 | |||
| 319 | /* Register the composition in composition_table. */ | 331 | /* Register the composition in composition_table. */ |
| 320 | cmp = (struct composition *) xmalloc (sizeof (struct composition)); | 332 | cmp = (struct composition *) xmalloc (sizeof (struct composition)); |
| 321 | 333 | ||
| 322 | cmp->method = (NILP (components) | 334 | cmp->method = method; |
| 323 | ? COMPOSITION_RELATIVE | ||
| 324 | : ((INTEGERP (components) || STRINGP (components)) | ||
| 325 | ? COMPOSITION_WITH_ALTCHARS | ||
| 326 | : COMPOSITION_WITH_RULE_ALTCHARS)); | ||
| 327 | cmp->hash_index = hash_index; | 335 | cmp->hash_index = hash_index; |
| 328 | glyph_len = (cmp->method == COMPOSITION_WITH_RULE_ALTCHARS | ||
| 329 | ? (ASIZE (key) + 1) / 2 | ||
| 330 | : ASIZE (key)); | ||
| 331 | cmp->glyph_len = glyph_len; | 336 | cmp->glyph_len = glyph_len; |
| 332 | cmp->offsets = (short *) xmalloc (sizeof (short) * glyph_len * 2); | 337 | cmp->offsets = xnmalloc (glyph_len, 2 * sizeof *cmp->offsets); |
| 333 | cmp->font = NULL; | 338 | cmp->font = NULL; |
| 334 | 339 | ||
| 335 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) | 340 | if (cmp->method != COMPOSITION_WITH_RULE_ALTCHARS) |
| @@ -656,7 +661,7 @@ static Lisp_Object | |||
| 656 | gstring_lookup_cache (Lisp_Object header) | 661 | gstring_lookup_cache (Lisp_Object header) |
| 657 | { | 662 | { |
| 658 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); | 663 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); |
| 659 | EMACS_INT i = hash_lookup (h, header, NULL); | 664 | ptrdiff_t i = hash_lookup (h, header, NULL); |
| 660 | 665 | ||
| 661 | return (i >= 0 ? HASH_VALUE (h, i) : Qnil); | 666 | return (i >= 0 ? HASH_VALUE (h, i) : Qnil); |
| 662 | } | 667 | } |
| @@ -691,7 +696,7 @@ composition_gstring_put_cache (Lisp_Object gstring, EMACS_INT len) | |||
| 691 | } | 696 | } |
| 692 | 697 | ||
| 693 | Lisp_Object | 698 | Lisp_Object |
| 694 | composition_gstring_from_id (int id) | 699 | composition_gstring_from_id (ptrdiff_t id) |
| 695 | { | 700 | { |
| 696 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); | 701 | struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table); |
| 697 | 702 | ||