diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-06-29 18:13:10 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-06-29 18:13:10 (GMT) |
commit | 709f9278ffe0739b8bc246247ff82868eff8b467 (patch) | |
tree | b881f1fa5dc17fc4dd92405184b0528058742ecf | |
parent | 5248fb06510fd1e34b13f7c4a69404ab926cf2be (diff) | |
download | tcl-709f9278ffe0739b8bc246247ff82868eff8b467.zip tcl-709f9278ffe0739b8bc246247ff82868eff8b467.tar.gz tcl-709f9278ffe0739b8bc246247ff82868eff8b467.tar.bz2 |
Improve many parsing-related functions to use size_t
-rw-r--r-- | generic/tclCompCmdsSZ.c | 2 | ||||
-rw-r--r-- | generic/tclCompExpr.c | 17 | ||||
-rw-r--r-- | generic/tclCompile.c | 32 | ||||
-rw-r--r-- | generic/tclCompile.h | 20 | ||||
-rw-r--r-- | generic/tclEncoding.c | 34 | ||||
-rw-r--r-- | generic/tclExecute.c | 9 | ||||
-rw-r--r-- | generic/tclIO.c | 54 | ||||
-rw-r--r-- | generic/tclInt.decls | 2 | ||||
-rw-r--r-- | generic/tclInt.h | 16 | ||||
-rw-r--r-- | generic/tclIntDecls.h | 4 | ||||
-rw-r--r-- | generic/tclParse.c | 42 | ||||
-rw-r--r-- | generic/tclUtil.c | 14 |
12 files changed, 118 insertions, 128 deletions
diff --git a/generic/tclCompCmdsSZ.c b/generic/tclCompCmdsSZ.c index 38839fd..b7dd7e5 100644 --- a/generic/tclCompCmdsSZ.c +++ b/generic/tclCompCmdsSZ.c @@ -1465,7 +1465,7 @@ void TclSubstCompile( Tcl_Interp *interp, const char *bytes, - int numBytes, + size_t numBytes, int flags, int line, CompileEnv *envPtr) diff --git a/generic/tclCompExpr.c b/generic/tclCompExpr.c index f26f7fb..b894863 100644 --- a/generic/tclCompExpr.c +++ b/generic/tclCompExpr.c @@ -510,7 +510,7 @@ static int ParseExpr(Tcl_Interp *interp, const char *start, int numBytes, OpNode **opTreePtr, Tcl_Obj *litList, Tcl_Obj *funcList, Tcl_Parse *parsePtr, int parseOnly); -static int ParseLexeme(const char *start, int numBytes, +static size_t ParseLexeme(const char *start, size_t numBytes, unsigned char *lexemePtr, Tcl_Obj **literalPtr); /* @@ -1819,7 +1819,7 @@ int Tcl_ParseExpr( Tcl_Interp *interp, /* Used for error reporting. */ const char *start, /* Start of source string to parse. */ - size_t xxx1, /* Number of bytes in string. If < 0, the + size_t numBytes, /* Number of bytes in string. If (size_t)-1, the * string consists of all bytes up to the * first null character. */ Tcl_Parse *parsePtr) /* Structure to fill with information about @@ -1827,14 +1827,13 @@ Tcl_ParseExpr( * information in the structure is ignored. */ { int code; - int numBytes = xxx1; OpNode *opTree = NULL; /* Will point to the tree of operators. */ Tcl_Obj *litList = Tcl_NewObj(); /* List to hold the literals. */ Tcl_Obj *funcList = Tcl_NewObj(); /* List to hold the functon names. */ Tcl_Parse *exprParsePtr = TclStackAlloc(interp, sizeof(Tcl_Parse)); /* Holds the Tcl_Tokens of substitutions. */ - if (numBytes < 0) { + if (numBytes == (size_t)-1) { numBytes = (start ? strlen(start) : 0); } @@ -1875,17 +1874,16 @@ Tcl_ParseExpr( *---------------------------------------------------------------------- */ -static int +static size_t ParseLexeme( const char *start, /* Start of lexeme to parse. */ - int numBytes, /* Number of bytes in string. */ + size_t numBytes, /* Number of bytes in string. */ unsigned char *lexemePtr, /* Write code of parsed lexeme to this * storage. */ Tcl_Obj **literalPtr) /* Write corresponding literal value to this storage, if non-NULL. */ { const char *end; - int scanned; Tcl_UniChar ch = 0; Tcl_Obj *literal = NULL; unsigned char byte; @@ -2064,12 +2062,13 @@ ParseLexeme( */ if (!TclIsBareword(*start) || *start == '_') { + size_t scanned; if (Tcl_UtfCharComplete(start, numBytes)) { scanned = TclUtfToUniChar(start, &ch); } else { char utfBytes[TCL_UTF_MAX]; - memcpy(utfBytes, start, (size_t) numBytes); + memcpy(utfBytes, start, numBytes); utfBytes[numBytes] = '\0'; scanned = TclUtfToUniChar(utfBytes, &ch); } @@ -2113,7 +2112,7 @@ void TclCompileExpr( Tcl_Interp *interp, /* Used for error reporting. */ const char *script, /* The source script to compile. */ - int numBytes, /* Number of bytes in script. */ + size_t numBytes, /* Number of bytes in script. */ CompileEnv *envPtr, /* Holds resulting instructions. */ int optimize) /* 0 for one-off expressions. */ { diff --git a/generic/tclCompile.c b/generic/tclCompile.c index b7d6433..a73060c 100644 --- a/generic/tclCompile.c +++ b/generic/tclCompile.c @@ -1302,8 +1302,8 @@ CompileSubstObj( } if (objPtr->typePtr != &substCodeType) { CompileEnv compEnv; - int numBytes; - const char *bytes = TclGetStringFromObj(objPtr, &numBytes); + const char *bytes = TclGetString(objPtr); + int numBytes = objPtr->length; /* TODO: Check for more TIP 280 */ TclInitCompileEnv(interp, &compEnv, bytes, numBytes, NULL, 0); @@ -1403,7 +1403,7 @@ TclInitCompileEnv( register CompileEnv *envPtr,/* Points to the CompileEnv structure to * initialize. */ const char *stringPtr, /* The source string to be compiled. */ - int numBytes, /* Number of bytes in source string. */ + size_t numBytes, /* Number of bytes in source string. */ const CmdFrame *invoker, /* Location context invoking the bcc */ int word) /* Index of the word in that context getting * compiled */ @@ -1780,7 +1780,6 @@ CompileCmdLiteral( Tcl_Obj *cmdObj, CompileEnv *envPtr) { - int numBytes; const char *bytes; Command *cmdPtr; int cmdLitIdx, extraLiteralFlags = LITERAL_CMD_NAME; @@ -1790,8 +1789,8 @@ CompileCmdLiteral( extraLiteralFlags |= LITERAL_UNSHARED; } - bytes = TclGetStringFromObj(cmdObj, &numBytes); - cmdLitIdx = TclRegisterLiteral(envPtr, bytes, numBytes, extraLiteralFlags); + bytes = TclGetString(cmdObj); + cmdLitIdx = TclRegisterLiteral(envPtr, bytes, cmdObj->length, extraLiteralFlags); if (cmdPtr) { TclSetCmdNameObj(interp, TclFetchLiteral(envPtr, cmdLitIdx), cmdPtr); @@ -2105,7 +2104,7 @@ TclCompileScript( * serves as context for finding and compiling * commands. May not be NULL. */ const char *script, /* The source script to compile. */ - int numBytes, /* Number of bytes in script. If < 0, the + size_t numBytes, /* Number of bytes in script. If (size_t)-1, the * script consists of all bytes up to the * first null character. */ CompileEnv *envPtr) /* Holds resulting instructions. */ @@ -2123,7 +2122,7 @@ TclCompileScript( /* Each iteration compiles one command from the script. */ - while (numBytes > 0) { + while (numBytes + 1 > 1) { Tcl_Parse parse; const char *next; @@ -2333,7 +2332,8 @@ TclCompileTokens( Tcl_DString textBuffer; /* Holds concatenated chars from adjacent * TCL_TOKEN_TEXT, TCL_TOKEN_BS tokens. */ char buffer[TCL_UTF_MAX]; - int i, numObjsToConcat, length, adjust; + int i, numObjsToConcat, adjust; + size_t length; unsigned char *entryCodeNext = envPtr->codeNext; #define NUM_STATIC_POS 20 int isLiteral, maxNumCL, numCL; @@ -2725,8 +2725,8 @@ PreventCycle( * can be sure we do not have any lingering cycles hiding in * the intrep. */ - int numBytes; - const char *bytes = TclGetStringFromObj(objPtr, &numBytes); + const char *bytes = TclGetString(objPtr); + size_t numBytes = objPtr->length; Tcl_Obj *copyPtr = Tcl_NewStringObj(bytes, numBytes); Tcl_IncrRefCount(copyPtr); @@ -2930,7 +2930,7 @@ TclFindCompiledLocal( register const char *name, /* Points to first character of the name of a * scalar or array variable. If NULL, a * temporary var should be created. */ - int nameBytes, /* Number of bytes in the name. */ + size_t nameBytes, /* Number of bytes in the name. */ int create, /* If 1, allocate a local frame entry for the * variable if it is new. */ CompileEnv *envPtr) /* Points to the current compile environment*/ @@ -2956,7 +2956,7 @@ TclFindCompiledLocal( LocalCache *cachePtr = envPtr->iPtr->varFramePtr->localCachePtr; const char *localName; Tcl_Obj **varNamePtr; - int len; + size_t len; if (!cachePtr || !name) { return -1; @@ -2983,8 +2983,8 @@ TclFindCompiledLocal( if (!TclIsVarTemporary(localPtr)) { char *localName = localPtr->name; - if ((nameBytes == localPtr->nameLength) && - (strncmp(name,localName,(unsigned)nameBytes) == 0)) { + if ((nameBytes == (size_t)localPtr->nameLength) && + (strncmp(name,localName,nameBytes) == 0)) { return i; } } @@ -3927,7 +3927,7 @@ TclFixupForwardJump( { unsigned char *jumpPc, *p; int firstCmd, lastCmd, firstRange, lastRange, k; - unsigned numBytes; + size_t numBytes; if (jumpDist <= distThreshold) { jumpPc = envPtr->codeStart + jumpFixupPtr->codeOffset; diff --git a/generic/tclCompile.h b/generic/tclCompile.h index ea97fa6..838afcb 100644 --- a/generic/tclCompile.h +++ b/generic/tclCompile.h @@ -181,7 +181,7 @@ typedef struct { */ typedef struct { - int srcOffset; /* Command location to find the entry. */ + size_t srcOffset; /* Command location to find the entry. */ int nline; /* Number of words in the command */ int *line; /* Line information for all words in the * command. */ @@ -842,7 +842,7 @@ typedef enum InstOperandType { typedef struct InstructionDesc { const char *name; /* Name of instruction. */ - int numBytes; /* Total number of bytes for instruction. */ + size_t numBytes; /* Total number of bytes for instruction. */ int stackEffect; /* The worst-case balance stack effect of the * instruction, used for stack requirements * computations. The value INT_MIN signals @@ -1000,7 +1000,7 @@ MODULE_SCOPE const AuxDataType tclJumptableInfoType; */ typedef struct { - size_t length; /* Size of array */ + size_t length; /* Size of array */ int varIndices[1]; /* Array of variable indices to manage when * processing the start and end of a [dict * update]. There is really more than one @@ -1055,7 +1055,7 @@ MODULE_SCOPE void TclCompileCmdWord(Tcl_Interp *interp, Tcl_Token *tokenPtr, int count, CompileEnv *envPtr); MODULE_SCOPE void TclCompileExpr(Tcl_Interp *interp, const char *script, - int numBytes, CompileEnv *envPtr, int optimize); + size_t numBytes, CompileEnv *envPtr, int optimize); MODULE_SCOPE void TclCompileExprWords(Tcl_Interp *interp, Tcl_Token *tokenPtr, int numWords, CompileEnv *envPtr); @@ -1063,7 +1063,7 @@ MODULE_SCOPE void TclCompileInvocation(Tcl_Interp *interp, Tcl_Token *tokenPtr, Tcl_Obj *cmdObj, int numWords, CompileEnv *envPtr); MODULE_SCOPE void TclCompileScript(Tcl_Interp *interp, - const char *script, int numBytes, + const char *script, size_t numBytes, CompileEnv *envPtr); MODULE_SCOPE void TclCompileSyntaxError(Tcl_Interp *interp, CompileEnv *envPtr); @@ -1076,7 +1076,7 @@ MODULE_SCOPE int TclCreateAuxData(void *clientData, const AuxDataType *typePtr, CompileEnv *envPtr); MODULE_SCOPE int TclCreateExceptRange(ExceptionRangeType type, CompileEnv *envPtr); -MODULE_SCOPE ExecEnv * TclCreateExecEnv(Tcl_Interp *interp, int size); +MODULE_SCOPE ExecEnv * TclCreateExecEnv(Tcl_Interp *interp, size_t size); MODULE_SCOPE Tcl_Obj * TclCreateLiteral(Interp *iPtr, const char *bytes, size_t length, size_t hash, int *newPtr, Namespace *nsPtr, int flags, @@ -1093,7 +1093,7 @@ MODULE_SCOPE void TclExpandJumpFixupArray(JumpFixupArray *fixupArrayPtr); MODULE_SCOPE int TclNRExecuteByteCode(Tcl_Interp *interp, ByteCode *codePtr); MODULE_SCOPE Tcl_Obj * TclFetchLiteral(CompileEnv *envPtr, size_t index); -MODULE_SCOPE int TclFindCompiledLocal(const char *name, int nameChars, +MODULE_SCOPE int TclFindCompiledLocal(const char *name, size_t nameChars, int create, CompileEnv *envPtr); MODULE_SCOPE int TclFixupForwardJump(CompileEnv *envPtr, JumpFixup *jumpFixupPtr, int jumpDist, @@ -1107,7 +1107,7 @@ MODULE_SCOPE ByteCode * TclInitByteCodeObj(Tcl_Obj *objPtr, const Tcl_ObjType *typePtr, CompileEnv *envPtr); MODULE_SCOPE void TclInitCompileEnv(Tcl_Interp *interp, CompileEnv *envPtr, const char *string, - int numBytes, const CmdFrame *invoker, int word); + size_t numBytes, const CmdFrame *invoker, int word); MODULE_SCOPE void TclInitJumpFixupArray(JumpFixupArray *fixupArrayPtr); MODULE_SCOPE void TclInitLiteralTable(LiteralTable *tablePtr); MODULE_SCOPE ExceptionRange *TclGetInnermostExceptionRange(CompileEnv *envPtr, @@ -1134,9 +1134,9 @@ MODULE_SCOPE void TclPrintByteCodeObj(Tcl_Interp *interp, MODULE_SCOPE int TclPrintInstruction(ByteCode *codePtr, const unsigned char *pc); MODULE_SCOPE void TclPrintObject(FILE *outFile, - Tcl_Obj *objPtr, int maxChars); + Tcl_Obj *objPtr, size_t maxChars); MODULE_SCOPE void TclPrintSource(FILE *outFile, - const char *string, int maxChars); + const char *string, size_t maxChars); MODULE_SCOPE void TclPushVarName(Tcl_Interp *interp, Tcl_Token *varTokenPtr, CompileEnv *envPtr, int flags, int *localIndexPtr, diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 4c57837..51c7094 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -1048,16 +1048,16 @@ Tcl_ExternalToUtfDString( Tcl_Encoding encoding, /* The encoding for the source string, or NULL * for the default system encoding. */ const char *src, /* Source string in specified encoding. */ - size_t xxx1, /* Source string length in bytes, or (size_t)-1 for + size_t srcLen, /* Source string length in bytes, or (size_t)-1 for * encoding-specific string length. */ Tcl_DString *dstPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { char *dst; - int srcLen = xxx1; Tcl_EncodingState state; const Encoding *encodingPtr; - int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars; + int flags, result, soFar, srcRead, dstWrote, dstChars; + size_t dstLen; Tcl_DStringInit(dstPtr); dst = Tcl_DStringValue(dstPtr); @@ -1070,7 +1070,7 @@ Tcl_ExternalToUtfDString( if (src == NULL) { srcLen = 0; - } else if (srcLen < 0) { + } else if (srcLen == (size_t)-1) { srcLen = encodingPtr->lengthProc(src); } @@ -1122,8 +1122,8 @@ Tcl_ExternalToUtf( Tcl_Encoding encoding, /* The encoding for the source string, or NULL * for the default system encoding. */ const char *src, /* Source string in specified encoding. */ - size_t xxx1, /* Source string length in bytes, or < 0 for - * encoding-specific string length. */ + size_t srcLen, /* Source string length in bytes, or (size_t)-1 + * for encoding-specific string length. */ int flags, /* Conversion control flags. */ Tcl_EncodingState *statePtr,/* Place for conversion routine to store state * information used during a piecewise @@ -1132,7 +1132,7 @@ Tcl_ExternalToUtf( * routine under control of flags argument. */ char *dst, /* Output buffer in which converted string is * stored. */ - size_t xxx11, /* The maximum length of output buffer in + size_t dstLen, /* The maximum length of output buffer in * bytes. */ int *srcReadPtr, /* Filled with the number of bytes from the * source string that were converted. This may @@ -1147,7 +1147,6 @@ Tcl_ExternalToUtf( * output buffer. */ { const Encoding *encodingPtr; - int srcLen = xxx1, dstLen = xxx11; int result, srcRead, dstWrote, dstChars = 0; int noTerminate = flags & TCL_ENCODING_NO_TERMINATE; int charLimited = (flags & TCL_ENCODING_CHAR_LIMIT) && dstCharsPtr; @@ -1161,7 +1160,7 @@ Tcl_ExternalToUtf( if (src == NULL) { srcLen = 0; - } else if (srcLen < 0) { + } else if (srcLen == (size_t)-1) { srcLen = encodingPtr->lengthProc(src); } if (statePtr == NULL) { @@ -1240,16 +1239,16 @@ Tcl_UtfToExternalDString( Tcl_Encoding encoding, /* The encoding for the converted string, or * NULL for the default system encoding. */ const char *src, /* Source string in UTF-8. */ - size_t xxx1, /* Source string length in bytes, or (size_t)-1 for + size_t srcLen, /* Source string length in bytes, or (size_t)-1 for * strlen(). */ Tcl_DString *dstPtr) /* Uninitialized or free DString in which the * converted string is stored. */ { char *dst; - int srcLen = xxx1; Tcl_EncodingState state; const Encoding *encodingPtr; - int flags, dstLen, result, soFar, srcRead, dstWrote, dstChars; + int flags, result, soFar, srcRead, dstWrote, dstChars; + size_t dstLen; Tcl_DStringInit(dstPtr); dst = Tcl_DStringValue(dstPtr); @@ -1262,7 +1261,7 @@ Tcl_UtfToExternalDString( if (src == NULL) { srcLen = 0; - } else if (srcLen < 0) { + } else if (srcLen == (size_t)-1) { srcLen = strlen(src); } flags = TCL_ENCODING_START | TCL_ENCODING_END; @@ -1316,8 +1315,8 @@ Tcl_UtfToExternal( Tcl_Encoding encoding, /* The encoding for the converted string, or * NULL for the default system encoding. */ const char *src, /* Source string in UTF-8. */ - size_t xxx1, /* Source string length in bytes, or < 0 for - * strlen(). */ + size_t srcLen, /* Source string length in bytes, or (size_t)-1 + * for strlen(). */ int flags, /* Conversion control flags. */ Tcl_EncodingState *statePtr,/* Place for conversion routine to store state * information used during a piecewise @@ -1326,7 +1325,7 @@ Tcl_UtfToExternal( * routine under control of flags argument. */ char *dst, /* Output buffer in which converted string * is stored. */ - size_t xxx11, /* The maximum length of output buffer in + size_t dstLen, /* The maximum length of output buffer in * bytes. */ int *srcReadPtr, /* Filled with the number of bytes from the * source string that were converted. This may @@ -1341,7 +1340,6 @@ Tcl_UtfToExternal( * output buffer. */ { const Encoding *encodingPtr; - int srcLen = xxx1, dstLen = xxx11; int result, srcRead, dstWrote, dstChars; Tcl_EncodingState state; @@ -1352,7 +1350,7 @@ Tcl_UtfToExternal( if (src == NULL) { srcLen = 0; - } else if (srcLen < 0) { + } else if (srcLen == (size_t)-1) { srcLen = strlen(src); } if (statePtr == NULL) { diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 9453996..358db5b 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -770,7 +770,7 @@ ExecEnv * TclCreateExecEnv( Tcl_Interp *interp, /* Interpreter for which the execution * environment is being created. */ - int size) /* The initial stack size, in number of words + size_t size) /* The initial stack size, in number of words * [sizeof(Tcl_Obj*)] */ { ExecEnv *eePtr = ckalloc(sizeof(ExecEnv)); @@ -1200,7 +1200,7 @@ TclStackFree( void * TclStackAlloc( Tcl_Interp *interp, - int numBytes) + size_t numBytes) { Interp *iPtr = (Interp *) interp; int numWords; @@ -1216,7 +1216,7 @@ void * TclStackRealloc( Tcl_Interp *interp, void *ptr, - int numBytes) + size_t numBytes) { Interp *iPtr = (Interp *) interp; ExecEnv *eePtr; @@ -8859,7 +8859,8 @@ TclGetSrcInfoForPc( ExtCmdLoc *eclPtr; ECL *locPtr = NULL; - int srcOffset, i; + size_t srcOffset; + int i; Interp *iPtr = (Interp *) *codePtr->interpHandle; Tcl_HashEntry *hePtr = Tcl_FindHashEntry(iPtr->lineBCPtr, codePtr); diff --git a/generic/tclIO.c b/generic/tclIO.c index 0b99c76..17f7469 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4042,20 +4042,20 @@ int Tcl_WriteRaw( Tcl_Channel chan, /* The channel to buffer output for. */ const char *src, /* Data to queue in output buffer. */ - size_t xxx1) /* Length of data in bytes, or (size_t)-1 for + size_t srcLen) /* Length of data in bytes, or (size_t)-1 for * strlen(). */ { Channel *chanPtr = ((Channel *) chan); - int srcLen = xxx1; ChannelState *statePtr = chanPtr->state; /* State info for channel */ - int errorCode, written; + int errorCode; + size_t written; if (CheckChannelErrors(statePtr, TCL_WRITABLE | CHANNEL_RAW_MODE) != 0) { return -1; } - if (srcLen < 0) { + if (srcLen == (size_t)-1) { srcLen = strlen(src); } @@ -4065,7 +4065,7 @@ Tcl_WriteRaw( */ written = ChanWrite(chanPtr, src, srcLen, &errorCode); - if (written < 0) { + if (written == (size_t)-1) { Tcl_SetErrno(errorCode); } @@ -4100,22 +4100,21 @@ Tcl_WriteChars( Tcl_Channel chan, /* The channel to buffer output for. */ const char *src, /* UTF-8 characters to queue in output * buffer. */ - size_t xxx1) /* Length of string in bytes, or (size_t)-1 for + size_t len) /* Length of string in bytes, or (size_t)-1 for * strlen(). */ { Channel *chanPtr = (Channel *) chan; - int len = xxx1; ChannelState *statePtr = chanPtr->state; /* State info for channel */ - int result; + int result, len1; Tcl_Obj *objPtr; if (CheckChannelErrors(statePtr, TCL_WRITABLE) != 0) { - return -1; + return (size_t)-1; } chanPtr = statePtr->topChanPtr; - if (len < 0) { + if (len == (size_t)-1) { len = strlen(src); } if (statePtr->encoding) { @@ -4134,8 +4133,8 @@ Tcl_WriteChars( } objPtr = Tcl_NewStringObj(src, len); - src = (char *) Tcl_GetByteArrayFromObj(objPtr, &len); - result = WriteBytes(chanPtr, src, len); + src = (char *) Tcl_GetByteArrayFromObj(objPtr, &len1); + result = WriteBytes(chanPtr, src, len1); TclDecrRefCount(objPtr); return result; } @@ -5618,10 +5617,9 @@ int Tcl_ReadRaw( Tcl_Channel chan, /* The channel from which to read. */ char *readBuf, /* Where to store input read. */ - size_t xxx1) /* Maximum number of bytes to read. */ + size_t bytesToRead) /* Maximum number of bytes to read. */ { Channel *chanPtr = (Channel *) chan; - int bytesToRead = xxx1; ChannelState *statePtr = chanPtr->state; /* State info for channel */ int copied = 0; @@ -5638,8 +5636,8 @@ Tcl_ReadRaw( while (chanPtr->inQueueHead && bytesToRead > 0) { ChannelBuffer *bufPtr = chanPtr->inQueueHead; int bytesInBuffer = BytesLeft(bufPtr); - int toCopy = (bytesInBuffer < bytesToRead) ? bytesInBuffer - : bytesToRead; + int toCopy = (bytesInBuffer < (int)bytesToRead) ? bytesInBuffer + : (int)bytesToRead; /* * Copy the current chunk into the read buffer. @@ -5682,13 +5680,7 @@ Tcl_ReadRaw( if (bytesToRead > 0) { int nread = ChanRead(chanPtr, readBuf, bytesToRead); - if (nread > 0) { - /* - * Successful read (short is OK) - add to bytes copied. - */ - - copied += nread; - } else if (nread < 0) { + if (nread == -1) { /* * An error signaled. If CHANNEL_BLOCKED, then the error is not * real, but an indication of blocked state. In that case, retain @@ -5702,6 +5694,12 @@ Tcl_ReadRaw( if (!GotFlag(statePtr, CHANNEL_BLOCKED) || copied == 0) { copied = -1; } + } else if (nread > 0) { + /* + * Successful read (short is OK) - add to bytes copied. + */ + + copied += nread; } else { /* * nread == 0. Driver is at EOF. Let that state filter up. @@ -5737,7 +5735,7 @@ int Tcl_ReadChars( Tcl_Channel chan, /* The channel to read. */ Tcl_Obj *objPtr, /* Input data is stored in this object. */ - size_t xxx1, /* Maximum number of characters to store, or + size_t toRead, /* Maximum number of characters to store, or * (size_t)-1 to read all available data (up to EOF or * when channel blocks). */ int appendFlag) /* If non-zero, data read from the channel @@ -5746,7 +5744,6 @@ Tcl_ReadChars( * of the object. */ { Channel *chanPtr = (Channel *) chan; - int toRead = xxx1; ChannelState *statePtr = chanPtr->state; /* State info for channel */ @@ -6616,7 +6613,7 @@ size_t Tcl_Ungets( Tcl_Channel chan, /* The channel for which to add the input. */ const char *str, /* The input itself. */ - size_t xxx1, /* The length of the input. */ + size_t len, /* The length of the input. */ int atEnd) /* If non-zero, add at end of queue; otherwise * add at head of queue. */ { @@ -6624,7 +6621,6 @@ Tcl_Ungets( ChannelState *statePtr; /* State of actual channel. */ ChannelBuffer *bufPtr; /* Buffer to contain the data. */ int flags; - int len = xxx1; chanPtr = (Channel *) chan; statePtr = chanPtr->state; @@ -6641,7 +6637,7 @@ Tcl_Ungets( flags = statePtr->flags; if (CheckChannelErrors(statePtr, TCL_READABLE) != 0) { - len = -1; + len = (size_t)-1; goto done; } statePtr->flags = flags; @@ -6658,7 +6654,7 @@ Tcl_Ungets( statePtr->inputEncodingFlags &= ~TCL_ENCODING_END; bufPtr = AllocChannelBuffer(len); - memcpy(InsertPoint(bufPtr), str, (size_t) len); + memcpy(InsertPoint(bufPtr), str, len); bufPtr->nextAdded += len; if (statePtr->inQueueHead == NULL) { diff --git a/generic/tclInt.decls b/generic/tclInt.decls index 7193fe1..54623a4 100644 --- a/generic/tclInt.decls +++ b/generic/tclInt.decls @@ -886,7 +886,7 @@ declare 214 { void TclSetObjNameOfExecutable(Tcl_Obj *name, Tcl_Encoding encoding) } declare 215 { - void *TclStackAlloc(Tcl_Interp *interp, int numBytes) + void *TclStackAlloc(Tcl_Interp *interp, size_t numBytes) } declare 216 { void TclStackFree(Tcl_Interp *interp, void *freePtr) diff --git a/generic/tclInt.h b/generic/tclInt.h index fd7ffca..af4d36d 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3029,7 +3029,7 @@ MODULE_SCOPE Tcl_Obj * TclLsetFlat(Tcl_Interp *interp, Tcl_Obj *listPtr, Tcl_Obj *valuePtr); MODULE_SCOPE Tcl_Command TclMakeEnsemble(Tcl_Interp *interp, const char *name, const EnsembleImplMap map[]); -MODULE_SCOPE int TclMaxListLength(const char *bytes, int numBytes, +MODULE_SCOPE int TclMaxListLength(const char *bytes, size_t numBytes, const char **endPtr); MODULE_SCOPE int TclMergeReturnOptions(Tcl_Interp *interp, int objc, Tcl_Obj *const objv[], Tcl_Obj **optionsPtrPtr, @@ -3046,15 +3046,15 @@ MODULE_SCOPE int TclObjInvokeNamespace(Tcl_Interp *interp, MODULE_SCOPE int TclObjUnsetVar2(Tcl_Interp *interp, Tcl_Obj *part1Ptr, Tcl_Obj *part2Ptr, int flags); MODULE_SCOPE int TclParseBackslash(const char *src, - int numBytes, size_t *readPtr, char *dst); -MODULE_SCOPE int TclParseHex(const char *src, int numBytes, + size_t numBytes, size_t *readPtr, char *dst); +MODULE_SCOPE int TclParseHex(const char *src, size_t numBytes, int *resultPtr); MODULE_SCOPE int TclParseNumber(Tcl_Interp *interp, Tcl_Obj *objPtr, const char *expected, const char *bytes, int numBytes, const char **endPtrPtr, int flags); MODULE_SCOPE void TclParseInit(Tcl_Interp *interp, const char *string, size_t numBytes, Tcl_Parse *parsePtr); -MODULE_SCOPE int TclParseAllWhiteSpace(const char *src, int numBytes); +MODULE_SCOPE int TclParseAllWhiteSpace(const char *src, size_t numBytes); MODULE_SCOPE int TclProcessReturn(Tcl_Interp *interp, int code, int level, Tcl_Obj *returnOpts); MODULE_SCOPE int TclpObjLstat(Tcl_Obj *pathPtr, Tcl_StatBuf *buf); @@ -3140,7 +3140,7 @@ MODULE_SCOPE void TclSpellFix(Tcl_Interp *interp, Tcl_Obj *const *objv, int objc, size_t subIdx, Tcl_Obj *bad, Tcl_Obj *fix); MODULE_SCOPE void * TclStackRealloc(Tcl_Interp *interp, void *ptr, - int numBytes); + 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); @@ -3152,15 +3152,15 @@ MODULE_SCOPE int TclStringMatch(const char *str, int strLen, MODULE_SCOPE int TclStringMatchObj(Tcl_Obj *stringObj, Tcl_Obj *patternObj, int flags); MODULE_SCOPE void TclSubstCompile(Tcl_Interp *interp, const char *bytes, - int numBytes, int flags, int line, + size_t numBytes, int flags, int line, struct CompileEnv *envPtr); MODULE_SCOPE int TclSubstOptions(Tcl_Interp *interp, int numOpts, Tcl_Obj *const opts[], int *flagPtr); MODULE_SCOPE void TclSubstParse(Tcl_Interp *interp, const char *bytes, - int numBytes, int flags, Tcl_Parse *parsePtr, + size_t numBytes, int flags, Tcl_Parse *parsePtr, Tcl_InterpState *statePtr); MODULE_SCOPE int TclSubstTokens(Tcl_Interp *interp, Tcl_Token *tokenPtr, - size_t count, int *tokensLeftPtr, int line, + int count, int *tokensLeftPtr, int line, int *clNextOuter, const char *outerScript); MODULE_SCOPE size_t TclTrim(const char *bytes, size_t numBytes, const char *trim, size_t numTrim, size_t *trimRight); diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h index 81f58da..a0099e8 100644 --- a/generic/tclIntDecls.h +++ b/generic/tclIntDecls.h @@ -460,7 +460,7 @@ EXTERN Tcl_Obj * TclGetObjNameOfExecutable(void); EXTERN void TclSetObjNameOfExecutable(Tcl_Obj *name, Tcl_Encoding encoding); /* 215 */ -EXTERN void * TclStackAlloc(Tcl_Interp *interp, int numBytes); +EXTERN void * TclStackAlloc(Tcl_Interp *interp, size_t numBytes); /* 216 */ EXTERN void TclStackFree(Tcl_Interp *interp, void *freePtr); /* 217 */ @@ -798,7 +798,7 @@ typedef struct TclIntStubs { void (*tclpFindExecutable) (const char *argv0); /* 212 */ Tcl_Obj * (*tclGetObjNameOfExecutable) (void); /* 213 */ void (*tclSetObjNameOfExecutable) (Tcl_Obj *name, Tcl_Encoding encoding); /* 214 */ - void * (*tclStackAlloc) (Tcl_Interp *interp, int numBytes); /* 215 */ + void * (*tclStackAlloc) (Tcl_Interp *interp, size_t numBytes); /* 215 */ void (*tclStackFree) (Tcl_Interp *interp, void *freePtr); /* 216 */ int (*tclPushStackFrame) (Tcl_Interp *interp, Tcl_CallFrame **framePtrPtr, Tcl_Namespace *namespacePtr, int isProcCallFrame); /* 217 */ void (*tclPopStackFrame) (Tcl_Interp *interp); /* 218 */ diff --git a/generic/tclParse.c b/generic/tclParse.c index bbfa5a7..8d29415 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -236,21 +236,20 @@ Tcl_ParseCommand( * NULL, then no error message is provided. */ const char *start, /* First character of string containing one or * more Tcl commands. */ - size_t xxx1, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If (size_t)-1, * the script consists of all bytes up to the * first null character. */ int nested, /* Non-zero means this is a nested command: * close bracket should be considered a * command terminator. If zero, then close * bracket has no special meaning. */ - register Tcl_Parse *parsePtr) + Tcl_Parse *parsePtr) /* Structure to fill in with information about * the parsed command; any previous * information in the structure is ignored. */ { - register const char *src; /* Points to current character in the + const char *src; /* Points to current character in the * command. */ - int numBytes = xxx1; char type; /* Result returned by CHAR_TYPE(*src). */ Tcl_Token *tokenPtr; /* Pointer to token being filled in. */ int wordIndex; /* Index of word token for current word. */ @@ -258,7 +257,7 @@ Tcl_ParseCommand( * command. */ const char *termPtr; /* Set by Tcl_ParseBraces/QuotedString to * point to char after terminating one. */ - int scanned; + size_t scanned; if ((start == NULL) && (numBytes != 0)) { if (interp != NULL) { @@ -267,7 +266,7 @@ Tcl_ParseCommand( } return TCL_ERROR; } - if (numBytes < 0) { + if (numBytes == (size_t)-1) { numBytes = strlen(start); } TclParseInit(interp, start, numBytes, parsePtr); @@ -735,7 +734,7 @@ ParseAllWhiteSpace( int TclParseAllWhiteSpace( const char *src, /* First character to parse. */ - int numBytes) /* Max number of byes to scan */ + size_t numBytes) /* Max number of byes to scan */ { int dummy; return ParseAllWhiteSpace(src, numBytes, &dummy); @@ -766,8 +765,8 @@ TclParseAllWhiteSpace( int TclParseHex( const char *src, /* First character to parse. */ - int numBytes, /* Max number of byes to scan */ - int *resultPtr) /* Points to storage provided by caller where + size_t numBytes, /* Max number of byes to scan */ + int *resultPtr) /* Points to storage provided by caller where * the character resulting from the * conversion is to be written. */ { @@ -822,7 +821,7 @@ int TclParseBackslash( const char *src, /* Points to the backslash character of a a * backslash sequence. */ - int numBytes, /* Max number of bytes to scan. */ + size_t numBytes, /* Max number of bytes to scan. */ size_t *readPtr, /* NULL, or points to storage where the number * of bytes scanned should be written. */ char *dst) /* NULL, or points to buffer where the UTF-8 @@ -833,7 +832,7 @@ TclParseBackslash( register const char *p = src+1; Tcl_UniChar unichar = 0; int result; - int count; + size_t count; char buf[TCL_UTF_MAX]; if (numBytes == 0) { @@ -1361,7 +1360,7 @@ Tcl_ParseVarName( * NULL, then no error message is provided. */ const char *start, /* Start of variable substitution string. * First character must be "$". */ - size_t xxx1, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If (size_t)-1, * the string consists of all bytes up to the * first null character. */ Tcl_Parse *parsePtr, /* Structure to fill in with information about @@ -1372,7 +1371,6 @@ Tcl_ParseVarName( * reinitialize it. */ { Tcl_Token *tokenPtr; - int numBytes = xxx1; register const char *src; int varIndex; unsigned array; @@ -1380,7 +1378,7 @@ Tcl_ParseVarName( if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes < 0) { + if (numBytes == (size_t)-1) { numBytes = strlen(start); } @@ -1640,7 +1638,7 @@ Tcl_ParseBraces( * NULL, then no error message is provided. */ const char *start, /* Start of string enclosed in braces. The * first character must be {'. */ - size_t xxx1, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If (size_t)-1, * the string consists of all bytes up to the * first null character. */ register Tcl_Parse *parsePtr, @@ -1656,7 +1654,6 @@ Tcl_ParseBraces( * successful. */ { Tcl_Token *tokenPtr; - int numBytes = xxx1; register const char *src; int startIndex, level; size_t length; @@ -1664,7 +1661,7 @@ Tcl_ParseBraces( if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes < 0) { + if (numBytes == (size_t)-1) { numBytes = strlen(start); } @@ -1844,7 +1841,7 @@ Tcl_ParseQuotedString( * NULL, then no error message is provided. */ const char *start, /* Start of the quoted string. The first * character must be '"'. */ - size_t xxx1, /* Total number of bytes in string. If < 0, + size_t numBytes, /* Total number of bytes in string. If (size_t)-1, * the string consists of all bytes up to the * first null character. */ register Tcl_Parse *parsePtr, @@ -1859,11 +1856,10 @@ Tcl_ParseQuotedString( * the quoted string's terminating close-quote * if the parse succeeds. */ { - int numBytes = xxx1; if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes < 0) { + if (numBytes == (size_t)-1) { numBytes = strlen(start); } @@ -1927,12 +1923,12 @@ void TclSubstParse( Tcl_Interp *interp, const char *bytes, - int numBytes, + size_t numBytes, int flags, Tcl_Parse *parsePtr, Tcl_InterpState *statePtr) { - int length = numBytes; + size_t length = numBytes; const char *p = bytes; TclParseInit(interp, p, length, parsePtr); @@ -2126,7 +2122,7 @@ TclSubstTokens( * errors. */ Tcl_Token *tokenPtr, /* Pointer to first in an array of tokens to * evaluate and concatenate. */ - size_t count, /* Number of tokens to consider at tokenPtr. + int count, /* Number of tokens to consider at tokenPtr. * Must be at least 1. */ int *tokensLeftPtr, /* If not NULL, points to memory where an * integer representing the number of tokens diff --git a/generic/tclUtil.c b/generic/tclUtil.c index c85f33d..428149a 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -385,12 +385,12 @@ static const Tcl_ObjType endOffsetType = { int TclMaxListLength( const char *bytes, - int numBytes, + size_t numBytes, const char **endPtr) { - int count = 0; + size_t count = 0; - if ((numBytes == 0) || ((numBytes == -1) && (*bytes == '\0'))) { + if ((numBytes == 0) || ((numBytes == (size_t)-1) && (*bytes == '\0'))) { /* Empty string case - quick exit */ goto done; } @@ -406,7 +406,7 @@ TclMaxListLength( */ while (numBytes) { - if ((numBytes == -1) && (*bytes == '\0')) { + if ((numBytes == (size_t)-1) && (*bytes == '\0')) { break; } if (TclIsSpaceProc(*bytes)) { @@ -417,9 +417,9 @@ TclMaxListLength( count++; do { bytes++; - numBytes -= (numBytes != -1); + numBytes -= (numBytes != (size_t)-1); } while (numBytes && TclIsSpaceProc(*bytes)); - if ((numBytes == 0) || ((numBytes == -1) && (*bytes == '\0'))) { + if ((numBytes == 0) || ((numBytes == (size_t)-1) && (*bytes == '\0'))) { break; } @@ -428,7 +428,7 @@ TclMaxListLength( */ } bytes++; - numBytes -= (numBytes != -1); + numBytes -= (numBytes != (size_t)-1); } /* |