diff options
| author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-21 20:18:54 (GMT) |
|---|---|---|
| committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2023-04-21 20:18:54 (GMT) |
| commit | 1fe7d754ed84d81bf0fb2928b1bccfc96348bd12 (patch) | |
| tree | 378f5af3c9a54b78db4b9e0d72521fe232b242ab /generic/tclStringObj.c | |
| parent | 4c6600039e95879fea2b3e5715592473edbd05e8 (diff) | |
| download | tcl-1fe7d754ed84d81bf0fb2928b1bccfc96348bd12.zip tcl-1fe7d754ed84d81bf0fb2928b1bccfc96348bd12.tar.gz tcl-1fe7d754ed84d81bf0fb2928b1bccfc96348bd12.tar.bz2 | |
Reduce diff between 8.7 and 9.0. Add some testcases
Diffstat (limited to 'generic/tclStringObj.c')
| -rw-r--r-- | generic/tclStringObj.c | 295 |
1 files changed, 150 insertions, 145 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index a6ed49f..010d822 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -46,28 +46,28 @@ static void AppendPrintfToObjVA(Tcl_Obj *objPtr, const char *format, va_list argList); static void AppendUnicodeToUnicodeRep(Tcl_Obj *objPtr, - const Tcl_UniChar *unicode, int appendNumChars); + const Tcl_UniChar *unicode, Tcl_Size appendNumChars); static void AppendUnicodeToUtfRep(Tcl_Obj *objPtr, - const Tcl_UniChar *unicode, int numChars); + const Tcl_UniChar *unicode, Tcl_Size numChars); static void AppendUtfToUnicodeRep(Tcl_Obj *objPtr, - const char *bytes, int numBytes); + const char *bytes, Tcl_Size numBytes); static void AppendUtfToUtfRep(Tcl_Obj *objPtr, - const char *bytes, int numBytes); + const char *bytes, Tcl_Size numBytes); static void DupStringInternalRep(Tcl_Obj *objPtr, Tcl_Obj *copyPtr); -static int ExtendStringRepWithUnicode(Tcl_Obj *objPtr, - const Tcl_UniChar *unicode, int numChars); +static Tcl_Size ExtendStringRepWithUnicode(Tcl_Obj *objPtr, + const Tcl_UniChar *unicode, Tcl_Size numChars); static void ExtendUnicodeRepWithString(Tcl_Obj *objPtr, - const char *bytes, int numBytes, - int numAppendChars); + const char *bytes, Tcl_Size numBytes, + Tcl_Size numAppendChars); static void FillUnicodeRep(Tcl_Obj *objPtr); static void FreeStringInternalRep(Tcl_Obj *objPtr); static void GrowStringBuffer(Tcl_Obj *objPtr, int needed, int flag); static void GrowUnicodeBuffer(Tcl_Obj *objPtr, int needed); static int SetStringFromAny(Tcl_Interp *interp, Tcl_Obj *objPtr); static void SetUnicodeObj(Tcl_Obj *objPtr, - const Tcl_UniChar *unicode, int numChars); -static int UnicodeLength(const Tcl_UniChar *unicode); + const Tcl_UniChar *unicode, Tcl_Size numChars); +static Tcl_Size UnicodeLength(const Tcl_UniChar *unicode); #if !defined(TCL_NO_DEPRECATED) static int UTF16Length(const unsigned short *unicode); #endif @@ -425,7 +425,7 @@ Tcl_Obj * Tcl_NewStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the new object. */ - int length) /* The number of bytes to copy from "bytes" + Tcl_Size length) /* The number of bytes to copy from "bytes" * when initializing the new object. If * negative, use bytes up to the first NUL * byte. */ @@ -437,10 +437,9 @@ Tcl_Obj * Tcl_NewStringObj( const char *bytes, /* Points to the first of the length bytes * used to initialize the new object. */ - int length) /* The number of bytes to copy from "bytes" - * when initializing the new object. If - * negative, use bytes up to the first NUL - * byte. */ + Tcl_Size length) /* The number of bytes to copy from "bytes" + * when initializing the new object. If negative, + * use bytes up to the first NUL byte. */ { Tcl_Obj *objPtr; @@ -717,7 +716,7 @@ int TclCheckEmptyString( Tcl_Obj *objPtr) { - int length = -1; + Tcl_Size length = TCL_INDEX_NONE; if (objPtr->bytes == &tclEmptyString) { return TCL_EMPTYSTRING_YES; @@ -763,10 +762,10 @@ int Tcl_GetUniChar( Tcl_Obj *objPtr, /* The object to get the Unicode charater * from. */ - int index) /* Get the index'th Unicode character. */ + Tcl_Size index) /* Get the index'th Unicode character. */ { String *stringPtr; - int ch, length; + int ch; if (index < 0) { return -1; @@ -778,6 +777,7 @@ Tcl_GetUniChar( */ if (TclIsPureByteArray(objPtr)) { + Tcl_Size length; unsigned char *bytes = Tcl_GetByteArrayFromObj(objPtr, &length); if (index >= length) { return -1; @@ -819,21 +819,22 @@ int TclGetUniChar( Tcl_Obj *objPtr, /* The object to get the Unicode character * from. */ - int index) /* Get the index'th Unicode character. */ + Tcl_Size index) /* Get the index'th Unicode character. */ { UniCharString *stringPtr; - int ch, length; + int ch; if (index < 0) { return -1; } /* - * Optimize the case where we're really dealing with a ByteArray object - * we don't need to convert to a string to perform the indexing operation. + * Optimize the ByteArray case: N need need to convert to a string to + * perform the indexing operation. */ if (TclIsPureByteArray(objPtr)) { + Tcl_Size length; unsigned char *bytes = Tcl_GetByteArrayFromObj(objPtr, &length); if (index >= length) { return -1; @@ -939,10 +940,10 @@ Tcl_GetUnicode( Tcl_UniChar * TclGetUnicodeFromObj_( - Tcl_Obj *objPtr, /* The object to find the unicode string + Tcl_Obj *objPtr, /* The object to find the Unicode string * for. */ int *lengthPtr) /* If non-NULL, the location where the string - * rep's unichar length should be stored. If + * rep's Tcl_UniChar length should be stored. If * NULL, no length is stored. */ { UniCharString *stringPtr; @@ -1014,9 +1015,9 @@ TclGetUnicodeFromObj( * * Create a Tcl Object that contains the chars between first and last of * the object indicated by "objPtr". If the object is not already a - * String object, convert it to one. If first is negative, the returned - * string start at the beginning of objPtr. If last is negative, the - * returned string ends at the end of objPtr. + * String object, convert it to one. If first is negative, the + * returned string start at the beginning of objPtr. If last is + * negative, the returned string ends at the end of objPtr. * * Results: * Returns a new Tcl Object of the String type. @@ -1119,7 +1120,7 @@ TclGetRange( * If numChars is unknown, compute it. */ - if (stringPtr->numChars == -1) { + if (stringPtr->numChars == TCL_INDEX_NONE) { TclNumUtfCharsM(stringPtr->numChars, objPtr->bytes, objPtr->length); } if (stringPtr->numChars == objPtr->length) { @@ -1192,7 +1193,7 @@ Tcl_SetStringObj( Tcl_Obj *objPtr, /* Object whose internal rep to init. */ const char *bytes, /* Points to the first of the length bytes * used to initialize the object. */ - int length) /* The number of bytes to copy from "bytes" + Tcl_Size length) /* The number of bytes to copy from "bytes" * when initializing the object. If negative, * use bytes up to the first NUL byte.*/ { @@ -1223,20 +1224,19 @@ Tcl_SetStringObj( * * Tcl_SetObjLength -- * - * This function changes the length of the string representation of an - * object. + * Changes the length of the string representation of objPtr. * * Results: * None. * * Side effects: - * If the size of objPtr's string representation is greater than length, - * then it is reduced to length and a new terminating null byte is stored - * in the strength. If the length of the string representation is greater - * than length, the storage space is reallocated to the given length; a - * null byte is stored at the end, but other bytes past the end of the - * original string representation are undefined. The object's internal - * representation is changed to "expendable string". + * If the size of objPtr's string representation is greater than length, a + * new terminating null byte is stored in objPtr->bytes at length, and + * bytes at positions past length have no meaning. If the length of the + * string representation is greater than length, the storage space is + * reallocated to length+1. + * + * The object's internal representation is changed to &tclStringType. * *---------------------------------------------------------------------- */ @@ -1245,20 +1245,15 @@ void Tcl_SetObjLength( Tcl_Obj *objPtr, /* Pointer to object. This object must not * currently be shared. */ - int length) /* Number of bytes desired for string + Tcl_Size length) /* Number of bytes desired for string * representation of object, not including * terminating null byte. */ { UniCharString *stringPtr; if (length < 0) { - /* - * Setting to a negative length is nonsense. This is probably the - * result of overflowing the signed integer range. - */ - - Tcl_Panic("Tcl_SetObjLength: negative length requested: " - "%d (integer overflow?)", length); + Tcl_Panic("Tcl_SetObjLength: length requested is negative: " + "%" TCL_SIZE_MODIFIER "d (integer overflow?)", length); } if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_SetObjLength"); @@ -1291,10 +1286,10 @@ Tcl_SetObjLength( objPtr->bytes[length] = 0; /* - * Invalidate the unicode data. + * Invalidate the Unicode data. */ - stringPtr->numChars = -1; + stringPtr->numChars = TCL_INDEX_NONE; stringPtr->hasUnicode = 0; } else { /* @@ -1350,20 +1345,17 @@ int Tcl_AttemptSetObjLength( Tcl_Obj *objPtr, /* Pointer to object. This object must not * currently be shared. */ - int length) /* Number of bytes desired for string + Tcl_Size length) /* Number of bytes desired for string * representation of object, not including * terminating null byte. */ { UniCharString *stringPtr; if (length < 0) { - /* - * Setting to a negative length is nonsense. This is probably the - * result of overflowing the signed integer range. - */ - + /* Negative lengths => most likely integer overflow */ return 0; } + if (Tcl_IsShared(objPtr)) { Tcl_Panic("%s called with shared object", "Tcl_AttemptSetObjLength"); } @@ -1404,7 +1396,7 @@ Tcl_AttemptSetObjLength( * Invalidate the Unicode data. */ - stringPtr->numChars = -1; + stringPtr->numChars = TCL_INDEX_NONE; stringPtr->hasUnicode = 0; } else { /* @@ -1505,14 +1497,14 @@ UTF16Length( } #endif -static int +static Tcl_Size UnicodeLength( const Tcl_UniChar *unicode) { - int numChars = 0; + Tcl_Size numChars = 0; if (unicode) { - while (numChars >= 0 && unicode[numChars] != 0) { + while ((numChars >= 0) && (unicode[numChars] != 0)) { numChars++; } } @@ -1525,7 +1517,7 @@ SetUnicodeObj( Tcl_Obj *objPtr, /* The object to set the string of. */ const Tcl_UniChar *unicode, /* The Unicode string used to initialize the * object. */ - int numChars) /* Number of characters in the Unicode + Tcl_Size numChars) /* Number of characters in the Unicode * string. */ { UniCharString *stringPtr; @@ -1576,18 +1568,18 @@ Tcl_AppendLimitedToObj( Tcl_Obj *objPtr, /* Points to the object to append to. */ const char *bytes, /* Points to the bytes to append to the * object. */ - int length, /* The number of bytes available to be - * appended from "bytes". If < 0, then all - * bytes up to a NUL byte are available. */ - int limit, /* The maximum number of bytes to append to + Tcl_Size length, /* The number of bytes available to be + * appended from "bytes". If -1, then + * all bytes up to a NUL byte are available. */ + Tcl_Size limit, /* The maximum number of bytes to append to * the object. */ const char *ellipsis) /* Ellipsis marker string, appended to the * object to indicate not all available bytes * at "bytes" were appended. */ { UniCharString *stringPtr; - int toCopy = 0; - int eLen = 0; + Tcl_Size toCopy = 0; + Tcl_Size eLen = 0; if (length < 0) { length = (bytes ? strlen(bytes) : 0); @@ -1672,8 +1664,8 @@ Tcl_AppendToObj( Tcl_Obj *objPtr, /* Points to the object to append to. */ const char *bytes, /* Points to the bytes to append to the * object. */ - int length) /* The number of bytes to append from "bytes". - * If < 0, then append all bytes up to NUL + Tcl_Size length) /* The number of bytes to append from "bytes". + * If negative, then append all bytes up to NUL * byte. */ { Tcl_AppendLimitedToObj(objPtr, bytes, length, INT_MAX, NULL); @@ -1701,7 +1693,8 @@ TclAppendUnicodeToObj( Tcl_Obj *objPtr, /* Points to the object to append to. */ const Tcl_UniChar *unicode, /* The Unicode string to append to the * object. */ - int length) /* Number of chars in unicode. */ + Tcl_Size length) /* Number of chars in Unicode. Negative + * lengths means nul terminated */ { UniCharString *stringPtr; @@ -1735,7 +1728,8 @@ Tcl_AppendUnicodeToObj( Tcl_Obj *objPtr, /* Points to the object to append to. */ const unsigned short *unicode, /* The unicode string to append to the * object. */ - int length) /* Number of chars in "unicode". */ + Tcl_Size length) /* Number of chars in Unicode. Negative + * lengths means nul terminated */ { String *stringPtr; @@ -1783,7 +1777,8 @@ Tcl_AppendObjToObj( Tcl_Obj *appendObjPtr) /* Object to append. */ { UniCharString *stringPtr; - int length, numChars, appendNumChars = -1; + Tcl_Size length, numChars; + Tcl_Size appendNumChars = TCL_INDEX_NONE; const char *bytes; /* @@ -1823,7 +1818,7 @@ Tcl_AppendObjToObj( * First, get the lengths. */ - int lengthSrc; + Tcl_Size lengthSrc; (void) Tcl_GetByteArrayFromObj(objPtr, &length); (void) Tcl_GetByteArrayFromObj(appendObjPtr, &lengthSrc); @@ -1929,10 +1924,10 @@ static void AppendUnicodeToUnicodeRep( Tcl_Obj *objPtr, /* Points to the object to append to. */ const Tcl_UniChar *unicode, /* String to append. */ - int appendNumChars) /* Number of chars of "unicode" to append. */ + Tcl_Size appendNumChars) /* Number of chars of "unicode" to append. */ { UniCharString *stringPtr; - int numChars; + Tcl_Size numChars; if (appendNumChars < 0) { appendNumChars = UnicodeLength(unicode); @@ -1956,7 +1951,7 @@ AppendUnicodeToUnicodeRep( uniCharStringCheckLimits(numChars); if (numChars > stringPtr->maxChars) { - int offset = -1; + Tcl_Size offset = TCL_INDEX_NONE; /* * Protect against case where Unicode points into the existing @@ -2018,13 +2013,13 @@ static void AppendUnicodeToUtfRep( Tcl_Obj *objPtr, /* Points to the object to append to. */ const Tcl_UniChar *unicode, /* String to convert to UTF. */ - int numChars) /* Number of chars of unicode to convert. */ + Tcl_Size numChars) /* Number of chars of Unicode to convert. */ { UniCharString *stringPtr = GET_UNICHAR_STRING(objPtr); numChars = ExtendStringRepWithUnicode(objPtr, unicode, numChars); - if (stringPtr->numChars != -1) { + if (stringPtr->numChars != TCL_INDEX_NONE) { stringPtr->numChars += numChars; } } @@ -2051,7 +2046,7 @@ static void AppendUtfToUnicodeRep( Tcl_Obj *objPtr, /* Points to the object to append to. */ const char *bytes, /* String to convert to Unicode. */ - int numBytes) /* Number of bytes of "bytes" to convert. */ + Tcl_Size numBytes) /* Number of bytes of "bytes" to convert. */ { UniCharString *stringPtr; @@ -2087,10 +2082,10 @@ static void AppendUtfToUtfRep( Tcl_Obj *objPtr, /* Points to the object to append to. */ const char *bytes, /* String to append. */ - int numBytes) /* Number of bytes of "bytes" to append. */ + Tcl_Size numBytes) /* Number of bytes of "bytes" to append. */ { UniCharString *stringPtr; - int newLength, oldLength; + Tcl_Size newLength, oldLength; if (numBytes == 0) { return; @@ -2112,7 +2107,7 @@ AppendUtfToUtfRep( stringPtr = GET_UNICHAR_STRING(objPtr); if (newLength > stringPtr->allocated) { - int offset = -1; + Tcl_Size offset = TCL_INDEX_NONE; /* * Protect against case where unicode points into the existing @@ -2247,12 +2242,12 @@ Tcl_AppendFormatToObj( Tcl_Interp *interp, Tcl_Obj *appendObj, const char *format, - int objc, + Tcl_Size objc, Tcl_Obj *const objv[]) { const char *span = format, *msg, *errCode; - int numBytes = 0, objIndex = 0, gotXpg = 0, gotSequential = 0; - int originalLength, limit; + int gotXpg = 0, gotSequential = 0; + Tcl_Size objIndex = 0, originalLength, limit, numBytes = 0; Tcl_UniChar ch = 0; static const char *mixedXPG = "cannot mix \"%\" and \"%n$\" conversion specifiers"; @@ -2275,11 +2270,13 @@ Tcl_AppendFormatToObj( while (*format != '\0') { char *end; int gotMinus = 0, gotHash = 0, gotZero = 0, gotSpace = 0, gotPlus = 0; - int width, gotPrecision, precision, sawFlag, useShort = 0, useBig = 0; + int gotPrecision, sawFlag, useShort = 0, useBig = 0; + Tcl_WideInt width, precision; #ifndef TCL_WIDE_INT_IS_LONG int useWide = 0; #endif - int newXpg, numChars, allocSegment = 0, segmentLimit, segmentNumBytes; + int newXpg, allocSegment = 0; + Tcl_Size numChars, segmentLimit, segmentNumBytes; Tcl_Obj *segment; int step = TclUtfToUniChar(format, &ch); @@ -2400,7 +2397,7 @@ Tcl_AppendFormatToObj( errCode = gotXpg ? "INDEXRANGE" : "FIELDVARMISMATCH"; goto errorMsg; } - if (TclGetIntFromObj(interp, objv[objIndex], &width) != TCL_OK) { + if (TclGetWideIntFromObj(interp, objv[objIndex], &width) != TCL_OK) { goto error; } if (width < 0) { @@ -2437,7 +2434,7 @@ Tcl_AppendFormatToObj( errCode = gotXpg ? "INDEXRANGE" : "FIELDVARMISMATCH"; goto errorMsg; } - if (TclGetIntFromObj(interp, objv[objIndex], &precision) + if (TclGetWideIntFromObj(interp, objv[objIndex], &precision) != TCL_OK) { goto error; } @@ -2558,7 +2555,8 @@ Tcl_AppendFormatToObj( long l; Tcl_WideInt w; mp_int big; - int toAppend, isNegative = 0; + int isNegative = 0; + Tcl_Size toAppend; #ifndef TCL_WIDE_INT_IS_LONG if (ch == 'p') { @@ -2654,7 +2652,7 @@ Tcl_AppendFormatToObj( switch (ch) { case 'd': { - int length; + Tcl_Size length; Tcl_Obj *pure; const char *bytes; @@ -2726,7 +2724,8 @@ Tcl_AppendFormatToObj( case 'b': { Tcl_WideUInt bits = (Tcl_WideUInt) 0; Tcl_WideInt numDigits = (Tcl_WideInt) 0; - int length, numBits = 4, base = 16, index = 0, shift = 0; + int numBits = 4, base = 16, index = 0, shift = 0; + Tcl_Size length; Tcl_Obj *pure; char *bytes; @@ -2887,14 +2886,14 @@ Tcl_AppendFormatToObj( *p++ = '+'; } if (width) { - p += snprintf(p, TCL_INTEGER_SPACE, "%d", width); + p += snprintf(p, TCL_INTEGER_SPACE, "%" TCL_LL_MODIFIER "d", width); if (width > length) { length = width; } } if (gotPrecision) { *p++ = '.'; - p += snprintf(p, TCL_INTEGER_SPACE, "%d", precision); + p += snprintf(p, TCL_INTEGER_SPACE, "%" TCL_LL_MODIFIER "d", precision); if (precision > INT_MAX - length) { msg = overflow; errCode = "OVERFLOW"; @@ -3020,7 +3019,7 @@ Tcl_Obj * Tcl_Format( Tcl_Interp *interp, const char *format, - int objc, + Tcl_Size objc, Tcl_Obj *const objv[]) { int result; @@ -3053,7 +3052,8 @@ AppendPrintfToObjVA( const char *format, va_list argList) { - int code, objc; + int code; + Tcl_Size objc; Tcl_Obj **objv, *list; const char *p; @@ -3334,12 +3334,14 @@ Tcl_Obj * TclStringRepeat( Tcl_Interp *interp, Tcl_Obj *objPtr, - int count, + Tcl_Size count, int flags) { Tcl_Obj *objResultPtr; int inPlace = flags & TCL_STRING_IN_PLACE; - int length = 0, unichar = 0, done = 1; + Tcl_Size length = 0; + int unichar = 0; + Tcl_Size done = 1; int binary = TclIsPureByteArray(objPtr); /* assert (count >= 2) */ @@ -3479,22 +3481,23 @@ TclStringRepeat( Tcl_Obj * TclStringCat( Tcl_Interp *interp, - int objc, + Tcl_Size objc, Tcl_Obj * const objv[], int flags) { Tcl_Obj *objResultPtr, * const *ov; - int oc, length = 0, binary = 1; + int binary = 1; + Tcl_Size oc, length = 0; int allowUniChar = 1, requestUniChar = 0, forceUniChar = 0; - int first = objc - 1; /* Index of first value possibly not empty */ - int last = 0; /* Index of last value possibly not empty */ + Tcl_Size first = objc - 1; /* Index of first value possibly not empty */ + Tcl_Size last = 0; /* Index of last value possibly not empty */ int inPlace = flags & TCL_STRING_IN_PLACE; /* assert ( objc >= 0 ) */ if (objc <= 1) { - /* Only one or no objects; return first or empty */ - return objc ? objv[0] : Tcl_NewObj(); + /* Negative (shouldn't be), one or no objects; return first or empty */ + return objc == 1 ? objv[0] : Tcl_NewObj(); } /* assert ( objc >= 2 ) */ @@ -3546,7 +3549,7 @@ TclStringCat( * Result will be pure byte array. Pre-size it */ - int numBytes; + Tcl_Size numBytes; ov = objv; oc = objc; do { @@ -3565,7 +3568,8 @@ TclStringCat( last = objc - oc; if (length == 0) { first = last; - } else if (numBytes > INT_MAX - length) { + } + if (length > (INT_MAX-numBytes)) { goto overflow; } length += numBytes; @@ -3583,7 +3587,7 @@ TclStringCat( Tcl_Obj *objPtr = *ov++; if ((objPtr->bytes == NULL) || (objPtr->length)) { - int numChars; + Tcl_Size numChars; TclGetUnicodeFromObj_(objPtr, &numChars); /* PANIC? */ if (numChars) { @@ -3632,7 +3636,7 @@ TclStringCat( first = last = objc - oc - 1; if (oc && (length == 0)) { - int numBytes; + Tcl_Size numBytes; /* assert ( pendingPtr != NULL ) */ @@ -3665,7 +3669,7 @@ TclStringCat( } while (oc && (length == 0)); while (oc) { - int numBytes; + Tcl_Size numBytes; Tcl_Obj *objPtr = *ov++; /* assert ( length > 0 && pendingPtr == NULL ) */ @@ -3700,7 +3704,7 @@ TclStringCat( */ if (inPlace && !Tcl_IsShared(*objv)) { - int start; + Tcl_Size start; objResultPtr = *objv++; objc--; Tcl_GetByteArrayFromObj(objResultPtr, &start); @@ -3719,7 +3723,7 @@ TclStringCat( */ if (TclIsPureByteArray(objPtr)) { - int more; + Tcl_Size more; unsigned char *src = Tcl_GetByteArrayFromObj(objPtr, &more); memcpy(dst, src, more); dst += more; @@ -3730,7 +3734,7 @@ TclStringCat( Tcl_UniChar *dst; if (inPlace && !Tcl_IsShared(*objv)) { - int start; + Tcl_Size start; objResultPtr = *objv++; objc--; @@ -3770,7 +3774,7 @@ TclStringCat( Tcl_Obj *objPtr = *objv++; if ((objPtr->bytes == NULL) || (objPtr->length)) { - int more; + Tcl_Size more; Tcl_UniChar *src = TclGetUnicodeFromObj_(objPtr, &more); memcpy(dst, src, more * sizeof(Tcl_UniChar)); dst += more; @@ -3781,7 +3785,7 @@ TclStringCat( char *dst; if (inPlace && !Tcl_IsShared(*objv)) { - int start; + Tcl_Size start; objResultPtr = *objv++; objc--; @@ -3817,7 +3821,7 @@ TclStringCat( Tcl_Obj *objPtr = *objv++; if ((objPtr->bytes == NULL) || (objPtr->length)) { - int more; + Tcl_Size more; char *src = TclGetStringFromObj(objPtr, &more); memcpy(dst, src, more); @@ -3860,11 +3864,12 @@ TclStringCmp( Tcl_Obj *value2Ptr, int checkEq, /* comparison is only for equality */ int nocase, /* comparison is not case sensitive */ - int reqlength) /* requested length in characters; - * TCL_INDEX_NONE to compare whole strings */ + Tcl_Size reqlength) /* requested length in characters; + * negative to compare whole strings */ { const char *s1, *s2; - int empty, length, match, s1len, s2len; + int empty, match; + Tcl_Size length, s1len, s2len; memCmpFn_t memCmpFn; if ((reqlength == 0) || (value1Ptr == value2Ptr)) { @@ -4053,12 +4058,12 @@ Tcl_Obj * TclStringFirst( Tcl_Obj *needle, Tcl_Obj *haystack, - int start) + Tcl_Size start) { int lh, ln = TclGetCharLength(needle); - Tcl_Obj *result; - int value = -1; + Tcl_Size value = TCL_INDEX_NONE; Tcl_UniChar *checkStr, *endStr, *uh, *un; + Tcl_Obj *obj; if (start < 0) { start = 0; @@ -4134,8 +4139,8 @@ TclStringFirst( } } firstEnd: - TclNewIndexObj(result, value); - return result; + TclNewIndexObj(obj, value); + return obj; } /* @@ -4162,10 +4167,10 @@ TclStringLast( Tcl_Obj *haystack, int last) { - int lh, ln = TclGetCharLength(needle); - Tcl_Obj *result; - int value = -1; + Tcl_Size lh, ln = TclGetCharLength(needle); + Tcl_Size value = TCL_INDEX_NONE; Tcl_UniChar *checkStr, *uh, *un; + Tcl_Obj *obj; if (ln == 0) { /* @@ -4221,8 +4226,8 @@ TclStringLast( checkStr--; } lastEnd: - TclNewIndexObj(result, value); - return result; + TclNewIndexObj(obj, value); + return obj; } /* @@ -4247,7 +4252,7 @@ static void ReverseBytes( unsigned char *to, /* Copy bytes into here... */ unsigned char *from, /* ...from here... */ - int count) /* Until this many are copied, */ + Tcl_Size count) /* Until this many are copied, */ /* reversing as you go. */ { unsigned char *src = from + count; @@ -4280,7 +4285,7 @@ TclStringReverse( #endif if (TclIsPureByteArray(objPtr)) { - int numBytes; + Tcl_Size numBytes; unsigned char *from = Tcl_GetByteArrayFromObj(objPtr, &numBytes); if (!inPlace || Tcl_IsShared(objPtr)) { @@ -4361,8 +4366,8 @@ TclStringReverse( } if (objPtr->bytes) { - int numChars = stringPtr->numChars; - int numBytes = objPtr->length; + Tcl_Size numChars = stringPtr->numChars; + Tcl_Size numBytes = objPtr->length; char *to, *from = objPtr->bytes; if (!inPlace || Tcl_IsShared(objPtr)) { @@ -4381,7 +4386,7 @@ TclStringReverse( * Pass 1. Reverse the bytes of each multi-byte character. */ - int bytesLeft = numBytes; + Tcl_Size bytesLeft = numBytes; int chw; while (bytesLeft) { @@ -4468,7 +4473,7 @@ TclStringReplace( */ if (TclIsPureByteArray(objPtr)) { - int numBytes; + Tcl_Size numBytes; unsigned char *bytes = Tcl_GetByteArrayFromObj(objPtr, &numBytes); if (insertPtr == NULL) { @@ -4491,7 +4496,7 @@ TclStringReplace( } if (TclIsPureByteArray(insertPtr)) { - int newBytes; + Tcl_Size newBytes; unsigned char *iBytes = Tcl_GetByteArrayFromObj(insertPtr, &newBytes); @@ -4506,7 +4511,7 @@ TclStringReplace( return objPtr; } - if (newBytes > INT_MAX - (numBytes - count)) { + if (newBytes > (INT_MAX - (numBytes - count))) { if (interp) { Tcl_SetObjResult(interp, Tcl_ObjPrintf( "max size for a Tcl value (%d bytes) exceeded", @@ -4536,7 +4541,7 @@ TclStringReplace( /* The traditional implementation... */ { - int numChars; + Tcl_Size numChars; Tcl_UniChar *ustring = TclGetUnicodeFromObj_(objPtr, &numChars); /* TODO: Is there an in-place option worth pursuing here? */ @@ -4545,7 +4550,7 @@ TclStringReplace( if (insertPtr) { Tcl_AppendObjToObj(result, insertPtr); } - if (first + count < numChars) { + if ((first + count) < numChars) { TclAppendUnicodeToObj(result, ustring + first + count, numChars - first - count); } @@ -4586,17 +4591,17 @@ static void ExtendUnicodeRepWithString( Tcl_Obj *objPtr, const char *bytes, - int numBytes, - int numAppendChars) + Tcl_Size numBytes, + Tcl_Size numAppendChars) { UniCharString *stringPtr = GET_UNICHAR_STRING(objPtr); - int needed, numOrigChars = 0; + Tcl_Size needed, numOrigChars = 0; Tcl_UniChar *dst, unichar = 0; if (stringPtr->hasUnicode) { numOrigChars = stringPtr->numChars; } - if (numAppendChars == -1) { + if (numAppendChars < 0) { TclNumUtfCharsM(numAppendChars, bytes, numBytes); } needed = numOrigChars + numAppendChars; @@ -4661,7 +4666,7 @@ DupStringInternalRep( UniCharString *srcStringPtr = GET_UNICHAR_STRING(srcPtr); UniCharString *copyStringPtr = NULL; - if (srcStringPtr->numChars == -1) { + if (srcStringPtr->numChars == TCL_INDEX_NONE) { /* * 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 @@ -4720,7 +4725,7 @@ DupStringInternalRep( * * Side effects: * Any old internal representation for objPtr is freed and the internal - * representation is set to "String". + * representation is set to &tclStringType. * *---------------------------------------------------------------------- */ @@ -4797,17 +4802,17 @@ UpdateStringOfString( } } -static int +static Tcl_Size ExtendStringRepWithUnicode( Tcl_Obj *objPtr, const Tcl_UniChar *unicode, - int numChars) + Tcl_Size numChars) { /* * Precondition: this is the "string" Tcl_ObjType. */ - int i, origLength, size = 0; + Tcl_Size i, origLength, size = 0; char *dst; UniCharString *stringPtr = GET_UNICHAR_STRING(objPtr); |
