diff options
author | dgp <dgp@noemail.net> | 2014-03-23 20:59:28 (GMT) |
---|---|---|
committer | dgp <dgp@noemail.net> | 2014-03-23 20:59:28 (GMT) |
commit | 156182a1e5a073fdacd1096a252b1c9e4ed09290 (patch) | |
tree | 4d992eee0064c3d2f62c7c5523936d0186228278 /generic/tclStringObj.c | |
parent | d42d1b867b2d0d0df42c0a7fa672095f0060238a (diff) | |
parent | 7fb9690c605010ec5391788c1cb9a85fba8416b9 (diff) | |
download | tcl-156182a1e5a073fdacd1096a252b1c9e4ed09290.zip tcl-156182a1e5a073fdacd1096a252b1c9e4ed09290.tar.gz tcl-156182a1e5a073fdacd1096a252b1c9e4ed09290.tar.bz2 |
Merge the checkins of the dgp-read-bytes branch onto the trunk, up to
and including checkin a1e82fb63e . Do not merge checkin bae1c688f2
which starts to take the dgp-read-bytes branch into directions apparently
unfriendly to stacked channels, which tests for [chan push] on the trunk
help us to detect.
FossilOrigin-Name: c4c1cd81e4e89d502fd3f2fb8280f698d7ce1950
Diffstat (limited to 'generic/tclStringObj.c')
-rw-r--r-- | generic/tclStringObj.c | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/generic/tclStringObj.c b/generic/tclStringObj.c index dffa38c..c04944d 100644 --- a/generic/tclStringObj.c +++ b/generic/tclStringObj.c @@ -1123,7 +1123,8 @@ Tcl_AppendLimitedToObj( if (ellipsis == NULL) { ellipsis = "..."; } - toCopy = Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes; + toCopy = (bytes == NULL) ? limit + : Tcl_UtfPrev(bytes+limit+1-strlen(ellipsis), bytes) - bytes; } /* @@ -1435,7 +1436,7 @@ AppendUnicodeToUnicodeRep( * the reallocs below. */ - if (unicode >= stringPtr->unicode + if (unicode && unicode >= stringPtr->unicode && unicode <= stringPtr->unicode + stringPtr->maxChars) { offset = unicode - stringPtr->unicode; } @@ -1457,8 +1458,10 @@ AppendUnicodeToUnicodeRep( * trailing null. */ - memmove(stringPtr->unicode + stringPtr->numChars, unicode, - appendNumChars * sizeof(Tcl_UniChar)); + if (unicode) { + memmove(stringPtr->unicode + stringPtr->numChars, unicode, + appendNumChars * sizeof(Tcl_UniChar)); + } stringPtr->unicode[numChars] = 0; stringPtr->numChars = numChars; stringPtr->allocated = 0; @@ -1597,7 +1600,7 @@ AppendUtfToUtfRep( * the reallocs below. */ - if (bytes >= objPtr->bytes + if (bytes && bytes >= objPtr->bytes && bytes <= objPtr->bytes + objPtr->length) { offset = bytes - objPtr->bytes; } @@ -1625,7 +1628,9 @@ AppendUtfToUtfRep( stringPtr->numChars = -1; stringPtr->hasUnicode = 0; - memmove(objPtr->bytes + oldLength, bytes, numBytes); + if (bytes) { + memmove(objPtr->bytes + oldLength, bytes, numBytes); + } objPtr->bytes[newLength] = 0; objPtr->length = newLength; } @@ -2658,6 +2663,38 @@ Tcl_ObjPrintf( /* *--------------------------------------------------------------------------- * + * TclGetStringStorage -- + * + * Returns the string storage space of a Tcl_Obj. + * + * Results: + * The pointer value objPtr->bytes is returned and the number of bytes + * allocated there is written to *sizePtr (if known). + * + * Side effects: + * May set objPtr->bytes. + * + *--------------------------------------------------------------------------- + */ + +char * +TclGetStringStorage( + Tcl_Obj *objPtr, + unsigned int *sizePtr) +{ + String *stringPtr; + + if (objPtr->typePtr != &tclStringType || objPtr->bytes == NULL) { + return TclGetStringFromObj(objPtr, (int *)sizePtr); + } + + stringPtr = GET_STRING(objPtr); + *sizePtr = stringPtr->allocated; + return objPtr->bytes; +} +/* + *--------------------------------------------------------------------------- + * * TclStringObjReverse -- * * Implements the [string reverse] operation. @@ -2848,7 +2885,11 @@ ExtendUnicodeRepWithString( } stringPtr->hasUnicode = 1; - stringPtr->numChars = needed; + if (bytes) { + stringPtr->numChars = needed; + } else { + numAppendChars = 0; + } for (dst=stringPtr->unicode + numOrigChars; numAppendChars-- > 0; dst++) { bytes += TclUtfToUniChar(bytes, dst); } |