*** empty log message ***
[bpt/emacs.git] / src / xfaces.c
index c3c4360..e0a4ca1 100644 (file)
@@ -527,6 +527,60 @@ extern Lisp_Object w32_list_fonts P_ ((struct frame *, Lisp_Object, int, int));
 
 #ifdef HAVE_X_WINDOWS
 
+#ifdef DEBUG_X_COLORS
+
+/* The following is a poor mans infrastructure for debugging X color
+   allocation problems on displays with PseudoColor-8.  Some X servers
+   like 3.3.5 XF86_SVGA with Matrox cards apparently don't implement
+   color reference counts completely so that they don't signal an
+   error when a color is freed whose reference count is already 0.
+   Other X servers do.  To help me debug this, the following code
+   implements a simple reference counting schema of its own, for a
+   single display/screen.  --gerd.  */
+
+/* Reference counts for pixel colors.  */
+
+int color_count[256];
+
+/* Register color PIXEL as allocated.  */
+
+void
+register_color (pixel)
+     unsigned long pixel;
+{
+  xassert (pixel < 256);
+  ++color_count[pixel];
+}
+
+
+/* Register color PIXEL as deallocated.  */
+
+void
+unregister_color (pixel)
+     unsigned long pixel;
+{
+  xassert (pixel < 256);
+  if (color_count[pixel] > 0)
+    --color_count[pixel];
+  else
+    abort ();
+}
+
+
+/* Register N colors from PIXELS as deallocated.  */
+
+void
+unregister_colors (pixels, n)
+     unsigned long *pixels;
+     int n;
+{
+  int i;
+  for (i = 0; i < n; ++i)
+    unregister_color (pixels[i]);
+}
+
+#endif /* DEBUG_X_COLORS */
+
 /* Free colors used on frame F.  PIXELS is an array of NPIXELS pixel
    color values.  Interrupt input must be blocked when this function
    is called.  */
@@ -564,10 +618,20 @@ x_free_colors (f, pixels, npixels)
              px[j++] = pixels[i];
 
          if (j)
-           XFreeColors (dpy, cmap, px, j, 0);
+           {
+             XFreeColors (dpy, cmap, px, j, 0);
+#ifdef DEBUG_X_COLORS
+             unregister_colors (px, j);
+#endif
+           }
        }
       else
-       XFreeColors (dpy, cmap, pixels, npixels, 0);
+       {
+         XFreeColors (dpy, cmap, pixels, npixels, 0);
+#ifdef DEBUG_X_COLORS
+         unregister_colors (pixels, npixels);
+#endif
+       }
     }
 }
 
@@ -2711,8 +2775,8 @@ check_lface_attrs (attrs)
           || SYMBOLP (attrs[LFACE_STIPPLE_INDEX])
           || !NILP (Fbitmap_spec_p (attrs[LFACE_STIPPLE_INDEX])));
   xassert (UNSPECIFIEDP (attrs[LFACE_FONT_INDEX])
-          || NILP (attr[LFACE_FONT_INDEX]));
-          || STRINGP (attr[LFACE_FONT_INDEX]));
+          || NILP (attrs[LFACE_FONT_INDEX])
+          || STRINGP (attrs[LFACE_FONT_INDEX]));
 #endif
 }
 
@@ -2838,7 +2902,7 @@ lface_fully_specified_p (attrs)
   int i;
 
   for (i = 1; i < LFACE_VECTOR_SIZE; ++i)
-    if (UNSPECIFIEDP (attrs[i]))
+    if (UNSPECIFIEDP (attrs[i]) && i != LFACE_FONT_INDEX)
       break;
 
   return i == LFACE_VECTOR_SIZE;
@@ -4432,6 +4496,7 @@ lface_same_font_attributes_p (lface1, lface2)
          && EQ (lface1[LFACE_SLANT_INDEX], lface2[LFACE_SLANT_INDEX])
          && (EQ (lface1[LFACE_FONT_INDEX], lface2[LFACE_FONT_INDEX])
              || (STRINGP (lface1[LFACE_FONT_INDEX])
+                 && STRINGP (lface2[LFACE_FONT_INDEX])
                  && xstricmp (XSTRING (lface1[LFACE_FONT_INDEX])->data,
                               XSTRING (lface2[LFACE_FONT_INDEX])->data))));
 }
@@ -4833,8 +4898,16 @@ lookup_face (f, attr, c, base_face)
 
 #if GLYPH_DEBUG
   xassert (face == FACE_FROM_ID (f, face->id));
+
+/* When this function is called from face_for_char (in this case, C is
+   a multibyte character), a fontset of a face returned by
+   realize_face is not yet set, i.e. FACE_SUITABLE_FOR_CHAR_P (FACE,
+   C) is not sutisfied.  The fontset is set for this face by
+   face_for_char later.  */
+#if 0
   if (FRAME_WINDOW_P (f))
     xassert (FACE_SUITABLE_FOR_CHAR_P (face, c));
+#endif
 #endif /* GLYPH_DEBUG */
   
   return face->id;
@@ -5935,7 +6008,6 @@ realize_x_face (cache, attrs, c, base_face)
   if (!NILP (stipple))
     face->stipple = load_pixmap (f, stipple, &face->pixmap_w, &face->pixmap_h);
 
-  xassert (face->fontset < 0);
   xassert (FACE_SUITABLE_FOR_CHAR_P (face, c));
   return face;
 #endif /* HAVE_WINDOW_SYSTEM */