Use an unused high bit in the XID to mark fonts in the global xid hash

2006-01-19  Matthias Clasen  <mclasen@redhat.com>

	* gdk/x11/gdkprivate-x11.h (XID_FONT_BIT):
	* gdk/x11/gdkfont-x11.c:
	* gdk/x11/gdkxid.c: Use an unused high bit in the
	XID to mark fonts in the global xid hash table.

	* gdk/x11/gdkcursor-x11.c (update_cursor): Skip fonts
	when iterating over the xid hash table, since calling
	GDK_IS_WINDOW () on an GdkFont can cause a segfault.
	(#327751, Ryan Lortie)
This commit is contained in:
Matthias Clasen 2006-01-20 04:35:24 +00:00 committed by Matthias Clasen
parent 292c69ac7d
commit 73153b42e8
4 changed files with 15 additions and 2 deletions

View File

@ -430,8 +430,12 @@ update_cursor (gpointer key,
gpointer value,
gpointer data)
{
XID *xid = key;
GdkCursor *cursor;
if (*xid & XID_FONT_BIT)
return;
if (!GDK_IS_WINDOW (value))
return;

View File

@ -50,6 +50,7 @@ struct _GdkFontPrivateX
GdkDisplay *display;
GSList *names;
XID xid;
};
static GHashTable *
@ -214,13 +215,14 @@ gdk_font_load_for_display (GdkDisplay *display,
private->xfont = xfont;
private->base.ref_count = 1;
private->names = NULL;
private->xid = xfont->fid | XID_FONT_BIT;
font = (GdkFont*) private;
font->type = GDK_FONT_FONT;
font->ascent = xfont->ascent;
font->descent = xfont->descent;
_gdk_xid_table_insert (display, &xfont->fid, font);
_gdk_xid_table_insert (display, &private->xid, font);
}
gdk_font_hash_insert (GDK_FONT_FONT, font, font_name);

View File

@ -86,6 +86,8 @@ struct _GdkVisualPrivate
GdkScreen *screen;
};
#define XID_FONT_BIT (1<<31)
void _gdk_xid_table_insert (GdkDisplay *display,
XID *xid,
gpointer data);

View File

@ -36,6 +36,11 @@ static gboolean gdk_xid_equal (XID *a,
XID *b);
/* The 3 high bits of XIDs are unused. We use one to mark fonts,
* since we must be able to skip fonts when iterating over all XIDs.
*/
#define XID_FONT_BIT (1<<31)
void
_gdk_xid_table_insert (GdkDisplay *display,
XID *xid,
@ -123,7 +128,7 @@ static gboolean
gdk_xid_equal (XID *a,
XID *b)
{
return (*a == *b);
return ((*a & ~XID_FONT_BIT) == (*b & ~XID_FONT_BIT));
}
#define __GDK_XID_C__