fixed gc protection
This commit is contained in:
parent
a678b14752
commit
992c2aa830
|
@ -10,6 +10,7 @@ double s48_extract_number(s48_value v) {
|
|||
}
|
||||
|
||||
void scx_extract_color(s48_value v, XColor* c) {
|
||||
S48_DECLARE_GC_PROTECT_1(v);
|
||||
s48_check_record_type(v, scx_color);
|
||||
c->pixel = scx_extract_pixel(S48_RECORD_REF(v, 0));
|
||||
c->flags = 0;
|
||||
|
@ -25,6 +26,7 @@ void scx_extract_color(s48_value v, XColor* c) {
|
|||
c->flags |= DoBlue;
|
||||
c->blue = s48_extract_number(S48_RECORD_REF(v, 3)) * 65536;
|
||||
}
|
||||
S48_GC_UNPROTECT();
|
||||
}
|
||||
|
||||
void scx_copy_color(const XColor* c, s48_value v) {
|
||||
|
@ -49,36 +51,40 @@ s48_value scx_enter_color(const XColor* c) {
|
|||
|
||||
s48_value scx_Create_Colormap (s48_value display, s48_value window,
|
||||
s48_value visual, s48_value alloc) {
|
||||
S48_DECLARE_GC_PROTECT_4(display, window, visual, alloc);
|
||||
Colormap cm = XCreateColormap(scx_extract_display(display),
|
||||
scx_extract_window(window),
|
||||
scx_extract_visual(visual),
|
||||
scx_extract_colormap_alloc(alloc));
|
||||
return scx_enter_colormap(cm);
|
||||
S48_GC_RETURN(scx_enter_colormap(cm));
|
||||
}
|
||||
|
||||
s48_value scx_Copy_Colormap_And_Free(s48_value display, s48_value colormap) {
|
||||
S48_DECLARE_GC_PROTECT_2(display, colormap);
|
||||
Colormap cm = XCopyColormapAndFree(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap));
|
||||
return scx_enter_colormap(cm);
|
||||
S48_GC_RETURN(scx_enter_colormap(cm));
|
||||
}
|
||||
|
||||
s48_value scx_Free_Colormap (s48_value display, s48_value colormap) {
|
||||
S48_DECLARE_GC_PROTECT_2(display, colormap);
|
||||
XFreeColormap(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Alloc_Color(s48_value display, s48_value colormap,
|
||||
s48_value color) {
|
||||
XColor cp;
|
||||
S48_DECLARE_GC_PROTECT_3(display, colormap, color);
|
||||
scx_extract_color(color, &cp);
|
||||
|
||||
if (!XAllocColor(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap), &cp))
|
||||
return S48_FALSE;
|
||||
S48_GC_RETURN(S48_FALSE);
|
||||
else {
|
||||
scx_copy_color(&cp, color);
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +92,8 @@ s48_value scx_Alloc_Named_Color(s48_value display, s48_value colormap,
|
|||
s48_value color_name) {
|
||||
XColor screen, exact;
|
||||
int r;
|
||||
S48_DECLARE_GC_PROTECT(2);
|
||||
s48_value s = S48_NULL, e = S48_NULL;
|
||||
S48_DECLARE_GC_PROTECT_5(display, colormap, color_name , s, e);
|
||||
|
||||
r = XAllocNamedColor(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
|
@ -94,14 +101,11 @@ s48_value scx_Alloc_Named_Color(s48_value display, s48_value colormap,
|
|||
&screen, &exact);
|
||||
|
||||
if (r != 0) {
|
||||
s48_value s = S48_NULL, e = S48_NULL;
|
||||
S48_GC_PROTECT_2(s, e);
|
||||
s = scx_enter_color(&screen);
|
||||
e = scx_enter_color(&exact);
|
||||
S48_GC_UNPROTECT();
|
||||
return s48_cons(s, e);
|
||||
S48_GC_RETURN(s48_cons(s, e));
|
||||
} else
|
||||
return S48_FALSE;
|
||||
S48_GC_RETURN(S48_FALSE);
|
||||
}
|
||||
|
||||
s48_value scx_Alloc_Color_Cells (s48_value display, s48_value colormap,
|
||||
|
@ -112,7 +116,8 @@ s48_value scx_Alloc_Color_Cells (s48_value display, s48_value colormap,
|
|||
unsigned long plane_masks[npl];
|
||||
unsigned long pixels[npx];
|
||||
s48_value pls = S48_NULL, pxs = S48_NULL;
|
||||
S48_DECLARE_GC_PROTECT(2);
|
||||
S48_DECLARE_GC_PROTECT_7(display, colormap, contig, nplanes, npixels,
|
||||
pls, pxs);
|
||||
|
||||
if (XAllocColorCells(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
|
@ -120,15 +125,13 @@ s48_value scx_Alloc_Color_Cells (s48_value display, s48_value colormap,
|
|||
plane_masks, npl,
|
||||
pixels, npx)) {
|
||||
int i;
|
||||
S48_GC_PROTECT_2(pls, pxs);
|
||||
for (i = npl-1; i >= 0; i--)
|
||||
pls = s48_cons(s48_enter_integer(plane_masks[i]), pls);
|
||||
for (i = npx-1; i >= 0; i--)
|
||||
pxs = s48_cons(scx_enter_pixel(pixels[i]), pxs);
|
||||
S48_GC_UNPROTECT();
|
||||
return s48_cons(pls, pxs);
|
||||
S48_GC_RETURN(s48_cons(pls, pxs));
|
||||
} else
|
||||
return S48_FALSE;
|
||||
S48_GC_RETURN(S48_FALSE);
|
||||
}
|
||||
|
||||
s48_value scx_Alloc_Color_Planes(s48_value display, s48_value colormap,
|
||||
|
@ -143,7 +146,8 @@ s48_value scx_Alloc_Color_Planes(s48_value display, s48_value colormap,
|
|||
unsigned long rmask, gmask, bmask;
|
||||
s48_value pxs = S48_NULL;
|
||||
s48_value res = S48_NULL;
|
||||
S48_DECLARE_GC_PROTECT(2);
|
||||
S48_DECLARE_GC_PROTECT_9(display, colormap, contig, ncolors, nreds, ngreens,
|
||||
nblues, pxs, res);
|
||||
|
||||
if (XAllocColorPlanes(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
|
@ -152,17 +156,15 @@ s48_value scx_Alloc_Color_Planes(s48_value display, s48_value colormap,
|
|||
nre, ngr, nbl,
|
||||
&rmask, &gmask, &bmask)) {
|
||||
int i;
|
||||
S48_GC_PROTECT_2(pxs, res);
|
||||
for (i = npx-1; i >= 0; i--)
|
||||
pxs = s48_cons(scx_enter_pixel(pixels[i]), pxs);
|
||||
res = s48_cons(s48_enter_integer(bmask), res);
|
||||
res = s48_cons(s48_enter_integer(gmask), res);
|
||||
res = s48_cons(s48_enter_integer(rmask), res);
|
||||
res = s48_cons(pxs, res);
|
||||
S48_GC_UNPROTECT();
|
||||
return res;
|
||||
S48_GC_RETURN(res);
|
||||
} else
|
||||
return S48_FALSE;
|
||||
S48_GC_RETURN(S48_FALSE);
|
||||
}
|
||||
|
||||
s48_value scx_Free_Colors(s48_value display, s48_value colormap,
|
||||
|
@ -170,13 +172,14 @@ s48_value scx_Free_Colors(s48_value display, s48_value colormap,
|
|||
int i, n = s48_list_length(pixels);
|
||||
unsigned long cpixels[n];
|
||||
s48_value l = pixels;
|
||||
S48_DECLARE_GC_PROTECT_5(display, colormap, pixels, planes, l);
|
||||
for (i = 0; i < n; i++) {
|
||||
cpixels[i] = scx_extract_pixel(S48_CAR(l));
|
||||
l = S48_CDR(l);
|
||||
}
|
||||
XFreeColors(scx_extract_display(display), scx_extract_colormap(colormap),
|
||||
cpixels, n, s48_extract_integer(planes));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Query_Colors(s48_value display, s48_value colormap,
|
||||
|
@ -184,6 +187,7 @@ s48_value scx_Query_Colors(s48_value display, s48_value colormap,
|
|||
int i, n = s48_list_length(colors);
|
||||
XColor ccolors[n];
|
||||
s48_value l = colors;
|
||||
S48_DECLARE_GC_PROTECT_4(display, colormap, colors, l);
|
||||
for (i = 0; i < n; i++) {
|
||||
scx_extract_color(S48_CAR(l), &ccolors[i]);
|
||||
l = S48_CDR(l);
|
||||
|
@ -195,36 +199,35 @@ s48_value scx_Query_Colors(s48_value display, s48_value colormap,
|
|||
scx_copy_color(&ccolors[i], S48_CAR(l));
|
||||
l = S48_CDR(l);
|
||||
}
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Lookup_Color(s48_value display, s48_value colormap,
|
||||
s48_value color_name) {
|
||||
XColor cexact, cscreen;
|
||||
S48_DECLARE_GC_PROTECT(1);
|
||||
s48_value r = S48_NULL;
|
||||
S48_DECLARE_GC_PROTECT_4(display, colormap, color_name, r);
|
||||
int res = XLookupColor(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
s48_extract_string(color_name),
|
||||
&cexact, &cscreen);
|
||||
if (res == 0) return S48_FALSE;
|
||||
S48_GC_PROTECT_1(r);
|
||||
if (res == 0) S48_GC_RETURN(S48_FALSE);
|
||||
r = scx_enter_color(&cscreen);
|
||||
r = s48_cons(scx_enter_color(&cexact), r);
|
||||
S48_GC_UNPROTECT();
|
||||
return r;
|
||||
S48_GC_RETURN(r);
|
||||
}
|
||||
|
||||
s48_value scx_Parse_Color(s48_value display, s48_value colormap,
|
||||
s48_value spec) {
|
||||
XColor ret;
|
||||
S48_DECLARE_GC_PROTECT_3(display, colormap, spec);
|
||||
if (XParseColor(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
s48_extract_string(spec),
|
||||
&ret)) {
|
||||
return scx_enter_color(&ret);
|
||||
S48_GC_RETURN(scx_enter_color(&ret));
|
||||
} else
|
||||
return S48_FALSE;
|
||||
S48_GC_RETURN(S48_FALSE);
|
||||
}
|
||||
|
||||
s48_value scx_Store_Colors(s48_value display, s48_value colormap,
|
||||
|
@ -232,6 +235,7 @@ s48_value scx_Store_Colors(s48_value display, s48_value colormap,
|
|||
int i, n = s48_list_length(colors);
|
||||
XColor ccolors[n];
|
||||
s48_value l = colors;
|
||||
S48_DECLARE_GC_PROTECT_4(display, colormap, colors, l);
|
||||
for (i = 0; i < n; i++) {
|
||||
scx_extract_color(S48_CAR(l), &ccolors[i]);
|
||||
l = S48_CDR(l);
|
||||
|
@ -240,13 +244,15 @@ s48_value scx_Store_Colors(s48_value display, s48_value colormap,
|
|||
XStoreColors(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
ccolors, n);
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Store_Named_Color(s48_value display, s48_value colormap,
|
||||
s48_value color_name, s48_value pixel,
|
||||
s48_value do_red, s48_value do_green,
|
||||
s48_value do_blue) {
|
||||
S48_DECLARE_GC_PROTECT_7(display, colormap, color_name, pixel, do_red,
|
||||
do_green, do_blue);
|
||||
XStoreNamedColor(scx_extract_display(display),
|
||||
scx_extract_colormap(colormap),
|
||||
s48_extract_string(color_name),
|
||||
|
@ -254,7 +260,7 @@ s48_value scx_Store_Named_Color(s48_value display, s48_value colormap,
|
|||
(S48_EXTRACT_BOOLEAN(do_red) ? DoRed : 0) |
|
||||
(S48_EXTRACT_BOOLEAN(do_green) ? DoGreen : 0) |
|
||||
(S48_EXTRACT_BOOLEAN(do_blue) ? DoBlue : 0));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
void scx_init_colormap(void) {
|
||||
|
|
|
@ -9,6 +9,7 @@ s48_value scx_Create_Pixmap_Cursor(s48_value display,
|
|||
s48_value x, s48_value y) {
|
||||
XColor f, b;
|
||||
Cursor xc;
|
||||
S48_DECLARE_GC_PROTECT_7(display, src, mask, foreground, background, x, y);
|
||||
scx_extract_color(foreground, &f);
|
||||
scx_extract_color(background, &b);
|
||||
xc = XCreatePixmapCursor(scx_extract_display(display),
|
||||
|
@ -17,7 +18,7 @@ s48_value scx_Create_Pixmap_Cursor(s48_value display,
|
|||
&f, &b,
|
||||
s48_extract_integer(x),
|
||||
s48_extract_integer(y));
|
||||
return scx_enter_cursor(xc);
|
||||
S48_GC_RETURN(scx_enter_cursor(xc));
|
||||
}
|
||||
|
||||
s48_value scx_Create_Glyph_Cursor(s48_value display,
|
||||
|
@ -26,6 +27,8 @@ s48_value scx_Create_Glyph_Cursor(s48_value display,
|
|||
s48_value foreground, s48_value background) {
|
||||
XColor f, b;
|
||||
Cursor xc;
|
||||
S48_DECLARE_GC_PROTECT_7(display, src_font, mask_font, srcc, maskc,
|
||||
foreground, background);
|
||||
scx_extract_color(foreground, &f);
|
||||
scx_extract_color(background, &b);
|
||||
xc = XCreateGlyphCursor(scx_extract_display(display),
|
||||
|
@ -34,43 +37,49 @@ s48_value scx_Create_Glyph_Cursor(s48_value display,
|
|||
s48_extract_integer(srcc),
|
||||
s48_extract_integer(maskc),
|
||||
&f, &b);
|
||||
return scx_enter_cursor(xc);
|
||||
S48_GC_RETURN(scx_enter_cursor(xc));
|
||||
}
|
||||
|
||||
s48_value scx_Create_Font_Cursor(s48_value display, s48_value shape) {
|
||||
Cursor xc = XCreateFontCursor(scx_extract_display(display),
|
||||
s48_extract_integer(shape));
|
||||
return scx_enter_cursor(xc);
|
||||
Cursor xc;
|
||||
S48_DECLARE_GC_PROTECT_2(display, shape);
|
||||
xc = XCreateFontCursor(scx_extract_display(display),
|
||||
s48_extract_integer(shape));
|
||||
S48_GC_RETURN(scx_enter_cursor(xc));
|
||||
}
|
||||
|
||||
s48_value scx_Define_Cursor(s48_value display, s48_value window,
|
||||
s48_value cursor) {
|
||||
S48_DECLARE_GC_PROTECT_3(display, window, cursor);
|
||||
XDefineCursor(scx_extract_display(display), scx_extract_window(window),
|
||||
scx_extract_cursor(cursor));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Undefine_Cursor(s48_value display, s48_value window) {
|
||||
S48_DECLARE_GC_PROTECT_2(display, window);
|
||||
XUndefineCursor(scx_extract_display(display),
|
||||
scx_extract_window(window));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Recolor_Cursor(s48_value display, s48_value cursor,
|
||||
s48_value foreground, s48_value background) {
|
||||
XColor f, b;
|
||||
S48_DECLARE_GC_PROTECT_4(display, cursor, foreground, background);
|
||||
scx_extract_color(foreground, &f);
|
||||
scx_extract_color(background, &b);
|
||||
XRecolorCursor(scx_extract_display(display),
|
||||
scx_extract_cursor(cursor),
|
||||
&f, &b);
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
s48_value scx_Free_Cursor(s48_value display, s48_value cursor) {
|
||||
S48_DECLARE_GC_PROTECT_2(display, cursor);
|
||||
XFreeCursor(scx_extract_display(display),
|
||||
scx_extract_cursor(cursor));
|
||||
return S48_UNSPECIFIC;
|
||||
S48_GC_RETURN(S48_UNSPECIFIC);
|
||||
}
|
||||
|
||||
void scx_init_cursor(void) {
|
||||
|
|
Loading…
Reference in New Issue