Tk Source Code

Artifact [3179aacc]
Login

Artifact 3179aacc9fcc2904c38714592923a7df71be27a19177a0da1d51c271b16de216:

Attachment "04d3e5ea8eeb.diff" to ticket [04d3e5ea] added by chrstphrchvz 2023-10-12 09:09:00.
diff --git generic/ttk/ttkCache.c generic/ttk/ttkCache.c
index f4d1846066..0411d5cd1d 100644
--- generic/ttk/ttkCache.c
+++ generic/ttk/ttkCache.c
@@ -243,18 +243,16 @@ static Tcl_Obj *CheckNamedColor(Ttk_ResourceCache cache, Tcl_Obj *objPtr)
     return objPtr;
 }
 
-/*
- * Template for allocation routines:
- */
-typedef void *(*Allocator)(Tcl_Interp *, Tk_Window, Tcl_Obj *);
+enum allocator {ALLOCATOR_3DBORDER, ALLOCATOR_COLOR, ALLOCATOR_FONT};
 
 static Tcl_Obj *Ttk_Use(
     Tcl_Interp *interp,
     Tcl_HashTable *table,
-    Allocator allocate,
+    enum allocator allocate,
     Tk_Window tkwin,
     Tcl_Obj *objPtr)
 {
+    void *allocResult = NULL;
     int newEntry;
     Tcl_HashEntry *entryPtr =
 	Tcl_CreateHashEntry(table,Tcl_GetString(objPtr),&newEntry);
@@ -267,7 +265,19 @@ static Tcl_Obj *Ttk_Use(
     cacheObj = Tcl_DuplicateObj(objPtr);
     Tcl_IncrRefCount(cacheObj);
 
-    if (allocate(interp, tkwin, cacheObj)) {
+    switch (allocate) {
+    case ALLOCATOR_FONT:
+	allocResult = Tk_AllocFontFromObj(interp, tkwin, cacheObj);
+	break;
+    case ALLOCATOR_COLOR:
+	allocResult = Tk_AllocColorFromObj(interp, tkwin, cacheObj);
+	break;
+    case ALLOCATOR_3DBORDER:
+	allocResult = Tk_Alloc3DBorderFromObj(interp, tkwin, cacheObj);
+	break;
+    }
+
+    if (allocResult) {
 	Tcl_SetHashValue(entryPtr, cacheObj);
 	return cacheObj;
     } else {
@@ -286,7 +296,7 @@ Tcl_Obj *Ttk_UseFont(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
 {
     InitCacheWindow(cache, tkwin);
     return Ttk_Use(cache->interp,
-	&cache->fontTable,(Allocator)Tk_AllocFontFromObj, tkwin, objPtr);
+	&cache->fontTable, ALLOCATOR_FONT, tkwin, objPtr);
 }
 
 /*
@@ -298,7 +308,7 @@ Tcl_Obj *Ttk_UseColor(Ttk_ResourceCache cache, Tk_Window tkwin, Tcl_Obj *objPtr)
     objPtr = CheckNamedColor(cache, objPtr);
     InitCacheWindow(cache, tkwin);
     return Ttk_Use(cache->interp,
-	&cache->colorTable,(Allocator)Tk_AllocColorFromObj, tkwin, objPtr);
+	&cache->colorTable, ALLOCATOR_COLOR, tkwin, objPtr);
 }
 
 /*
@@ -311,7 +321,7 @@ Tcl_Obj *Ttk_UseBorder(
     objPtr = CheckNamedColor(cache, objPtr);
     InitCacheWindow(cache, tkwin);
     return Ttk_Use(cache->interp,
-	&cache->borderTable,(Allocator)Tk_Alloc3DBorderFromObj, tkwin, objPtr);
+	&cache->borderTable, ALLOCATOR_3DBORDER, tkwin, objPtr);
 }
 
 /* NullImageChanged --