summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-28 13:36:00 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-02-28 13:36:00 (GMT)
commit62d9150ef53073a2ab29f2ba1b46551f273e56ec (patch)
treee4e381889cb9b5ad4810a754541e88250e66964f
parent7c9fe49b51603b91dd59e1cfa55f10dcf3c2ceea (diff)
parent4227ef37bbd67235ead035bb544b3bcf864b1e87 (diff)
downloadtcl-62d9150ef53073a2ab29f2ba1b46551f273e56ec.zip
tcl-62d9150ef53073a2ab29f2ba1b46551f273e56ec.tar.gz
tcl-62d9150ef53073a2ab29f2ba1b46551f273e56ec.tar.bz2
Merge 8.7
-rw-r--r--generic/tclIO.c7
-rw-r--r--generic/tclIO.h2
-rw-r--r--tests/io.test21
3 files changed, 29 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 8a7cb2b..ff74a99 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -7552,7 +7552,7 @@ Tcl_Eof(
ChannelState *statePtr = ((Channel *) chan)->state;
/* State of real channel structure. */
- if (GotFlag(statePtr, CHANNEL_NONBLOCKING)
+ if (GotFlag(statePtr, CHANNEL_NONBLOCKING|CHANNEL_FCOPY)
&& GotFlag(statePtr, CHANNEL_ENCODING_ERROR)) {
return 0;
}
@@ -9694,6 +9694,7 @@ CopyData(
* the bottom of the stack.
*/
+ SetFlag(inStatePtr, CHANNEL_FCOPY);
inBinary = (inStatePtr->encoding == NULL);
outBinary = (outStatePtr->encoding == NULL);
sameEncoding = inStatePtr->encoding == outStatePtr->encoding
@@ -9809,6 +9810,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
}
@@ -9900,6 +9902,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
@@ -9922,6 +9925,7 @@ CopyData(
TclDecrRefCount(bufObj);
bufObj = NULL;
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return TCL_OK;
}
} /* while */
@@ -9974,6 +9978,7 @@ CopyData(
}
}
}
+ ResetFlag(inStatePtr, CHANNEL_FCOPY);
return result;
}
diff --git a/generic/tclIO.h b/generic/tclIO.h
index 62cf6e8..588c7d4 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -235,6 +235,8 @@ typedef struct ChannelState {
* flushed after every newline. */
#define CHANNEL_UNBUFFERED (1<<5) /* Output to the channel must always
* be flushed immediately. */
+#define CHANNEL_FCOPY (1<<6) /* Channel is currently doing an fcopy
+ * mode. */
#define BG_FLUSH_SCHEDULED (1<<7) /* A background flush of the queued
* output buffers has been
* scheduled. */
diff --git a/tests/io.test b/tests/io.test
index 59b6c66..065eb4c 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -7692,6 +7692,27 @@ test io-52.19 {coverage of eofChar handling} {
close $out
file size $path(test2)
} 8
+test io-52.20 {TclCopyChannel & encodings} -setup {
+ set out [open $path(utf8-fcopy.txt) w]
+ fconfigure $out -encoding utf-8 -translation lf
+ puts $out "Á"
+ close $out
+} -constraints {fcopy} -body {
+ # binary to encoding => the input has to be
+ # in utf-8 to make sense to the encoder
+
+ set in [open $path(utf8-fcopy.txt) r]
+ set out [open $path(kyrillic.txt) w]
+
+ # Using "-encoding ascii" means reading the "Á" gives an error
+ fconfigure $in -encoding ascii -strictencoding 1
+ fconfigure $out -encoding koi8-r -translation lf
+
+ fcopy $in $out
+} -cleanup {
+ close $in
+ close $out
+} -returnCodes 1 -match glob -result {error reading "file*": illegal byte sequence}
test io-52.21 {TclCopyChannel & encodings} -setup {
set out [open $path(utf8-fcopy.txt) w]
fconfigure $out -encoding utf-8 -translation lf