Check for overflow when converting integer to cons and back.
[bpt/emacs.git] / src / font.c
index 7d8b94b..326c9d8 100644 (file)
@@ -48,7 +48,7 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include "nsterm.h"
 #endif /* HAVE_NS */
 
-static Lisp_Object Qopentype;
+Lisp_Object Qopentype;
 
 /* Important character set strings.  */
 Lisp_Object Qascii_0, Qiso8859_1, Qiso10646_1, Qunicode_bmp, Qunicode_sip;
@@ -136,7 +136,7 @@ Lisp_Object Qja, Qko;
 
 static Lisp_Object QCuser_spec;
 
-/* Alist of font registry symbol and the corresponding charsets
+/* Alist of font registry symbols and the corresponding charset
    information.  The information is retrieved from
    Vfont_encoding_alist on demand.
 
@@ -226,9 +226,9 @@ static int num_font_drivers;
 
 
 /* Return a Lispy value of a font property value at STR and LEN bytes.
-   If STR is "*", it returns nil.
-   If FORCE_SYMBOL is zero and all characters in STR are digits, it
-   returns an integer.  Otherwise, it returns a symbol interned from
+   If STR is "*", return nil.
+   If FORCE_SYMBOL is zero and all characters in STR are digits,
+   return an integer.  Otherwise, return a symbol interned from
    STR.  */
 
 Lisp_Object
@@ -251,9 +251,9 @@ font_intern_prop (const char *str, int len, int force_symbol)
     }
 
   /* The following code is copied from the function intern (in
-     lread.c), and modified to suite our purpose.  */
+     lread.c), and modified to suit our purpose.  */
   obarray = Vobarray;
-  if (!VECTORP (obarray) || XVECTOR (obarray)->size == 0)
+  if (!VECTORP (obarray) || ASIZE (obarray) == 0)
     obarray = check_obarray (obarray);
   parse_str_as_multibyte ((unsigned char *) str, len, &nchars, &nbytes);
   if (len == nchars || len != nbytes)
@@ -305,7 +305,7 @@ font_pixel_size (FRAME_PTR f, Lisp_Object spec)
    font vector.  If VAL is not valid (i.e. not registered in
    font_style_table), return -1 if NOERROR is zero, and return a
    proper index if NOERROR is nonzero.  In that case, register VAL in
-   font_style_table if VAL is a symbol, and return a closest index if
+   font_style_table if VAL is a symbol, and return the closest index if
    VAL is an integer.  */
 
 int
@@ -473,7 +473,7 @@ font_registry_charsets (Lisp_Object registry, struct charset **encoding, struct
 }
 
 \f
-/* Font property value validaters.  See the comment of
+/* Font property value validators.  See the comment of
    font_property_table for the meaning of the arguments.  */
 
 static Lisp_Object font_prop_validate (int, Lisp_Object, Lisp_Object);
@@ -591,7 +591,7 @@ font_prop_validate_otf (Lisp_Object prop, Lisp_Object val)
   return val;
 }
 
-/* Structure of known font property keys and validater of the
+/* Structure of known font property keys and validator of the
    values.  */
 static const struct
 {
@@ -742,7 +742,7 @@ enum xlfd_field_mask
 };
 
 
-/* Parse P pointing the pixel/point size field of the form
+/* Parse P pointing to the pixel/point size field of the form
    `[A B C D]' which specifies a transformation matrix:
 
        A  B  0
@@ -775,7 +775,7 @@ parse_matrix (const char *p)
 }
 
 /* Expand a wildcard field in FIELD (the first N fields are filled) to
-   multiple fields to fill in all 14 XLFD fields while restring a
+   multiple fields to fill in all 14 XLFD fields while restricting a
    field position by its contents.  */
 
 static int
@@ -1271,9 +1271,9 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
     f[XLFD_SPACING_INDEX] = "*", len += 2;
   if (INTEGERP (AREF (font,  FONT_AVGWIDTH_INDEX)))
     {
-      f[XLFD_AVGWIDTH_INDEX] = p = alloca (11);
-      len += sprintf (p, "%ld",
-                      (long) XINT (AREF (font, FONT_AVGWIDTH_INDEX))) + 1;
+      f[XLFD_AVGWIDTH_INDEX] = p = alloca (22);
+      len += sprintf (p, "%"pI"d",
+                     XINT (AREF (font, FONT_AVGWIDTH_INDEX))) + 1;
     }
   else
     f[XLFD_AVGWIDTH_INDEX] = "*", len += 2;
@@ -1598,7 +1598,7 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
     }
 
   if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
-    len += sprintf (work, ":dpi=%ld", (long)XINT (AREF (font, FONT_DPI_INDEX)));
+    len += sprintf (work, ":dpi=%"pI"d", XINT (AREF (font, FONT_DPI_INDEX)));
   if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
     len += strlen (":spacing=100");
   if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
@@ -1611,7 +1611,7 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
       if (STRINGP (value))
        len += SBYTES (value);
       else if (INTEGERP (value))
