From dd5d3c66f734b9a6586850eff5f6a3aea09e0e4e Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 22 Oct 2024 22:09:28 +0000 Subject: [PATCH 1/2] Remaining fixes for [f91aa24bbe] --- generic/tkConfig.c | 5 +++++ generic/tkEntry.c | 14 +++++++------- generic/tkEntry.h | 2 +- generic/tkScale.c | 21 ++++++++++----------- generic/tkScale.h | 6 +++--- generic/tkTest.c | 6 +++--- generic/ttk/ttkEntry.c | 30 +++++++++++++++--------------- generic/ttk/ttkScroll.c | 4 ++-- generic/ttk/ttkTreeview.c | 4 ++-- generic/ttk/ttkWidget.h | 2 +- macosx/tkMacOSXImage.c | 20 ++++++++++---------- macosx/tkMacOSXScale.c | 4 ++-- macosx/tkMacOSXWindowEvent.c | 2 +- macosx/tkMacOSXWm.c | 15 ++++++--------- macosx/tkMacOSXWm.h | 2 +- unix/tkUnixScale.c | 20 ++++++++++++-------- 16 files changed, 81 insertions(+), 76 deletions(-) diff --git a/generic/tkConfig.c b/generic/tkConfig.c index e7ed63c3f..878c450ac 100644 --- a/generic/tkConfig.c +++ b/generic/tkConfig.c @@ -769,6 +769,11 @@ DoObjConfig( } *((char **)oldInternalPtr) = *((char **)internalPtr); *((char **)internalPtr) = newStr; +#if 1 + Tcl_AppendResult(interp, "STRING should use Tcl_Obj for: \"", + optionPtr->specPtr->optionName+1, "\"", (char *)NULL); + return TCL_ERROR; +#endif } break; } diff --git a/generic/tkEntry.c b/generic/tkEntry.c index b0d769465..c479c36ec 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -313,7 +313,7 @@ static const Tk_OptionSpec sbOptSpec[] = { {TK_OPTION_STRING, "-validatecommand", "validateCommand","ValidateCommand", NULL, offsetof(Entry, validateCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-values", "values", "Values", - DEF_SPINBOX_VALUES, TCL_INDEX_NONE, offsetof(Spinbox, valueStr), + DEF_SPINBOX_VALUES, offsetof(Spinbox, valueObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_SYNONYM, "-vcmd", NULL, NULL, NULL, 0, TCL_INDEX_NONE, 0, "-validatecommand", 0}, @@ -1118,7 +1118,7 @@ ConfigureEntry( Spinbox *sbPtr = (Spinbox *) entryPtr; /* Only used when this widget is of type * TK_SPINBOX */ - char *oldValues = NULL; + Tcl_Obj *oldValues = NULL; Tcl_Obj *oldFormat = NULL; int error; int oldExport = 0; @@ -1147,7 +1147,7 @@ ConfigureEntry( oldExport = (entryPtr->exportSelection) && (!Tcl_IsSafe(entryPtr->interp)); if (entryPtr->type == TK_SPINBOX) { - oldValues = sbPtr->valueStr; + oldValues = sbPtr->valueObj; oldFormat = sbPtr->reqFormatObj; oldFrom = sbPtr->fromValue; oldTo = sbPtr->toValue; @@ -1267,16 +1267,16 @@ ConfigureEntry( * See if we have to rearrange our listObj data. */ - if (oldValues != sbPtr->valueStr) { + if (oldValues != sbPtr->valueObj) { if (sbPtr->listObj != NULL) { Tcl_DecrRefCount(sbPtr->listObj); } sbPtr->listObj = NULL; - if (sbPtr->valueStr != NULL) { + if (sbPtr->valueObj != NULL) { Tcl_Obj *newObjPtr; Tcl_Size nelems; - newObjPtr = Tcl_NewStringObj(sbPtr->valueStr, TCL_INDEX_NONE); + newObjPtr = Tcl_NewStringObj(Tcl_GetString(sbPtr->valueObj), TCL_INDEX_NONE); if (Tcl_ListObjLength(interp, newObjPtr, &nelems) != TCL_OK) { valuesChanged = -1; @@ -1379,7 +1379,7 @@ ConfigureEntry( */ EntryValueChanged(entryPtr, Tcl_GetString(objPtr)); - } else if ((sbPtr->valueStr == NULL) + } else if ((sbPtr->valueObj == NULL) && !DOUBLES_EQ(sbPtr->fromValue, sbPtr->toValue) && (!DOUBLES_EQ(sbPtr->fromValue, oldFrom) || !DOUBLES_EQ(sbPtr->toValue, oldTo))) { diff --git a/generic/tkEntry.h b/generic/tkEntry.h index 32b09167e..5d08e3fc7 100644 --- a/generic/tkEntry.h +++ b/generic/tkEntry.h @@ -235,7 +235,7 @@ typedef struct { * digits and other information; used for the * value. */ - char *valueStr; /* Values List. Malloc'ed. */ + Tcl_Obj *valueObj; /* Values List. */ Tcl_Obj *listObj; /* Pointer to the list object being used */ int eIndex; /* Holds the current index into elements */ int nElements; /* Holds the current count of elements */ diff --git a/generic/tkScale.c b/generic/tkScale.c index 80b08cbee..8f118c12e 100644 --- a/generic/tkScale.c +++ b/generic/tkScale.c @@ -52,7 +52,7 @@ static const Tk_OptionSpec optionSpecs[] = { DEF_SCALE_BORDER_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, borderWidth), 0, 0, 0}, {TK_OPTION_STRING, "-command", "command", "Command", - DEF_SCALE_COMMAND, TCL_INDEX_NONE, offsetof(TkScale, command), + DEF_SCALE_COMMAND, offsetof(TkScale, commandObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_CURSOR, "-cursor", "cursor", "Cursor", DEF_SCALE_CURSOR, TCL_INDEX_NONE, offsetof(TkScale, cursor), @@ -80,7 +80,7 @@ static const Tk_OptionSpec optionSpecs[] = { "HighlightThickness", DEF_SCALE_HIGHLIGHT_WIDTH, TCL_INDEX_NONE, offsetof(TkScale, highlightWidth), 0, 0, 0}, {TK_OPTION_STRING, "-label", "label", "Label", - DEF_SCALE_LABEL, TCL_INDEX_NONE, offsetof(TkScale, label), + DEF_SCALE_LABEL, offsetof(TkScale, labelObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_PIXELS, "-length", "length", "Length", DEF_SCALE_LENGTH, TCL_INDEX_NONE, offsetof(TkScale, length), 0, 0, 0}, @@ -291,10 +291,10 @@ Tk_ScaleObjCmd( scalePtr->resolution = 1.0; scalePtr->digits = 0; scalePtr->bigIncrement = 0.0; - scalePtr->command = NULL; + scalePtr->commandObj = NULL; scalePtr->repeatDelay = 0; scalePtr->repeatInterval = 0; - scalePtr->label = NULL; + scalePtr->labelObj = NULL; scalePtr->labelLength = 0; scalePtr->state = STATE_NORMAL; scalePtr->borderWidth = 0; @@ -669,8 +669,6 @@ ConfigureScale( ComputeFormat(scalePtr, 0); ComputeFormat(scalePtr, 1); - scalePtr->labelLength = scalePtr->label ? strlen(scalePtr->label) : 0; - Tk_SetBackgroundFromBorder(scalePtr->tkwin, scalePtr->bgBorder); if (scalePtr->highlightWidth < 0) { @@ -1024,7 +1022,7 @@ ComputeScaleGeometry( if (scalePtr->orient == ORIENT_HORIZONTAL) { y = scalePtr->inset; extraSpace = 0; - if (scalePtr->labelLength != 0) { + if (scalePtr->labelObj != NULL) { scalePtr->horizLabelY = y + SPACING; y += scalePtr->fontHeight; extraSpace = SPACING; @@ -1114,13 +1112,14 @@ ComputeScaleGeometry( } scalePtr->vertTroughX = x; x += 2*scalePtr->borderWidth + scalePtr->width; - if (scalePtr->labelLength == 0) { + if (scalePtr->labelObj == NULL) { scalePtr->vertLabelX = 0; } else { + Tcl_Size labelLength; + const char *label= Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); scalePtr->vertLabelX = x + fm.ascent/2; x = scalePtr->vertLabelX + fm.ascent/2 - + Tk_TextWidth(scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength); + + Tk_TextWidth(scalePtr->tkfont, label, labelLength); } Tk_GeometryRequest(scalePtr->tkwin, x + scalePtr->inset, scalePtr->length + 2*scalePtr->inset); @@ -1457,7 +1456,7 @@ TkScaleSetValue( * configuring the widget -command option even if the value did not change. */ - if ((invokeCommand) && (scalePtr->command != NULL)) { + if ((invokeCommand) && (scalePtr->commandObj != NULL)) { scalePtr->flags |= INVOKE_COMMAND; } TkEventuallyRedrawScale(scalePtr, REDRAW_SLIDER); diff --git a/generic/tkScale.h b/generic/tkScale.h index 7ecf1a1de..3f4550d15 100644 --- a/generic/tkScale.h +++ b/generic/tkScale.h @@ -79,15 +79,15 @@ typedef struct TkScale { * tick interval. */ double bigIncrement; /* Amount to use for large increments to scale * value. (0 means we pick a value). */ - char *command; /* Command prefix to use when invoking Tcl + Tcl_Obj *commandObj; /* Command prefix to use when invoking Tcl * commands because the scale value changed. * NULL means don't invoke commands. */ int repeatDelay; /* How long to wait before auto-repeating on * scrolling actions (in ms). */ int repeatInterval; /* Interval between autorepeats (in ms). */ - char *label; /* Label to display above or to right of + Tcl_Obj *labelObj; /* Label to display above or to right of * scale; NULL means don't display a label. */ - Tcl_Size labelLength; /* Number of non-NULL chars. in label. */ + Tcl_Size labelLength; /* Not used any more. */ enum state state; /* Values are active, normal, or disabled. * Value of scale cannot be changed when * disabled. */ diff --git a/generic/tkTest.c b/generic/tkTest.c index f0ee30fbd..20434a343 100644 --- a/generic/tkTest.c +++ b/generic/tkTest.c @@ -824,7 +824,7 @@ TestobjconfigObjCmd( int boolValue; int integer; double doubleValue; - char *string; + Tcl_Obj *stringObj; int index; XColor *colorPtr; Tk_Font tkfont; @@ -851,7 +851,7 @@ TestobjconfigObjCmd( {TK_OPTION_DOUBLE, "-double", "double", "Double", "3.14159", TCL_INDEX_NONE, offsetof(InternalRecord, doubleValue), 0, 0, 0x4}, {TK_OPTION_STRING, "-string", "string", "String", "foo", - TCL_INDEX_NONE, offsetof(InternalRecord, string), + offsetof(InternalRecord, stringObj), TCL_INDEX_NONE, TK_CONFIG_NULL_OK, 0, 0x8}, {TK_OPTION_STRING_TABLE, "-stringtable", "StringTable", "stringTable", "one", @@ -912,7 +912,7 @@ TestobjconfigObjCmd( recordPtr->boolValue = 0; recordPtr->integer = 0; recordPtr->doubleValue = 0.0; - recordPtr->string = NULL; + recordPtr->stringObj = NULL; recordPtr->index = 0; recordPtr->colorPtr = NULL; recordPtr->tkfont = NULL; diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index a43e3f045..65e1d10b1 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -105,10 +105,10 @@ typedef struct { int exportSelection; /* Tie internal selection to X selection? */ VMODE validate; /* Validation mode */ - char *validateCmd; /* Validation script template */ - char *invalidCmd; /* Invalid callback script template */ + Tcl_Obj *validateCmdObj; /* Validation script template */ + Tcl_Obj *invalidCmdObj; /* Invalid callback script template */ - char *showChar; /* Used to derive displayString */ + Tcl_Obj *showCharObj; /* Used to derive displayString */ Tcl_Obj *fontObj; /* Text font to use */ Tcl_Obj *widthObj; /* Desired width of window (in avgchars) */ @@ -166,7 +166,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { DEF_ENTRY_FONT, offsetof(Entry, entry.fontObj),TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-invalidcommand", "invalidCommand", "InvalidCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.invalidCmd), + NULL, offsetof(Entry, entry.invalidCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_JUSTIFY, "-justify", "justify", "Justify", "left", TCL_INDEX_NONE, offsetof(Entry, entry.justify), @@ -175,7 +175,7 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { NULL, offsetof(Entry, entry.placeholderObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-show", "show", "Show", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.showChar), + NULL, offsetof(Entry, entry.showCharObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_STRING, "-state", "state", "State", "normal", offsetof(Entry, entry.stateObj), TCL_INDEX_NONE, @@ -187,13 +187,13 @@ static const Tk_OptionSpec EntryOptionSpecs[] = { "none", TCL_INDEX_NONE, offsetof(Entry, entry.validate), TK_OPTION_ENUM_VAR, validateStrings, 0}, {TK_OPTION_STRING, "-validatecommand", "validateCommand", "ValidateCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.validateCmd), + NULL, offsetof(Entry, entry.validateCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, 0}, {TK_OPTION_INT, "-width", "width", "Width", DEF_ENTRY_WIDTH, offsetof(Entry, entry.widthObj), TCL_INDEX_NONE, 0,0,GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Entry, entry.xscroll.scrollCmd), + NULL, offsetof(Entry, entry.xscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, /* EntryStyleData options: @@ -604,7 +604,7 @@ EntryValidateChange( VMODE vmode = entryPtr->entry.validate; int code, change_ok; - if ((entryPtr->entry.validateCmd == NULL) + if ((entryPtr->entry.validateCmdObj == NULL) || (entryPtr->core.flags & VALIDATING) || !EntryNeedsValidation(vmode, reason)) { @@ -616,7 +616,7 @@ EntryValidateChange( /* Run -validatecommand and check return value: */ code = RunValidationScript(interp, entryPtr, - entryPtr->entry.validateCmd, "-validatecommand", + Tcl_GetString(entryPtr->entry.validateCmdObj), "-validatecommand", newValue, index, count, reason); if (code != TCL_OK) { goto done; @@ -632,9 +632,9 @@ EntryValidateChange( /* Run the -invalidcommand if validation failed: */ - if (!change_ok && entryPtr->entry.invalidCmd != NULL) { + if (!change_ok && entryPtr->entry.invalidCmdObj != NULL) { code = RunValidationScript(interp, entryPtr, - entryPtr->entry.invalidCmd, "-invalidcommand", + Tcl_GetString(entryPtr->entry.invalidCmdObj), "-invalidcommand", newValue, index, count, reason); if (code != TCL_OK) { goto done; @@ -764,8 +764,8 @@ EntryStoreValue(Entry *entryPtr, const char *value) entryPtr->entry.numChars = numChars; entryPtr->entry.displayString - = entryPtr->entry.showChar - ? EntryDisplayString(entryPtr->entry.showChar, numChars) + = entryPtr->entry.showCharObj + ? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), numChars) : entryPtr->entry.string ; @@ -1059,8 +1059,8 @@ static int EntryConfigure(Tcl_Interp *interp, void *recordPtr, int mask) ckfree(entryPtr->entry.displayString); entryPtr->entry.displayString - = entryPtr->entry.showChar - ? EntryDisplayString(entryPtr->entry.showChar, entryPtr->entry.numChars) + = entryPtr->entry.showCharObj + ? EntryDisplayString(Tcl_GetString(entryPtr->entry.showCharObj), entryPtr->entry.numChars) : entryPtr->entry.string ; diff --git a/generic/ttk/ttkScroll.c b/generic/ttk/ttkScroll.c index b14a0b2a0..1bbd7138c 100644 --- a/generic/ttk/ttkScroll.c +++ b/generic/ttk/ttkScroll.c @@ -82,7 +82,7 @@ static int UpdateScrollbar(Tcl_Interp *interp, ScrollHandle h) h->flags &= ~SCROLL_UPDATE_REQUIRED; - if (s->scrollCmd == NULL) { + if (s->scrollCmdObj == NULL) { return TCL_OK; } @@ -90,7 +90,7 @@ static int UpdateScrollbar(Tcl_Interp *interp, ScrollHandle h) Tcl_PrintDouble(interp, (double)s->first / s->total, arg1+1); Tcl_PrintDouble(interp, (double)s->last / s->total, arg2+1); Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, s->scrollCmd, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(s->scrollCmdObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, arg1, TCL_INDEX_NONE); Tcl_DStringAppend(&buf, arg2, TCL_INDEX_NONE); diff --git a/generic/ttk/ttkTreeview.c b/generic/ttk/ttkTreeview.c index d54f8b8ef..f925cad2b 100644 --- a/generic/ttk/ttkTreeview.c +++ b/generic/ttk/ttkTreeview.c @@ -550,10 +550,10 @@ static const Tk_OptionSpec TreeviewOptionSpecs[] = { 0, 0, GEOMETRY_CHANGED}, {TK_OPTION_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.xscroll.scrollCmd), + NULL, offsetof(Treeview, tree.xscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, {TK_OPTION_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand", - NULL, TCL_INDEX_NONE, offsetof(Treeview, tree.yscroll.scrollCmd), + NULL, offsetof(Treeview, tree.yscroll.scrollCmdObj), TCL_INDEX_NONE, TK_OPTION_NULL_OK, 0, SCROLLCMD_CHANGED}, WIDGET_TAKEFOCUS_TRUE, diff --git a/generic/ttk/ttkWidget.h b/generic/ttk/ttkWidget.h index 453b78822..62a628d86 100644 --- a/generic/ttk/ttkWidget.h +++ b/generic/ttk/ttkWidget.h @@ -186,7 +186,7 @@ typedef struct { int first; /* First visible item */ int last; /* Last visible item */ int total; /* Total #items */ - char *scrollCmd; /* Widget option */ + Tcl_Obj *scrollCmdObj; /* Widget option */ } Scrollable; typedef struct ScrollHandleRec *ScrollHandle; diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 30cfc602a..18d0c3ae8 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -1100,8 +1100,8 @@ struct TkMacOSXNSImageModel { int ring; /* Thickness of the focus ring. */ double alpha; /* Transparency, between 0.0 and 1.0*/ char *imageName ; /* Malloc'ed image name. */ - char *source; /* Malloc'ed string describing the image. */ - char *as; /* Malloc'ed interpretation of source */ + Tcl_Obj *sourceObj; /* Describing the image. */ + Tcl_Obj *asObj; /* Interpretation of source */ int flags; /* Sundry flags, defined below. */ bool pressed; /* Image is for use in a pressed button.*/ bool templ; /* Image is for use as a template.*/ @@ -1163,9 +1163,9 @@ static Tk_ImageType TkMacOSXNSImageType = { static const Tk_OptionSpec systemImageOptions[] = { {TK_OPTION_STRING, "-source", NULL, NULL, DEF_SOURCE, - -1, offsetof(TkMacOSXNSImageModel, source), 0, NULL, 0}, + offsetof(TkMacOSXNSImageModel, sourceObj), -1, 0, NULL, 0}, {TK_OPTION_STRING, "-as", NULL, NULL, DEF_AS, - -1, offsetof(TkMacOSXNSImageModel, as), 0, NULL, 0}, + offsetof(TkMacOSXNSImageModel, asObj), -1, 0, NULL, 0}, {TK_OPTION_INT, "-width", NULL, NULL, DEF_WIDTH, -1, offsetof(TkMacOSXNSImageModel, width), 0, NULL, 0}, {TK_OPTION_INT, "-height", NULL, NULL, DEF_HEIGHT, @@ -1296,7 +1296,7 @@ TkMacOSXNSImageConfigureModel( modelPtr->height = oldHeight; } - if (modelPtr->source == NULL || modelPtr->source[0] == '0') { + if (modelPtr->sourceObj == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("-source is required.", TCL_INDEX_NONE)); Tcl_SetErrorCode(interp, "TK", "IMAGE", "SYSTEM", "BAD_VALUE", NULL); goto errorExit; @@ -1313,7 +1313,7 @@ TkMacOSXNSImageConfigureModel( goto errorExit; } - source = [[NSString alloc] initWithUTF8String: modelPtr->source]; + source = [[NSString alloc] initWithUTF8String: Tcl_GetString(modelPtr->sourceObj)]; switch (sourceInterpretation) { case NAME_SOURCE: newImage = [[NSImage imageNamed:source] copy]; @@ -1550,8 +1550,8 @@ TkMacOSXNSImageCreate( modelPtr->instancePtr = NULL; modelPtr->image = NULL; modelPtr->darkModeImage = NULL; - modelPtr->source = NULL; - modelPtr->as = NULL; + modelPtr->sourceObj = NULL; + modelPtr->asObj = NULL; /* * Process configuration options given in the image create command. @@ -1736,8 +1736,8 @@ TkMacOSXNSImageDelete( Tcl_DeleteCommand(modelPtr->interp, modelPtr->imageName); ckfree(modelPtr->imageName); - ckfree(modelPtr->source); - ckfree(modelPtr->as); + Tcl_DecrRefCount(modelPtr->sourceObj); + Tcl_DecrRefCount(modelPtr->asObj); [modelPtr->image release]; [modelPtr->darkModeImage release]; ckfree(modelPtr); diff --git a/macosx/tkMacOSXScale.c b/macosx/tkMacOSXScale.c index 96a61b8d2..477253b51 100644 --- a/macosx/tkMacOSXScale.c +++ b/macosx/tkMacOSXScale.c @@ -167,14 +167,14 @@ TkpDisplayScale( */ Tcl_Preserve(scalePtr); - if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { + if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->commandObj != NULL)) { Tcl_Preserve(interp); if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->format, scalePtr->value) < 0) { string[TCL_DOUBLE_SPACE - 1] = '\0'; } Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(scalePtr->commandObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE); Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); diff --git a/macosx/tkMacOSXWindowEvent.c b/macosx/tkMacOSXWindowEvent.c index fc32a7bb6..0cc91a53e 100644 --- a/macosx/tkMacOSXWindowEvent.c +++ b/macosx/tkMacOSXWindowEvent.c @@ -868,7 +868,7 @@ TkWmProtocolEventProc( Tcl_Preserve(protPtr); interp = protPtr->interp; Tcl_Preserve(interp); - result = Tcl_EvalEx(interp, protPtr->command, TCL_INDEX_NONE, TCL_EVAL_GLOBAL); + result = Tcl_EvalEx(interp, Tcl_GetString(protPtr->commandObj), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); if (result != TCL_OK) { Tcl_AppendObjToErrorInfo(interp, Tcl_ObjPrintf( "\n (command for \"%s\" window manager protocol)", diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 5c763a566..19f2a1633 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -3733,8 +3733,6 @@ WmProtocolCmd( WmInfo *wmPtr = winPtr->wmInfoPtr; ProtocolHandler *protPtr, *prevPtr; Atom protocol; - char *cmd; - Tcl_Size cmdLength; Tcl_Obj *resultObj; if ((objc < 3) || (objc > 5)) { @@ -3767,7 +3765,7 @@ WmProtocolCmd( protPtr = protPtr->nextPtr) { if (protPtr->protocol == protocol) { Tcl_SetObjResult(interp, - Tcl_NewStringObj(protPtr->command, TCL_INDEX_NONE)); + Tcl_NewStringObj(Tcl_GetString(protPtr->commandObj), TCL_INDEX_NONE)); return TCL_OK; } } @@ -3787,21 +3785,20 @@ WmProtocolCmd( } else { prevPtr->nextPtr = protPtr->nextPtr; } - if (protPtr->command) - ckfree(protPtr->command); + if (protPtr->commandObj) + Tcl_DecrRefCount(protPtr->commandObj); Tcl_EventuallyFree(protPtr, TCL_DYNAMIC); break; } } - cmd = Tcl_GetStringFromObj(objv[4], &cmdLength); - if (cmdLength > 0) { + if (Tcl_GetString(objv[4])[0]) { protPtr = (ProtocolHandler *)ckalloc(sizeof(ProtocolHandler)); protPtr->protocol = protocol; protPtr->nextPtr = wmPtr->protPtr; wmPtr->protPtr = protPtr; protPtr->interp = interp; - protPtr->command = (char *)ckalloc(cmdLength+1); - strcpy(protPtr->command, cmd); + protPtr->commandObj = objv[4]; + Tcl_IncrRefCount(protPtr->commandObj); } return TCL_OK; } diff --git a/macosx/tkMacOSXWm.h b/macosx/tkMacOSXWm.h index 12c4e8f9e..d243e762f 100644 --- a/macosx/tkMacOSXWm.h +++ b/macosx/tkMacOSXWm.h @@ -29,7 +29,7 @@ typedef struct ProtocolHandler { * same top-level window, or NULL for end of * list. */ Tcl_Interp *interp; /* Interpreter in which to invoke command. */ - char* command; /* Tcl command to invoke when a client message + Tcl_Obj* commandObj; /* Tcl command to invoke when a client message * for this protocol arrives. The actual size * of the structure varies to accommodate the * needs of the actual command. THIS MUST BE diff --git a/unix/tkUnixScale.c b/unix/tkUnixScale.c index 8f4d23b7c..be14b94b0 100644 --- a/unix/tkUnixScale.c +++ b/unix/tkUnixScale.c @@ -224,13 +224,15 @@ DisplayVerticalScale( * Draw the label to the right of the scale. */ - if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) { + if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelObj != NULL)) { Tk_FontMetrics fm; + Tcl_Size labelLength; + const char *label = Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength, scalePtr->vertLabelX, + scalePtr->tkfont, label, + labelLength, scalePtr->vertLabelX, scalePtr->inset + (3 * fm.ascent) / 2); } } @@ -447,13 +449,15 @@ DisplayHorizontalScale( * Draw the label at the top of the scale. */ - if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelLength != 0)) { + if ((scalePtr->flags & REDRAW_OTHER) && (scalePtr->labelObj != NULL)) { Tk_FontMetrics fm; + Tcl_Size labelLength; + const char *label = Tcl_GetStringFromObj(scalePtr->labelObj, &labelLength); Tk_GetFontMetrics(scalePtr->tkfont, &fm); Tk_DrawChars(scalePtr->display, drawable, scalePtr->textGC, - scalePtr->tkfont, scalePtr->label, - scalePtr->labelLength, scalePtr->inset + fm.ascent/2, + scalePtr->tkfont, label, labelLength, + scalePtr->inset + fm.ascent/2, scalePtr->horizLabelY + fm.ascent); } } @@ -565,14 +569,14 @@ TkpDisplayScale( */ Tcl_Preserve(scalePtr); - if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->command != NULL)) { + if ((scalePtr->flags & INVOKE_COMMAND) && (scalePtr->commandObj != NULL)) { Tcl_Preserve(interp); if (snprintf(string, TCL_DOUBLE_SPACE, scalePtr->valueFormat, scalePtr->value) < 0) { string[TCL_DOUBLE_SPACE - 1] = '\0'; } Tcl_DStringInit(&buf); - Tcl_DStringAppend(&buf, scalePtr->command, TCL_INDEX_NONE); + Tcl_DStringAppend(&buf, Tcl_GetString(scalePtr->commandObj), TCL_INDEX_NONE); Tcl_DStringAppend(&buf, " ", TCL_INDEX_NONE); Tcl_DStringAppend(&buf, string, TCL_INDEX_NONE); result = Tcl_EvalEx(interp, Tcl_DStringValue(&buf), TCL_INDEX_NONE, TCL_EVAL_GLOBAL); From 93452ca4bfcbea91662b4575cac0fa8644da01ad Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 22 Oct 2024 22:24:42 +0000 Subject: [PATCH 2/2] tweaks --- generic/tkEntry.c | 2 +- macosx/tkMacOSXWm.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/generic/tkEntry.c b/generic/tkEntry.c index c479c36ec..5917b1897 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -1276,7 +1276,7 @@ ConfigureEntry( Tcl_Obj *newObjPtr; Tcl_Size nelems; - newObjPtr = Tcl_NewStringObj(Tcl_GetString(sbPtr->valueObj), TCL_INDEX_NONE); + newObjPtr = sbPtr->valueObj; if (Tcl_ListObjLength(interp, newObjPtr, &nelems) != TCL_OK) { valuesChanged = -1; diff --git a/macosx/tkMacOSXWm.c b/macosx/tkMacOSXWm.c index 19f2a1633..f5eff529b 100644 --- a/macosx/tkMacOSXWm.c +++ b/macosx/tkMacOSXWm.c @@ -3764,8 +3764,7 @@ WmProtocolCmd( for (protPtr = wmPtr->protPtr; protPtr != NULL; protPtr = protPtr->nextPtr) { if (protPtr->protocol == protocol) { - Tcl_SetObjResult(interp, - Tcl_NewStringObj(Tcl_GetString(protPtr->commandObj), TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, protPtr->commandObj); return TCL_OK; } }