use vectors for symbol slots
[bpt/emacs.git] / src / font.c
index 5faf477..ddf2856 100644 (file)
@@ -207,6 +207,9 @@ font_make_object (int size, Lisp_Object entity, int pixelsize)
     = (struct font *) allocate_pseudovector (size, FONT_OBJECT_MAX, PVEC_FONT);
   int i;
 
+  /* GC can happen before the driver is set up,
+     so avoid dangling pointer here (Bug#17771).  */
+  font->driver = NULL;
   XSETFONT (font_object, font);
 
   if (! NILP (entity))
@@ -279,10 +282,8 @@ font_intern_prop (const char *str, ptrdiff_t len, bool force_symbol)
 
   if (SYMBOLP (tem))
     return tem;
-  if (len == nchars || len != nbytes)
-    tem = make_unibyte_string (str, len);
-  else
-    tem = make_multibyte_string (str, nchars, len);
+  tem = make_specified_string (str, nchars, len,
+                              len != nchars && len == nbytes);
   return Fintern (tem, obarray);
 }
 
@@ -2803,7 +2804,7 @@ font_matching_entity (struct frame *f, Lisp_Object *attrs, Lisp_Object spec)
        ASET (work, FONT_TYPE_INDEX, driver_list->driver->type);
        entity = assoc_no_quit (work, XCDR (cache));
        if (CONSP (entity))
-         entity = XCDR (entity);
+         entity = AREF (XCDR (entity), 0);
        else
          {
            entity = driver_list->driver->match (f, work);
@@ -3337,7 +3338,6 @@ font_done_for_face (struct frame *f, struct face *face)
 {
   if (face->font->driver->done_face)
     face->font->driver->done_face (f, face);
-  face->extra = NULL;
 }
 
 
@@ -5061,6 +5061,8 @@ font_deferred_log (const char *action, Lisp_Object arg, Lisp_Object result)
 void
 syms_of_font (void)
 {
+#include "font.x"
+
   sort_shift_bits[FONT_TYPE_INDEX] = 0;
   sort_shift_bits[FONT_SLANT_INDEX] = 2;
   sort_shift_bits[FONT_WEIGHT_INDEX] = 9;
@@ -5121,41 +5123,6 @@ syms_of_font (void)
 #endif /* HAVE_LIBOTF */
 #endif /* 0 */
 
-  defsubr (&Sfontp);
-  defsubr (&Sfont_spec);
-  defsubr (&Sfont_get);
-#ifdef HAVE_WINDOW_SYSTEM
-  defsubr (&Sfont_face_attributes);
-#endif
-  defsubr (&Sfont_put);
-  defsubr (&Slist_fonts);
-  defsubr (&Sfont_family_list);
-  defsubr (&Sfind_font);
-  defsubr (&Sfont_xlfd_name);
-  defsubr (&Sclear_font_cache);
-  defsubr (&Sfont_shape_gstring);
-  defsubr (&Sfont_variation_glyphs);
-#if 0
-  defsubr (&Sfont_drive_otf);
-  defsubr (&Sfont_otf_alternates);
-#endif /* 0 */
-
-#ifdef FONT_DEBUG
-  defsubr (&Sopen_font);
-  defsubr (&Sclose_font);
-  defsubr (&Squery_font);
-  defsubr (&Sfont_get_glyphs);
-  defsubr (&Sfont_match_p);
-  defsubr (&Sfont_at);
-#if 0
-  defsubr (&Sdraw_string);
-#endif
-  defsubr (&Sframe_font_cache);
-#endif /* FONT_DEBUG */
-#ifdef HAVE_WINDOW_SYSTEM
-  defsubr (&Sfont_info);
-#endif
-
   DEFVAR_LISP ("font-encoding-alist", Vfont_encoding_alist,
               doc: /*
 Alist of fontname patterns vs the corresponding encoding and repertory info.
@@ -5189,19 +5156,19 @@ Each element has the form:
     [NUMERIC-VALUE SYMBOLIC-NAME ALIAS-NAME ...]
 NUMERIC-VALUE is an integer, and SYMBOLIC-NAME and ALIAS-NAME are symbols. */);
   Vfont_weight_table = BUILD_STYLE_TABLE (weight_table);
-  XSYMBOL (intern_c_string ("font-weight-table"))->constant = 1;
+  SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-weight-table")), 1);
 
   DEFVAR_LISP_NOPRO ("font-slant-table", Vfont_slant_table,
               doc: /*  Vector of font slant symbols vs the corresponding numeric values.
 See `font-weight-table' for the format of the vector. */);
   Vfont_slant_table = BUILD_STYLE_TABLE (slant_table);
-  XSYMBOL (intern_c_string ("font-slant-table"))->constant = 1;
+  SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-slant-table")), 1);
 
   DEFVAR_LISP_NOPRO ("font-width-table", Vfont_width_table,
               doc: /*  Alist of font width symbols vs the corresponding numeric values.
 See `font-weight-table' for the format of the vector. */);
   Vfont_width_table = BUILD_STYLE_TABLE (width_table);
-  XSYMBOL (intern_c_string ("font-width-table"))->constant = 1;
+  SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-width-table")), 1);
 
   staticpro (&font_style_table);
   font_style_table = make_uninit_vector (3);