Tcl Source Code

Check-in [128d902c33]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:[272e866f1e][965a39e314] Revise ReadBytes so that it uses the bytearray growth algorithm already in TclAppendBytesToByteArray() rather than poorly making its own.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | bug-272e866f1e
Files: files | file ages | folders
SHA1: 128d902c33efffa7eb8ab6f353f7fe7d680739d2
User & Date: dgp 2014-01-15 20:21:07.838
Context
2014-01-17
09:43
remove some dead code Closed-Leaf check-in: a9e0697268 user: dkf tags: bug-272e866f1e
2014-01-15
20:21
[272e866f1e][965a39e314] Revise ReadBytes so that it uses the bytearray growth algorithm already in ... check-in: 128d902c33 user: dgp tags: bug-272e866f1e
19:04
[2992970] Restore the safety of Tcl_AppendObjToObj(x, x) for bytearrays. Also moves overflow checkin... Closed-Leaf check-in: e5267e9dcd user: dgp tags: bug-2992970
Changes
Unified Diff Ignore Whitespace Patch
Changes to generic/tclIO.c.
6019
6020
6021
6022
6023
6024
6025

6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039




6040
6041
6042
6043
6044
6045
6046

6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058

6059
6060
6061
6062
6063

6064
6065
6066
6067
6068
6069
6070
    srcLen = BytesLeft(bufPtr);

    toRead = bytesToRead;
    if ((unsigned) toRead > (unsigned) srcLen) {
	toRead = srcLen;
    }


    dst = (char *) Tcl_GetByteArrayFromObj(objPtr, &length);
    if (toRead > length - offset - 1) {
	/*
	 * Double the existing size of the object or make enough room to hold
	 * all the characters we may get from the source buffer, whichever is
	 * larger.
	 */

	length = offset * 2;
	if (offset < toRead) {
	    length = offset + toRead + 1;
	}
	dst = (char *) Tcl_SetByteArrayLength(objPtr, length);
    }




    dst += offset;

    if (GotFlag(statePtr, INPUT_NEED_NL)) {
	ResetFlag(statePtr, INPUT_NEED_NL);
	if ((srcLen == 0) || (*src != '\n')) {
	    *dst = '\r';
	    *offsetPtr += 1;

	    return 1;
	}
	*dst++ = '\n';
	src++;
	srcLen--;
	toRead--;
    }

    srcRead = srcLen;
    dstWrote = toRead;
    if (TranslateInputEOL(statePtr, dst, src, &dstWrote, &srcRead) != 0) {
	if (dstWrote == 0) {

	    return -1;
	}
    }
    bufPtr->nextRemoved += srcRead;
    *offsetPtr += dstWrote;

    return dstWrote;
}

/*
 *---------------------------------------------------------------------------
 *
 * ReadChars --







>














>
>
>
>







>












>





>







6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
    srcLen = BytesLeft(bufPtr);

    toRead = bytesToRead;
    if ((unsigned) toRead > (unsigned) srcLen) {
	toRead = srcLen;
    }

#if 0
    dst = (char *) Tcl_GetByteArrayFromObj(objPtr, &length);
    if (toRead > length - offset - 1) {
	/*
	 * Double the existing size of the object or make enough room to hold
	 * all the characters we may get from the source buffer, whichever is
	 * larger.
	 */

	length = offset * 2;
	if (offset < toRead) {
	    length = offset + toRead + 1;
	}
	dst = (char *) Tcl_SetByteArrayLength(objPtr, length);
    }
#else
    TclAppendBytesToByteArray(objPtr, NULL, toRead);
    dst = (char *) Tcl_GetByteArrayFromObj(objPtr, &length);
#endif
    dst += offset;

    if (GotFlag(statePtr, INPUT_NEED_NL)) {
	ResetFlag(statePtr, INPUT_NEED_NL);
	if ((srcLen == 0) || (*src != '\n')) {
	    *dst = '\r';
	    *offsetPtr += 1;
	    Tcl_SetByteArrayLength(objPtr, *offsetPtr);
	    return 1;
	}
	*dst++ = '\n';
	src++;
	srcLen--;
	toRead--;
    }

    srcRead = srcLen;
    dstWrote = toRead;
    if (TranslateInputEOL(statePtr, dst, src, &dstWrote, &srcRead) != 0) {
	if (dstWrote == 0) {
	    Tcl_SetByteArrayLength(objPtr, *offsetPtr);
	    return -1;
	}
    }
    bufPtr->nextRemoved += srcRead;
    *offsetPtr += dstWrote;
    Tcl_SetByteArrayLength(objPtr, *offsetPtr);
    return dstWrote;
}

/*
 *---------------------------------------------------------------------------
 *
 * ReadChars --