summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclBasic.c16
-rw-r--r--generic/tclCmdIL.c4
-rw-r--r--generic/tclEnv.c21
-rw-r--r--generic/tclExecute.c24
-rw-r--r--generic/tclInt.decls2
-rw-r--r--generic/tclInt.h41
-rw-r--r--generic/tclIntDecls.h4
-rw-r--r--generic/tclNamesp.c13
-rw-r--r--generic/tclStringObj.c118
-rw-r--r--generic/tclUtil.c21
-rw-r--r--unix/tclUnixInit.c8
11 files changed, 145 insertions, 127 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 39c8335..1a4b09e 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -53,7 +53,7 @@ typedef struct {
* cancellation. */
char *result; /* The script cancellation result or NULL for
* a default result. */
- int length; /* Length of the above error message. */
+ size_t length; /* Length of the above error message. */
ClientData clientData; /* Ignored */
int flags; /* Additional flags */
} CancelInfo;
@@ -3630,7 +3630,7 @@ Tcl_Canceled(
if (flags & TCL_LEAVE_ERR_MSG) {
const char *id, *message = NULL;
- int length;
+ size_t length;
/*
* Setup errorCode variables so that we can differentiate between
@@ -4222,7 +4222,7 @@ TEOV_Error(
Interp *iPtr = (Interp *) interp;
Tcl_Obj *listPtr;
const char *cmdString;
- int cmdLen;
+ size_t cmdLen;
int objc = PTR2INT(data[0]);
Tcl_Obj **objv = data[1];
@@ -4378,8 +4378,8 @@ TEOV_RunEnterTraces(
{
Interp *iPtr = (Interp *) interp;
Command *cmdPtr = *cmdPtrPtr;
- size_t newEpoch, cmdEpoch = cmdPtr->cmdEpoch;
- int length, traceCode = TCL_OK;
+ size_t length, newEpoch, cmdEpoch = cmdPtr->cmdEpoch;
+ int traceCode = TCL_OK;
const char *command = TclGetStringFromObj(commandPtr, &length);
/*
@@ -4431,7 +4431,7 @@ TEOV_RunLeaveTraces(
Tcl_Obj *commandPtr = data[1];
Command *cmdPtr = data[2];
Tcl_Obj **objv = data[3];
- int length;
+ size_t length;
const char *command = TclGetStringFromObj(commandPtr, &length);
if (!(cmdPtr->flags & CMD_IS_DELETED)) {
@@ -5680,7 +5680,7 @@ TclNREvalObjEx(
*/
const char *script;
- int numSrcBytes;
+ size_t numSrcBytes;
/*
* Now we check if we have data about invisible continuation lines for
@@ -5734,7 +5734,7 @@ TEOEx_ByteCodeCallback(
}
if ((result != TCL_OK) && (result != TCL_ERROR) && !allowExceptions) {
const char *script;
- int numSrcBytes;
+ size_t numSrcBytes;
ProcessUnexpectedResult(interp, result);
result = TCL_ERROR;
diff --git a/generic/tclCmdIL.c b/generic/tclCmdIL.c
index 018a9f5..d520ce9 100644
--- a/generic/tclCmdIL.c
+++ b/generic/tclCmdIL.c
@@ -658,7 +658,7 @@ InfoCommandsCmd(
Tcl_Obj *listPtr, *elemObjPtr;
int specificNsInPattern = 0;/* Init. to avoid compiler warning. */
Tcl_Command cmd;
- int i;
+ size_t i;
/*
* Get the pattern and find the "effective namespace" in which to list
@@ -1403,7 +1403,7 @@ TclInfoFrame(
ADD_PAIR("proc", procNameObj);
} else if (procPtr->cmdPtr->clientData) {
ExtraFrameInfo *efiPtr = procPtr->cmdPtr->clientData;
- int i;
+ size_t i;
/*
* This is a non-standard command. Luckily, it's told us how to
diff --git a/generic/tclEnv.c b/generic/tclEnv.c
index 40ced17..560fcb1 100644
--- a/generic/tclEnv.c
+++ b/generic/tclEnv.c
@@ -18,7 +18,7 @@
TCL_DECLARE_MUTEX(envMutex) /* To serialize access to environ. */
static struct {
- int cacheSize; /* Number of env strings in cache. */
+ size_t cacheSize; /* Number of env strings in cache. */
char **cache; /* Array containing all of the environment
* strings that Tcl has allocated. */
#ifndef USE_PUTENV
@@ -26,7 +26,7 @@ static struct {
* need to track this in case another
* subsystem swaps around the environ array
* like we do. */
- int ourEnvironSize; /* Non-zero means that the environ array was
+ size_t ourEnvironSize; /* Non-zero means that the environ array was
* malloced and has this many total entries
* allocated to it (not all may be in use at
* once). Zero means that the environment
@@ -204,7 +204,7 @@ TclSetEnv(
{
Tcl_DString envString;
unsigned nameLength, valueLength;
- int index, length;
+ size_t index, length;
char *p, *oldValue;
const char *p2;
@@ -217,7 +217,7 @@ TclSetEnv(
Tcl_MutexLock(&envMutex);
index = TclpFindVariable(name, &length);
- if (index == -1) {
+ if (index == (size_t)-1) {
#ifndef USE_PUTENV
/*
* We need to handle the case where the environment may be changed
@@ -301,7 +301,7 @@ TclSetEnv(
* string in the cache.
*/
- if ((index != -1) && (environ[index] == p)) {
+ if ((index != (size_t)-1) && (environ[index] == p)) {
ReplaceString(oldValue, p);
#ifdef HAVE_PUTENV_THAT_COPIES
} else {
@@ -401,8 +401,7 @@ TclUnsetEnv(
const char *name) /* Name of variable to remove (UTF-8). */
{
char *oldValue;
- int length;
- int index;
+ size_t length, index;
#ifdef USE_PUTENV_FOR_UNSET
Tcl_DString envString;
char *string;
@@ -418,7 +417,7 @@ TclUnsetEnv(
* needless work and to avoid recursion on the unset.
*/
- if (index == -1) {
+ if (index == (size_t)-1) {
Tcl_MutexUnlock(&envMutex);
return;
}
@@ -517,13 +516,13 @@ TclGetEnv(
* value of the environment variable is
* stored. */
{
- int length, index;
+ size_t length, index;
const char *result;
Tcl_MutexLock(&envMutex);
index = TclpFindVariable(name, &length);
result = NULL;
- if (index != -1) {
+ if (index != (size_t)-1) {
Tcl_DString envStr;
result = Tcl_ExternalToUtfDString(NULL, environ[index], -1, &envStr);
@@ -650,7 +649,7 @@ ReplaceString(
const char *oldStr, /* Old environment string. */
char *newStr) /* New environment string. */
{
- int i;
+ size_t i;
/*
* Check to see if the old value was allocated by Tcl. If so, it needs to
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 358db5b..d7ec5e1 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -625,7 +625,7 @@ static void FreeExprCodeInternalRep(Tcl_Obj *objPtr);
static ExceptionRange * GetExceptRangeForPc(const unsigned char *pc,
int searchMode, ByteCode *codePtr);
static const char * GetSrcInfoForPc(const unsigned char *pc,
- ByteCode *codePtr, int *lengthPtr,
+ ByteCode *codePtr, size_t *lengthPtr,
const unsigned char **pcBeg, int *cmdIdxPtr);
static Tcl_Obj ** GrowEvaluationStack(ExecEnv *eePtr, int growth,
int move);
@@ -7176,11 +7176,12 @@ TEBCresume(
}
if ((result == TCL_ERROR) && !(iPtr->flags & ERR_ALREADY_LOGGED)) {
const unsigned char *pcBeg;
+ size_t xxx1length;
- bytes = GetSrcInfoForPc(pc, codePtr, &length, &pcBeg, NULL);
+ bytes = GetSrcInfoForPc(pc, codePtr, &xxx1length, &pcBeg, NULL);
DECACHE_STACK_INFO();
TclLogCommandInfo(interp, codePtr->source, bytes,
- bytes ? length : 0, pcBeg, tosPtr);
+ bytes ? xxx1length : 0, pcBeg, tosPtr);
CACHE_STACK_INFO();
}
iPtr->flags &= ~ERR_ALREADY_LOGGED;
@@ -7342,9 +7343,10 @@ TEBCresume(
instStartCmdFailed:
{
const char *bytes;
+ size_t xxx1length;
checkInterp = 1;
- length = 0;
+ xxx1length = 0;
/*
* We used to switch to direct eval; for NRE-awareness we now
@@ -7357,11 +7359,11 @@ TEBCresume(
}
codePtr->flags |= TCL_BYTECODE_RECOMPILE;
- bytes = GetSrcInfoForPc(pc, codePtr, &length, NULL, NULL);
+ bytes = GetSrcInfoForPc(pc, codePtr, &xxx1length, NULL, NULL);
opnd = TclGetUInt4AtPtr(pc+1);
pc += (opnd-1);
assert(bytes);
- PUSH_OBJECT(Tcl_NewStringObj(bytes, length));
+ PUSH_OBJECT(Tcl_NewStringObj(bytes, xxx1length));
goto instEvalStk;
}
}
@@ -8906,7 +8908,7 @@ GetSrcInfoForPc(
* in codePtr's code. */
ByteCode *codePtr, /* The bytecode sequence in which to look up
* the command source for the pc. */
- int *lengthPtr, /* If non-NULL, the location where the length
+ size_t *lengthPtr, /* If non-NULL, the location where the length
* of the command's source should be stored.
* If NULL, no length is stored. */
const unsigned char **pcBeg,/* If non-NULL, the bytecode location
@@ -8916,18 +8918,18 @@ GetSrcInfoForPc(
* of the command containing the pc should
* be stored. */
{
- int pcOffset = (pc - codePtr->codeStart);
- int numCmds = codePtr->numCommands;
+ size_t pcOffset = (pc - codePtr->codeStart);
+ size_t numCmds = codePtr->numCommands;
unsigned char *codeDeltaNext, *codeLengthNext;
unsigned char *srcDeltaNext, *srcLengthNext;
- int codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
+ size_t codeOffset, codeLen, codeEnd, srcOffset, srcLen, delta, i;
int bestDist = INT_MAX; /* Distance of pc to best cmd's start pc. */
int bestSrcOffset = -1; /* Initialized to avoid compiler warning. */
int bestSrcLength = -1; /* Initialized to avoid compiler warning. */
int bestCmdIdx = -1;
/* The pc must point within the bytecode */
- assert ((pcOffset >= 0) && (pcOffset < codePtr->numCodeBytes));
+ assert (pcOffset < codePtr->numCodeBytes);
/*
* Decode the code and source offset and length for each command. The
diff --git a/generic/tclInt.decls b/generic/tclInt.decls
index efc1ac3..07044c6 100644
--- a/generic/tclInt.decls
+++ b/generic/tclInt.decls
@@ -913,7 +913,7 @@ declare 226 {
int TclObjBeingDeleted(Tcl_Obj *objPtr)
}
declare 227 {
- void TclSetNsPath(Namespace *nsPtr, int pathLength,
+ void TclSetNsPath(Namespace *nsPtr, size_t pathLength,
Tcl_Namespace *pathAry[])
}
# Used to be needed for TclOO-extension; unneeded now that TclOO is in the
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 899c4d6..27ea666 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -347,7 +347,7 @@ typedef struct Namespace {
Tcl_Obj *unknownHandlerPtr; /* A script fragment to be used when command
* resolution in this namespace fails. TIP
* 181. */
- int commandPathLength; /* The length of the explicit path. */
+ size_t commandPathLength; /* The length of the explicit path. */
NamespacePathEntry *commandPathArray;
/* The explicit path of the namespace as an
* array. */
@@ -1227,7 +1227,7 @@ typedef struct CmdFrame {
} data;
Tcl_Obj *cmdObj;
const char *cmd; /* The executed command, if possible... */
- int len; /* ... and its length. */
+ size_t len; /* ... and its length. */
const struct CFWordBC *litarg;
/* Link to set of literal arguments which have
* ben pushed on the lineLABCPtr stack by
@@ -1325,7 +1325,7 @@ typedef struct {
* proc field is NULL. */
} ExtraFrameInfoField;
typedef struct {
- int length; /* Length of array. */
+ size_t length; /* Length of array. */
ExtraFrameInfoField fields[2];
/* Really as long as necessary, but this is
* long enough for nearly anything. */
@@ -2857,8 +2857,8 @@ MODULE_SCOPE void TclArgumentGet(Tcl_Interp *interp, Tcl_Obj *obj,
CmdFrame **cfPtrPtr, int *wordPtr);
MODULE_SCOPE double TclBignumToDouble(const mp_int *bignum);
MODULE_SCOPE int TclByteArrayMatch(const unsigned char *string,
- int strLen, const unsigned char *pattern,
- int ptnLen, int flags);
+ size_t strLen, const unsigned char *pattern,
+ size_t ptnLen, int flags);
MODULE_SCOPE double TclCeil(const mp_int *a);
MODULE_SCOPE void TclChannelPreserve(Tcl_Channel chan);
MODULE_SCOPE void TclChannelRelease(Tcl_Channel chan);
@@ -3074,7 +3074,7 @@ MODULE_SCOPE int TclCreateSocketAddress(Tcl_Interp *interp,
MODULE_SCOPE int TclpThreadCreate(Tcl_ThreadId *idPtr,
Tcl_ThreadCreateProc *proc, void *clientData,
size_t stackSize, int flags);
-MODULE_SCOPE int TclpFindVariable(const char *name, int *lengthPtr);
+MODULE_SCOPE size_t TclpFindVariable(const char *name, size_t *lengthPtr);
MODULE_SCOPE void TclpInitLibraryPath(char **valuePtr,
size_t *lengthPtr, Tcl_Encoding *encodingPtr);
MODULE_SCOPE void TclpInitLock(void);
@@ -3143,11 +3143,11 @@ MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr,
size_t numBytes);
typedef int (*memCmpFn_t)(const void*, const void*, size_t);
MODULE_SCOPE int TclStringCmp(Tcl_Obj *value1Ptr, Tcl_Obj *value2Ptr,
- int checkEq, int nocase, int reqlength);
+ int checkEq, int nocase, size_t reqlength);
MODULE_SCOPE int TclStringCmpOpts(Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[], int *nocase,
int *reqlength);
-MODULE_SCOPE int TclStringMatch(const char *str, int strLen,
+MODULE_SCOPE int TclStringMatch(const char *str, size_t strLen,
const char *pattern, int ptnLen, int flags);
MODULE_SCOPE int TclStringMatchObj(Tcl_Obj *stringObj,
Tcl_Obj *patternObj, int flags);
@@ -3959,14 +3959,14 @@ MODULE_SCOPE int TclCompileAssembleCmd(Tcl_Interp *interp,
MODULE_SCOPE Tcl_Obj * TclStringCat(Tcl_Interp *interp, int objc,
Tcl_Obj *const objv[], int flags);
-MODULE_SCOPE int TclStringFirst(Tcl_Obj *needle, Tcl_Obj *haystack,
- int start);
-MODULE_SCOPE int TclStringLast(Tcl_Obj *needle, Tcl_Obj *haystack,
- int last);
+MODULE_SCOPE size_t TclStringFirst(Tcl_Obj *needle, Tcl_Obj *haystack,
+ size_t start);
+MODULE_SCOPE size_t TclStringLast(Tcl_Obj *needle, Tcl_Obj *haystack,
+ size_t last);
MODULE_SCOPE Tcl_Obj * TclStringRepeat(Tcl_Interp *interp, Tcl_Obj *objPtr,
- int count, int flags);
+ size_t count, int flags);
MODULE_SCOPE Tcl_Obj * TclStringReplace(Tcl_Interp *interp, Tcl_Obj *objPtr,
- int first, int count, Tcl_Obj *insertPtr,
+ size_t first, size_t count, Tcl_Obj *insertPtr,
int flags);
MODULE_SCOPE Tcl_Obj * TclStringReverse(Tcl_Obj *objPtr, int flags);
@@ -4135,7 +4135,7 @@ typedef const char *TclDTraceStr;
/*
* Invalidate the string rep first so we can use the bytes value for our
* pointer chain, and signal an obj deletion (as opposed to shimmering) with
- * 'length == -1'.
+ * 'length == (size_t)-1'.
* Use empty 'if ; else' to handle use in unbraced outer if/else conditions.
*/
@@ -4337,13 +4337,22 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr, const char *file,
static inline const char *TclGetStringFromObj(Tcl_Obj *objPtr, size_t *lenPtr) {
const char *response = Tcl_GetString(objPtr);
if (lenPtr) *lenPtr = objPtr->length;
- return response;
+ return response;
+ }
+ static inline Tcl_UniChar *TclGetUnicodeFromObj(Tcl_Obj *objPtr, size_t *lengthPtr) {
+ Tcl_GetUnicodeFromObj(objPtr, NULL);
+ *lenPtr = *((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1)
+ return Tcl_GetUnicodeFromObj(objPtr, NULL);
}
#else
#define TclGetStringFromObj(objPtr, lenPtr) \
(((objPtr)->bytes \
? 0 : Tcl_GetString((objPtr)), \
*(lenPtr) = (objPtr)->length, (objPtr)->bytes))
+#define TclGetUnicodeFromObj(objPtr, lenPtr) \
+ (Tcl_GetUnicodeFromObj(objPtr, NULL), \
+ *lenPtr = *((size_t *) (objPtr)->internalRep.twoPtrValue.ptr1), \
+ Tcl_GetUnicodeFromObj(objPtr, NULL))
#endif
/*
diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h
index fd4ab70..ea35dc4 100644
--- a/generic/tclIntDecls.h
+++ b/generic/tclIntDecls.h
@@ -484,7 +484,7 @@ EXTERN Tcl_Obj * TclTraceDictPath(Tcl_Interp *interp,
/* 226 */
EXTERN int TclObjBeingDeleted(Tcl_Obj *objPtr);
/* 227 */
-EXTERN void TclSetNsPath(Namespace *nsPtr, int pathLength,
+EXTERN void TclSetNsPath(Namespace *nsPtr, size_t pathLength,
Tcl_Namespace *pathAry[]);
/* Slot 228 is reserved */
/* 229 */
@@ -810,7 +810,7 @@ typedef struct TclIntStubs {
TclPlatformType * (*tclGetPlatform) (void); /* 224 */
Tcl_Obj * (*tclTraceDictPath) (Tcl_Interp *interp, Tcl_Obj *rootPtr, int keyc, Tcl_Obj *const keyv[], int flags); /* 225 */
int (*tclObjBeingDeleted) (Tcl_Obj *objPtr); /* 226 */
- void (*tclSetNsPath) (Namespace *nsPtr, int pathLength, Tcl_Namespace *pathAry[]); /* 227 */
+ void (*tclSetNsPath) (Namespace *nsPtr, size_t pathLength, Tcl_Namespace *pathAry[]); /* 227 */
void (*reserved228)(void);
int (*tclPtrMakeUpvar) (Tcl_Interp *interp, Var *otherP1Ptr, const char *myName, int myFlags, int index); /* 229 */
Var * (*tclObjLookupVar) (Tcl_Interp *interp, Tcl_Obj *part1Ptr, const char *part2, int flags, const char *msg, const int createPart1, const int createPart2, Var **arrayPtrPtr); /* 230 */
diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c
index b0d4ee0..3aaf465 100644
--- a/generic/tclNamesp.c
+++ b/generic/tclNamesp.c
@@ -2606,7 +2606,7 @@ Tcl_FindCommand(
cmdPtr = NULL;
if (cxtNsPtr->commandPathLength!=0 && strncmp(name, "::", 2)
&& !(flags & TCL_NAMESPACE_ONLY)) {
- int i;
+ size_t i;
Namespace *pathNsPtr, *realNsPtr, *dummyNsPtr;
(void) TclGetNamespaceForQualName(interp, name, cxtNsPtr,
@@ -4004,7 +4004,8 @@ NamespacePathCmd(
Tcl_Obj *const objv[]) /* Argument objects. */
{
Namespace *nsPtr = (Namespace *) TclGetCurrentNamespace(interp);
- int i, nsObjc, result = TCL_ERROR;
+ size_t i;
+ int nsObjc, result = TCL_ERROR;
Tcl_Obj **nsObjv;
Tcl_Namespace **namespaceList = NULL;
@@ -4041,7 +4042,7 @@ NamespacePathCmd(
namespaceList = TclStackAlloc(interp,
sizeof(Tcl_Namespace *) * nsObjc);
- for (i=0 ; i<nsObjc ; i++) {
+ for (i=0 ; i<(size_t)nsObjc ; i++) {
if (TclGetNamespaceFromObj(interp, nsObjv[i],
&namespaceList[i]) != TCL_OK) {
goto badNamespace;
@@ -4086,13 +4087,13 @@ NamespacePathCmd(
void
TclSetNsPath(
Namespace *nsPtr, /* Namespace whose path is to be set. */
- int pathLength, /* Length of pathAry. */
+ size_t pathLength, /* Length of pathAry. */
Tcl_Namespace *pathAry[]) /* Array of namespaces that are the path. */
{
if (pathLength != 0) {
NamespacePathEntry *tmpPathArray =
ckalloc(sizeof(NamespacePathEntry) * pathLength);
- int i;
+ size_t i;
for (i=0 ; i<pathLength ; i++) {
tmpPathArray[i].nsPtr = (Namespace *) pathAry[i];
@@ -4143,7 +4144,7 @@ static void
UnlinkNsPath(
Namespace *nsPtr)
{
- int i;
+ size_t i;
for (i=0 ; i<nsPtr->commandPathLength ; i++) {
NamespacePathEntry *nsPathPtr = &nsPtr->commandPathArray[i];
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c
index 2b1f533..df533e2 100644
--- a/generic/tclStringObj.c
+++ b/generic/tclStringObj.c
@@ -1371,7 +1371,7 @@ Tcl_AppendObjToObj(
if (appendObjPtr->typePtr == &tclStringType) {
Tcl_UniChar *unicode =
- Tcl_GetUnicodeFromObj(appendObjPtr, &numChars);
+ TclGetUnicodeFromObj(appendObjPtr, &numChars);
AppendUnicodeToUnicodeRep(objPtr, unicode, numChars);
} else {
@@ -2796,12 +2796,12 @@ Tcl_Obj *
TclStringRepeat(
Tcl_Interp *interp,
Tcl_Obj *objPtr,
- int count,
+ size_t count,
int flags)
{
Tcl_Obj *objResultPtr;
int inPlace = flags & TCL_STRING_IN_PLACE;
- int length = 0, unichar = 0, done = 1;
+ size_t length = 0, unichar = 0, done = 1;
int binary = TclIsPureByteArray(objPtr);
/* assert (count >= 2) */
@@ -2824,13 +2824,15 @@ TclStringRepeat(
if (binary) {
/* Result will be pure byte array. Pre-size it */
- Tcl_GetByteArrayFromObj(objPtr, &length);
+ int xxx1length;
+ Tcl_GetByteArrayFromObj(objPtr, &xxx1length);
+ length = xxx1length;
} else if (unichar) {
/* Result will be pure Tcl_UniChar array. Pre-size it. */
- Tcl_GetUnicodeFromObj(objPtr, &length);
+ TclGetUnicodeFromObj(objPtr, &length);
} else {
/* Result will be concat of string reps. Pre-size it. */
- Tcl_GetStringFromObj(objPtr, &length);
+ (void)TclGetStringFromObj(objPtr, &length);
}
if (length == 0) {
@@ -2904,7 +2906,7 @@ TclStringRepeat(
if (0 == Tcl_AttemptSetObjLength(objResultPtr, count*length)) {
if (interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "string size overflow: unable to alloc %u bytes",
+ "string size overflow: unable to alloc %" TCL_Z_MODIFIER "u bytes",
count*length));
Tcl_SetErrorCode(interp, "TCL", "MEMORY", NULL);
}
@@ -3037,15 +3039,13 @@ TclStringCat(
Tcl_Obj *objPtr = *ov++;
if ((objPtr->bytes == NULL) || (objPtr->length)) {
- int numChars;
+ size_t numChars;
- Tcl_GetUnicodeFromObj(objPtr, &numChars); /* PANIC? */
+ TclGetUnicodeFromObj(objPtr, &numChars); /* PANIC? */
if (numChars) {
last = objc - oc;
if (length == 0) {
first = last;
- } else if (numChars > INT_MAX - length) {
- goto overflow;
}
length += numChars;
}
@@ -3180,12 +3180,12 @@ TclStringCat(
Tcl_UniChar *dst;
if (inPlace && !Tcl_IsShared(*objv)) {
- int start;
+ size_t start;
objResultPtr = *objv++; objc--;
/* Ugly interface! Force resize of the unicode array. */
- Tcl_GetUnicodeFromObj(objResultPtr, &start);
+ TclGetUnicodeFromObj(objResultPtr, &start);
Tcl_InvalidateStringRep(objResultPtr);
if (0 == Tcl_AttemptSetObjLength(objResultPtr, length)) {
if (interp) {
@@ -3220,8 +3220,8 @@ TclStringCat(
Tcl_Obj *objPtr = *objv++;
if ((objPtr->bytes == NULL) || (objPtr->length)) {
- int more;
- Tcl_UniChar *src = Tcl_GetUnicodeFromObj(objPtr, &more);
+ size_t more;
+ Tcl_UniChar *src = TclGetUnicodeFromObj(objPtr, &more);
memcpy(dst, src, more * sizeof(Tcl_UniChar));
dst += more;
}
@@ -3309,10 +3309,11 @@ int TclStringCmp(
Tcl_Obj *value2Ptr,
int checkEq, /* comparison is only for equality */
int nocase, /* comparison is not case sensitive */
- int reqlength) /* requested length */
+ size_t reqlength) /* requested length */
{
char *s1, *s2;
- int empty, length, match, s1len, s2len;
+ int empty, match;
+ size_t length, s1len, s2len;
memCmpFn_t memCmpFn;
if ((reqlength == 0) || (value1Ptr == value2Ptr)) {
@@ -3324,6 +3325,7 @@ int TclStringCmp(
if (!nocase && TclIsPureByteArray(value1Ptr)
&& TclIsPureByteArray(value2Ptr)) {
+ int xxx1s1len, xxx1s2len;
/*
* Use binary versions of comparisons since that won't cause undue
* type conversions and it is much faster. Only do this if we're
@@ -3331,8 +3333,9 @@ int TclStringCmp(
* arrays anyway, and we have no memcasecmp() for some reason... :^)
*/
- s1 = (char *) Tcl_GetByteArrayFromObj(value1Ptr, &s1len);
- s2 = (char *) Tcl_GetByteArrayFromObj(value2Ptr, &s2len);
+ s1 = (char *) Tcl_GetByteArrayFromObj(value1Ptr, &xxx1s1len);
+ s2 = (char *) Tcl_GetByteArrayFromObj(value2Ptr, &xxx1s2len);
+ s1len = xxx1s1len; s2len = xxx1s2len;
memCmpFn = memcmp;
} else if ((value1Ptr->typePtr == &tclStringType)
&& (value2Ptr->typePtr == &tclStringType)) {
@@ -3344,15 +3347,15 @@ int TclStringCmp(
*/
if (nocase) {
- s1 = (char *) Tcl_GetUnicodeFromObj(value1Ptr, &s1len);
- s2 = (char *) Tcl_GetUnicodeFromObj(value2Ptr, &s2len);
+ s1 = (char *) TclGetUnicodeFromObj(value1Ptr, &s1len);
+ s2 = (char *) TclGetUnicodeFromObj(value2Ptr, &s2len);
memCmpFn = (memCmpFn_t)Tcl_UniCharNcasecmp;
} else {
s1len = Tcl_GetCharLength(value1Ptr);
s2len = Tcl_GetCharLength(value2Ptr);
- if ((s1len == (int)value1Ptr->length)
+ if ((s1len == value1Ptr->length)
&& (value1Ptr->bytes != NULL)
- && (s2len == (int)value2Ptr->length)
+ && (s2len == value2Ptr->length)
&& (value2Ptr->bytes != NULL)) {
s1 = value1Ptr->bytes;
s2 = value2Ptr->bytes;
@@ -3427,7 +3430,7 @@ int TclStringCmp(
* length was requested.
*/
- if ((reqlength < 0) && !nocase) {
+ if ((reqlength == (size_t)-1) && !nocase) {
memCmpFn = (memCmpFn_t) TclpUtfNcmp2;
} else {
s1len = Tcl_NumUtfChars(s1, s1len);
@@ -3439,15 +3442,15 @@ int TclStringCmp(
}
length = (s1len < s2len) ? s1len : s2len;
- if (reqlength > 0 && reqlength < length) {
- length = reqlength;
- } else if (reqlength < 0) {
+ if (reqlength == (size_t)-1) {
/*
* The requested length is negative, so we ignore it by setting it
* to length + 1 so we correct the match var.
*/
reqlength = length + 1;
+ } else if (reqlength > 0 && reqlength < length) {
+ length = reqlength;
}
if (checkEq && (s1len != s2len)) {
@@ -3479,7 +3482,7 @@ int TclStringCmp(
* Results:
* If needle is found as a substring of haystack, the index of the
* first instance of such a find is returned. If needle is not present
- * as a substring of haystack, -1 is returned.
+ * as a substring of haystack, (size_t)-1 is returned.
*
* Side effects:
* needle and haystack may have their Tcl_ObjType changed.
@@ -3487,15 +3490,15 @@ int TclStringCmp(
*---------------------------------------------------------------------------
*/
-int
+size_t
TclStringFirst(
Tcl_Obj *needle,
Tcl_Obj *haystack,
- int start)
+ size_t start)
{
- int lh, ln = Tcl_GetCharLength(needle);
+ size_t lh, ln = Tcl_GetCharLength(needle);
- if (start < 0) {
+ if (start == (size_t)-1) {
start = 0;
}
if (ln == 0) {
@@ -3507,10 +3510,13 @@ TclStringFirst(
if (TclIsPureByteArray(needle) && TclIsPureByteArray(haystack)) {
unsigned char *end, *try, *bh;
- unsigned char *bn = Tcl_GetByteArrayFromObj(needle, &ln);
+ int xxx1ln, xxx1lh;
+ unsigned char *bn = Tcl_GetByteArrayFromObj(needle, &xxx1ln);
+ ln = xxx1ln;
/* Find bytes in bytes */
- bh = Tcl_GetByteArrayFromObj(haystack, &lh);
+ bh = Tcl_GetByteArrayFromObj(haystack, &xxx1lh);
+ lh = xxx1lh;
end = bh + lh;
try = bh + start;
@@ -3550,9 +3556,9 @@ TclStringFirst(
{
Tcl_UniChar *try, *end, *uh;
- Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln);
+ Tcl_UniChar *un = TclGetUnicodeFromObj(needle, &ln);
- uh = Tcl_GetUnicodeFromObj(haystack, &lh);
+ uh = TclGetUnicodeFromObj(haystack, &lh);
end = uh + lh;
for (try = uh + start; try + ln <= end; try++) {
@@ -3583,13 +3589,13 @@ TclStringFirst(
*---------------------------------------------------------------------------
*/
-int
+size_t
TclStringLast(
Tcl_Obj *needle,
Tcl_Obj *haystack,
- int last)
+ size_t last)
{
- int lh, ln = Tcl_GetCharLength(needle);
+ size_t lh, ln = Tcl_GetCharLength(needle);
if (ln == 0) {
/*
@@ -3598,7 +3604,7 @@ TclStringLast(
* TODO: When we one day make this a true substring
* finder, change this to "return last", after limitation.
*/
- return -1;
+ return (size_t)-1;
}
lh = Tcl_GetCharLength(haystack);
@@ -3607,12 +3613,14 @@ TclStringLast(
}
if (last < ln - 1) {
- return -1;
+ return (size_t)-1;
}
if (TclIsPureByteArray(needle) && TclIsPureByteArray(haystack)) {
- unsigned char *try, *bh = Tcl_GetByteArrayFromObj(haystack, &lh);
- unsigned char *bn = Tcl_GetByteArrayFromObj(needle, &ln);
+ int xxx1lh, xxx1ln;
+ unsigned char *try, *bh = Tcl_GetByteArrayFromObj(haystack, &xxx1lh);
+ unsigned char *bn = Tcl_GetByteArrayFromObj(needle, &xxx1ln);
+ lh = xxx1lh; ln = xxx1ln;
try = bh + last + 1 - ln;
while (try >= bh) {
@@ -3626,8 +3634,8 @@ TclStringLast(
}
{
- Tcl_UniChar *try, *uh = Tcl_GetUnicodeFromObj(haystack, &lh);
- Tcl_UniChar *un = Tcl_GetUnicodeFromObj(needle, &ln);
+ Tcl_UniChar *try, *uh = TclGetUnicodeFromObj(haystack, &lh);
+ Tcl_UniChar *un = TclGetUnicodeFromObj(needle, &ln);
try = uh + last + 1 - ln;
while (try >= uh) {
@@ -3817,18 +3825,14 @@ Tcl_Obj *
TclStringReplace(
Tcl_Interp *interp, /* For error reporting, may be NULL */
Tcl_Obj *objPtr, /* String to act upon */
- int first, /* First index to replace */
- int count, /* How many chars to replace */
+ size_t first, /* First index to replace */
+ size_t count, /* How many chars to replace */
Tcl_Obj *insertPtr, /* Replacement string, may be NULL */
int flags) /* TCL_STRING_IN_PLACE => attempt in-place */
{
int inPlace = flags & TCL_STRING_IN_PLACE;
Tcl_Obj *result;
- /* Caller is expected to pass sensible arguments */
- assert ( count >= 0 ) ;
- assert ( first >= 0 ) ;
-
/* Replace nothing with nothing */
if ((insertPtr == NULL) && (count == 0)) {
if (inPlace) {
@@ -3864,7 +3868,7 @@ TclStringReplace(
}
/* Replace everything */
- if ((first == 0) && (count == numBytes)) {
+ if ((first == 0) && (count == (size_t)numBytes)) {
return insertPtr;
}
@@ -3873,7 +3877,7 @@ TclStringReplace(
unsigned char *iBytes
= Tcl_GetByteArrayFromObj(insertPtr, &newBytes);
- if (count == newBytes && inPlace && !Tcl_IsShared(objPtr)) {
+ if (count == (size_t)newBytes && inPlace && !Tcl_IsShared(objPtr)) {
/*
* Removal count and replacement count are equal.
* Other conditions permit. Do in-place splice.
@@ -3884,7 +3888,7 @@ TclStringReplace(
return objPtr;
}
- if (newBytes > INT_MAX - (numBytes - count)) {
+ if ((size_t)newBytes > INT_MAX - (numBytes - count)) {
if (interp) {
Tcl_SetObjResult(interp, Tcl_ObjPrintf(
"max size for a Tcl value (%d bytes) exceeded",
@@ -3914,8 +3918,8 @@ TclStringReplace(
/* The traditional implementation... */
{
- int numChars;
- Tcl_UniChar *ustring = Tcl_GetUnicodeFromObj(objPtr, &numChars);
+ size_t numChars;
+ Tcl_UniChar *ustring = TclGetUnicodeFromObj(objPtr, &numChars);
/* TODO: Is there an in-place option worth pursuing here? */
@@ -3923,7 +3927,7 @@ TclStringReplace(
if (insertPtr) {
Tcl_AppendObjToObj(result, insertPtr);
}
- if (first + count < numChars) {
+ if (first + count < (size_t)numChars) {
Tcl_AppendUnicodeToObj(result, ustring + first + count,
numChars - first - count);
}
diff --git a/generic/tclUtil.c b/generic/tclUtil.c
index 099bd63..d9d2896 100644
--- a/generic/tclUtil.c
+++ b/generic/tclUtil.c
@@ -2391,11 +2391,11 @@ Tcl_StringCaseMatch(
int
TclByteArrayMatch(
const unsigned char *string,/* String. */
- int strLen, /* Length of String */
+ size_t strLen, /* Length of String */
const unsigned char *pattern,
/* Pattern, which may contain special
* characters. */
- int ptnLen, /* Length of Pattern */
+ size_t ptnLen, /* Length of Pattern */
int flags)
{
const unsigned char *stringEnd, *patternEnd;
@@ -2572,7 +2572,8 @@ TclStringMatchObj(
int flags) /* Only TCL_MATCH_NOCASE should be passed, or
* 0. */
{
- int match, length, plen;
+ int match;
+ size_t length, plen;
/*
* Promote based on the type of incoming object.
@@ -2584,15 +2585,17 @@ TclStringMatchObj(
if ((strObj->typePtr == &tclStringType) || (strObj->typePtr == NULL)) {
Tcl_UniChar *udata, *uptn;
- udata = Tcl_GetUnicodeFromObj(strObj, &length);
- uptn = Tcl_GetUnicodeFromObj(ptnObj, &plen);
+ udata = TclGetUnicodeFromObj(strObj, &length);
+ uptn = TclGetUnicodeFromObj(ptnObj, &plen);
match = TclUniCharMatch(udata, length, uptn, plen, flags);
} else if (TclIsPureByteArray(strObj) && TclIsPureByteArray(ptnObj)
&& !flags) {
unsigned char *data, *ptn;
+ int xxx1length, xxx1plen;
- data = Tcl_GetByteArrayFromObj(strObj, &length);
- ptn = Tcl_GetByteArrayFromObj(ptnObj, &plen);
+ data = Tcl_GetByteArrayFromObj(strObj, &xxx1length);
+ ptn = Tcl_GetByteArrayFromObj(ptnObj, &xxx1plen);
+ length = xxx1length; plen = xxx1plen;
match = TclByteArrayMatch(data, length, ptn, plen, 0);
} else {
match = Tcl_StringCaseMatch(TclGetString(strObj),
@@ -2776,7 +2779,7 @@ Tcl_DStringAppendElement(
if (dsPtr->string == dsPtr->staticSpace) {
char *newString = ckalloc(dsPtr->spaceAvl);
- memcpy(newString, dsPtr->string, (size_t) dsPtr->length);
+ memcpy(newString, dsPtr->string, dsPtr->length);
dsPtr->string = newString;
} else {
int offset = -1;
@@ -3521,7 +3524,7 @@ GetEndOffsetFromObj(
/* TODO: Handle overflow cases sensibly */
*indexPtr = endValue + (int)objPtr->internalRep.wideValue;
- if ((*indexPtr < -1) && (endValue > 0)) *indexPtr = -1;
+ if ((*indexPtr < -1) && (endValue > 0)) *indexPtr = -1;
return TCL_OK;
}
diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c
index c4f7991..6af83c5 100644
--- a/unix/tclUnixInit.c
+++ b/unix/tclUnixInit.c
@@ -981,7 +981,7 @@ TclpSetVariables(
*
* Results:
* The return value is the index in environ of an entry with the name
- * "name", or -1 if there is no such entry. The integer at *lengthPtr is
+ * "name", or (size_t)-1 if there is no such entry. The integer at *lengthPtr is
* filled in with the length of name (if a matching entry is found) or
* the length of the environ array (if no matching entry is found).
*
@@ -991,16 +991,16 @@ TclpSetVariables(
*----------------------------------------------------------------------
*/
-int
+size_t
TclpFindVariable(
const char *name, /* Name of desired environment variable
* (native). */
- int *lengthPtr) /* Used to return length of name (for
+ size_t *lengthPtr) /* Used to return length of name (for
* successful searches) or number of non-NULL
* entries in environ (for unsuccessful
* searches). */
{
- int i, result = -1;
+ size_t i, result = (size_t)-1;
register const char *env, *p1, *p2;
Tcl_DString envString;