summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2024-08-28 12:42:38 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2024-08-28 12:42:38 (GMT)
commit737f6447422a84d722dfa1b05bd62522064a0884 (patch)
treeed64fa77378dcb88096902cb2088033c1f1eb906
parent770fc947435f5aa6318ca47f37fe3f71bc42c120 (diff)
downloadtk-737f6447422a84d722dfa1b05bd62522064a0884.zip
tk-737f6447422a84d722dfa1b05bd62522064a0884.tar.gz
tk-737f6447422a84d722dfa1b05bd62522064a0884.tar.bz2
Fix performance part of [610a73a179]: Canvas widget handles pixel objects incorrectly in Tk 9.0core-bug-610a73a179
-rw-r--r--generic/tk3d.c5
-rw-r--r--generic/tkGet.c2
-rw-r--r--generic/tkOldConfig.c66
-rw-r--r--tests/canvImg.test2
-rw-r--r--tests/canvText.test2
-rw-r--r--tests/canvas.test2
6 files changed, 37 insertions, 42 deletions
diff --git a/generic/tk3d.c b/generic/tk3d.c
index be7ba9b..8082f0c 100644
--- a/generic/tk3d.c
+++ b/generic/tk3d.c
@@ -677,9 +677,10 @@ Tk_GetRelief(
relief = TK_RELIEF_SUNKEN;
} else {
if (interp) {
+ int ambigeous = (c == 'r' || c == 's') && (name[1] == '\0');
Tcl_SetObjResult(interp,
- Tcl_ObjPrintf("bad relief \"%.50s\": must be %s",
- name, "flat, groove, raised, ridge, solid, or sunken"));
+ Tcl_ObjPrintf("%s relief \"%.50s\": must be %s",
+ ambigeous ? "ambigeous" : "bad", name, "flat, groove, raised, ridge, solid, or sunken"));
Tcl_SetErrorCode(interp, "TK", "VALUE", "RELIEF", (char *)NULL);
}
return TCL_ERROR;
diff --git a/generic/tkGet.c b/generic/tkGet.c
index f109582..1994697 100644
--- a/generic/tkGet.c
+++ b/generic/tkGet.c
@@ -153,7 +153,7 @@ Tk_GetAnchor(
error:
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad anchor position \"%s\": must be"
+ "bad anchor \"%s\": must be"
" n, ne, e, se, s, sw, w, nw, or center", string));
Tcl_SetErrorCode(interp, "TK", "VALUE", "ANCHOR", (char *)NULL);
return TCL_ERROR;
diff --git a/generic/tkOldConfig.c b/generic/tkOldConfig.c
index 0f22e3b..e51cef2 100644
--- a/generic/tkOldConfig.c
+++ b/generic/tkOldConfig.c
@@ -33,8 +33,8 @@
*/
static int DoConfig(Tcl_Interp *interp, Tk_Window tkwin,
- Tk_ConfigSpec *specPtr, Tk_Uid value,
- int valueIsUid, void *widgRec);
+ Tk_ConfigSpec *specPtr, Tcl_Obj *value,
+ void *widgRec);
static Tk_ConfigSpec * FindConfigSpec(Tcl_Interp *interp,
Tk_ConfigSpec *specs, const char *argvName,
int needFlags, int hateFlags);
@@ -144,8 +144,7 @@ Tk_ConfigureWidget(
Tcl_SetErrorCode(interp, "TK", "VALUE_MISSING", (char *)NULL);
return TCL_ERROR;
}
- arg = Tcl_GetString(objv[1]);
- if (DoConfig(interp, tkwin, specPtr, arg, 0, widgRec) != TCL_OK) {
+ if (DoConfig(interp, tkwin, specPtr, objv[1], widgRec) != TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (processing \"%.40s\" option)",specPtr->argvName));
return TCL_ERROR;
@@ -177,14 +176,18 @@ Tk_ConfigureWidget(
value = Tk_GetOption(tkwin, specPtr->dbName, specPtr->dbClass);
}
if (value != NULL) {
- if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
+ Tcl_Obj *arg = Tcl_NewStringObj(value, TCL_INDEX_NONE);
+ Tcl_IncrRefCount(arg);
+ if (DoConfig(interp, tkwin, specPtr, arg, widgRec) !=
TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (%s \"%.50s\" in widget \"%.50s\")",
"database entry for", specPtr->dbName,
Tk_PathName(tkwin)));
+ Tcl_DecrRefCount(arg);
return TCL_ERROR;
}
+ Tcl_DecrRefCount(arg);
} else {
if (specPtr->defValue != NULL) {
value = Tk_GetUid(specPtr->defValue);
@@ -193,14 +196,18 @@ Tk_ConfigureWidget(
}
if ((value != NULL) && !(specPtr->specFlags
& TK_CONFIG_DONT_SET_DEFAULT)) {
- if (DoConfig(interp, tkwin, specPtr, value, 1, widgRec) !=
+ Tcl_Obj *arg = Tcl_NewStringObj(value, TCL_INDEX_NONE);
+ Tcl_IncrRefCount(arg);
+ if (DoConfig(interp, tkwin, specPtr, arg, widgRec) !=
TCL_OK) {
Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf(
"\n (%s \"%.50s\" in widget \"%.50s\")",
"default value for", specPtr->dbName,
Tk_PathName(tkwin)));
+ Tcl_DecrRefCount(arg);
return TCL_ERROR;
}
+ Tcl_DecrRefCount(arg);
}
}
}
@@ -332,17 +339,14 @@ DoConfig(
Tk_Window tkwin, /* Window containing widget (needed to set up
* X resources). */
Tk_ConfigSpec *specPtr, /* Specifier to apply. */
- Tk_Uid value, /* Value to use to fill in widgRec. */
- int valueIsUid, /* Non-zero means value is a Tk_Uid; zero
- * means it's an ordinary string. */
+ Tcl_Obj *arg, /* Value to use to fill in widgRec. */
void *widgRec) /* Record whose fields are to be modified.
* Values must be properly initialized. */
{
void *ptr;
- Tk_Uid uid;
- int nullValue;
+ int nullValue = 0;
+ const char *value = Tcl_GetString(arg);
- nullValue = 0;
if ((*value == 0) && (specPtr->specFlags & (TK_CONFIG_NULL_OK|TCL_NULL_OK|1))) {
nullValue = 1;
}
@@ -354,17 +358,17 @@ DoConfig(
ptr = (char *)widgRec + specPtr->offset;
switch (specPtr->type) {
case TK_CONFIG_BOOLEAN:
- if (Tcl_GetBoolean(interp, value, (int *)ptr) != TCL_OK) {
+ if (Tcl_GetBooleanFromObj(interp, arg, (int *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_INT:
- if (Tcl_GetInt(interp, value, (int *)ptr) != TCL_OK) {
+ if (Tcl_GetIntFromObj(interp, arg, (int *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_DOUBLE:
- if (Tcl_GetDouble(interp, value, (double *)ptr) != TCL_OK) {
+ if (Tcl_GetDoubleFromObj(interp, arg, (double *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
@@ -388,8 +392,7 @@ DoConfig(
if (nullValue) {
*((Tk_Uid *) ptr) = NULL;
} else {
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- *((Tk_Uid *) ptr) = uid;
+ *((Tk_Uid *) ptr) = Tk_GetUid(value);
}
break;
case TK_CONFIG_COLOR: {
@@ -398,8 +401,7 @@ DoConfig(
if (nullValue) {
newPtr = NULL;
} else {
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- newPtr = Tk_GetColor(interp, tkwin, uid);
+ newPtr = Tk_GetColor(interp, tkwin, value);
if (newPtr == NULL) {
return TCL_ERROR;
}
@@ -432,8 +434,7 @@ DoConfig(
if (nullValue) {
newBmp = None;
} else {
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- newBmp = Tk_GetBitmap(interp, tkwin, uid);
+ newBmp = Tk_GetBitmap(interp, tkwin, value);
if (newBmp == None) {
return TCL_ERROR;
}
@@ -451,8 +452,7 @@ DoConfig(
if (nullValue) {
newBorder = NULL;
} else {
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- newBorder = Tk_Get3DBorder(interp, tkwin, uid);
+ newBorder = Tk_Get3DBorder(interp, tkwin, value);
if (newBorder == NULL) {
return TCL_ERROR;
}
@@ -465,8 +465,7 @@ DoConfig(
break;
}
case TK_CONFIG_RELIEF:
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- if (Tk_GetRelief(interp, uid, (int *)ptr) != TCL_OK) {
+ if (Tk_GetReliefFromObj(interp, arg, (int *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
@@ -477,8 +476,7 @@ DoConfig(
if (nullValue) {
newCursor = NULL;
} else {
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- newCursor = Tk_GetCursor(interp, tkwin, uid);
+ newCursor = Tk_GetCursor(interp, tkwin, value);
if (newCursor == NULL) {
return TCL_ERROR;
}
@@ -494,33 +492,29 @@ DoConfig(
break;
}
case TK_CONFIG_JUSTIFY:
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- if (Tk_GetJustify(interp, uid, (Tk_Justify *) ptr) != TCL_OK) {
+ if (Tk_GetJustify(interp, value, (Tk_Justify *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_ANCHOR:
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- if (Tk_GetAnchor(interp, uid, (Tk_Anchor *) ptr) != TCL_OK) {
+ if (Tk_GetAnchorFromObj(interp, arg, (Tk_Anchor *) ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_CAP_STYLE:
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- if (Tk_GetCapStyle(interp, uid, (int *)ptr) != TCL_OK) {
+ if (Tk_GetCapStyle(interp, value, (int *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_JOIN_STYLE:
- uid = valueIsUid ? (Tk_Uid) value : Tk_GetUid(value);
- if (Tk_GetJoinStyle(interp, uid, (int *)ptr) != TCL_OK) {
+ if (Tk_GetJoinStyle(interp, value, (int *)ptr) != TCL_OK) {
return TCL_ERROR;
}
break;
case TK_CONFIG_PIXELS:
if (nullValue) {
*(int *)ptr = INT_MIN;
- } else if (Tk_GetPixels(interp, tkwin, value, (int *)ptr)
+ } else if (Tk_GetPixelsFromObj(interp, tkwin, arg, (int *)ptr)
!= TCL_OK) {
return TCL_ERROR;
}
diff --git a/tests/canvImg.test b/tests/canvImg.test
index 2bbaafc..2ac7435 100644
--- a/tests/canvImg.test
+++ b/tests/canvImg.test
@@ -29,7 +29,7 @@ test canvImg-1.2 {options for image items} -body {
.c create image 50 50 -anchor gorp -tags i1
} -cleanup {
.c delete all
-} -returnCodes error -result {bad anchor position "gorp": must be n, ne, e, se, s, sw, w, nw, or center}
+} -returnCodes error -result {bad anchor "gorp": must be n, ne, e, se, s, sw, w, nw, or center}
test canvImg-1.3 {options for image items} -constraints testImageType -setup {
image create test foo
.c delete all
diff --git a/tests/canvText.test b/tests/canvText.test
index c6ee1d3..1263ad4 100644
--- a/tests/canvText.test
+++ b/tests/canvText.test
@@ -26,7 +26,7 @@ test canvText-1.1 {configuration options: good value for "anchor"} -body {
} -result {nw nw}
test canvasText-1.2 {configuration options: bad value for "anchor"} -body {
.c itemconfigure test -anchor xyz
-} -returnCodes error -result {bad anchor position "xyz": must be n, ne, e, se, s, sw, w, nw, or center}
+} -returnCodes error -result {bad anchor "xyz": must be n, ne, e, se, s, sw, w, nw, or center}
test canvText-1.3 {configuration options: good value for "fill"} -body {
.c itemconfigure test -fill #ff0000
list [lindex [.c itemconfigure test -fill] 4] [.c itemcget test -fill]
diff --git a/tests/canvas.test b/tests/canvas.test
index e75ab36..7b1e883 100644
--- a/tests/canvas.test
+++ b/tests/canvas.test
@@ -138,7 +138,7 @@ test canvas-1.33 {configuration options: good value for "relief"} -body {
} -result {groove}
test canvas-1.34 {configuration options: bad value for "relief"} -body {
.c configure -relief r
-} -returnCodes error -result {bad relief "r": must be flat, groove, raised, ridge, solid, or sunken}
+} -returnCodes error -result {ambiguous relief "r": must be flat, groove, raised, ridge, solid, or sunken}
test canvas-1.35 {configuration options: good value for "selectbackground"} -body {
.c configure -selectbackground #110022
.c cget -selectbackground