diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-21 13:32:45 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-21 13:32:45 (GMT) |
commit | c32b5a727445c796b53e7b3e84b14774de2baa78 (patch) | |
tree | e47601910f365d5c37d184e9422037bbe84618d6 /generic/tclCmdIL.c | |
parent | 574471316705773a548b5b0fcd895e2ae7d8a8c9 (diff) | |
parent | c091b78af60d2f2f46c162bed19465380cf8d4bf (diff) | |
download | tcl-c32b5a727445c796b53e7b3e84b14774de2baa78.zip tcl-c32b5a727445c796b53e7b3e84b14774de2baa78.tar.gz tcl-c32b5a727445c796b53e7b3e84b14774de2baa78.tar.bz2 |
Merge 9.0
Diffstat (limited to 'generic/tclCmdIL.c')
-rw-r--r-- | generic/tclCmdIL.c | 199 |
1 files changed, 100 insertions, 99 deletions
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c index 769dfc3..1d8139a 100644 --- a/generic/tclCmdIL.c +++ b/generic/tclCmdIL.c @@ -51,7 +51,7 @@ typedef struct SortElement { */ typedef int (*SortStrCmpFn_t) (const char *, const char *); -typedef int (*SortMemCmpFn_t) (const void *, const void *, size_t); +typedef int (*SortMemCmpFn_t) (const void *, const void *, Tcl_Size); /* * The "lsort" command needs to pass certain information down to the function @@ -74,7 +74,7 @@ typedef struct { * NULL if no indexes supplied, and points to * singleIndex field when only one * supplied. */ - size_t indexc; /* Number of indexes in indexv array. */ + Tcl_Size indexc; /* Number of indexes in indexv array. */ int singleIndex; /* Static space for common index case. */ int unique; int numElements; @@ -252,7 +252,7 @@ IfConditionCallback( Interp *iPtr = (Interp *) interp; Tcl_Size objc = PTR2INT(data[0]); Tcl_Obj *const *objv = (Tcl_Obj *const *)data[1]; - size_t i = PTR2INT(data[2]); + Tcl_Size i = PTR2INT(data[2]); Tcl_Obj *boolObj = (Tcl_Obj *)data[3]; int value, thenScriptIndex = 0; const char *clause; @@ -504,7 +504,7 @@ InfoArgsCmd( localPtr = localPtr->nextPtr) { if (TclIsVarArgument(localPtr)) { Tcl_ListObjAppendElement(interp, listObjPtr, - Tcl_NewStringObj(localPtr->name, TCL_INDEX_NONE)); + Tcl_NewStringObj(localPtr->name, -1)); } } Tcl_SetObjResult(interp, listObjPtr); @@ -541,7 +541,7 @@ InfoBodyCmd( Interp *iPtr = (Interp *) interp; const char *name, *bytes; Proc *procPtr; - size_t numBytes; + Tcl_Size numBytes; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "procname"); @@ -651,7 +651,7 @@ InfoCommandsCmd( Tcl_Obj *listPtr, *elemObjPtr; int specificNsInPattern = 0;/* Init. to avoid compiler warning. */ Tcl_Command cmd; - size_t i; + Tcl_Size i; /* * Get the pattern and find the "effective namespace" in which to list @@ -716,7 +716,7 @@ InfoCommandsCmd( Tcl_GetCommandFullName(interp, cmd, elemObjPtr); } else { cmdName = (const char *)Tcl_GetHashKey(&nsPtr->cmdTable, entryPtr); - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); } Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); Tcl_SetObjResult(interp, listPtr); @@ -744,7 +744,7 @@ InfoCommandsCmd( if (entryPtr != NULL) { cmdName = (const char *)Tcl_GetHashKey(tablePtr, entryPtr); Tcl_ListObjAppendElement(interp, listPtr, - Tcl_NewStringObj(cmdName, TCL_INDEX_NONE)); + Tcl_NewStringObj(cmdName, -1)); Tcl_SetObjResult(interp, listPtr); return TCL_OK; } @@ -766,7 +766,7 @@ InfoCommandsCmd( elemObjPtr = Tcl_NewObj(); Tcl_GetCommandFullName(interp, cmd, elemObjPtr); } else { - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); } Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); } @@ -789,7 +789,7 @@ InfoCommandsCmd( || Tcl_StringMatch(cmdName, simplePattern)) { if (Tcl_FindHashEntry(&nsPtr->cmdTable,cmdName) == NULL) { Tcl_ListObjAppendElement(interp, listPtr, - Tcl_NewStringObj(cmdName, TCL_INDEX_NONE)); + Tcl_NewStringObj(cmdName, -1)); } } entryPtr = Tcl_NextHashEntry(&search); @@ -818,7 +818,7 @@ InfoCommandsCmd( cmdName = (const char *)Tcl_GetHashKey(&nsPtr->cmdTable, entryPtr); if ((simplePattern == NULL) || Tcl_StringMatch(cmdName, simplePattern)) { - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); (void) Tcl_CreateHashEntry(&addedCommandsTable, elemObjPtr, &isNew); @@ -844,7 +844,7 @@ InfoCommandsCmd( cmdName = (const char *)Tcl_GetHashKey(&pathNsPtr->cmdTable, entryPtr); if ((simplePattern == NULL) || Tcl_StringMatch(cmdName, simplePattern)) { - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); (void) Tcl_CreateHashEntry(&addedCommandsTable, elemObjPtr, &isNew); if (isNew) { @@ -871,7 +871,7 @@ InfoCommandsCmd( cmdName = (const char *)Tcl_GetHashKey(&globalNsPtr->cmdTable, entryPtr); if ((simplePattern == NULL) || Tcl_StringMatch(cmdName, simplePattern)) { - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); if (Tcl_FindHashEntry(&addedCommandsTable, (char *) elemObjPtr) == NULL) { Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); @@ -1291,7 +1291,7 @@ TclInfoFrame( * str. */ - ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], TCL_INDEX_NONE)); + ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], -1)); if (framePtr->line) { ADD_PAIR("line", Tcl_NewWideIntObj(framePtr->line[0])); } else { @@ -1305,7 +1305,7 @@ TclInfoFrame( * Precompiled. Result contains the type as signal, nothing else. */ - ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], TCL_INDEX_NONE)); + ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], -1)); break; case TCL_LOCATION_BC: { @@ -1330,7 +1330,7 @@ TclInfoFrame( * Possibly modified: type, path! */ - ADD_PAIR("type", Tcl_NewStringObj(typeString[fPtr->type], TCL_INDEX_NONE)); + ADD_PAIR("type", Tcl_NewStringObj(typeString[fPtr->type], -1)); if (fPtr->line) { ADD_PAIR("line", Tcl_NewWideIntObj(fPtr->line[0])); } @@ -1358,7 +1358,7 @@ TclInfoFrame( * Evaluation of a script file. */ - ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], TCL_INDEX_NONE)); + ADD_PAIR("type", Tcl_NewStringObj(typeString[framePtr->type], -1)); ADD_PAIR("line", Tcl_NewWideIntObj(framePtr->line[0])); ADD_PAIR("file", framePtr->data.eval.path); @@ -1396,7 +1396,7 @@ TclInfoFrame( ADD_PAIR("proc", procNameObj); } else if (procPtr->cmdPtr->clientData) { ExtraFrameInfo *efiPtr = (ExtraFrameInfo *)procPtr->cmdPtr->clientData; - size_t i; + Tcl_Size i; /* * This is a non-standard command. Luckily, it's told us how to @@ -1404,7 +1404,7 @@ TclInfoFrame( */ for (i=0 ; i<efiPtr->length ; i++) { - lv[lc++] = Tcl_NewStringObj(efiPtr->fields[i].name, TCL_INDEX_NONE); + lv[lc++] = Tcl_NewStringObj(efiPtr->fields[i].name, -1); if (efiPtr->fields[i].proc) { lv[lc++] = efiPtr->fields[i].proc(efiPtr->fields[i].clientData); @@ -1492,7 +1492,7 @@ InfoFunctionsCmd( " }\n" " }\n" " ::return $cmds\n" -" } [::namespace current]] ", TCL_INDEX_NONE); +" } [::namespace current]] ", -1); if (objc == 2) { Tcl_Obj *arg = Tcl_NewListObj(1, &(objv[1])); @@ -1545,12 +1545,12 @@ InfoHostnameCmd( name = Tcl_GetHostName(); if (name) { - Tcl_SetObjResult(interp, Tcl_NewStringObj(name, TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(name, -1)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewStringObj( - "unable to determine name of host", TCL_INDEX_NONE)); + "unable to determine name of host", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "HOSTNAME", "UNKNOWN", NULL); return TCL_ERROR; } @@ -1665,12 +1665,12 @@ InfoLibraryCmd( libDirName = Tcl_GetVar2(interp, "tcl_library", NULL, TCL_GLOBAL_ONLY); if (libDirName != NULL) { - Tcl_SetObjResult(interp, Tcl_NewStringObj(libDirName, TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(libDirName, -1)); return TCL_OK; } Tcl_SetObjResult(interp, Tcl_NewStringObj( - "no library has been specified for Tcl", TCL_INDEX_NONE)); + "no library has been specified for Tcl", -1)); Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "VARIABLE", "tcl_library",NULL); return TCL_ERROR; } @@ -1797,7 +1797,7 @@ InfoPatchLevelCmd( patchlevel = Tcl_GetVar2(interp, "tcl_patchLevel", NULL, (TCL_GLOBAL_ONLY | TCL_LEAVE_ERR_MSG)); if (patchlevel != NULL) { - Tcl_SetObjResult(interp, Tcl_NewStringObj(patchlevel, TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(patchlevel, -1)); return TCL_OK; } return TCL_ERROR; @@ -1910,7 +1910,7 @@ InfoProcsCmd( Tcl_GetCommandFullName(interp, (Tcl_Command) cmdPtr, elemObjPtr); } else { - elemObjPtr = Tcl_NewStringObj(simplePattern, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(simplePattern, -1); } Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); } @@ -1938,7 +1938,7 @@ InfoProcsCmd( Tcl_GetCommandFullName(interp, (Tcl_Command) cmdPtr, elemObjPtr); } else { - elemObjPtr = Tcl_NewStringObj(cmdName, TCL_INDEX_NONE); + elemObjPtr = Tcl_NewStringObj(cmdName, -1); } Tcl_ListObjAppendElement(interp, listPtr, elemObjPtr); } @@ -1977,7 +1977,7 @@ InfoProcsCmd( if (TclIsProc(cmdPtr) || ((realCmdPtr != NULL) && TclIsProc(realCmdPtr))) { Tcl_ListObjAppendElement(interp, listPtr, - Tcl_NewStringObj(cmdName, TCL_INDEX_NONE)); + Tcl_NewStringObj(cmdName, -1)); } } } @@ -2075,7 +2075,7 @@ InfoSharedlibCmd( } #ifdef TCL_SHLIB_EXT - Tcl_SetObjResult(interp, Tcl_NewStringObj(TCL_SHLIB_EXT, TCL_INDEX_NONE)); + Tcl_SetObjResult(interp, Tcl_NewStringObj(TCL_SHLIB_EXT, -1)); #endif return TCL_OK; } @@ -2172,7 +2172,7 @@ InfoCmdTypeCmd( Tcl_AppendResult(interp, "native", NULL); } else { Tcl_SetObjResult(interp, - Tcl_NewStringObj(TclGetCommandTypeName(command), TCL_INDEX_NONE)); + Tcl_NewStringObj(TclGetCommandTypeName(command), -1)); } return TCL_OK; } @@ -2201,7 +2201,7 @@ Tcl_JoinObjCmd( Tcl_Size objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* The argument objects. */ { - size_t length, listLen; + Tcl_Size length, listLen; int isArithSeries = 0; Tcl_Obj *resObjPtr = NULL, *joinObjPtr, **elemPtrs; @@ -2250,7 +2250,7 @@ Tcl_JoinObjCmd( if (length == 0) { resObjPtr = TclStringCat(interp, listLen, elemPtrs, 0); } else { - size_t i; + Tcl_Size i; resObjPtr = Tcl_NewObj(); if (isArithSeries) { @@ -2325,7 +2325,7 @@ Tcl_LassignObjCmd( { Tcl_Obj *listCopyPtr; Tcl_Obj **listObjv; /* The contents of the list. */ - size_t listObjc; /* The length of the list. */ + Tcl_Size listObjc; /* The length of the list. */ int code = TCL_OK; if (objc < 2) { @@ -2456,7 +2456,7 @@ Tcl_LinsertObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { Tcl_Obj *listPtr; - size_t len, index; + Tcl_Size len, index; int result; if (objc < 3) { @@ -2479,7 +2479,7 @@ Tcl_LinsertObjCmd( if (result != TCL_OK) { return result; } - if (index + 1 > len + 1) { + if (index > len) { index = len; } @@ -2575,7 +2575,7 @@ Tcl_LlengthObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { - size_t listLen; + Tcl_Size listLen; int result; Tcl_Obj *objPtr; @@ -2624,7 +2624,7 @@ Tcl_LpopObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { - size_t listLen; + Tcl_Size listLen; int result; Tcl_Obj *elemPtr, *stored; Tcl_Obj *listPtr, **elemPtrs; @@ -2653,7 +2653,7 @@ Tcl_LpopObjCmd( if (!listLen) { /* empty list, throw the same error as with index "end" */ Tcl_SetObjResult(interp, Tcl_NewStringObj( - "index \"end\" out of range", TCL_INDEX_NONE)); + "index \"end\" out of range", -1)); Tcl_SetErrorCode(interp, "TCL", "VALUE", "INDEX" "OUTOFRANGE", NULL); return TCL_ERROR; @@ -2727,7 +2727,7 @@ Tcl_LrangeObjCmd( /* Argument objects. */ { int result; - size_t listLen, first, last; + Tcl_Size listLen, first, last; if (objc != 4) { Tcl_WrongNumArgs(interp, 1, objv, "list first last"); return TCL_ERROR; @@ -2786,8 +2786,8 @@ LremoveIndexCompare( const void *el1Ptr, const void *el2Ptr) { - size_t idx1 = *((const size_t *) el1Ptr); - size_t idx2 = *((const size_t *) el2Ptr); + Tcl_Size idx1 = *((const Tcl_Size *) el1Ptr); + Tcl_Size idx2 = *((const Tcl_Size *) el2Ptr); /* * This will put the larger element first. @@ -2803,8 +2803,8 @@ Tcl_LremoveObjCmd( Tcl_Size objc, /* Number of arguments. */ Tcl_Obj *const objv[]) /* Argument objects. */ { - int prevIdx, first, num; - size_t i, idxc, *idxv, listLen; + Tcl_Size i, idxc, prevIdx, first, num; + Tcl_Size *idxv, listLen; Tcl_Obj *listObj; /* @@ -2826,7 +2826,7 @@ Tcl_LremoveObjCmd( Tcl_SetObjResult(interp, listObj); return TCL_OK; } - idxv = (size_t *)Tcl_Alloc((objc - 2) * sizeof(size_t)); + idxv = (Tcl_Size *)Tcl_Alloc((objc - 2) * sizeof(*idxv)); for (i = 2; i < objc; i++) { if (TclGetIntForIndexM(interp, objv[i], /*endValue*/ listLen - 1, &idxv[i - 2]) != TCL_OK) { @@ -2841,7 +2841,7 @@ Tcl_LremoveObjCmd( */ if (idxc > 1) { - qsort(idxv, idxc, sizeof(size_t), LremoveIndexCompare); + qsort(idxv, idxc, sizeof(*idxv), LremoveIndexCompare); } /* @@ -2854,7 +2854,7 @@ Tcl_LremoveObjCmd( num = 0; first = listLen; for (i = 0, prevIdx = -1 ; i < idxc ; i++) { - int idx = idxv[i]; + Tcl_Size idx = idxv[i]; /* * Repeated index and sanity check. @@ -2864,7 +2864,7 @@ Tcl_LremoveObjCmd( continue; } prevIdx = idx; - if (idx < 0 || idx >= (int)listLen) { + if (idx < 0 || idx >= listLen) { continue; } @@ -2923,7 +2923,7 @@ Tcl_LrepeatObjCmd( Tcl_Obj *const objv[]) /* The argument objects. */ { - int elementCount, i, totalElems; + Tcl_Size elementCount, i, totalElems; Tcl_Obj *listPtr, **dataArray = NULL; /* @@ -2935,12 +2935,12 @@ Tcl_LrepeatObjCmd( Tcl_WrongNumArgs(interp, 1, objv, "count ?value ...?"); return TCL_ERROR; } - if (TCL_OK != TclGetIntFromObj(interp, objv[1], &elementCount)) { + if (TCL_OK != TclGetSizeIntFromObj(interp, objv[1], &elementCount)) { return TCL_ERROR; } if (elementCount < 0) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "bad count \"%d\": must be integer >= 0", elementCount)); + "bad count \"%" TCL_SIZE_MODIFIER "d\": must be integer >= 0", elementCount)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LREPEAT", "NEGARG", NULL); return TCL_ERROR; @@ -2955,9 +2955,9 @@ Tcl_LrepeatObjCmd( /* Final sanity check. Do not exceed limits on max list length. */ - if (elementCount && (size_t)objc > LIST_MAX/elementCount) { + if (elementCount && objc > LIST_MAX/elementCount) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( - "max length of a Tcl list (%" TCL_Z_MODIFIER "u elements) exceeded", LIST_MAX)); + "max length of a Tcl list (%" TCL_SIZE_MODIFIER "d elements) exceeded", LIST_MAX)); Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL); return TCL_ERROR; } @@ -2997,7 +2997,7 @@ Tcl_LrepeatObjCmd( dataArray[i] = tmpPtr; } } else { - size_t j, k = 0; + Tcl_Size j, k = 0; for (i=0 ; i<elementCount ; i++) { for (j=0 ; j<objc ; j++) { @@ -3037,7 +3037,7 @@ Tcl_LreplaceObjCmd( Tcl_Obj *const objv[]) /* Argument objects. */ { Tcl_Obj *listPtr; - size_t numToDelete, listLen, first, last; + Tcl_Size numToDelete, listLen, first, last; int result; if (objc < 4) { @@ -3067,16 +3067,16 @@ Tcl_LreplaceObjCmd( return result; } - if (first == TCL_INDEX_NONE) { + if (first < 0) { first = 0; } else if (first > listLen) { first = listLen; } - if (last + 1 > listLen) { + if (last >= listLen) { last = listLen - 1; } - if (first + 1 <= last + 1) { + if (first <= last) { numToDelete = last - first + 1; } else { numToDelete = 0; @@ -3138,7 +3138,7 @@ Tcl_LreverseObjCmd( Tcl_Obj *const objv[]) /* Argument values. */ { Tcl_Obj **elemv; - size_t elemc, i, j; + Tcl_Size elemc, i, j; if (objc != 2) { Tcl_WrongNumArgs(interp, 1, objv, "list"); @@ -3243,8 +3243,9 @@ Tcl_LsearchObjCmd( Tcl_Obj *const objv[]) /* Argument values. */ { const char *bytes, *patternBytes; - int match, index, result=TCL_OK, bisect; - size_t i, length = 0, listc, elemLen, start, groupSize, groupOffset, lower, upper; + int match, result=TCL_OK, bisect; + Tcl_Size i, length = 0, listc, elemLen, start, index; + Tcl_Size groupSize, groupOffset, lower, upper; int allocatedIndexVector = 0; int isIncreasing; Tcl_WideInt patWide, objWide, wide; @@ -3303,7 +3304,7 @@ Tcl_LsearchObjCmd( return TCL_ERROR; } - for (i = 1; i < (size_t)objc-2; i++) { + for (i = 1; i < objc-2; i++) { enum lsearchoptions idx; if (Tcl_GetIndexFromObj(interp, objv[i], options, "option", 0, &idx) != TCL_OK) { @@ -3373,9 +3374,9 @@ Tcl_LsearchObjCmd( Tcl_DecrRefCount(startPtr); startPtr = NULL; } - if (i + 4 > (size_t)objc) { + if (i > objc-4) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "missing starting index", TCL_INDEX_NONE)); + "missing starting index", -1)); Tcl_SetErrorCode(interp, "TCL", "ARGUMENT", "MISSING", NULL); result = TCL_ERROR; goto done; @@ -3396,10 +3397,10 @@ Tcl_LsearchObjCmd( Tcl_IncrRefCount(startPtr); break; case LSEARCH_STRIDE: /* -stride */ - if (i + 4 > (size_t)objc) { + if (i > objc-4) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "\"-stride\" option must be " - "followed by stride length", TCL_INDEX_NONE)); + "followed by stride length", -1)); Tcl_SetErrorCode(interp, "TCL", "ARGUMENT", "MISSING", NULL); result = TCL_ERROR; goto done; @@ -3410,7 +3411,7 @@ Tcl_LsearchObjCmd( } if (wide < 1) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "stride length must be at least 1", TCL_INDEX_NONE)); + "stride length must be at least 1", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BADSTRIDE", NULL); result = TCL_ERROR; @@ -3421,13 +3422,13 @@ Tcl_LsearchObjCmd( break; case LSEARCH_INDEX: { /* -index */ Tcl_Obj **indices; - size_t j; + Tcl_Size j; if (allocatedIndexVector) { TclStackFree(interp, sortInfo.indexv); allocatedIndexVector = 0; } - if (i + 4 > (size_t)objc) { + if (i > objc-4) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "\"-index\" option must be followed by list index", -1)); @@ -3500,7 +3501,7 @@ Tcl_LsearchObjCmd( if (returnSubindices && sortInfo.indexc==0) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "-subindices cannot be used without -index option", TCL_INDEX_NONE)); + "-subindices cannot be used without -index option", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BAD_OPTION_MIX", NULL); result = TCL_ERROR; @@ -3509,7 +3510,7 @@ Tcl_LsearchObjCmd( if (bisect && (allMatches || negatedMatch)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "-bisect is not compatible with -all or -not", TCL_INDEX_NONE)); + "-bisect is not compatible with -all or -not", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BAD_OPTION_MIX", NULL); result = TCL_ERROR; @@ -3576,10 +3577,10 @@ Tcl_LsearchObjCmd( */ groupOffset = TclIndexDecode(sortInfo.indexv[0], groupSize - 1); - if (groupOffset >= groupSize) { + if (groupOffset < 0 || groupOffset >= groupSize) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "when used with \"-stride\", the leading \"-index\"" - " value must be within the group", TCL_INDEX_NONE)); + " value must be within the group", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSEARCH", "BADINDEX", NULL); result = TCL_ERROR; @@ -3616,7 +3617,7 @@ Tcl_LsearchObjCmd( * "did not match anything at all" result straight away. [Bug 1374778] */ - if (start >= (size_t)listc) { + if (start >= listc) { if (allMatches || inlineReturn) { Tcl_ResetResult(interp); } else { @@ -3907,7 +3908,7 @@ Tcl_LsearchObjCmd( Tcl_ListObjAppendElement(interp, listPtr, itemPtr); } } else if (returnSubindices) { - size_t j; + Tcl_Size j; TclNewIndexObj(itemPtr, i+groupOffset); for (j=0 ; j<sortInfo.indexc ; j++) { @@ -3931,7 +3932,7 @@ Tcl_LsearchObjCmd( Tcl_SetObjResult(interp, listPtr); } else if (!inlineReturn) { if (returnSubindices) { - size_t j; + Tcl_Size j; TclNewIndexObj(itemPtr, index+groupOffset); for (j=0 ; j<sortInfo.indexc ; j++) { @@ -4208,7 +4209,7 @@ Tcl_LseqObjCmd( Tcl_Obj *arithSeriesPtr; SequenceOperators opmode; SequenceDecoded decoded; - size_t i; + Tcl_Size i; int arg_key = 0, value_i = 0; // Default constants Tcl_Obj *zero = Tcl_NewIntObj(0); @@ -4492,10 +4493,10 @@ Tcl_LsortObjCmd( int indices, nocase = 0, indexc; int sortMode = SORTMODE_ASCII; int group, allocatedIndexVector = 0; - size_t j, idx, groupSize, groupOffset, length; + Tcl_Size j, idx, groupSize, groupOffset, length; Tcl_WideInt wide; Tcl_Obj *resultPtr, *cmdPtr, **listObjPtrs, *listObj, *indexPtr; - size_t i, elmArrSize; + Tcl_Size i, elmArrSize; SortElement *elementArray = NULL, *elementPtr; SortInfo sortInfo; /* Information about this sort that needs to * be passed to the comparison function. */ @@ -4539,7 +4540,7 @@ Tcl_LsortObjCmd( groupSize = 1; groupOffset = 0; indexPtr = NULL; - for (i = 1; i < (size_t)objc-1; i++) { + for (i = 1; i < objc-1; i++) { if (Tcl_GetIndexFromObj(interp, objv[i], switches, "option", 0, &index) != TCL_OK) { sortInfo.resultCode = TCL_ERROR; @@ -4550,10 +4551,10 @@ Tcl_LsortObjCmd( sortInfo.sortMode = SORTMODE_ASCII; break; case LSORT_COMMAND: - if (i + 2 == (size_t)objc) { + if (i == objc-2) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "\"-command\" option must be followed " - "by comparison command", TCL_INDEX_NONE)); + "by comparison command", -1)); Tcl_SetErrorCode(interp, "TCL", "ARGUMENT", "MISSING", NULL); sortInfo.resultCode = TCL_ERROR; goto done; @@ -4572,10 +4573,10 @@ Tcl_LsortObjCmd( sortInfo.isIncreasing = 1; break; case LSORT_INDEX: { - size_t sortindex; + Tcl_Size sortindex; Tcl_Obj **indexv; - if (i + 2 == (size_t)objc) { + if (i == objc-2) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "\"-index\" option must be followed by list index", -1)); @@ -4637,10 +4638,10 @@ Tcl_LsortObjCmd( indices = 1; break; case LSORT_STRIDE: - if (i + 2 == (size_t)objc) { + if (i == objc-2) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "\"-stride\" option must be " - "followed by stride length", TCL_INDEX_NONE)); + "followed by stride length", -1)); Tcl_SetErrorCode(interp, "TCL", "ARGUMENT", "MISSING", NULL); sortInfo.resultCode = TCL_ERROR; goto done; @@ -4651,7 +4652,7 @@ Tcl_LsortObjCmd( } if (wide < 2) { Tcl_SetObjResult(interp, Tcl_NewStringObj( - "stride length must be at least 2", TCL_INDEX_NONE)); + "stride length must be at least 2", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSORT", "BADSTRIDE", NULL); sortInfo.resultCode = TCL_ERROR; @@ -4770,10 +4771,10 @@ Tcl_LsortObjCmd( */ groupOffset = TclIndexDecode(sortInfo.indexv[0], groupSize - 1); - if (groupOffset >= groupSize) { + if (groupOffset < 0 || groupOffset >= groupSize) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "when used with \"-stride\", the leading \"-index\"" - " value must be within the group", TCL_INDEX_NONE)); + " value must be within the group", -1)); Tcl_SetErrorCode(interp, "TCL", "OPERATION", "LSORT", "BADINDEX", NULL); sortInfo.resultCode = TCL_ERROR; @@ -5014,10 +5015,10 @@ Tcl_LeditObjCmd( Tcl_Obj *finalValuePtr; /* Value finally assigned to the variable. */ int createdNewObj; int result; - size_t first; - size_t last; - size_t listLen; - size_t numToDelete; + Tcl_Size first; + Tcl_Size last; + Tcl_Size listLen; + Tcl_Size numToDelete; if (objc + 1 < 5) { Tcl_WrongNumArgs(interp, 1, objv, @@ -5050,17 +5051,17 @@ Tcl_LeditObjCmd( return result; } - if (first == TCL_INDEX_NONE) { + if (first < 0) { first = 0; } else if (first > listLen) { first = listLen; } /* The +1 in comparisons are necessitated by indices being unsigned */ - if ((last + 1) > listLen) { + if (last >= listLen) { last = listLen - 1; } - if ((first + 1) <= (last + 1)) { + if (first <= last) { numToDelete = last - first + 1; } else { numToDelete = 0; @@ -5300,7 +5301,7 @@ SortCompare( if (TclGetIntFromObj(infoPtr->interp, Tcl_GetObjResult(infoPtr->interp), &order) != TCL_OK) { Tcl_SetObjResult(infoPtr->interp, Tcl_NewStringObj( - "-compare command returned non-integer result", TCL_INDEX_NONE)); + "-compare command returned non-integer result", -1)); Tcl_SetErrorCode(infoPtr->interp, "TCL", "OPERATION", "LSORT", "COMPARISONFAILED", NULL); infoPtr->resultCode = TCL_ERROR; @@ -5474,7 +5475,7 @@ SelectObjFromSublist( SortInfo *infoPtr) /* Information passed from the top-level * "lsearch" or "lsort" command. */ { - size_t i; + Tcl_Size i; /* * Quick check for case when no "-index" option is there. @@ -5490,7 +5491,7 @@ SelectObjFromSublist( */ for (i=0 ; i<infoPtr->indexc ; i++) { - size_t listLen; + Tcl_Size listLen; int index; Tcl_Obj *currentObj; @@ -5507,7 +5508,7 @@ SelectObjFromSublist( return NULL; } if (currentObj == NULL) { - if (index == (int)TCL_INDEX_NONE) { + if (index == TCL_INDEX_NONE) { index = TCL_INDEX_END - infoPtr->indexv[i]; Tcl_SetObjResult(infoPtr->interp, Tcl_ObjPrintf( "element end-%d missing from sublist \"%s\"", |