From: Gerd Moellmann Date: Sat, 4 Mar 2000 15:58:49 +0000 (+0000) Subject: (x_free_colors): Access colormap of frame using X-Git-Tag: emacs-pretest-21.0.90~4776 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=276104706d05b309a1ef829a5f1d78214560bcd5;p=emacs.git (x_free_colors): Access colormap of frame using FRAME_X_COLORMAP. Be paranoid about freeing black and white when default colormap is used. --- diff --git a/src/xfaces.c b/src/xfaces.c index 829fb6e7eda..89b8e4c7b5f 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -548,20 +548,30 @@ x_free_colors (f, pixels, npixels) if (class != StaticColor && class != StaticGray && class != TrueColor) { Display *dpy = FRAME_X_DISPLAY (f); - Colormap cmap = DefaultColormapOfScreen (FRAME_X_SCREEN (f)); - int screen_no = XScreenNumberOfScreen (FRAME_X_SCREEN (f)); - unsigned long black = BlackPixel (dpy, screen_no); - unsigned long white = WhitePixel (dpy, screen_no); - unsigned long *px; - int i, j; - - px = (unsigned long *) alloca (npixels * sizeof *px); - for (i = j = 0; i < npixels; ++i) - if (pixels[i] != black && pixels[i] != white) - px[j++] = pixels[i]; - - if (j) - XFreeColors (dpy, cmap, px, j, 0); + Colormap cmap = FRAME_X_COLORMAP (f); + Screen *screen = FRAME_X_SCREEN (f); + int default_cmap_p = cmap == DefaultColormapOfScreen (screen); + + if (default_cmap_p) + { + /* Be paranoid. If using the default color map, don't ever + try to free the default black and white colors. */ + int screen_no = XScreenNumberOfScreen (screen); + unsigned long black = BlackPixel (dpy, screen_no); + unsigned long white = WhitePixel (dpy, screen_no); + unsigned long *px; + int i, j; + + px = (unsigned long *) alloca (npixels * sizeof *px); + for (i = j = 0; i < npixels; ++i) + if (pixels[i] != black && pixels[i] != white) + px[j++] = pixels[i]; + + if (j) + XFreeColors (dpy, cmap, px, j, 0); + } + else + XFreeColors (dpy, cmap, pixels, npixels, 0); } }