Use ptrdiff_t for composition IDs.
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 19 Jul 2011 21:39:36 +0000 (14:39 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 19 Jul 2011 21:39:36 +0000 (14:39 -0700)
* character.c (lisp_string_width):
* composite.c (composition_table_size, n_compositions)
(get_composition_id, composition_gstring_from_id):
* dispextern.h (struct glyph_string.cmp_id, struct composition_it.id):
* xdisp.c (BUILD_COMPOSITE_GLYPH_STRING):
* window.c (Frecenter):
Use ptrdiff_t, not int, for composition IDs.
* composite.c (get_composition_id): Check for integer overflow.
* composite.h: Adjust prototypes to match the above changes.

src/ChangeLog
src/character.c
src/composite.c
src/composite.h
src/dispextern.h
src/window.c
src/xdisp.c

index 30af92a..b3125b2 100644 (file)
@@ -1,5 +1,16 @@
 2011-07-19  Paul Eggert  <eggert@cs.ucla.edu>
 
+       Use ptrdiff_t for composition IDs.
+       * character.c (lisp_string_width):
+       * composite.c (composition_table_size, n_compositions)
+       (get_composition_id, composition_gstring_from_id):
+       * dispextern.h (struct glyph_string.cmp_id, struct composition_it.id):
+       * xdisp.c (BUILD_COMPOSITE_GLYPH_STRING):
+       * window.c (Frecenter):
+       Use ptrdiff_t, not int, for composition IDs.
+       * composite.c (get_composition_id): Check for integer overflow.
+       * composite.h: Adjust prototypes to match the above changes.
+
        Use ptrdiff_t for hash table indexes.
        * category.c (hash_get_category_set):
        * ccl.c (ccl_driver):
index c2f23e0..5e2eccf 100644 (file)
@@ -423,7 +423,7 @@ lisp_string_width (Lisp_Object string, EMACS_INT precision,
     {
       EMACS_INT chars, bytes, thiswidth;
       Lisp_Object val;
-      int cmp_id;
+      ptrdiff_t cmp_id;
       EMACS_INT ignore, end;
 
       if (find_composition (i, -1, &ignore, &end, &val, string)
index 43041f7..b25699b 100644 (file)
@@ -142,10 +142,10 @@ Lisp_Object Qcomposition;
 struct composition **composition_table;
 
 /* The current size of `composition_table'.  */
-static int composition_table_size;
+static ptrdiff_t composition_table_size;
 
 /* Number of compositions currently made. */
-int n_compositions;
+ptrdiff_t n_compositions;
 
 /* Hash table for compositions.  The key is COMPONENTS-VEC of
    `composition' property.  The value is the corresponding
@@ -172,7 +172,7 @@ Lisp_Object composition_temp;
 
    If the composition is invalid, return -1.  */
 
-int
+ptrdiff_t
 get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
                    Lisp_Object prop, Lisp_Object string)
 {
@@ -260,18 +260,22 @@ get_composition_id (EMACS_INT charpos, EMACS_INT bytepos, EMACS_INT nchars,
   /* Check if we have sufficient memory to store this information.  */
   if (composition_table_size == 0)
     {
-      composition_table_size = 256;
       composition_table
-       = (struct composition **) xmalloc (sizeof (composition_table[0])
-                                          * composition_table_size);
+       = (struct composition **) xmalloc (sizeof (composition_table[0]) * 256);
+      composition_table_size = 256;
     }
   else if (composition_table_size <= n_compositions)
     {
-      composition_table_size += 256;
+      if ((min (MOST_POSITIVE_FIXNUM,
+               min (PTRDIFF_MAX, SIZE_MAX) / sizeof composition_table[0])
+          - 256)
+         < composition_table_size)
+       memory_full (SIZE_MAX);
       composition_table
        = (struct composition **) xrealloc (composition_table,
                                            sizeof (composition_table[0])
-                                           * composition_table_size);
+                                           * (composition_table_size + 256));
+      composition_table_size += 256;
     }
 
   key_contents = XVECTOR (key)->contents;
@@ -691,7 +695,7 @@ composition_gstring_put_cache (Lisp_Object gstring, EMACS_INT len)
 }
 
 Lisp_Object
-composition_gstring_from_id (int id)
+composition_gstring_from_id (ptrdiff_t id)
 {
   struct Lisp_Hash_Table *h = XHASH_TABLE (gstring_hash_table);
 
index 8cedfdb..a43e419 100644 (file)
@@ -204,7 +204,7 @@ struct composition {
    COMPOSITION-ID.  */
 extern struct composition **composition_table;
 /* Number of the currently registered compositions.  */
-extern int n_compositions;
+extern ptrdiff_t n_compositions;
 
 /* Mask bits for CHECK_MASK arg to update_compositions.
    For a change in the region FROM and TO, check compositions ... */
@@ -216,8 +216,8 @@ extern int n_compositions;
 
 extern Lisp_Object Qcomposition;
 extern Lisp_Object composition_hash_table;
-extern int get_composition_id (EMACS_INT, EMACS_INT, EMACS_INT,
-                              Lisp_Object, Lisp_Object);
+extern ptrdiff_t get_composition_id (EMACS_INT, EMACS_INT, EMACS_INT,
+                                    Lisp_Object, Lisp_Object);
 extern int find_composition (EMACS_INT, EMACS_INT, EMACS_INT *, EMACS_INT *,
                             Lisp_Object *, Lisp_Object);
 extern void update_compositions (EMACS_INT, EMACS_INT, int);
@@ -299,7 +299,7 @@ struct face;
 struct font_metrics;
 
 extern Lisp_Object composition_gstring_put_cache (Lisp_Object, EMACS_INT);
-extern Lisp_Object composition_gstring_from_id (int);
+extern Lisp_Object composition_gstring_from_id (ptrdiff_t);
 extern int composition_gstring_p (Lisp_Object);
 extern int composition_gstring_width (Lisp_Object, EMACS_INT, EMACS_INT,
                                       struct font_metrics *);
index bb4da7d..1d7bf5d 100644 (file)
@@ -1240,7 +1240,7 @@ struct glyph_string
   struct composition *cmp;
 
   /* If not negative, this string describes a compos.  */
-  int cmp_id;
+  ptrdiff_t cmp_id;
 
   /* Start and end glyph indices in a glyph-string.  */
   int cmp_from, cmp_to;
@@ -2056,7 +2056,7 @@ struct composition_it
   EMACS_INT stop_pos;
   /* ID number of the composition or glyph-string.  If negative, we
      are not iterating over a composition now.  */
-  int id;
+  ptrdiff_t id;
   /* If non-negative, character that triggers the automatic
      composition at `stop_pos', and this is an automatic composition.
      If negative, this is a static composition.  This is set to -2
index 3f5a743..04fea6b 100644 (file)
@@ -5069,7 +5069,7 @@ and redisplay normally--don't erase and redraw the frame.  */)
          && (!EQ (Vrecenter_redisplay, Qtty)
              || !NILP (Ftty_type (selected_frame))))
        {
-         int i;
+         ptrdiff_t i;
 
          /* Invalidate pixel data calculated for all compositions.  */
          for (i = 0; i < n_compositions; i++)
index 43f60ab..55296db 100644 (file)
@@ -22002,7 +22002,7 @@ compute_overhangs_and_x (struct glyph_string *s, int x, int backward_p)
   do {                                                                     \
     int face_id = (row)->glyphs[area][START].face_id;                      \
     struct face *base_face = FACE_FROM_ID (f, face_id);                            \
-    int cmp_id = (row)->glyphs[area][START].u.cmp.id;                      \
+    ptrdiff_t cmp_id = (row)->glyphs[area][START].u.cmp.id;                \
     struct composition *cmp = composition_table[cmp_id];                   \
     XChar2b *char2b;                                                       \
     struct glyph_string *first_s IF_LINT (= NULL);                         \