diff options
| -rw-r--r-- | generic/tclIO.c | 57 | ||||
| -rw-r--r-- | tests/io.test | 8 |
2 files changed, 37 insertions, 28 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index c0a42be..db0fa0d 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -5936,32 +5936,6 @@ DoReadChars( #define UTF_EXPANSION_FACTOR 1024 int factor = UTF_EXPANSION_FACTOR; - binaryMode = (encoding == GetBinaryEncoding()) - && (statePtr->inputTranslation == TCL_TRANSLATE_LF) - && (statePtr->inEofChar == '\0'); - - if (appendFlag) { - if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL))) { - binaryMode = 0; - } - } else { - if (binaryMode) { - Tcl_SetByteArrayLength(objPtr, 0); - } else { - Tcl_SetObjLength(objPtr, 0); - - /* - * We're going to access objPtr->bytes directly, so we must ensure - * that this is actually a string object (otherwise it might have - * been pure Unicode). - * - * Probably not needed anymore. - */ - - TclGetString(objPtr); - } - } - if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) { /* TODO: We don't need this call? */ UpdateInterest(chanPtr); @@ -6006,6 +5980,37 @@ DoReadChars( chanPtr = statePtr->topChanPtr; TclChannelPreserve((Tcl_Channel)chanPtr); + + binaryMode = (encoding == GetBinaryEncoding()) + && (statePtr->inputTranslation == TCL_TRANSLATE_LF) + && (statePtr->inEofChar == '\0'); + + if (appendFlag) { + if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL))) { + binaryMode = 0; + } + } else { + if (binaryMode) { + Tcl_SetByteArrayLength(objPtr, 0); + } else { + Tcl_SetObjLength(objPtr, 0); + + /* + * We're going to access objPtr->bytes directly, so we must ensure + * that this is actually a string object (otherwise it might have + * been pure Unicode). + * + * Probably not needed anymore. + */ + + TclGetString(objPtr); + } + } + + + + + /* * Must clear the BLOCKED|EOF flags here since we check before reading. */ diff --git a/tests/io.test b/tests/io.test index 1f2d78b..4e8fb4d 100644 --- a/tests/io.test +++ b/tests/io.test @@ -9411,12 +9411,16 @@ test io-75.12 { unset res } -match glob -result {{error reading "file*":\ invalid or incomplete multibyte or wide character} 4181} -test io-75.13 {invalid utf-8 encoding read is not ignored (-profile strict)} -setup { +test io-75.13 { + In nonblocking mode when there is an encoding error the data that has been + successfully read so far is returned first and then the error is returned + on the next call to [read]. +} -setup { set fn [makeFile {} io-75.13] set f [open $fn w+] fconfigure $f -encoding binary # \x81 is invalid in utf-8 - puts -nonewline $f "A\x81" + puts -nonewline $f A\x81 flush $f seek $f 0 fconfigure $f -encoding utf-8 -blocking 0 -eofchar "" -translation lf -profile strict |