-       len += sprintf (work, "%ld", (long) XINT (value));
+       len += sprintf (work, "%"pI"d", XINT (value));
       else if (SYMBOLP (value))
        len += (NILP (value) ? 5 : 4); /* for "false" or "true" */
     }
@@ -1638,10 +1638,9 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
       p += sprintf (p, ":%s=%s", style_names[i],
                    SDATA (SYMBOL_NAME (styles[i])));
   if (INTEGERP (AREF (font, FONT_DPI_INDEX)))
-    p += sprintf (p, ":dpi=%ld", (long) XINT (AREF (font, FONT_DPI_INDEX)));
+    p += sprintf (p, ":dpi=%"pI"d", XINT (AREF (font, FONT_DPI_INDEX)));
   if (INTEGERP (AREF (font, FONT_SPACING_INDEX)))
-    p += sprintf (p, ":spacing=%ld",
-                  (long) XINT (AREF (font, FONT_SPACING_INDEX)));
+    p += sprintf (p, ":spacing=%"pI"d", XINT (AREF (font, FONT_SPACING_INDEX)));
   if (INTEGERP (AREF (font, FONT_AVGWIDTH_INDEX)))
     {
       if (XINT (AREF (font, FONT_AVGWIDTH_INDEX)) == 0)
@@ -1795,14 +1794,16 @@ check_otf_features (otf_features)
     {
       CHECK_SYMBOL (Fcar (val));
       if (SBYTES (SYMBOL_NAME (XCAR (val))) > 4)
-       error ("Invalid OTF GSUB feature: %s", SYMBOL_NAME (XCAR (val)));
+       error ("Invalid OTF GSUB feature: %s",
+              SDATA (SYMBOL_NAME (XCAR (val))));
     }
   otf_features = XCDR (otf_features);
   for (val = Fcar (otf_features); ! NILP (val);  val = Fcdr (val))
     {
       CHECK_SYMBOL (Fcar (val));
       if (SBYTES (SYMBOL_NAME (XCAR (val))) > 4)
-       error ("Invalid OTF GPOS feature: %s", SYMBOL_NAME (XCAR (val)));
+       error ("Invalid OTF GPOS feature: %s",
+              SDATA (SYMBOL_NAME (XCAR (val))));
     }
 }
 
@@ -2053,14 +2054,14 @@ font_rescale_ratio (Lisp_Object font_entity)
    font-spec.  The score value is 32 bit (`unsigned'), and the smaller
    the value is, the closer the font is to the font-spec.
 
-   The lowest 2 bits of the score is used for driver type.  The font
+   The lowest 2 bits of the score are used for driver type.  The font
    available by the most preferred font driver is 0.
 
-   Each 7-bit in the higher 28 bits are used for numeric properties
+   The 4 7-bit fields in the higher 28 bits are used for numeric properties
    WEIGHT, SLANT, WIDTH, and SIZE.  */
 
 /* How many bits to shift to store the difference value of each font
-   property in a score.  Note that flots for FONT_TYPE_INDEX and
+   property in a score.  Note that floats for FONT_TYPE_INDEX and
    FONT_REGISTRY_INDEX are not used.  */
 static int sort_shift_bits[FONT_SIZE_INDEX + 1];
 
@@ -2597,7 +2598,7 @@ font_clear_cache (FRAME_PTR f, Lisp_Object cache, struct font_driver *driver)
 static Lisp_Object scratch_font_spec, scratch_font_prefer;
 
 /* Check each font-entity in VEC, and return a list of font-entities
-   that satisfy this condition:
+   that satisfy these conditions:
      (1) matches with SPEC and SIZE if SPEC is not nil, and
      (2) doesn't match with any regexps in Vface_ignored_fonts (if non-nil).
 */
@@ -3017,8 +3018,8 @@ font_clear_prop (Lisp_Object *attrs, enum font_property_index prop)
   attrs[LFACE_FONT_INDEX] = font;
 }
 
-/* Selecte a font from ENTITIES (list of font-entity vectors) that
-   supports C and matches best with ATTRS and PIXEL_SIZE.  */
+/* Select a font from ENTITIES (list of font-entity vectors) that
+   supports C and is the best match for ATTRS and PIXEL_SIZE.  */
 
 static Lisp_Object
 font_select_entity (Lisp_Object frame, Lisp_Object entities, Lisp_Object *attrs, int pixel_size, int c)
@@ -3061,8 +3062,8 @@ font_select_entity (Lisp_Object frame, Lisp_Object entities, Lisp_Object *attrs,
   return font_sort_entities (entities, prefer, frame, c);
 }
 
-/* Return a font-entity satisfying SPEC and best matching with face's
-   font related attributes in ATTRS.  C, if not negative, is a
+/* Return a font-entity that satisfies SPEC and is the best match for
+   face's font related attributes in ATTRS.  C, if not negative, is a
    character that the entity must support.  */
 
 Lisp_Object
@@ -3253,8 +3254,8 @@ font_open_for_lface (FRAME_PTR f, Lisp_Object entity, Lisp_Object *attrs, Lisp_O
 }
 
 
-/* Find a font satisfying SPEC and best matching with face's
-   attributes in ATTRS on FRAME, and return the opened
+/* Find a font that satisfies SPEC and is the best match for
+   face's attributes in ATTRS on FRAME, and return the opened
    font-object.  */
 
 Lisp_Object
@@ -3266,8 +3267,7 @@ font_load_for_lface (FRAME_PTR f, Lisp_Object *attrs, Lisp_Object spec)
   if (NILP (entity))
     {
       /* No font is listed for SPEC, but each font-backend may have
-        the different criteria about "font matching".  So, try
-        it.  */
+        different criteria about "font matching".  So, try it.  */
       entity = font_matching_entity (f, attrs, spec);
       if (NILP (entity))
        return Qnil;
@@ -3306,7 +3306,7 @@ font_done_for_face (FRAME_PTR f, struct face *face)
 }
 
 
-/* Open a font matching with font-spec SPEC on frame F.  If no proper
+/* Open a font that is a match for font-spec SPEC on frame F.  If no proper
    font is found, return Qnil.  */
 
 Lisp_Object
@@ -3330,7 +3330,7 @@ font_open_by_spec (FRAME_PTR f, Lisp_Object spec)
 }
 
 
-/* Open a font matching with NAME on frame F.  If no proper font is
+/* Open a font that matches NAME on frame F.  If no proper font is
    found, return Qnil.  */
 
 Lisp_Object
@@ -3354,7 +3354,7 @@ font_open_by_name (FRAME_PTR f, const char *name)
 /* Register font-driver DRIVER.  This function is used in two ways.
 
    The first is with frame F non-NULL.  In this case, make DRIVER
-   available (but not yet activated) on F.  All frame creaters
+   available (but not yet activated) on F.  All frame creators
    (e.g. Fx_create_frame) must call this function at least once with
    an available font-driver.
 
@@ -3681,7 +3681,7 @@ font_at (int c, EMACS_INT pos, struct face *face, struct window *w,
 #ifdef HAVE_WINDOW_SYSTEM
 
 /* Check how many characters after POS (at most to *LIMIT) can be
-   displayed by the same font on the window W.  FACE, if non-NULL, is
+   displayed by the same font in the window W.  FACE, if non-NULL, is
    the face selected for the character at POS.  If STRING is not nil,
    it is the string to check instead of the current buffer.  In that
    case, FACE must be not NULL.
@@ -3825,7 +3825,7 @@ GSUB and GPOS may contain `nil' element.  In such a case, the font
 must not have any of the remaining elements.
 
 For instance, if the VALUE is `(thai nil nil (mark))', the font must
-be an OpenType font, and whose GPOS table of `thai' script's default
+be an OpenType font whose GPOS table of `thai' script's default
 language system must contain `mark' feature.
 
 usage: (font-spec ARGS...)  */)
