diff options
-rw-r--r-- | doc/AddErrInfo.3 | 2 | ||||
-rw-r--r-- | doc/DString.3 | 2 | ||||
-rw-r--r-- | doc/StringObj.3 | 6 | ||||
-rw-r--r-- | doc/TclZlib.3 | 4 | ||||
-rw-r--r-- | doc/Utf.3 | 4 | ||||
-rw-r--r-- | generic/tclIO.c | 26 | ||||
-rw-r--r-- | generic/tclIORChan.c | 6 | ||||
-rw-r--r-- | generic/tclInt.h | 2 | ||||
-rw-r--r-- | generic/tclLiteral.c | 8 | ||||
-rw-r--r-- | generic/tclNamesp.c | 6 | ||||
-rw-r--r-- | generic/tclObj.c | 12 | ||||
-rw-r--r-- | generic/tclParse.c | 18 | ||||
-rw-r--r-- | generic/tclRegexp.c | 10 | ||||
-rw-r--r-- | generic/tclStringObj.c | 91 | ||||
-rw-r--r-- | generic/tclStringRep.h | 2 | ||||
-rw-r--r-- | generic/tclUtil.c | 16 | ||||
-rw-r--r-- | generic/tclZipfs.c | 18 | ||||
-rw-r--r-- | unix/tclUnixFCmd.c | 6 | ||||
-rw-r--r-- | unix/tclUnixInit.c | 4 | ||||
-rw-r--r-- | win/tclWinInit.c | 9 | ||||
-rw-r--r-- | win/tclWinPipe.c | 4 |
21 files changed, 124 insertions, 132 deletions
diff --git a/doc/AddErrInfo.3 b/doc/AddErrInfo.3 index 10052cf..95451d3 100644 --- a/doc/AddErrInfo.3 +++ b/doc/AddErrInfo.3 @@ -61,7 +61,7 @@ in the form of a Tcl_Obj value. .AP size_t length in The number of bytes to copy from \fImessage\fR when appending to the \fB\-errorinfo\fR return option. -If (size_t)-1, all bytes up to the first null byte are used. +If TCL_AUTO_LENGTH, all bytes up to the first null byte are used. .AP Tcl_Obj *errorObjPtr in The \fB\-errorcode\fR return option will be set to this value. .AP char *element in diff --git a/doc/DString.3 b/doc/DString.3 index 25c4c63..b4d0922 100644 --- a/doc/DString.3 +++ b/doc/DString.3 @@ -48,7 +48,7 @@ Pointer to characters to append to dynamic string. .AP "const char" *element in Pointer to characters to append as list element to dynamic string. .AP size_t length in -Number of bytes from \fIbytes\fR to add to dynamic string. If (size_t)-1, +Number of bytes from \fIbytes\fR to add to dynamic string. If TCL_AUTO_LENGTH, add all characters up to null terminating character. .AP size_t newLength in New length for dynamic string, not including null terminating diff --git a/doc/StringObj.3 b/doc/StringObj.3 index 93d8868..56ed654 100644 --- a/doc/StringObj.3 +++ b/doc/StringObj.3 @@ -87,14 +87,14 @@ Tcl_Obj * Points to the first byte of an array of UTF-8-encoded bytes used to set or append to a string value. This byte array may contain embedded null characters -unless \fInumChars\fR is (size_t)-1. (Applications needing null bytes +unless \fInumChars\fR is TCL_AUTO_LENGTH. (Applications needing null bytes should represent them as the two-byte sequence \fI\e700\e600\fR, use \fBTcl_ExternalToUtf\fR to convert, or \fBTcl_NewByteArrayObj\fR if the string is a collection of uninterpreted bytes.) .AP size_t length in The number of bytes to copy from \fIbytes\fR when initializing, setting, or appending to a string value. -If (size_t)-1, all bytes up to the first null are used. +If TCL_AUTO_LENGTH, all bytes up to the first null are used. .AP "const Tcl_UniChar" *unicode in Points to the first byte of an array of Unicode characters used to set or append to a string value. @@ -103,7 +103,7 @@ unless \fInumChars\fR is negative. .AP size_t numChars in The number of Unicode characters to copy from \fIunicode\fR when initializing, setting, or appending to a string value. -If (size_t)-1, all characters up to the first null character are used. +If TCL_AUTO_LENGTH, all characters up to the first null character are used. .AP size_t index in The index of the Unicode character to return. .AP size_t first in diff --git a/doc/TclZlib.3 b/doc/TclZlib.3 index 4bb0983..4093cfc 100644 --- a/doc/TclZlib.3 +++ b/doc/TclZlib.3 @@ -108,8 +108,8 @@ into a state where the decompressor can recover from on corruption, or \fBTCL_ZLIB_FINALIZE\fR to ensure that the stream is finished and that any trailer demanded by the format is written. .AP size_t count in -The maximum number of bytes to get from the stream, or (size_t)-1 to get all remaining -bytes from the stream's buffers. +The maximum number of bytes to get from the stream, or TCL_AUTO_LENGTH to get +all remaining bytes from the stream's buffers. .AP Tcl_Obj *compDict in A byte array value that is the compression dictionary to use with the stream. Note that this is \fInot a Tcl dictionary\fR, and it is recommended that this @@ -96,7 +96,7 @@ A null-terminated Unicode string. A null-terminated Unicode string. .AP size_t length in The length of the UTF-8 string in bytes (not UTF-8 characters). If -(size_t)-1, all bytes up to the first null byte are used. +TCL_AUTO_LENGTH, all bytes up to the first null byte are used. .AP size_t uniLength in The length of the Unicode string in characters. .AP "Tcl_DString" *dsPtr in/out @@ -243,7 +243,7 @@ characters. \fBTcl_UtfAtIndex\fR returns a pointer to the specified character (not byte) \fIindex\fR in the UTF-8 string \fIsrc\fR. The source string must contain at least \fIindex\fR characters. This is equivalent to calling -\fBTcl_UtfNext\fR \fIindex\fR times. If \fIindex\fR is (size_t)-1, +\fBTcl_UtfNext\fR \fIindex\fR times. If \fIindex\fR is TCL_AUTO_LENGTH, the return pointer points to the first character in the source string. .PP \fBTcl_UtfBackslash\fR is a utility procedure used by several of the Tcl diff --git a/generic/tclIO.c b/generic/tclIO.c index 621c728..4a32216 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -3986,8 +3986,8 @@ Tcl_ClearChannelHandlers( * No encoding conversions are applied to the bytes being read. * * Results: - * The number of bytes written or (size_t)-1 in case of error. If (size_t)-1, - * Tcl_GetErrno will return the error code. + * The number of bytes written or TCL_IO_FAILURE in case of error. If + * TCL_IO_FAILURE, Tcl_GetErrno will return the error code. * * Side effects: * May buffer up output and may cause output to be produced on the @@ -4040,8 +4040,8 @@ Tcl_Write( * No encoding conversions are applied to the bytes being read. * * Results: - * The number of bytes written or (size_t)-1 in case of error. If (size_t)-1, - * Tcl_GetErrno will return the error code. + * The number of bytes written or TCL_IO_FAILURE in case of error. If + * TCL_IO_FAILURE, Tcl_GetErrno will return the error code. * * Side effects: * May buffer up output and may cause output to be produced on the @@ -4054,7 +4054,7 @@ size_t Tcl_WriteRaw( Tcl_Channel chan, /* The channel to buffer output for. */ const char *src, /* Data to queue in output buffer. */ - size_t srcLen) /* Length of data in bytes, or (size_t)-1 for + size_t srcLen) /* Length of data in bytes, or -1 for * strlen(). */ { Channel *chanPtr = ((Channel *) chan); @@ -4064,10 +4064,10 @@ Tcl_WriteRaw( size_t written; if (CheckChannelErrors(statePtr, TCL_WRITABLE | CHANNEL_RAW_MODE) != 0) { - return (size_t)-1; + return TCL_IO_FAILURE; } - if (srcLen == (size_t)-1) { + if (srcLen == TCL_AUTO_LENGTH) { srcLen = strlen(src); } @@ -4077,7 +4077,7 @@ Tcl_WriteRaw( */ written = ChanWrite(chanPtr, src, srcLen, &errorCode); - if (written == (size_t)-1) { + if (written == TCL_IO_FAILURE) { Tcl_SetErrno(errorCode); } @@ -4097,8 +4097,8 @@ Tcl_WriteRaw( * specified channel to the topmost channel in a stack. * * Results: - * The number of bytes written or (size_t)-1 in case of error. If (size_t)-1, - * Tcl_GetErrno will return the error code. + * The number of bytes written or TCL_IO_FAILURE in case of error. If + * TCL_IO_FAILURE, Tcl_GetErrno will return the error code. * * Side effects: * May buffer up output and may cause output to be produced on the @@ -4112,7 +4112,7 @@ Tcl_WriteChars( Tcl_Channel chan, /* The channel to buffer output for. */ const char *src, /* UTF-8 characters to queue in output * buffer. */ - size_t len) /* Length of string in bytes, or (size_t)-1 for + size_t len) /* Length of string in bytes, or -1 for * strlen(). */ { Channel *chanPtr = (Channel *) chan; @@ -6614,7 +6614,7 @@ TranslateInputEOL( * channel, at either the head or tail of the queue. * * Results: - * The number of bytes stored in the channel, or (size_t)-1 on error. + * The number of bytes stored in the channel, or TCL_IO_FAILURE on error. * * Side effects: * Adds input to the input queue of a channel. @@ -6650,7 +6650,7 @@ Tcl_Ungets( flags = statePtr->flags; if (CheckChannelErrors(statePtr, TCL_READABLE) != 0) { - len = (size_t)-1; + len = TCL_IO_FAILURE; goto done; } statePtr->flags = flags; diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c index bc5bb04..31cd0bf 100644 --- a/generic/tclIORChan.c +++ b/generic/tclIORChan.c @@ -1287,7 +1287,7 @@ ReflectInput( PassReceivedError(rcPtr->chan, &p); *errorCodePtr = EINVAL; } - p.input.toRead = (size_t)-1; + p.input.toRead = TCL_AUTO_LENGTH; } else { *errorCodePtr = EOK; } @@ -2992,7 +2992,7 @@ ForwardProc( } else { ForwardSetObjError(paramPtr, resObj); } - paramPtr->input.toRead = (size_t)-1; + paramPtr->input.toRead = TCL_IO_FAILURE; } else { /* * Process a regular result. @@ -3005,7 +3005,7 @@ ForwardProc( if (paramPtr->input.toRead < bytec) { ForwardSetStaticError(paramPtr, msg_read_toomuch); - paramPtr->input.toRead = (size_t)-1; + paramPtr->input.toRead = TCL_IO_FAILURE; } else { if (bytec + 1 > 1) { memcpy(paramPtr->input.buf, bytev, bytec); diff --git a/generic/tclInt.h b/generic/tclInt.h index c10798c..85dcc74 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -1506,7 +1506,7 @@ typedef struct LiteralEntry { * table, the number of ByteCode structures * that share the literal object; the literal * entry can be freed when refCount drops to - * 0. If in a local literal table, (size_t)-1. */ + * 0. If in a local literal table, -1. */ Namespace *nsPtr; /* Namespace in which this literal is used. We * try to avoid sharing literal non-FQ command * names among different namespaces to reduce diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c index 4a8970a..b59efdf 100644 --- a/generic/tclLiteral.c +++ b/generic/tclLiteral.c @@ -193,7 +193,7 @@ TclCreateLiteral( * Is it in the interpreter's global literal table? */ - if (hash == (size_t) -1) { + if (hash == TCL_AUTO_LENGTH) { hash = HashString(bytes, length); } globalHash = (hash & globalTablePtr->mask); @@ -397,7 +397,7 @@ TclRegisterLiteral( int new; Namespace *nsPtr; - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = (bytes ? strlen(bytes) : 0); } hash = HashString(bytes, length); @@ -453,7 +453,7 @@ TclRegisterLiteral( objIndex = AddLocalLiteralEntry(envPtr, objPtr, localHash); #ifdef TCL_COMPILE_DEBUG - if (globalPtr != NULL && (globalPtr->refCount < 1 || globalPtr->refCount == (size_t)-1)) { + if (globalPtr != NULL && ((globalPtr->refCount < 1) || (globalPtr->refCount == TCL_AUTO_LENGTH))) { Tcl_Panic("%s: global literal \"%.*s\" had bad refCount %d", "TclRegisterLiteral", (length>60? 60 : (int)length), bytes, (int)globalPtr->refCount); @@ -615,7 +615,7 @@ TclAddLiteralObj( lPtr = &envPtr->literalArrayPtr[objIndex]; lPtr->objPtr = objPtr; Tcl_IncrRefCount(objPtr); - lPtr->refCount = (size_t)-1; /* i.e., unused */ + lPtr->refCount = TCL_AUTO_LENGTH; /* i.e., unused */ lPtr->nextPtr = NULL; if (litPtrPtr) { diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index 3933e4c..6fd1916 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -4909,7 +4909,7 @@ TclLogCommandInfo( * command (must be <= command). */ const char *command, /* First character in command that generated * the error. */ - size_t length, /* Number of bytes in command ((size_t)-1 means + size_t length, /* Number of bytes in command (-1 means * use all bytes up to first null byte). */ const unsigned char *pc, /* Current pc of bytecode execution context */ Tcl_Obj **tosPtr) /* Current stack of bytecode execution @@ -4941,7 +4941,7 @@ TclLogCommandInfo( } } - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = strlen(command); } overflow = (length > (size_t)limit); @@ -5121,7 +5121,7 @@ Tcl_LogCommandInfo( * command (must be <= command). */ const char *command, /* First character in command that generated * the error. */ - size_t length) /* Number of bytes in command ((size_t)-1 means use + size_t length) /* Number of bytes in command (-1 means use * all bytes up to first null byte). */ { TclLogCommandInfo(interp, script, command, length, NULL, NULL); diff --git a/generic/tclObj.c b/generic/tclObj.c index 6a54e22..40a8bfe 100644 --- a/generic/tclObj.c +++ b/generic/tclObj.c @@ -1319,16 +1319,16 @@ TclFreeObj( * sure we do not accept a second free when falling from 0 to -1. * Skip that possibility so any double free will trigger the panic. */ - objPtr->refCount = (size_t)-1; + objPtr->refCount = TCL_AUTO_LENGTH; /* * 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 == (size_t)-1'. + * with 'length == TCL_AUTO_LENGTH'. */ TclInvalidateStringRep(objPtr); - objPtr->length = (size_t)-1; + objPtr->length = TCL_AUTO_LENGTH; if (ObjDeletePending(context)) { PushObjToDelete(context, objPtr); @@ -1498,7 +1498,7 @@ int TclObjBeingDeleted( Tcl_Obj *objPtr) { - return (objPtr->length == (size_t)-1); + return (objPtr->length == TCL_AUTO_LENGTH); } /* @@ -1617,7 +1617,7 @@ Tcl_GetString( objPtr->typePtr->name); } objPtr->typePtr->updateStringProc(objPtr); - if (objPtr->bytes == NULL || objPtr->length == (size_t)-1 + if (objPtr->bytes == NULL || objPtr->length == TCL_AUTO_LENGTH || objPtr->bytes[objPtr->length] != '\0') { Tcl_Panic("UpdateStringProc for type '%s' " "failed to create a valid string rep", @@ -1676,7 +1676,7 @@ Tcl_GetStringFromObj( objPtr->typePtr->name); } objPtr->typePtr->updateStringProc(objPtr); - if (objPtr->bytes == NULL || objPtr->length == (size_t)-1 + if (objPtr->bytes == NULL || objPtr->length == TCL_AUTO_LENGTH || objPtr->bytes[objPtr->length] != '\0') { Tcl_Panic("UpdateStringProc for type '%s' " "failed to create a valid string rep", diff --git a/generic/tclParse.c b/generic/tclParse.c index 4f82143..e2aedd1 100644 --- a/generic/tclParse.c +++ b/generic/tclParse.c @@ -190,7 +190,7 @@ void TclParseInit( Tcl_Interp *interp, /* Interpreter to use for error reporting */ const char *start, /* Start of string to be parsed. */ - size_t numBytes, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If -1, * the script consists of all bytes up to the * first null character. */ Tcl_Parse *parsePtr) /* Points to struct to initialize */ @@ -236,7 +236,7 @@ Tcl_ParseCommand( * NULL, then no error message is provided. */ const char *start, /* First character of string containing one or * more Tcl commands. */ - size_t numBytes, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If -1, * the script consists of all bytes up to the * first null character. */ int nested, /* Non-zero means this is a nested command: @@ -266,7 +266,7 @@ Tcl_ParseCommand( } return TCL_ERROR; } - if (numBytes == (size_t)-1) { + if (numBytes == TCL_AUTO_LENGTH) { numBytes = strlen(start); } TclParseInit(interp, start, numBytes, parsePtr); @@ -1360,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 numBytes, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If -1, * the string consists of all bytes up to the * first null character. */ Tcl_Parse *parsePtr, /* Structure to fill in with information about @@ -1378,7 +1378,7 @@ Tcl_ParseVarName( if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes == (size_t)-1) { + if (numBytes == TCL_AUTO_LENGTH) { numBytes = strlen(start); } @@ -1638,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 numBytes, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If -1, * the string consists of all bytes up to the * first null character. */ register Tcl_Parse *parsePtr, @@ -1661,7 +1661,7 @@ Tcl_ParseBraces( if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes == (size_t)-1) { + if (numBytes == TCL_AUTO_LENGTH) { numBytes = strlen(start); } @@ -1841,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 numBytes, /* Total number of bytes in string. If (size_t)-1, + size_t numBytes, /* Total number of bytes in string. If -1, * the string consists of all bytes up to the * first null character. */ register Tcl_Parse *parsePtr, @@ -1859,7 +1859,7 @@ Tcl_ParseQuotedString( if ((numBytes == 0) || (start == NULL)) { return TCL_ERROR; } - if (numBytes == (size_t)-1) { + if (numBytes == TCL_AUTO_LENGTH) { numBytes = strlen(start); } diff --git a/generic/tclRegexp.c b/generic/tclRegexp.c index 71f6581..fa4f2fa 100644 --- a/generic/tclRegexp.c +++ b/generic/tclRegexp.c @@ -71,7 +71,7 @@ typedef struct { * expression patterns. NULL means that this * slot isn't used. Malloc-ed. */ size_t patLengths[NUM_REGEXPS];/* Number of non-null characters in - * corresponding entry in patterns. (size_t)-1 means + * corresponding entry in patterns. -1 means * entry isn't used. */ struct TclRegexp *regexps[NUM_REGEXPS]; /* Compiled forms of above strings. Also @@ -306,7 +306,7 @@ RegExpExecUniChar( size_t numChars, /* Length of Tcl_UniChar string. */ size_t nm, /* How many subexpression matches (counting * the whole match as subexpression 0) are of - * interest. (size_t)-1 means "don't know". */ + * interest. -1 means "don't know". */ int flags) /* Regular expression flags. */ { int status; @@ -363,7 +363,7 @@ TclRegExpRangeUniChar( * passed to Tcl_RegExpExec. */ size_t index, /* 0 means give the range of the entire match, * > 0 means give the range of a matching - * subrange, (size_t)-1 means the range of the + * subrange, -1 means the range of the * rm_extend field. */ int *startPtr, /* Store address of first character in * (sub-)range here. */ @@ -372,7 +372,7 @@ TclRegExpRangeUniChar( { TclRegexp *regexpPtr = (TclRegexp *) re; - if ((regexpPtr->flags®_EXPECT) && index == (size_t)-1) { + if ((regexpPtr->flags®_EXPECT) && index == TCL_AUTO_LENGTH) { *startPtr = regexpPtr->details.rm_extend.rm_so; *endPtr = regexpPtr->details.rm_extend.rm_eo; } else if (index > regexpPtr->re.re_nsub) { @@ -445,7 +445,7 @@ Tcl_RegExpExecObj( * should begin. */ size_t nmatches, /* How many subexpression matches (counting * the whole match as subexpression 0) are of - * interest. (size_t)-1 means all of them. */ + * interest. -1 means all of them. */ int flags) /* Regular expression execution flags. */ { TclRegexp *regexpPtr = (TclRegexp *) re; diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index 0f2bcae..e6a3b41 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -267,13 +267,12 @@ Tcl_NewStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the new object. */ size_t length) /* The number of bytes to copy from "bytes" - * when initializing the new object. If - * negative, use bytes up to the first NUL - * byte. */ + * when initializing the new object. If -1, + * use bytes up to the first NUL byte. */ { Tcl_Obj *objPtr; - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = (bytes? strlen(bytes) : 0); } TclNewStringObj(objPtr, bytes, length); @@ -316,9 +315,8 @@ Tcl_DbNewStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the new object. */ size_t length, /* The number of bytes to copy from "bytes" - * when initializing the new object. If - * (size_t)-1, use bytes up to the first NUL - * byte. */ + * when initializing the new object. If -1, + * use bytes up to the first NUL byte. */ const char *file, /* The name of the source file calling this * function; used for debugging. */ int line) /* Line number in the source file; used for @@ -326,7 +324,7 @@ Tcl_DbNewStringObj( { Tcl_Obj *objPtr; - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = (bytes? strlen(bytes) : 0); } TclDbNewObj(objPtr, file, line); @@ -339,9 +337,8 @@ Tcl_DbNewStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the new object. */ size_t length, /* The number of bytes to copy from "bytes" - * when initializing the new object. If - * (size_t)-1, use bytes up to the first NUL - * byte. */ + * when initializing the new object. If -1, + * use bytes up to the first NUL byte. */ const char *file, /* The name of the source file calling this * function; used for debugging. */ int line) /* Line number in the source file; used for @@ -446,7 +443,7 @@ Tcl_GetCharLength( * If numChars is unknown, compute it. */ - if (numChars == (size_t)-1) { + if (numChars == TCL_AUTO_LENGTH) { TclNumUtfChars(numChars, objPtr->bytes, objPtr->length); stringPtr->numChars = numChars; } @@ -549,7 +546,7 @@ Tcl_GetUniChar( * If numChars is unknown, compute it. */ - if (stringPtr->numChars == (size_t)-1) { + if (stringPtr->numChars == TCL_AUTO_LENGTH) { TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length); } if (stringPtr->numChars == objPtr->length) { @@ -654,7 +651,7 @@ Tcl_GetRange( String *stringPtr; size_t length; - if (first == (size_t)-1) { + if (first == TCL_AUTO_LENGTH1) { first = 0; } if (last + 2 <= first + 1) { @@ -690,7 +687,7 @@ Tcl_GetRange( * If numChars is unknown, compute it. */ - if (stringPtr->numChars == (size_t)-1) { + if (stringPtr->numChars == TCL_AUTO_LENGTH) { TclNumUtfChars(stringPtr->numChars, objPtr->bytes, objPtr->length); } if (stringPtr->numChars == objPtr->length) { @@ -762,7 +759,7 @@ Tcl_SetStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the object. */ size_t length) /* The number of bytes to copy from "bytes" - * when initializing the object. If (size_t)-1, + * when initializing the object. If -1, * use bytes up to the first NUL byte.*/ { if (Tcl_IsShared(objPtr)) { @@ -781,7 +778,7 @@ Tcl_SetStringObj( */ TclInvalidateStringRep(objPtr); - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = (bytes? strlen(bytes) : 0); } TclInitStringRep(objPtr, bytes, length); @@ -854,7 +851,7 @@ Tcl_SetObjLength( * Invalidate the unicode data. */ - stringPtr->numChars = (size_t)-1; + stringPtr->numChars = TCL_AUTO_LENGTH; stringPtr->hasUnicode = 0; } else { /* @@ -956,7 +953,7 @@ Tcl_AttemptSetObjLength( * Invalidate the unicode data. */ - stringPtr->numChars = (size_t)-1; + stringPtr->numChars = TCL_AUTO_LENGTH; stringPtr->hasUnicode = 0; } else { /* @@ -1029,7 +1026,7 @@ UnicodeLength( size_t numChars = 0; if (unicode) { - while (numChars != (size_t)-1 && unicode[numChars] != 0) { + while ((numChars != TCL_AUTO_LENGTH) && (unicode[numChars] != 0)) { numChars++; } } @@ -1047,7 +1044,7 @@ SetUnicodeObj( { String *stringPtr; - if (numChars == (size_t)-1) { + if (numChars == TCL_AUTO_LENGTH) { numChars = UnicodeLength(unicode); } @@ -1094,7 +1091,7 @@ Tcl_AppendLimitedToObj( const char *bytes, /* Points to the bytes to append to the * object. */ size_t length, /* The number of bytes available to be - * appended from "bytes". If (size_t)-1, then + * appended from "bytes". If -1, then * all bytes up to a NUL byte are available. */ size_t limit, /* The maximum number of bytes to append to * the object. */ @@ -1109,7 +1106,7 @@ Tcl_AppendLimitedToObj( Tcl_Panic("%s called with shared object", "Tcl_AppendLimitedToObj"); } - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { length = (bytes ? strlen(bytes) : 0); } if (length == 0) { @@ -1176,10 +1173,10 @@ Tcl_AppendToObj( const char *bytes, /* Points to the bytes to append to the * object. */ size_t length) /* The number of bytes to append from "bytes". - * If (size_t)-1, then append all bytes up to NUL + * If -1, then append all bytes up to NUL * byte. */ { - Tcl_AppendLimitedToObj(objPtr, bytes, length, (size_t)-1, NULL); + Tcl_AppendLimitedToObj(objPtr, bytes, length, TCL_AUTO_LENGTH, NULL); } /* @@ -1259,7 +1256,7 @@ Tcl_AppendObjToObj( { String *stringPtr; size_t length, numChars; - size_t appendNumChars = (size_t)-1; + size_t appendNumChars = TCL_AUTO_LENGTH; const char *bytes; /* @@ -1364,7 +1361,7 @@ Tcl_AppendObjToObj( bytes = TclGetStringFromObj(appendObjPtr, &length); numChars = stringPtr->numChars; - if ((numChars != (size_t)-1) && (appendObjPtr->typePtr == &tclStringType)) { + if ((numChars != TCL_AUTO_LENGTH) && (appendObjPtr->typePtr == &tclStringType)) { String *appendStringPtr = GET_STRING(appendObjPtr); appendNumChars = appendStringPtr->numChars; @@ -1372,7 +1369,7 @@ Tcl_AppendObjToObj( AppendUtfToUtfRep(objPtr, bytes, length); - if (numChars != (size_t)-1 && appendNumChars != (size_t)-1) { + if ((numChars != TCL_AUTO_LENGTH() && (appendNumChars != TCL_AUTO_LENGTH)) { stringPtr->numChars = numChars + appendNumChars; } } @@ -1403,7 +1400,7 @@ AppendUnicodeToUnicodeRep( String *stringPtr; size_t numChars; - if (appendNumChars == (size_t)-1) { + if (appendNumChars == TCL_AUTO_LENGTH) { appendNumChars = UnicodeLength(unicode); } if (appendNumChars == 0) { @@ -1425,7 +1422,7 @@ AppendUnicodeToUnicodeRep( stringCheckLimits(numChars); if (numChars > stringPtr->maxChars) { - size_t offset = (size_t)-1; + size_t offset = TCL_AUTO_LENGTH; /* * Protect against case where unicode points into the existing @@ -1445,7 +1442,7 @@ AppendUnicodeToUnicodeRep( * Relocate unicode if needed; see above. */ - if (offset != (size_t)-1) { + if (offset != TCL_AUTO_LENGTH) { unicode = stringPtr->unicode + offset; } } @@ -1493,7 +1490,7 @@ AppendUnicodeToUtfRep( numChars = ExtendStringRepWithUnicode(objPtr, unicode, numChars); - if (stringPtr->numChars != (size_t)-1) { + if (stringPtr->numChars != TCL_AUTO_LENGTH) { stringPtr->numChars += numChars; } } @@ -1578,7 +1575,7 @@ AppendUtfToUtfRep( stringPtr = GET_STRING(objPtr); if (newLength > stringPtr->allocated) { - size_t offset = (size_t)-1; + size_t offset = TCL_AUTO_LENGTH; /* * Protect against case where unicode points into the existing @@ -1602,7 +1599,7 @@ AppendUtfToUtfRep( * Relocate bytes if needed; see above. */ - if (offset != (size_t)-1) { + if (offset != TCL_AUTO_LENGTH) { bytes = objPtr->bytes + offset; } } @@ -1611,7 +1608,7 @@ AppendUtfToUtfRep( * Invalidate the unicode data. */ - stringPtr->numChars = (size_t)-1; + stringPtr->numChars = TCL_AUTO_LENGTH; stringPtr->hasUnicode = 0; if (bytes) { @@ -3399,7 +3396,7 @@ TclStringCmp( * length was requested. */ - if ((reqlength == (size_t)-1) && !nocase) { + if ((reqlength == TCL_AUTO_LENGTH) && !nocase) { memCmpFn = (memCmpFn_t) TclpUtfNcmp2; } else { s1len = Tcl_NumUtfChars(s1, s1len); @@ -3411,7 +3408,7 @@ TclStringCmp( } length = (s1len < s2len) ? s1len : s2len; - if (reqlength == (size_t)-1) { + if (reqlength == TCL_AUTO_LENGTH) { /* * The requested length is negative, so we ignore it by setting it * to length + 1 so we correct the match var. @@ -3451,7 +3448,7 @@ 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, (size_t)-1 is returned. + * as a substring of haystack, TCL_IO_FAILURE is returned. * * Side effects: * needle and haystack may have their Tcl_ObjType changed. @@ -3467,7 +3464,7 @@ TclStringFirst( { size_t lh, ln = Tcl_GetCharLength(needle); - if (start == (size_t)-1) { + if (start == TCL_AUTO_LENGTH) { start = 0; } if (ln == 0) { @@ -3547,7 +3544,7 @@ TclStringFirst( * Results: * If needle is found as a substring of haystack, the index of the * last 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, TCL_IO_FAILURE is returned. * * Side effects: * needle and haystack may have their Tcl_ObjType changed. @@ -3570,7 +3567,7 @@ TclStringLast( * TODO: When we one day make this a true substring * finder, change this to "return last", after limitation. */ - return (size_t)-1; + return TCL_IO_FAILURE; } lh = Tcl_GetCharLength(haystack); @@ -3579,7 +3576,7 @@ TclStringLast( } if (last < ln - 1) { - return (size_t)-1; + return TCL_IO_FAILURE; } if (TclIsPureByteArray(needle) && TclIsPureByteArray(haystack)) { @@ -3609,7 +3606,7 @@ TclStringLast( } try--; } - return -1; + return TCL_IO_FAILURE; } } @@ -3720,7 +3717,7 @@ TclStringReverse( } to = objPtr->bytes; - if ((numChars == (size_t)-1) || (numChars < numBytes)) { + if ((numChars == TCL_AUTO_LENGTH) || (numChars < numBytes)) { /* * Either numChars == -1 and we don't know how many chars are * represented by objPtr->bytes and we need Pass 1 just in case, @@ -3942,7 +3939,7 @@ ExtendUnicodeRepWithString( if (stringPtr->hasUnicode) { numOrigChars = stringPtr->numChars; } - if (numAppendChars == (size_t)-1) { + if (numAppendChars == TCL_AUTO_LENGTH) { TclNumUtfChars(numAppendChars, bytes, numBytes); } needed = numOrigChars + numAppendChars; @@ -3994,7 +3991,7 @@ DupStringInternalRep( String *srcStringPtr = GET_STRING(srcPtr); String *copyStringPtr = NULL; - if (srcStringPtr->numChars == (size_t)-1) { + if (srcStringPtr->numChars == TCL_AUTO_LENGTH) { /* * The String struct in the source value holds zero useful data. Don't * bother copying it. Don't even bother allocating space in which to @@ -4144,7 +4141,7 @@ ExtendStringRepWithUnicode( char *dst; String *stringPtr = GET_STRING(objPtr); - if (numChars == (size_t)-1) { + if (numChars == TCL_AUTO_LENGTH) { numChars = UnicodeLength(unicode); } diff --git a/generic/tclStringRep.h b/generic/tclStringRep.h index 767751d..a8b3b08 100644 --- a/generic/tclStringRep.h +++ b/generic/tclStringRep.h @@ -47,7 +47,7 @@ */ typedef struct { - size_t numChars; /* The number of chars in the string. (size_t)-1 means + size_t numChars; /* The number of chars in the string. -1 means * this value has not been calculated. Any other * means that there is a valid Unicode rep, or * that the number of UTF bytes == the number diff --git a/generic/tclUtil.c b/generic/tclUtil.c index 812bcad..74ab749 100644 --- a/generic/tclUtil.c +++ b/generic/tclUtil.c @@ -952,7 +952,7 @@ Tcl_ScanElement( * This function is a companion function to Tcl_ConvertCountedElement. It * scans a string to see what needs to be done to it (e.g. add * backslashes or enclosing braces) to make the string into a valid Tcl - * list element. If length is (size_t)-1, then the string is scanned from src up + * list element. If length is -1, then the string is scanned from src up * to the first null byte. * * Results: @@ -970,7 +970,7 @@ Tcl_ScanElement( size_t Tcl_ScanCountedElement( const char *src, /* String to convert to Tcl list element. */ - size_t length, /* Number of bytes in src, or (size_t)-1. */ + size_t length, /* Number of bytes in src, or -1. */ int *flagPtr) /* Where to store information to guide * Tcl_ConvertElement. */ { @@ -1035,7 +1035,7 @@ TclScanElement( int braceCount = 0; /* Count of all braces '{' '}' seen. */ #endif /* COMPAT */ - if ((p == NULL) || (length == 0) || ((*p == '\0') && (length == (size_t)-1))) { + if ((p == NULL) || (length == 0) || ((*p == '\0') && (length == TCL_AUTO_LENGTH))) { /* * Empty string element must be brace quoted. */ @@ -1124,7 +1124,7 @@ TclScanElement( break; case '\\': /* TYPE_SUBS */ extra++; /* Escape '\' => '\\' */ - if ((length == 1) || ((length == (size_t)-1) && (p[1] == '\0'))) { + if ((length == 1) || ((length == TCL_AUTO_LENGTH) && (p[1] == '\0'))) { /* * Final backslash. Cannot format with brace quoting. */ @@ -1155,7 +1155,7 @@ TclScanElement( #endif /* COMPAT */ break; case '\0': /* TYPE_SUBS */ - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { goto endOfString; } /* TODO: Panic on improper encoding? */ @@ -1427,7 +1427,7 @@ TclConvertElement( */ if (conversion == CONVERT_NONE) { - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { /* TODO: INT_MAX overflow? */ while (*src) { *p++ = *src++; @@ -1446,7 +1446,7 @@ TclConvertElement( if (conversion == CONVERT_BRACE) { *p = '{'; p++; - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { /* TODO: INT_MAX overflow? */ while (*src) { *p++ = *src++; @@ -1519,7 +1519,7 @@ TclConvertElement( p++; continue; case '\0': - if (length == (size_t)-1) { + if (length == TCL_AUTO_LENGTH) { return (size_t)(p - dst); } diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index c098af4..693bf89 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -458,12 +458,6 @@ static Tcl_ChannelType ZipChannelType = { NULL, /* Thread action function, NULL'able */ NULL, /* Truncate function, NULL'able */ }; - -/* - * Miscellaneous constants. - */ - -#define ERROR_LENGTH ((size_t) -1) /* *------------------------------------------------------------------------- @@ -1115,7 +1109,7 @@ ZipFSOpenArchive( } if (Tcl_GetChannelHandle(zf->chan, TCL_READABLE, &handle) != TCL_OK) { zf->length = Tcl_Seek(zf->chan, 0, SEEK_END); - if (zf->length == ERROR_LENGTH) { + if (zf->length == TCL_IO_FAILURE) { ZIPFS_POSIX_ERROR(interp, "seek error"); goto error; } @@ -1174,7 +1168,7 @@ ZipFSOpenArchive( } #else /* !_WIN32 */ zf->length = lseek(PTR2INT(handle), 0, SEEK_END); - if (zf->length == ERROR_LENGTH || zf->length < ZIP_CENTRAL_END_LEN) { + if (zf->length == TCL_IO_FAILURE || zf->length < ZIP_CENTRAL_END_LEN) { ZIPFS_POSIX_ERROR(interp, "invalid file size"); goto error; } @@ -2140,7 +2134,7 @@ ZipAddFile( nbyte = nbytecompr = 0; while (1) { len = Tcl_Read(in, buf, bufsize); - if (len == ERROR_LENGTH) { + if (len == TCL_IO_FAILURE) { if (nbyte == 0 && errno == EISDIR) { Tcl_Close(interp, in); return TCL_OK; @@ -2256,7 +2250,7 @@ ZipAddFile( } do { len = Tcl_Read(in, buf, bufsize); - if (len == ERROR_LENGTH) { + if (len == TCL_IO_FAILURE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "read error on %s: %s", path, Tcl_PosixError(interp))); deflateEnd(&stream); @@ -2317,7 +2311,7 @@ ZipAddFile( nbytecompr = (passwd ? 12 : 0); while (1) { len = Tcl_Read(in, buf, bufsize); - if (len == ERROR_LENGTH) { + if (len == TCL_IO_FAILURE) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "read error on \"%s\": %s", path, Tcl_PosixError(interp))); @@ -2602,7 +2596,7 @@ ZipFSMkZipOrImgObjCmd( return TCL_ERROR; } i = Tcl_Seek(in, 0, SEEK_END); - if (i == ERROR_LENGTH) { + if (i == TCL_IO_FAILURE) { cperr: memset(passBuf, 0, sizeof(passBuf)); Tcl_DecrRefCount(list); diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c index fadf18d..7a79f3e 100644 --- a/unix/tclUnixFCmd.c +++ b/unix/tclUnixFCmd.c @@ -613,18 +613,18 @@ TclUnixCopyFile( buffer = Tcl_Alloc(blockSize); while (1) { nread = (size_t) read(srcFd, buffer, blockSize); - if ((nread == (size_t) -1) || (nread == 0)) { + if ((nread == TCL_IO_FAILURE) || (nread == 0)) { break; } if ((size_t) write(dstFd, buffer, nread) != nread) { - nread = (size_t) -1; + nread = TCL_IO_FAILURE; break; } } Tcl_Free(buffer); close(srcFd); - if ((close(dstFd) != 0) || (nread == (size_t) -1)) { + if ((close(dstFd) != 0) || (nread == TCL_IO_FAILURE)) { unlink(dst); /* INTL: Native. */ return TCL_ERROR; } diff --git a/unix/tclUnixInit.c b/unix/tclUnixInit.c index 21e8f20..eacf157 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 (size_t)-1 if there is no such entry. The integer at *lengthPtr is + * "name", or TCL_IO_FAILURE 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). * @@ -1000,7 +1000,7 @@ TclpFindVariable( * entries in environ (for unsuccessful * searches). */ { - size_t i, result = (size_t)-1; + size_t i, result = TCL_IO_FAILURE; register const char *env, *p1, *p2; Tcl_DString envString; diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 0dadc24..11d182a 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -607,9 +607,10 @@ TclpSetVariables( * * Results: * The return value is the index in environ of an entry with the name - * "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). + * "name", or TCL_IO_FAILURE 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). * * Side effects: * None. @@ -626,7 +627,7 @@ TclpFindVariable( * entries in environ (for unsuccessful * searches). */ { - size_t i, length, result = (size_t)-1; + size_t i, length, result = TCL_IO_FAILURE; register const char *env, *p1, *p2; char *envUpper, *nameUpper; Tcl_DString envString; diff --git a/win/tclWinPipe.c b/win/tclWinPipe.c index eda9fe0..47af1e1 100644 --- a/win/tclWinPipe.c +++ b/win/tclWinPipe.c @@ -851,7 +851,7 @@ TclpCloseFile( * Results: * Returns the process id for the child process. If the pid was not known * by Tcl, either because the pid was not created by Tcl or the child - * process has already been reaped, (size_t)-1 is returned. + * process has already been reaped, TCL_IO_FAILURE is returned. * * Side effects: * None. @@ -875,7 +875,7 @@ TclpGetPid( } } Tcl_MutexUnlock(&pipeMutex); - return (size_t)-1; + return TCL_IO_FAILURE; } /* |