From e1bfe977169f9b112ee0a0093eafa78f788629b5 Mon Sep 17 00:00:00 2001 From: culler Date: Mon, 9 Nov 2020 13:32:29 +0000 Subject: Fix [f9fa926666] on macOS only: crash when creating a label whose text is a single emoji. --- generic/tkGet.c | 5 +++ macosx/tkMacOSXColor.c | 94 ++------------------------------------------------ xlib/xgc.c | 32 +---------------- 3 files changed, 9 insertions(+), 122 deletions(-) diff --git a/generic/tkGet.c b/generic/tkGet.c index f2aed2c..989584e 100644 --- a/generic/tkGet.c +++ b/generic/tkGet.c @@ -694,6 +694,11 @@ TkGetDoublePixels( char *end; double d; + if (!tkwin) { + Tcl_SetObjResult(interp, Tcl_ObjPrintf("bad screen")); + Tcl_SetErrorCode(interp, "TK", "VALUE", "FRACTIONAL_PIXELS", NULL); + return TCL_ERROR; + } d = strtod((char *) string, &end); if (end == string) { goto error; diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index 5f549b1..d3c76e5 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -485,89 +485,6 @@ TkSetMacColor( /* *---------------------------------------------------------------------- * - * TkpInitGCCache, TkpFreeGCCache, CopyCachedColor, SetCachedColor -- - * - * Maintain a per-GC cache of previously converted CGColorRefs - * - * Results: - * None resp. retained CGColorRef for CopyCachedColor() - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -void -TkpInitGCCache( - GC gc) -{ - bzero(TkpGetGCCache(gc), sizeof(TkpGCCache)); -} - -void -TkpFreeGCCache( - GC gc) -{ - TkpGCCache *gcCache = TkpGetGCCache(gc); - - if (gcCache->cachedForegroundColor) { - CFRelease(gcCache->cachedForegroundColor); - } - if (gcCache->cachedBackgroundColor) { - CFRelease(gcCache->cachedBackgroundColor); - } -} - -static CGColorRef -CopyCachedColor( - GC gc, - unsigned long pixel) -{ - TkpGCCache *gcCache = TkpGetGCCache(gc); - CGColorRef cgColor = NULL; - - if (gcCache) { - if (gcCache->cachedForeground == pixel) { - cgColor = gcCache->cachedForegroundColor; - } else if (gcCache->cachedBackground == pixel) { - cgColor = gcCache->cachedBackgroundColor; - } - if (cgColor) { - CFRetain(cgColor); - } - } - return cgColor; -} - -static void -SetCachedColor( - GC gc, - unsigned long pixel, - CGColorRef cgColor) -{ - TkpGCCache *gcCache = TkpGetGCCache(gc); - - if (gcCache && cgColor) { - if (gc->foreground == pixel) { - if (gcCache->cachedForegroundColor) { - CFRelease(gcCache->cachedForegroundColor); - } - gcCache->cachedForegroundColor = (CGColorRef) CFRetain(cgColor); - gcCache->cachedForeground = pixel; - } else if (gc->background == pixel) { - if (gcCache->cachedBackgroundColor) { - CFRelease(gcCache->cachedBackgroundColor); - } - gcCache->cachedBackgroundColor = (CGColorRef) CFRetain(cgColor); - gcCache->cachedBackground = pixel; - } - } -} - -/* - *---------------------------------------------------------------------- - * * TkMacOSXCreateCGColor -- * * Creates a CGColorRef from a X style pixel value. @@ -586,11 +503,8 @@ TkMacOSXCreateCGColor( GC gc, unsigned long pixel) /* Pixel value to convert. */ { - CGColorRef cgColor = CopyCachedColor(gc, pixel); - - if (!cgColor && TkSetMacColor(pixel, &cgColor)) { - SetCachedColor(gc, pixel, cgColor); - } + CGColorRef cgColor; + TkSetMacColor(pixel, &cgColor); return cgColor; } @@ -683,9 +597,7 @@ TkMacOSXSetColorInContext( context, kHIThemeOrientationNormal); break; default: - if (SetCGColorComponents(entry, pixel, &cgColor)){ - SetCachedColor(gc, pixel, cgColor); - } + SetCGColorComponents(entry, pixel, &cgColor); break; } } diff --git a/xlib/xgc.c b/xlib/xgc.c index c0dbe84..56753c3 100644 --- a/xlib/xgc.c +++ b/xlib/xgc.c @@ -16,9 +16,6 @@ #if !defined(MAC_OSX_TK) # include -# define TkpInitGCCache(gc) -# define TkpFreeGCCache(gc) -# define TkpGetGCCache(gc) #else # include # include @@ -33,10 +30,7 @@ typedef struct { XGCValues gc; char dash[MAX_DASH_LIST_SIZE]; -#ifdef MAC_OSX_TK - TkpGCCache cache; -#endif -} XGCValuesWithCache; +} XGCValuesWithDash; /* *---------------------------------------------------------------------- @@ -161,32 +155,9 @@ XCreateGC( clip_mask->type = TKP_CLIP_PIXMAP; clip_mask->value.pixmap = values->clip_mask; } - TkpInitGCCache(gp); - return gp; } -#ifdef MAC_OSX_TK -/* - *---------------------------------------------------------------------- - * - * TkpGetGCCache -- - * - * Results: - * Pointer to the TkpGCCache at the end of the GC. - * - * Side effects: - * None. - * - *---------------------------------------------------------------------- - */ - -TkpGCCache* -TkpGetGCCache(GC gc) { - return (gc ? &((XGCValuesWithCache *)gc)->cache : NULL); -} -#endif - /* *---------------------------------------------------------------------- * @@ -268,7 +239,6 @@ int XFreeGC( if (gc != NULL) { FreeClipMask(gc); - TkpFreeGCCache(gc); ckfree(gc); } return Success; -- cgit v0.12