summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c74
1 files changed, 34 insertions, 40 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index a45f39a..cea8119 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -1675,11 +1675,8 @@ Tcl_CreateChannel(
* interpretation that Tcl_Channels give to the "-encoding binary" option.
*/
- statePtr->encoding = NULL;
name = Tcl_GetEncodingName(NULL);
- if (strcmp(name, "binary") != 0) {
- statePtr->encoding = Tcl_GetEncoding(NULL, name);
- }
+ statePtr->encoding = Tcl_GetEncoding(NULL, name);
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags,
@@ -3480,7 +3477,8 @@ TclClose(
stickyError = 0;
- if (GotFlag(statePtr, TCL_WRITABLE) && (statePtr->encoding != NULL)
+ if (GotFlag(statePtr, TCL_WRITABLE)
+ && (statePtr->encoding != GetBinaryEncoding())
&& !(statePtr->outputEncodingFlags & TCL_ENCODING_START)) {
int code = CheckChannelErrors(statePtr, TCL_WRITABLE);
@@ -4269,11 +4267,7 @@ Tcl_WriteObj(
do {
int chunkSize = srcLen > INT_MAX ? INT_MAX : srcLen;
int written;
- if (statePtr->encoding == NULL) {
- written = WriteBytes(chanPtr, src, chunkSize);
- } else {
- written = WriteChars(chanPtr, src, chunkSize);
- }
+ written = WriteChars(chanPtr, src, chunkSize);
if (written < 0) {
return TCL_INDEX_NONE;
}
@@ -4651,7 +4645,7 @@ Tcl_GetsObj(
* done on objPtr.
*/
- if ((statePtr->encoding == NULL)
+ if (statePtr->encoding == GetBinaryEncoding()
&& ((statePtr->inputTranslation == TCL_TRANSLATE_LF)
|| (statePtr->inputTranslation == TCL_TRANSLATE_CR))
&& Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL) != NULL) {
@@ -4682,15 +4676,6 @@ Tcl_GetsObj(
}
/*
- * If there is no encoding, use "iso8859-1" -- Tcl_GetsObj() doesn't
- * produce ByteArray objects.
- */
-
- if (encoding == NULL) {
- encoding = GetBinaryEncoding();
- }
-
- /*
* Object used by FilterInputBytes to keep track of how much data has been
* consumed from the channel buffers.
*/
@@ -5236,7 +5221,7 @@ TclGetsObjBinary(
* XXX - unimplemented.
*/
- if (statePtr->encoding != NULL) {
+ if (statePtr->encoding != GetBinaryEncoding()) {
}
/*
@@ -5951,7 +5936,7 @@ DoReadChars(
#define UTF_EXPANSION_FACTOR 1024
int factor = UTF_EXPANSION_FACTOR;
- binaryMode = (encoding == NULL)
+ binaryMode = (encoding == GetBinaryEncoding())
&& (statePtr->inputTranslation == TCL_TRANSLATE_LF)
&& (statePtr->inEofChar == '\0');
@@ -6244,8 +6229,7 @@ ReadChars(
* UTF-8. On output, contains another guess
* based on the data seen so far. */
{
- Tcl_Encoding encoding = statePtr->encoding? statePtr->encoding
- : GetBinaryEncoding();
+ Tcl_Encoding encoding = statePtr->encoding;
Tcl_EncodingState savedState = statePtr->inputEncodingState;
ChannelBuffer *bufPtr = statePtr->inQueueHead;
int savedIEFlags = statePtr->inputEncodingFlags;
@@ -7971,12 +7955,8 @@ Tcl_GetChannelOption(
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-encoding");
}
- if (statePtr->encoding == NULL) {
- Tcl_DStringAppendElement(dsPtr, "binary");
- } else {
- Tcl_DStringAppendElement(dsPtr,
- Tcl_GetEncodingName(statePtr->encoding));
- }
+ Tcl_DStringAppendElement(dsPtr,
+ Tcl_GetEncodingName(statePtr->encoding));
if (len > 0) {
return TCL_OK;
}
@@ -8196,7 +8176,13 @@ Tcl_SetChannelOption(
int profile;
if ((newValue[0] == '\0') || (strcmp(newValue, "binary") == 0)) {
- encoding = NULL;
+ encoding = Tcl_GetEncoding(NULL, "iso8859-1");
+ CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
+ CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
} else {
encoding = Tcl_GetEncoding(interp, newValue);
if (encoding == NULL) {
@@ -8209,7 +8195,7 @@ Tcl_SetChannelOption(
* iso2022, the terminated escape sequence must write to the buffer.
*/
- if ((statePtr->encoding != NULL)
+ if ((statePtr->encoding != GetBinaryEncoding())
&& !(statePtr->outputEncodingFlags & TCL_ENCODING_START)
&& (CheckChannelErrors(statePtr, TCL_WRITABLE) == 0)) {
statePtr->outputEncodingFlags |= TCL_ENCODING_END;
@@ -8304,7 +8290,13 @@ Tcl_SetChannelOption(
translation = TCL_TRANSLATE_LF;
statePtr->inEofChar = 0;
Tcl_FreeEncoding(statePtr->encoding);
- statePtr->encoding = NULL;
+ statePtr->encoding = Tcl_GetEncoding(NULL, "iso8859-1");
+ CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
+ CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
} else if (strcmp(readMode, "lf") == 0) {
translation = TCL_TRANSLATE_LF;
} else if (strcmp(readMode, "cr") == 0) {
@@ -8353,7 +8345,13 @@ Tcl_SetChannelOption(
} else if (strcmp(writeMode, "binary") == 0) {
statePtr->outputTranslation = TCL_TRANSLATE_LF;
Tcl_FreeEncoding(statePtr->encoding);
- statePtr->encoding = NULL;
+ statePtr->encoding = Tcl_GetEncoding(NULL, "iso8859-1");
+ CHANNEL_PROFILE_SET(statePtr->inputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->inputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
+ CHANNEL_PROFILE_SET(statePtr->outputEncodingFlags
+ ,CHANNEL_PROFILE_GET(statePtr->outputEncodingFlags)
+ |TCL_ENCODING_PROFILE_STRICT);
} else if (strcmp(writeMode, "lf") == 0) {
statePtr->outputTranslation = TCL_TRANSLATE_LF;
} else if (strcmp(writeMode, "cr") == 0) {
@@ -10271,13 +10269,9 @@ Lossless(
&& outStatePtr->outputTranslation == TCL_TRANSLATE_LF
&& (
(
- (inStatePtr->encoding == NULL
- || inStatePtr->encoding == GetBinaryEncoding()
- )
+ inStatePtr->encoding == GetBinaryEncoding()
&&
- (outStatePtr->encoding == NULL
- || outStatePtr->encoding == GetBinaryEncoding()
- )
+ outStatePtr->encoding == GetBinaryEncoding()
)
||
(