@@ -4188,7 +4188,7 @@ DEFUN ("font-xlfd-name", Ffont_xlfd_name, Sfont_xlfd_name, 1, 2, 0,
 FONT is a font-spec, font-entity, or font-object.
 If the name is too long for XLFD (maximum 255 chars), return nil.
 If the 2nd optional arg FOLD-WILDCARDS is non-nil,
-the consecutive wildcards are folded to one.  */)
+the consecutive wildcards are folded into one.  */)
   (Lisp_Object font, Lisp_Object fold_wildcards)
 {
   char name[256];
@@ -4388,16 +4388,8 @@ where
   for (i = 0; i < 255; i++)
     if (variations[i])
       {
-       Lisp_Object code;
        int vs = (i < 16 ? 0xFE00 + i : 0xE0100 + (i - 16));
-       /* Stops GCC whining about limited range of data type.  */
-       EMACS_INT var = variations[i];
-
-       if (var > MOST_POSITIVE_FIXNUM)
-         code = Fcons (make_number ((variations[i]) >> 16),
-                       make_number ((variations[i]) & 0xFFFF));
-       else
-         code = make_number (variations[i]);
+       Lisp_Object code = INTEGER_TO_CONS (variations[i]);
        val = Fcons (Fcons (make_number (vs), code), val);
       }
   return val;
@@ -4435,7 +4427,7 @@ the value is 0.
 If GSTRING-OUT is too short to hold produced glyphs, no glyphs are
 produced in GSTRING-OUT, and the value is nil.
 
-See the documentation of `font-make-gstring' for the format of
+See the documentation of `composition-get-gstring' for the format of
 glyph-string.  */)
   (Lisp_Object otf_features, Lisp_Object gstring_in, Lisp_Object from, Lisp_Object to, Lisp_Object gstring_out, Lisp_Object index)
 {
@@ -4570,10 +4562,10 @@ The value is a vector:
   [ NAME FILENAME PIXEL-SIZE SIZE ASCENT DESCENT SPACE-WIDTH AVERAGE-WIDTH
     CAPABILITY ]
 
-NAME is a string of the font name (or nil if the font backend doesn't
+NAME is the font name, a string (or nil if the font backend doesn't
 provide a name).
 
-FILENAME is a string of the font file (or nil if the font backend
+FILENAME is the font file name, a string (or nil if the font backend
 doesn't provide a file name).
 
 PIXEL-SIZE is a pixel size by which the font is opened.