diff --git a/c/libs/xft.c b/c/libs/xft.c index fbccfa9..b81cb5b 100644 --- a/c/libs/xft.c +++ b/c/libs/xft.c @@ -52,9 +52,9 @@ s48_value scx_XftPatternGet(s48_value sxp, s48_value sobj, s48_value sid) s48_value rv = S48_UNSPECIFIC; s48_value rl = S48_UNSPECIFIC; struct xft_pattern_property *tbl; + S48_DECLARE_GC_PROTECT(5); - S48_DECLARE_GC_PROTECT(2); - S48_GC_PROTECT_2(rl, rv); + S48_GC_PROTECT_5(rl, rv, sxp, sobj, sid); p = scx_extract_xftpattern(sxp); obj = s48_extract_integer(sobj); i = (int) s48_extract_integer(sid); @@ -101,7 +101,9 @@ s48_value scx_XftPatternAdd(s48_value sxp, s48_value sobj, int obj; Bool append, rv; struct xft_pattern_property *tbl; + S48_DECLARE_GC_PROTECT(4); + S48_GC_PROTECT_4(sxp, sobj, sval, sappend); p = scx_extract_xftpattern(sxp); obj = s48_extract_integer(sobj); append = S48_TRUE_P(sappend); @@ -127,6 +129,7 @@ s48_value scx_XftPatternAdd(s48_value sxp, s48_value sobj, } rv = XftPatternAdd(p, tbl->name, v, append); + S48_GC_UNPROTECT(); return rv ? S48_TRUE : S48_FALSE; } @@ -134,12 +137,15 @@ s48_value scx_XftFontMatch(s48_value sdpy, s48_value sscreenno, s48_value sxp) { XftPattern *p; XftResult r; - + S48_DECLARE_GC_PROTECT(3); + + S48_GC_PROTECT_3(sdpy, sscreenno, sxp); p = XftFontMatch((Display *) scx_extract_display(sdpy), s48_extract_integer(sscreenno), scx_extract_xftpattern(sxp), &r); + S48_GC_UNPROTECT(); if (p == NULL) return s48_list_2(S48_FALSE, S48_UNSPECIFIC); else @@ -148,32 +154,47 @@ s48_value scx_XftFontMatch(s48_value sdpy, s48_value sscreenno, s48_value sxp) s48_value scx_XftFontOpenPattern(s48_value sdpy, s48_value sxp) { - return scx_enter_xftfont(XftFontOpenPattern(scx_extract_display(sdpy), - scx_extract_xftpattern(sxp))); + XftFont *xf; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sdpy, sxp); + xf = XftFontOpenPattern(scx_extract_display(sdpy), scx_extract_xftpattern(sxp)); + S48_GC_UNPROTECT(); + return scx_enter_xftfont(xf); } s48_value scx_XftFontOpenName(s48_value sdpy, s48_value sscreenno, s48_value sname) { XftFont *xf; + S48_DECLARE_GC_PROTECT(3); + S48_GC_PROTECT_3(sdpy, sscreenno, sname); xf = XftFontOpenName(scx_extract_display(sdpy), s48_extract_integer(sscreenno), s48_extract_string(sname)); + S48_GC_UNPROTECT(); return scx_enter_xftfont(xf); } s48_value scx_XftFontOpenXlfd(s48_value sdpy, s48_value sscreenno, s48_value sxlfd) { XftFont *xf; + S48_DECLARE_GC_PROTECT(3); + S48_GC_PROTECT_3(sdpy, sscreenno, sxlfd); xf = XftFontOpenXlfd(scx_extract_display(sdpy), s48_extract_integer(sscreenno), s48_extract_string(sxlfd)); + S48_GC_UNPROTECT(); return scx_enter_xftfont(xf); } s48_value scx_XftFontClose(s48_value sdpy, s48_value sxf) { + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sdpy, sxf); XftFontClose(scx_extract_display(sdpy), scx_extract_xftfont(sxf)); + S48_GC_UNPROTECT(); return S48_UNSPECIFIC; } @@ -181,29 +202,37 @@ s48_value scx_XftDrawCreate(s48_value sdpy, s48_value sdrawable, s48_value svisual, s48_value scolormap) { XftDraw *d; + S48_DECLARE_GC_PROTECT(4); + S48_GC_PROTECT_4(sdpy, sdrawable, svisual, scolormap); d = XftDrawCreate(scx_extract_display(sdpy), scx_extract_drawable(sdrawable), scx_extract_visual(svisual), scx_extract_colormap(scolormap)); - + S48_GC_UNPROTECT(); return scx_enter_xftdraw(d); } s48_value scx_XftDrawCreateBitmap(s48_value sdpy, s48_value sdrawable) { XftDraw *d; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(sdpy, sdrawable); d = XftDrawCreateBitmap(scx_extract_display(sdpy), scx_extract_drawable(sdrawable)); - + S48_GC_UNPROTECT(); return scx_enter_xftdraw(d); } s48_value scx_XftDrawChange(s48_value sxd, s48_value sdrawable) { + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sxd, sdrawable); XftDrawChange(scx_extract_xftdraw(sxd), scx_extract_drawable(sdrawable)); + S48_GC_UNPROTECT(); return S48_UNSPECIFIC; } @@ -253,13 +282,16 @@ s48_value scx_XftDrawDestroy(s48_value sxd) s48_value scx_XftTextExtents8(s48_value sdpy, s48_value sxf, s48_value sstr) { XGlyphInfo *extents; + S48_DECLARE_GC_PROTECT(3); + S48_GC_PROTECT_3(sdpy, sxf, sstr); XftTextExtents8(scx_extract_display(sdpy), scx_extract_xftfont(sxf), (XftChar8 *) s48_extract_string(sstr), S48_STRING_LENGTH(sstr), extents); + S48_GC_UNPROTECT(); return scx_enter_glyphinfo(extents); } @@ -267,11 +299,15 @@ s48_value scx_XftDrawString8(s48_value sxd, s48_value sxc, s48_value sxf, s48_value sx, s48_value sy, s48_value sstr) { + S48_DECLARE_GC_PROTECT(6); + + S48_GC_PROTECT_6(sxd, sxc, sxf, sx, sy, sstr); XftDrawString8(scx_extract_xftdraw(sxd), scx_extract_xftcolor(sxc), scx_extract_xftfont(sxf), s48_extract_integer(sx), s48_extract_integer(sy), (XftChar8 *) s48_extract_string(sstr), S48_STRING_LENGTH(sstr)); + S48_GC_UNPROTECT(); return S48_UNSPECIFIC; } @@ -279,16 +315,25 @@ s48_value scx_XftDrawRect(s48_value sxd, s48_value sxc, s48_value sx, s48_value sy, s48_value sw, s48_value sh) { + S48_DECLARE_GC_PROTECT(6); + + S48_GC_PROTECT_6(sxd, sxc, sx, sy, sw, sh); XftDrawRect(scx_extract_xftdraw(sxd), scx_extract_xftcolor(sxc), s48_extract_integer(sx), s48_extract_integer(sy), s48_extract_integer(sw), s48_extract_integer(sh)); + S48_GC_UNPROTECT(); return S48_UNSPECIFIC; } s48_value scx_XftDrawSetClip(s48_value sxd, s48_value sreg) { - return (XftDrawSetClip(scx_extract_xftdraw(sxd), scx_extract_region(sreg)) - ? S48_TRUE : S48_FALSE); + Bool b; + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sxd, sreg); + b = XftDrawSetClip(scx_extract_xftdraw(sxd), scx_extract_region(sreg)); + S48_GC_UNPROTECT(); + return b ? S48_TRUE : S48_FALSE; } s48_value scx_XftObjectSetCreate(void) @@ -306,9 +351,12 @@ s48_value scx_XftObjectSetAdd(s48_value sxo, s48_value sobj) { struct xft_pattern_property *tbl; Bool b; + S48_DECLARE_GC_PROTECT(2); + S48_GC_PROTECT_2(sxo, sobj); tbl = lookup_pattern_property_by_id(s48_extract_integer(sobj)); b = XftObjectSetAdd(scx_extract_xftobjectset(sxo), tbl->name); + S48_GC_UNPROTECT(); return b ? S48_TRUE : S48_FALSE; } @@ -316,12 +364,14 @@ s48_value scx_XftListFontsPatternObjects(s48_value sdpy, s48_value sscreenno, s48_value sxp, s48_value sxo) { XftFontSet *fs; + S48_DECLARE_GC_PROTECT(4); + S48_GC_PROTECT_4(sdpy, sscreenno, sxp, sxo); fs = XftListFontsPatternObjects(scx_extract_display(sdpy), s48_extract_integer(sscreenno), scx_extract_xftpattern(sxp), scx_extract_xftobjectset(sxo)); - + S48_GC_UNPROTECT(); return scx_enter_xftfontset(fs); } @@ -339,21 +389,24 @@ s48_value scx_XftFontSetDestroy(s48_value sxfs) s48_value scx_XftFontSetAdd(s48_value sxfs, s48_value sxp) { Bool b; - + S48_DECLARE_GC_PROTECT(2); + + S48_GC_PROTECT_2(sxfs, sxp); b = XftFontSetAdd(scx_extract_xftfontset(sxfs), scx_extract_xftpattern(sxp)); + S48_GC_UNPROTECT(); return b ? S48_TRUE : S48_FALSE; } s48_value scx_XftColorAllocName(s48_value sdpy, s48_value svisual, s48_value scolormap, s48_value sname) { - s48_value res; + s48_value res = S48_FALSE; XftColor *xftcolor = NULL; Bool b; - S48_DECLARE_GC_PROTECT(1); + S48_DECLARE_GC_PROTECT(5); - S48_GC_PROTECT_1(res); + S48_GC_PROTECT_5(res, sdpy, svisual, scolormap, sname); b = XftColorAllocName(scx_extract_display(sdpy), scx_extract_visual(svisual), scx_extract_colormap(scolormap), s48_extract_string(sname), xftcolor); @@ -363,16 +416,37 @@ s48_value scx_XftColorAllocName(s48_value sdpy, s48_value svisual, return res; } +s48_value scx_XftColorAllocValue(s48_value sdpy, s48_value svisual, + s48_value scolormap, s48_value sxrendercolor) +{ + s48_value res = S48_FALSE; + XftColor *xftcolor = NULL; + Bool b; + S48_DECLARE_GC_PROTECT(5); + + S48_GC_PROTECT_5(res, sdpy, svisual, scolormap, sxrendercolor); + b = XftColorAllocValue(scx_extract_display(sdpy), scx_extract_visual(svisual), + scx_extract_colormap(scolormap), + scx_extract_xrendercolor(sxrendercolor), + xftcolor); + res = s48_list_2(b ? S48_TRUE : S48_FALSE, + b ? scx_enter_xftcolor(xftcolor) : S48_FALSE); + S48_GC_UNPROTECT(); + return res; +} + s48_value scx_XftColorFree(s48_value sdpy, s48_value svisual, s48_value scolormap, s48_value sxc) { + S48_DECLARE_GC_PROTECT(4); + + S48_GC_PROTECT_4(sdpy, svisual, scolormap, sxc); XftColorFree(scx_extract_display(sdpy), scx_extract_visual(svisual), scx_extract_colormap(scolormap), scx_extract_xftcolor(sxc)); + S48_GC_UNPROTECT(); return S48_UNSPECIFIC; } -/* TODO: XftColorAllocValue */ - s48_value scx_XftPatternPrint(s48_value sxp) { XftPatternPrint(scx_extract_xftpattern(sxp)); @@ -448,6 +522,7 @@ void scx_xft_init(void) S48_EXPORT_FUNCTION(scx_XftFontSetAdd); S48_EXPORT_FUNCTION(scx_XftColorAllocName); + S48_EXPORT_FUNCTION(scx_XftColorAllocValue); S48_EXPORT_FUNCTION(scx_XftColorFree); S48_EXPORT_FUNCTION(scx_XftPatternPrint); diff --git a/c/libs/xrender.c b/c/libs/xrender.c index ee02c17..9a8cb26 100644 --- a/c/libs/xrender.c +++ b/c/libs/xrender.c @@ -14,17 +14,18 @@ s48_value scx_enter_glyphinfo(XGlyphInfo *i) return girec; } -#define scx_extract_glyphinfo(x) \ - ((XGlyphInfo *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xrender_glyphinfo_record_type))) - #define XGLYPHINFO_GET(FUN, FN) \ s48_value FUN(s48_value sv) { \ return s48_enter_integer(scx_extract_glyphinfo(sv)->FN); \ } #define XGLYPHINFO_SET(FUN, FN) \ - s48_value FUN(s48_value sv, s48_value nv) { \ - scx_extract_glyphinfo(sv)->FN = s48_enter_integer(nv); \ + s48_value FUN(s48_value sv, s48_value nv) { \ + S48_DECLARE_GC_PROTECT(2); \ + \ + S48_GC_PROTECT_2(sv, nv); \ + scx_extract_glyphinfo(sv)->FN = s48_enter_integer(nv); \ + S48_GC_UNPROTECT(); \ return S48_UNSPECIFIC; \ } @@ -56,17 +57,18 @@ s48_value scx_enter_xrendercolor(XRenderColor *xrc) return rcrec; } -#define scx_extract_xrendercolor(x) \ - ((XRenderColor *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xrender_xrendercolor_record_type))) - #define XRENDERCOLOR_GET(FUN, FN) \ s48_value FUN(s48_value sv) { \ return s48_enter_integer(scx_extract_xrendercolor(sv)->FN); \ } #define XRENDERCOLOR_SET(FUN, FN) \ - s48_value FUN(s48_value sv, s48_value nv) { \ - scx_extract_xrendercolor(sv)->FN = s48_enter_integer(nv); \ + s48_value FUN(s48_value sv, s48_value nv) { \ + S48_DECLARE_GC_PROTECT(2); \ + \ + S48_GC_PROTECT_2(sv, nv); \ + scx_extract_xrendercolor(sv)->FN = s48_enter_integer(nv); \ + S48_GC_UNPROTECT(); \ return S48_UNSPECIFIC; \ } diff --git a/c/libs/xrender.h b/c/libs/xrender.h index ac95f1e..415d8e0 100644 --- a/c/libs/xrender.h +++ b/c/libs/xrender.h @@ -8,8 +8,11 @@ static s48_value scx_xrender_glyphinfo_record_type = S48_FALSE; static s48_value scx_xrender_xrendercolor_record_type = S48_FALSE; s48_value scx_enter_glyphinfo(XGlyphInfo *i); -XGlyphInfo* scx_extract_glyphinfo(s48_value v); +#define scx_extract_glyphinfo(x) \ + ((XGlyphInfo *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xrender_glyphinfo_record_type))) s48_value scx_enter_xrendercolor(XRenderColor *xrc); -XRenderColor* scx_extract_xrendercolor(s48_value v); +#define scx_extract_xrendercolor(x) \ + ((XRenderColor *) s48_extract_integer(s48_checked_record_ref(x, 0, scx_xrender_xrendercolor_record_type))) +