From f0ea214c57459a16eaa686227c785defd8e00ea8 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 31 Aug 2023 11:17:23 +0000 Subject: Backport some test improvements from 9.0 --- generic/tclCmdIL.c | 2 +- generic/tclTest.c | 29 +++++++++++++++++------------ generic/tclTestObj.c | 12 ++++++------ 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 8682c8b..f57a54a 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -2839,7 +2839,7 @@ Tcl_LremoveObjCmd( Tcl_SetObjResult(interp, listObj); return TCL_OK; } - idxv = (Tcl_Size *)Tcl_Alloc((objc - 2) * sizeof(*idxv)); + idxv = (Tcl_Size *)ckalloc((objc - 2) * sizeof(*idxv)); for (i = 2; i < objc; i++) { status = (TclGetIntForIndexM(interp, objv[i], /*endValue*/ listLen - 1, &idxv[i - 2]) != TCL_OK); diff --git a/generic/tclTest.c b/generic/tclTest.c index ef9997a..83dad7d 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -236,10 +236,7 @@ static Tcl_ResolveCompiledVarProc InterpCompiledVarResolver; static void MainLoop(void); static Tcl_CmdProc NoopCmd; static Tcl_ObjCmdProc NoopObjCmd; -static int ObjTraceProc(void *clientData, - Tcl_Interp *interp, int level, const char *command, - Tcl_Command commandToken, int objc, - Tcl_Obj *const objv[]); +static Tcl_CmdObjTraceProc ObjTraceProc; static void ObjTraceDeleteProc(void *clientData); static void PrintParse(Tcl_Interp *interp, Tcl_Parse *parsePtr); static void SpecialFree(char *blockPtr); @@ -1170,6 +1167,8 @@ TestcmdinfoObjCmd( Tcl_AppendResult(interp, " stringProc", NULL); } else if (info.isNativeObjectProc == 1) { Tcl_AppendResult(interp, " nativeObjectProc", NULL); + } else if (info.isNativeObjectProc == 2) { + Tcl_AppendResult(interp, " nativeObjectProc2", NULL); } else { Tcl_SetObjResult(interp, Tcl_ObjPrintf("Invalid isNativeObjectProc value %d", info.isNativeObjectProc)); @@ -1302,7 +1301,7 @@ TestcmdtokenCmd( return TCL_ERROR; } if (strcmp(argv[1], "create") == 0) { - refPtr = (TestCommandTokenRef *)Tcl_Alloc(sizeof(TestCommandTokenRef)); + refPtr = (TestCommandTokenRef *)ckalloc(sizeof(TestCommandTokenRef)); refPtr->token = Tcl_CreateCommand(interp, argv[2], CmdProc0, refPtr, CmdDelProc0); refPtr->id = nextCommandTokenRefId; @@ -1509,10 +1508,10 @@ static int ObjTraceProc( TCL_UNUSED(void *), Tcl_Interp *interp, /* Tcl interpreter */ - TCL_UNUSED(int) /*level*/, + TCL_UNUSED(int) /* level */, const char *command, TCL_UNUSED(Tcl_Command), - TCL_UNUSED(int) /*objc*/, + TCL_UNUSED(int) /* objc */, Tcl_Obj *const objv[]) /* Argument objects. */ { const char *word = Tcl_GetString(objv[0]); @@ -5727,7 +5726,10 @@ TestbytestringObjCmd( int objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* The argument objects. */ { - Tcl_Size n = 0; + struct { + Tcl_Size n; + int m; /* This variable should not be overwritten */ + } x = {0, 1}; const char *p; if (objc != 2) { @@ -5735,11 +5737,15 @@ TestbytestringObjCmd( return TCL_ERROR; } - p = (const char *)Tcl_GetBytesFromObj(interp, objv[1], &n); + p = (const char *)Tcl_GetBytesFromObj(interp, objv[1], &x.n); if (p == NULL) { return TCL_ERROR; } - Tcl_SetObjResult(interp, Tcl_NewStringObj(p, n)); + if (x.m != 1) { + Tcl_AppendResult(interp, "Tcl_GetBytesFromObj() overwrites variable", NULL); + return TCL_ERROR; + } + Tcl_SetObjResult(interp, Tcl_NewStringObj(p, x.n)); return TCL_OK; } @@ -8656,7 +8662,7 @@ MyCompiledVarFetch( } hPtr = Tcl_CreateHashEntry((Tcl_HashTable *) &iPtr->globalNsPtr->varTable, - (char *) resVarInfo->nameObj, &isNewVar); + (char *)resVarInfo->nameObj, &isNewVar); if (hPtr) { var = (Tcl_Var) TclVarHashGetValue(hPtr); } else { @@ -8825,4 +8831,3 @@ int TestApplyLambdaObjCmd ( * indent-tabs-mode: nil * End: */ - diff --git a/generic/tclTestObj.c b/generic/tclTestObj.c index 0080938..b4d70f0 100644 --- a/generic/tclTestObj.c +++ b/generic/tclTestObj.c @@ -101,7 +101,7 @@ TclObjTest_Init( */ Tcl_Obj **varPtr; - varPtr = (Tcl_Obj **) ckalloc(NUMBER_OF_OBJECT_VARS *sizeof(varPtr[0])); + varPtr = (Tcl_Obj **)ckalloc(NUMBER_OF_OBJECT_VARS *sizeof(varPtr[0])); if (!varPtr) { return TCL_ERROR; } @@ -1063,15 +1063,15 @@ TestobjCmd( const Tcl_ObjType *targetType; Tcl_Obj **varPtr; const char *subcommands[] = { - "freeallvars", "bug3598580", "types", - "objtype", "newobj", "set", + "freeallvars", "bug3598580", + "types", "objtype", "newobj", "set", "assign", "convert", "duplicate", "invalidateStringRep", "refcount", "type", NULL }; enum testobjCmdIndex { - TESTOBJ_FREEALLVARS, TESTOBJ_BUG3598580, TESTOBJ_TYPES, - TESTOBJ_OBJTYPE, TESTOBJ_NEWOBJ, TESTOBJ_SET, + TESTOBJ_FREEALLVARS, TESTOBJ_BUG3598580, + TESTOBJ_TYPES, TESTOBJ_OBJTYPE, TESTOBJ_NEWOBJ, TESTOBJ_SET, TESTOBJ_ASSIGN, TESTOBJ_CONVERT, TESTOBJ_DUPLICATE, TESTOBJ_INVALIDATESTRINGREP, TESTOBJ_REFCOUNT, TESTOBJ_TYPE, } cmdIndex; @@ -1535,7 +1535,7 @@ TeststringobjCmd( Tcl_SetObjResult(interp, varPtr[varIndex]); break; case 13: /* newunicode*/ - unicode = (unsigned short *) ckalloc(((unsigned)objc - 3) * sizeof(unsigned short)); + unicode = (unsigned short *)ckalloc(((unsigned)objc - 3) * sizeof(unsigned short)); for (i = 0; i < (objc - 3); ++i) { int val; if (Tcl_GetIntFromObj(interp, objv[i + 3], &val) != TCL_OK) { -- cgit v0.12