From 2d07a092e5512407f7e484e7a4f058bd31264c0a Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sun, 27 Feb 2022 18:29:55 +0000 Subject: More size_t usage, e.g. for "foreach" --- generic/tclCmdAH.c | 6 +++--- generic/tclCompCmds.c | 37 ++++++++++++++++++------------------- generic/tclCompile.h | 20 ++++++++++---------- generic/tclDisassemble.c | 17 +++++++++-------- generic/tclExecute.c | 20 ++++++++++---------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c index 9bab9bf..00bcdff 100644 --- a/generic/tclCmdAH.c +++ b/generic/tclCmdAH.c @@ -2474,9 +2474,9 @@ EachloopCmd( int objc, /* The arguments being passed in... */ Tcl_Obj *const objv[]) { - int numLists = (objc-2) / 2; + size_t i, j, numLists = (objc-2) / 2; struct ForeachState *statePtr; - int i, j, result; + int result; if (objc < 4 || (objc%2 != 0)) { Tcl_WrongNumArgs(interp, 1, objv, @@ -2558,7 +2558,7 @@ EachloopCmd( if ((statePtr->argcList[i] % statePtr->varcList[i]) != 0) { j++; } - if (j > statePtr->maxj) { + if (j > (size_t)statePtr->maxj) { statePtr->maxj = j; } } diff --git a/generic/tclCompCmds.c b/generic/tclCompCmds.c index 82d09ac..39a21c8 100644 --- a/generic/tclCompCmds.c +++ b/generic/tclCompCmds.c @@ -2845,9 +2845,9 @@ CompileEachloopCmd( * body's code. Misuse loopCtTemp for storing the jump size. */ - jumpBackOffset = envPtr->exceptArrayPtr[range].continueOffset - - envPtr->exceptArrayPtr[range].codeOffset; - infoPtr->loopCtTemp = -jumpBackOffset; + jumpBackOffset = envPtr->exceptArrayPtr[range].codeOffset - + envPtr->exceptArrayPtr[range].continueOffset; + infoPtr->loopCtTemp = jumpBackOffset; /* * The command's result is an empty string if not collecting. If @@ -2895,7 +2895,7 @@ DupForeachInfo( ForeachInfo *srcPtr = (ForeachInfo *)clientData; ForeachInfo *dupPtr; ForeachVarList *srcListPtr, *dupListPtr; - int numVars, i, j, numLists = srcPtr->numLists; + size_t numVars, i, j, numLists = srcPtr->numLists; dupPtr = (ForeachInfo *)Tcl_Alloc(offsetof(ForeachInfo, varLists) + numLists * sizeof(ForeachVarList *)); @@ -2943,8 +2943,7 @@ FreeForeachInfo( { ForeachInfo *infoPtr = (ForeachInfo *)clientData; ForeachVarList *listPtr; - int numLists = infoPtr->numLists; - int i; + size_t i, numLists = infoPtr->numLists; for (i = 0; i < numLists; i++) { listPtr = infoPtr->varLists[i]; @@ -2979,7 +2978,7 @@ PrintForeachInfo( { ForeachInfo *infoPtr = (ForeachInfo *)clientData; ForeachVarList *varsPtr; - int i, j; + size_t i, j; Tcl_AppendToObj(appendObj, "data=[", -1); @@ -2987,24 +2986,24 @@ PrintForeachInfo( if (i) { Tcl_AppendToObj(appendObj, ", ", -1); } - Tcl_AppendPrintfToObj(appendObj, "%%v%u", - (unsigned) (infoPtr->firstValueTemp + i)); + Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u", + (infoPtr->firstValueTemp + i)); } - Tcl_AppendPrintfToObj(appendObj, "], loop=%%v%u", - (unsigned) infoPtr->loopCtTemp); + Tcl_AppendPrintfToObj(appendObj, "], loop=%%v%" TCL_Z_MODIFIER "u", + infoPtr->loopCtTemp); for (i=0 ; inumLists ; i++) { if (i) { Tcl_AppendToObj(appendObj, ",", -1); } - Tcl_AppendPrintfToObj(appendObj, "\n\t\t it%%v%u\t[", - (unsigned) (infoPtr->firstValueTemp + i)); + Tcl_AppendPrintfToObj(appendObj, "\n\t\t it%%v%" TCL_Z_MODIFIER "u\t[", + (infoPtr->firstValueTemp + i)); varsPtr = infoPtr->varLists[i]; for (j=0 ; jnumVars ; j++) { if (j) { Tcl_AppendToObj(appendObj, ", ", -1); } - Tcl_AppendPrintfToObj(appendObj, "%%v%u", - (unsigned) varsPtr->varIndexes[j]); + Tcl_AppendPrintfToObj(appendObj, "%%v%" TCL_Z_MODIFIER "u", + (size_t)varsPtr->varIndexes[j]); } Tcl_AppendToObj(appendObj, "]", -1); } @@ -3019,9 +3018,9 @@ PrintNewForeachInfo( { ForeachInfo *infoPtr = (ForeachInfo *)clientData; ForeachVarList *varsPtr; - int i, j; + size_t i, j; - Tcl_AppendPrintfToObj(appendObj, "jumpOffset=%+d, vars=", + Tcl_AppendPrintfToObj(appendObj, "jumpOffset=%+" TCL_Z_MODIFIER "d, vars=", infoPtr->loopCtTemp); for (i=0 ; inumLists ; i++) { if (i) { @@ -3049,7 +3048,7 @@ DisassembleForeachInfo( { ForeachInfo *infoPtr = (ForeachInfo *)clientData; ForeachVarList *varsPtr; - int i, j; + size_t i, j; Tcl_Obj *objPtr, *innerPtr; /* @@ -3096,7 +3095,7 @@ DisassembleNewForeachInfo( { ForeachInfo *infoPtr = (ForeachInfo *)clientData; ForeachVarList *varsPtr; - int i, j; + size_t i, j; Tcl_Obj *objPtr, *innerPtr; /* diff --git a/generic/tclCompile.h b/generic/tclCompile.h index b7d98b6..c24150d 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -871,7 +871,7 @@ typedef struct InstructionDesc { * computations. The value INT_MIN signals * that the instruction's worst case effect is * (1-opnd1). */ - int numOperands; /* Number of operands. */ + size_t numOperands; /* Number of operands. */ InstOperandType opTypes[MAX_INSTRUCTION_OPERANDS]; /* The type of each operand. */ } InstructionDesc; @@ -934,14 +934,14 @@ typedef enum { typedef struct JumpFixup { TclJumpType jumpType; /* Indicates the kind of jump. */ - unsigned int codeOffset; /* Offset of the first byte of the one-byte + size_t codeOffset; /* Offset of the first byte of the one-byte * forward jump's code. */ - int cmdIndex; /* Index of the first command after the one + size_t cmdIndex; /* Index of the first command after the one * for which the jump was emitted. Used to * update the code offsets for subsequent * commands if the two-byte jump at jumpPc * must be replaced with a five-byte one. */ - int exceptIndex; /* Index of the first range entry in the + size_t exceptIndex; /* Index of the first range entry in the * ExceptionRange array after the current one. * This field is used to adjust the code * offsets in subsequent ExceptionRange @@ -953,8 +953,8 @@ typedef struct JumpFixup { typedef struct JumpFixupArray { JumpFixup *fixup; /* Points to start of jump fixup array. */ - int next; /* Index of next free array entry. */ - int end; /* Index of last usable entry in array. */ + size_t next; /* Index of next free array entry. */ + size_t end; /* Index of last usable entry in array. */ int mallocedArray; /* 1 if array was expanded and fixups points * into the heap, else 0. */ JumpFixup staticFixupSpace[JUMPFIXUP_INIT_ENTRIES]; @@ -969,7 +969,7 @@ typedef struct JumpFixupArray { */ typedef struct ForeachVarList { - int numVars; /* The number of variables in the list. */ + size_t numVars; /* The number of variables in the list. */ int varIndexes[TCLFLEXARRAY];/* An array of the indexes ("slot numbers") * for each variable in the procedure's array * of local variables. Only scalar variables @@ -986,11 +986,11 @@ typedef struct ForeachVarList { */ typedef struct ForeachInfo { - int numLists; /* The number of both the variable and value + size_t numLists; /* The number of both the variable and value * lists of the foreach command. */ - int firstValueTemp; /* Index of the first temp var in a proc frame + size_t firstValueTemp; /* Index of the first temp var in a proc frame * used to point to a value list. */ - int loopCtTemp; /* Index of temp var in a proc frame holding + size_t loopCtTemp; /* Index of temp var in a proc frame holding * the loop's iteration count. Used to * determine next value list element to assign * each loop var. */ diff --git a/generic/tclDisassemble.c b/generic/tclDisassemble.c index f946221..4839586 100644 --- a/generic/tclDisassemble.c +++ b/generic/tclDisassemble.c @@ -541,7 +541,8 @@ FormatInstruction( const InstructionDesc *instDesc = &tclInstructionTable[opCode]; unsigned char *codeStart = codePtr->codeStart; unsigned pcOffset = pc - codeStart; - int opnd = 0, i, j, numBytes = 1; + int opnd = 0, j, numBytes = 1; + size_t i; int localCt = procPtr ? procPtr->numCompiledLocals : 0; CompiledLocal *localPtr = procPtr ? procPtr->firstLocalPtr : NULL; char suffixBuffer[128]; /* Additional info to print after main opcode @@ -941,8 +942,8 @@ DisassembleByteCodeAsDicts( Tcl_Obj *description, *literals, *variables, *instructions, *inst; Tcl_Obj *aux, *exn, *commands, *file; unsigned char *pc, *opnd, *codeOffPtr, *codeLenPtr, *srcOffPtr, *srcLenPtr; - int codeOffset, codeLength, sourceOffset, sourceLength; - int i, val, line; + int val, line, codeOffset, codeLength, sourceOffset, sourceLength; + size_t i; ByteCodeGetInternalRep(objPtr, &tclByteCodeType, codePtr); @@ -951,7 +952,7 @@ DisassembleByteCodeAsDicts( */ TclNewObj(literals); - for (i=0 ; inumLitObjects ; i++) { + for (i=0 ; i<(size_t)codePtr->numLitObjects ; i++) { Tcl_ListObjAppendElement(NULL, literals, codePtr->objArrayPtr[i]); } @@ -961,7 +962,7 @@ DisassembleByteCodeAsDicts( TclNewObj(variables); if (codePtr->procPtr) { - int localCount = codePtr->procPtr->numCompiledLocals; + size_t localCount = codePtr->procPtr->numCompiledLocals; CompiledLocal *localPtr = codePtr->procPtr->firstLocalPtr; for (i=0 ; inextPtr) { @@ -1111,7 +1112,7 @@ DisassembleByteCodeAsDicts( */ TclNewObj(aux); - for (i=0 ; inumAuxDataItems ; i++) { + for (i=0 ; i<(size_t)codePtr->numAuxDataItems ; i++) { AuxData *auxData = &codePtr->auxDataArrayPtr[i]; Tcl_Obj *auxDesc = Tcl_NewStringObj(auxData->type->name, -1); @@ -1138,7 +1139,7 @@ DisassembleByteCodeAsDicts( */ TclNewObj(exn); - for (i=0 ; inumExceptRanges ; i++) { + for (i=0 ; i<(size_t)codePtr->numExceptRanges ; i++) { ExceptionRange *rangePtr = &codePtr->exceptArrayPtr[i]; switch (rangePtr->type) { @@ -1178,7 +1179,7 @@ DisassembleByteCodeAsDicts( srcOffPtr = codePtr->srcDeltaStart; srcLenPtr = codePtr->srcLengthStart; codeOffset = sourceOffset = 0; - for (i=0 ; inumCommands ; i++) { + for (i=0 ; i<(size_t)codePtr->numCommands ; i++) { Tcl_Obj *cmd; codeOffset += Decode(codeOffPtr); diff --git a/generic/tclExecute.c b/generic/tclExecute.c index bea9798..ab4aef7 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -4424,11 +4424,11 @@ TEBCresume( if (traceInstructions) { strncpy(cmdNameBuf, TclGetString(objv[0]), 20); } else { - fprintf(stdout, "%d: (%u) invoking ", + fprintf(stdout, "%d: (%" TCL_Z_MODIFIER "u) invoking ", iPtr->numLevels, - (unsigned)(pc - codePtr->codeStart)); + (size_t)(pc - codePtr->codeStart)); } - for (i = 0; i < opnd; i++) { + for (i = 0; i < (size_t)opnd; i++) { TclPrintObject(stdout, objv[i], 15); fprintf(stdout, " "); } @@ -6218,11 +6218,11 @@ TEBCresume( ForeachInfo *infoPtr; Tcl_Obj *listPtr, **elements; ForeachVarList *varListPtr; - int numLists, listLen, numVars; - int listTmpDepth; + size_t numLists, numVars; + int listTmpDepth, listLen; size_t iterNum, iterMax, iterTmp; - int varIndex, valIndex, j; - long i; + size_t varIndex, valIndex, j; + size_t i; case INST_FOREACH_START: /* @@ -6330,7 +6330,7 @@ TEBCresume( valIndex = (iterNum * numVars); for (j = 0; j < numVars; j++) { - if (valIndex >= listLen) { + if (valIndex >= (size_t)listLen) { TclNewObj(valuePtr); } else { valuePtr = elements[valIndex]; @@ -6355,7 +6355,7 @@ TEBCresume( if (TclPtrSetVarIdx(interp, varPtr, NULL, NULL, NULL, valuePtr, TCL_LEAVE_ERR_MSG, varIndex)==NULL){ CACHE_STACK_INFO(); - TRACE_APPEND(("ERROR init. index temp %d: %.30s", + TRACE_APPEND(("ERROR init. index temp %" TCL_Z_MODIFIER "d: %.30s", varIndex, O2S(Tcl_GetObjResult(interp)))); goto gotError; } @@ -6402,7 +6402,7 @@ TEBCresume( tmpPtr = OBJ_AT_DEPTH(1); infoPtr = (ForeachInfo *)tmpPtr->internalRep.twoPtrValue.ptr1; numLists = infoPtr->numLists; - TRACE_APPEND(("=> appending to list at depth %d\n", 3 + numLists)); + TRACE_APPEND(("=> appending to list at depth %" TCL_Z_MODIFIER "d\n", 3 + numLists)); objPtr = OBJ_AT_DEPTH(3 + numLists); Tcl_ListObjAppendElement(NULL, objPtr, OBJ_AT_TOS); -- cgit v0.12