Skip to content

Commit

Permalink
Experiment: Break Tk_GetColor/Tk_Get3DBorder's Tk_Uid contract in the…
Browse files Browse the repository at this point in the history
… worst possible way: Allocate a new object before every call, and dispose it immediately afterwards. This shows that the Tk_Uid argument doesn't really need to be a Tk_Uid
  • Loading branch information
jan.nijtmans committed Aug 31, 2024
1 parent 0775a7c commit 13d9114
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
21 changes: 19 additions & 2 deletions generic/tk3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ Tk_Alloc3DBorderFromObj(
*--------------------------------------------------------------
*/

Tk_3DBorder
Tk_Get3DBorder(
static Tk_3DBorder
Tk_Get3DBorder_(
Tcl_Interp *interp, /* Place to store an error message. */
Tk_Window tkwin, /* Token for window in which border will be
* drawn. */
Expand Down Expand Up @@ -254,6 +254,23 @@ Tk_Get3DBorder(
borderPtr->bgGC = Tk_GetGC(tkwin, GCForeground, &gcValues);
return (Tk_3DBorder) borderPtr;
}

Tk_3DBorder
Tk_Get3DBorder(
Tcl_Interp *interp, /* Place to store an error message. */
Tk_Window tkwin, /* Token for window in which border will be
* drawn. */
Tk_Uid colorName) /* String giving name of color for window
* background. */
{
Tk_3DBorder x;
Tcl_Obj *obj = Tcl_NewStringObj(colorName, -1);

x = Tk_Get3DBorder_(interp, tkwin, Tcl_GetString(obj));
Tcl_DecrRefCount(obj);
return x;

}

/*
*--------------------------------------------------------------
Expand Down
19 changes: 17 additions & 2 deletions generic/tkColor.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ Tk_AllocColorFromObj(
*----------------------------------------------------------------------
*/

XColor *
Tk_GetColor(
static XColor *
Tk_GetColor_(
Tcl_Interp *interp, /* Place to leave error message if color can't
* be found. */
Tk_Window tkwin, /* Window in which color will be used. */
Expand Down Expand Up @@ -265,6 +265,21 @@ Tk_GetColor(
return &tkColPtr->color;
}

XColor *
Tk_GetColor(
Tcl_Interp *interp, /* Place to leave error message if color can't
* be found. */
Tk_Window tkwin, /* Window in which color will be used. */
Tk_Uid name) /* Name of color to be allocated (in form
* suitable for passing to XParseColor). */
{
XColor *x;
Tcl_Obj *obj = Tcl_NewStringObj(name, -1);

x = Tk_GetColor_(interp, tkwin, Tcl_GetString(obj));
Tcl_DecrRefCount(obj);
return x;
}
/*
*----------------------------------------------------------------------
*
Expand Down

0 comments on commit 13d9114

Please sign in to comment.