summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2023-05-30 12:22:20 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2023-05-30 12:22:20 (GMT)
commit75bdb756898a30047bb33ecf3f322062fcd27180 (patch)
tree7278dd27c525ccc3b71c91da02fb7ddf84346c9f
parentaf838a5d529d837dc588e5c57d07d94dd612afcc (diff)
parent13f6f72bb70d2f85f1ca638290bab6c606d9ae33 (diff)
downloadtcl-75bdb756898a30047bb33ecf3f322062fcd27180.zip
tcl-75bdb756898a30047bb33ecf3f322062fcd27180.tar.gz
tcl-75bdb756898a30047bb33ecf3f322062fcd27180.tar.bz2
Merge 8.7
-rw-r--r--generic/tclIO.c37
-rw-r--r--generic/tclIOCmd.c2
-rw-r--r--tests/io.test99
3 files changed, 64 insertions, 74 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 965a395..4d327b3 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -659,7 +659,7 @@ TclFinalizeIOSubsystem(void)
statePtr->refCount--;
}
- if (statePtr->refCount + 1 <= 1) {
+ if (statePtr->refCount <= 0) {
/*
* Close it only if the refcount indicates that the channel is
* not referenced from any interpreter. If it is, that
@@ -1078,7 +1078,7 @@ CheckForStdChannelsBeingClosed(
if (tsdPtr->stdinInitialized == 1
&& tsdPtr->stdinChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stdinChannel)->state) {
- if (statePtr->refCount + 1 < 3) {
+ if (statePtr->refCount < 2) {
statePtr->refCount = 0;
tsdPtr->stdinChannel = NULL;
return;
@@ -1086,7 +1086,7 @@ CheckForStdChannelsBeingClosed(
} else if (tsdPtr->stdoutInitialized == 1
&& tsdPtr->stdoutChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stdoutChannel)->state) {
- if (statePtr->refCount + 1 < 3) {
+ if (statePtr->refCount < 2) {
statePtr->refCount = 0;
tsdPtr->stdoutChannel = NULL;
return;
@@ -1094,7 +1094,7 @@ CheckForStdChannelsBeingClosed(
} else if (tsdPtr->stderrInitialized == 1
&& tsdPtr->stderrChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stderrChannel)->state) {
- if (statePtr->refCount + 1 < 3) {
+ if (statePtr->refCount < 2) {
statePtr->refCount = 0;
tsdPtr->stderrChannel = NULL;
return;
@@ -1256,7 +1256,7 @@ Tcl_UnregisterChannel(
* If the refCount reached zero, close the actual channel.
*/
- if (statePtr->refCount + 1 <= 1) {
+ if (statePtr->refCount <= 0) {
Tcl_Preserve(statePtr);
if (!GotFlag(statePtr, BG_FLUSH_SCHEDULED)) {
/*
@@ -1681,11 +1681,11 @@ Tcl_CreateChannel(
statePtr->inputEncodingState = NULL;
statePtr->inputEncodingFlags = TCL_ENCODING_START;
ENCODING_PROFILE_SET(statePtr->inputEncodingFlags,
- TCL_ENCODING_PROFILE_DEFAULT);
+ TCL_ENCODING_PROFILE_TCL8);
statePtr->outputEncodingState = NULL;
statePtr->outputEncodingFlags = TCL_ENCODING_START;
ENCODING_PROFILE_SET(statePtr->outputEncodingFlags,
- TCL_ENCODING_PROFILE_DEFAULT);
+ TCL_ENCODING_PROFILE_TCL8);
/*
* Set the channel up initially in AUTO input translation mode to accept
@@ -2004,7 +2004,7 @@ static void
ChannelFree(
Channel *chanPtr)
{
- if (!chanPtr->refCount) {
+ if (chanPtr->refCount == 0) {
Tcl_Free(chanPtr);
return;
}
@@ -2179,7 +2179,7 @@ Tcl_UnstackChannel(
* necessary.
*/
- if (statePtr->refCount + 1 <= 1) {
+ if (statePtr->refCount <= 0) {
if (Tcl_CloseEx(interp, chan, 0) != TCL_OK) {
/*
* TIP #219, Tcl Channel Reflection API.
@@ -2547,7 +2547,7 @@ static int
IsShared(
ChannelBuffer *bufPtr)
{
- return bufPtr->refCount + 1 > 2;
+ return bufPtr->refCount > 1;
}
/*
@@ -2996,7 +2996,7 @@ FlushChannel(
* current output buffer.
*/
- if (GotFlag(statePtr, CHANNEL_CLOSED) && (statePtr->refCount + 1 <= 1) &&
+ if (GotFlag(statePtr, CHANNEL_CLOSED) && (statePtr->refCount <= 0) &&
(statePtr->outQueueHead == NULL) &&
((statePtr->curOutPtr == NULL) ||
IsBufferEmpty(statePtr->curOutPtr))) {
@@ -3457,7 +3457,7 @@ TclClose(
statePtr = chanPtr->state;
chanPtr = statePtr->topChanPtr;
- if (statePtr->refCount + 1 > 1) {
+ if (statePtr->refCount > 0) {
Tcl_Panic("called Tcl_Close on channel with refCount > 0");
}
@@ -4192,7 +4192,6 @@ Tcl_WriteChars(
}
objPtr = Tcl_NewStringObj(src, len);
- Tcl_IncrRefCount(objPtr);
src = (char *) Tcl_GetByteArrayFromObj(objPtr, &len);
if (src == NULL) {
Tcl_SetErrno(EILSEQ);
@@ -4366,8 +4365,8 @@ Write(
while (srcLen + saved + endEncoding > 0 && !encodingError) {
ChannelBuffer *bufPtr;
char *dst;
- int result, srcRead, dstLen, dstWrote;
- Tcl_Size srcLimit = srcLen;
+ int result, srcRead, dstLen, dstWrote;
+ Tcl_Size srcLimit = srcLen;
if (nextNewLine) {
srcLimit = nextNewLine - src;
@@ -4557,7 +4556,7 @@ Tcl_Gets(
TclNewObj(objPtr);
charsStored = Tcl_GetsObj(chan, objPtr);
- if (charsStored + 1 > 1) {
+ if (charsStored > 0) {
TclDStringAppendObj(lineRead, objPtr);
}
TclDecrRefCount(objPtr);
@@ -5998,7 +5997,7 @@ DoReadChars(
}
ResetFlag(statePtr, CHANNEL_BLOCKED|CHANNEL_EOF);
statePtr->inputEncodingFlags &= ~TCL_ENCODING_END;
- for (copied = 0; toRead > 0 || toRead == TCL_INDEX_NONE; ) {
+ for (copied = 0; toRead != 0 ; ) {
int copiedNow = -1;
if (statePtr->inQueueHead != NULL) {
if (binaryMode) {
@@ -8217,7 +8216,7 @@ Tcl_SetChannelOption(
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"bad value for -eofchar: must be non-NUL ASCII"
- " character", -1));
+ " character", TCL_INDEX_NONE));
}
Tcl_Free((void *)argv);
return TCL_ERROR;
@@ -10642,7 +10641,7 @@ Tcl_IsChannelShared(
ChannelState *statePtr = ((Channel *) chan)->state;
/* State of real channel structure. */
- return ((statePtr->refCount + 1 > 2) ? 1 : 0);
+ return ((statePtr->refCount > 1) ? 1 : 0);
}
/*
diff --git a/generic/tclIOCmd.c b/generic/tclIOCmd.c
index 93c50ec..37be141 100644
--- a/generic/tclIOCmd.c
+++ b/generic/tclIOCmd.c
@@ -1788,9 +1788,9 @@ ChanPendingObjCmd(
Tcl_Obj *const objv[]) /* Argument objects. */
{
Tcl_Channel chan;
- int mode;
static const char *const options[] = {"input", "output", NULL};
enum pendingOptionsEnum {PENDING_INPUT, PENDING_OUTPUT} index;
+ int mode;
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "mode channelId");
diff --git a/tests/io.test b/tests/io.test
index 5acd553..db114e6 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -2428,7 +2428,7 @@ test io-28.3 {CloseChannel, not called before output queue is empty} \
close $f
set x 01234567890123456789012345678901
for {set i 0} {$i < 11} {incr i} {
- set x "$x$x"
+ set x "$x$x"
}
set f [open $path(output) w]
close $f
@@ -4633,29 +4633,29 @@ test io-33.10 {Tcl_Gets, exercising double buffering} {
} 300
test io-33.11 {TclGetsObjBinary, [10dc6daa37]} -setup {
proc driver {cmd args} {
- variable buffer
- variable index
- set chan [lindex $args 0]
- switch -- $cmd {
- initialize {
- set index($chan) 0
- set buffer($chan) .......
- return {initialize finalize watch read}
- }
- finalize {
- unset index($chan) buffer($chan)
- return
- }
- watch {}
- read {
- set n [lindex $args 1]
+ variable buffer
+ variable index
+ set chan [lindex $args 0]
+ switch -- $cmd {
+ initialize {
+ set index($chan) 0
+ set buffer($chan) .......
+ return {initialize finalize watch read}
+ }
+ finalize {
+ unset index($chan) buffer($chan)
+ return
+ }
+ watch {}
+ read {
+ set n [lindex $args 1]
if {$n > 3} {set n 3}
- set new [expr {$index($chan) + $n}]
- set result [string range $buffer($chan) $index($chan) $new-1]
- set index($chan) $new
- return $result
- }
- }
+ set new [expr {$index($chan) + $n}]
+ set result [string range $buffer($chan) $index($chan) $new-1]
+ set index($chan) $new
+ return $result
+ }
+ }
}
} -body {
set c [chan create read [namespace which driver]]
@@ -6448,10 +6448,10 @@ test io-47.3 {deleting fileevent on interpreter delete} {testfevent fileevent} {
fileevent $f readable {script 1}
fileevent $f2 readable {script 2}
testfevent cmd "fileevent $f3 readable {script 3}
- fileevent $f4 readable {script 4}"
+ fileevent $f4 readable {script 4}"
testfevent delete
set x [list [fileevent $f readable] [fileevent $f2 readable] \
- [fileevent $f3 readable] [fileevent $f4 readable]]
+ [fileevent $f3 readable] [fileevent $f4 readable]]
close $f
close $f2
close $f3
@@ -6495,7 +6495,7 @@ test io-47.6 {file events on shared files, deleting file events} {testfevent fil
fileevent $f readable {script 2}
fileevent $f readable {}
set x [list [testfevent cmd "fileevent $f readable"] \
- [fileevent $f readable]]
+ [fileevent $f readable]]
testfevent delete
close $f
set x
@@ -7756,7 +7756,7 @@ test io-52.22 {TclCopyChannel & encodings} -setup {
fconfigure $in -encoding ascii -profile strict
fconfigure $out -encoding koi8-r -translation lf
proc ::xxx args {
- set ::s0 $args
+ set ::s0 $args
}
fcopy $in $out -command ::xxx
@@ -7783,7 +7783,7 @@ test io-52.23 {TclCopyChannel & encodings} -setup {
fconfigure $in -encoding utf-8
fconfigure $out -encoding ascii -translation lf -profile strict
proc ::xxx args {
- set ::s0 $args
+ set ::s0 $args
}
fcopy $in $out -command ::xxx
@@ -7846,7 +7846,7 @@ test io-53.2 {CopyData} {fcopy} {
set s1 [file size $thisScript]
set s2 [file size $path(test1)]
if {("$s1" == "$s2") && ($s0 == $s1)} {
- lappend result ok
+ lappend result ok
}
set result
} {0 0 ok}
@@ -9289,7 +9289,7 @@ test io-75.6 {invalid utf-8 encoding, gets is not ignored (-profile strict)} -se
flush $f
seek $f 0
fconfigure $f -encoding utf-8 -buffering none -eofchar {} \
- -translation lf -profile strict
+ -translation lf -profile strict
} -body {
gets $f
} -cleanup {
@@ -9309,14 +9309,14 @@ test io-75.7 {
flush $f
seek $f 0
fconfigure $f -encoding utf-8 -buffering none -eofchar {} -translation lf \
- -profile strict
+ -profile strict
} -body {
- read $f
+ list [catch {read $f} msg] $msg
} -cleanup {
close $f
removeFile io-75.7
-} -match glob -returnCodes 1 -result {error reading "file*":\
- invalid or incomplete multibyte or wide character}
+} -match glob -result {1 {error reading "file*":\
+ invalid or incomplete multibyte or wide character}}
test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup {
set fn [makeFile {} io-75.8]
@@ -9341,7 +9341,6 @@ test io-75.8 {invalid utf-8 encoding eof handling (-profile strict)} -setup {
} -result {41 1 {}}
test io-75.8.eoflater {invalid utf-8 encoding eof handling (-profile strict)} -setup {
- set res {}
set fn [makeFile {} io-75.8]
set f [open $fn w+]
# This also configures the channel encoding profile as strict.
@@ -9353,9 +9352,7 @@ test io-75.8.eoflater {invalid utf-8 encoding eof handling (-profile strict)} -s
fconfigure $f -encoding utf-8 -buffering none -eofchar \x1A \
-translation lf -profile strict
} -body {
- set status [catch {read $f} cres copts]
- lappend res $status
- lappend res [eof $f]
+ set res [list [catch {read $f} cres] [eof $f]]
chan configure $f -encoding iso8859-1
lappend res [read $f 1]
chan configure $f -encoding utf-8
@@ -9382,8 +9379,7 @@ test io-strict-multibyte-eof {
seek $chan 0
chan configure $chan -encoding utf-8 -profile strict
} -body {
- set status [catch {read $chan 1} cres]
- lappend res $status $cres
+ list [catch {read $chan 1} cres] $cres
} -cleanup {
close $chan
unset res
@@ -9452,8 +9448,7 @@ test io-75.11 {shiftjis encoding error read results in raw bytes} -setup {
} -body {
set d [read $f]
binary scan $d H* hd
- lappend hd [catch {set d [read $f]} msg]
- lappend hd $msg
+ lappend hd [catch {set d [read $f]} msg] $msg
} -cleanup {
close $f
removeFile io-75.11
@@ -9504,8 +9499,7 @@ test io-75.13 {
} -body {
set d [read $f]
binary scan $d H* hd
- lappend hd [catch {read $f} msg]
- lappend hd $msg
+ lappend hd [catch {read $f} msg] $msg
} -cleanup {
close $f
removeFile io-75.13
@@ -9519,8 +9513,8 @@ test io-75.14 {
} -setup {
set chan [file tempfile]
fconfigure $chan -encoding binary
- # \xc0\n is an invalid utf-8 sequence
- puts -nonewline $chan a\nb\nc\xc0\nd\n
+ # \xC0\n is an invalid utf-8 sequence
+ puts -nonewline $chan a\nb\nc\xC0\nd\n
flush $chan
seek $chan 0
fconfigure $chan -encoding utf-8 -buffering none -eofchar {} \
@@ -9528,8 +9522,7 @@ test io-75.14 {
} -body {
lappend res [gets $chan]
lappend res [gets $chan]
- set status [catch {gets $chan} cres copts]
- lappend res $status $cres
+ lappend res [catch {gets $chan} cres] $cres
chan configure $chan -profile tcl8
lappend res [gets $chan]
lappend res [gets $chan]
@@ -9546,18 +9539,16 @@ test io-75.15 {
set res {}
set chan [file tempfile]
fconfigure $chan -encoding binary
- # \xc0\x40 is an invalid utf-8 sequence
- puts $chan hello\nAB\nCD\xc0\x40EF\nGHI
+ # \xC0\x40 is an invalid utf-8 sequence
+ puts $chan hello\nAB\nCD\xC0\x40EF\nGHI
seek $chan 0
} -body {
#Now try to read it with [gets]
fconfigure $chan -encoding utf-8 -profile strict
lappend res [gets $chan]
lappend res [gets $chan]
- set status [catch {gets $chan} cres copts]
- lappend res $status $cres
- set status [catch {gets $chan} cres copts]
- lappend res $status $cres
+ lappend res [catch {gets $chan} cres] $cres
+ lappend res [catch {gets $chan} cres] $cres
chan configure $chan -translation binary
set data [read $chan 4]
foreach char [split $data {}] {