summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2022-10-16 11:10:36 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2022-10-16 11:10:36 (GMT)
commit6cda753ae057b0c4e0b485b64262b5d61de28334 (patch)
treea1eb625a52d88becf80d9427ffe00085c8b8c73c
parentc5a0eca4bc7d0274b95c8ade407fbf3c25bf00e5 (diff)
downloadtcl-6cda753ae057b0c4e0b485b64262b5d61de28334.zip
tcl-6cda753ae057b0c4e0b485b64262b5d61de28334.tar.gz
tcl-6cda753ae057b0c4e0b485b64262b5d61de28334.tar.bz2
new TIP about -eofchar handling
-rw-r--r--generic/tclIO.c74
-rw-r--r--generic/tclIO.h4
-rw-r--r--tests/chan.test2
-rw-r--r--tests/chanio.test22
-rw-r--r--tests/io.test26
-rw-r--r--tests/ioCmd.test6
6 files changed, 39 insertions, 95 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 48aa18d..2e821a7 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -1688,7 +1688,6 @@ Tcl_CreateChannel(
statePtr->inputTranslation = TCL_TRANSLATE_AUTO;
statePtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
statePtr->inEofChar = 0;
- statePtr->outEofChar = 0;
statePtr->unreportedError = 0;
statePtr->refCount = 0;
@@ -3077,18 +3076,6 @@ CloseChannel(
}
/*
- * If the EOF character is set in the channel, append that to the output
- * device.
- */
-
- if ((statePtr->outEofChar != 0) && GotFlag(statePtr, TCL_WRITABLE)) {
- int dummy;
- char c = (char) statePtr->outEofChar;
-
- (void) ChanWrite(chanPtr, &c, 1, &dummy);
- }
-
- /*
* TIP #219, Tcl Channel Reflection API.
* Move a leftover error message in the channel bypass into the
* interpreter bypass. Just clear it if there is no interpreter.
@@ -3853,18 +3840,6 @@ CloseChannelPart(
}
/*
- * If the EOF character is set in the channel, append that to the
- * output device.
- */
-
- if ((statePtr->outEofChar != 0) && GotFlag(statePtr, TCL_WRITABLE)) {
- int dummy;
- char c = (char) statePtr->outEofChar;
-
- (void) ChanWrite(chanPtr, &c, 1, &dummy);
- }
-
- /*
* TIP #219, Tcl Channel Reflection API.
* Move a leftover error message in the channel bypass into the
* interpreter bypass. Just clear it if there is no interpreter.
@@ -7958,40 +7933,13 @@ Tcl_GetChannelOption(
if (len == 0) {
Tcl_DStringAppendElement(dsPtr, "-eofchar");
}
- if (((flags & (TCL_READABLE|TCL_WRITABLE)) ==
- (TCL_READABLE|TCL_WRITABLE)) && (len == 0)) {
- Tcl_DStringStartSublist(dsPtr);
- }
- if (flags & TCL_READABLE) {
- if (statePtr->inEofChar == 0) {
- Tcl_DStringAppendElement(dsPtr, "");
- } else {
- char buf[4];
-
- sprintf(buf, "%c", statePtr->inEofChar);
- Tcl_DStringAppendElement(dsPtr, buf);
- }
- }
- if (flags & TCL_WRITABLE) {
- if (statePtr->outEofChar == 0) {
- Tcl_DStringAppendElement(dsPtr, "");
- } else {
- char buf[4];
-
- sprintf(buf, "%c", statePtr->outEofChar);
- Tcl_DStringAppendElement(dsPtr, buf);
- }
- }
- if (!(flags & (TCL_READABLE|TCL_WRITABLE))) {
- /*
- * Not readable or writable (e.g. server socket)
- */
-
+ if (!(flags & TCL_READABLE) || (statePtr->inEofChar == 0)) {
Tcl_DStringAppendElement(dsPtr, "");
- }
- if (((flags & (TCL_READABLE|TCL_WRITABLE)) ==
- (TCL_READABLE|TCL_WRITABLE)) && (len == 0)) {
- Tcl_DStringEndSublist(dsPtr);
+ } else {
+ char buf[4];
+
+ sprintf(buf, "%c", statePtr->inEofChar);
+ Tcl_DStringAppendElement(dsPtr, buf);
}
if (len > 0) {
return TCL_OK;
@@ -8234,13 +8182,11 @@ Tcl_SetChannelOption(
}
if (argc == 0) {
statePtr->inEofChar = 0;
- statePtr->outEofChar = 0;
} else if (argc == 1 || argc == 2) {
- int outIndex = (argc - 1);
int inValue = (int) argv[0][0];
- int outValue = (int) argv[outIndex][0];
+ int outValue = (argc == 2) ? (int) argv[1][0] : 0;
- if (inValue & 0x80 || outValue & 0x80) {
+ if (inValue & 0x80 || outValue) {
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
"bad value for -eofchar: must be non-NUL ASCII"
@@ -8252,9 +8198,6 @@ Tcl_SetChannelOption(
if (GotFlag(statePtr, TCL_READABLE)) {
statePtr->inEofChar = inValue;
}
- if (GotFlag(statePtr, TCL_WRITABLE)) {
- statePtr->outEofChar = outValue;
- }
} else {
if (interp) {
Tcl_SetObjResult(interp, Tcl_NewStringObj(
@@ -8387,7 +8330,6 @@ Tcl_SetChannelOption(
statePtr->outputTranslation = TCL_PLATFORM_TRANSLATION;
}
} else if (strcmp(writeMode, "binary") == 0) {
- statePtr->outEofChar = 0;
statePtr->outputTranslation = TCL_TRANSLATE_LF;
Tcl_FreeEncoding(statePtr->encoding);
statePtr->encoding = NULL;
diff --git a/generic/tclIO.h b/generic/tclIO.h
index a4cc602..490f26c 100644
--- a/generic/tclIO.h
+++ b/generic/tclIO.h
@@ -158,8 +158,10 @@ typedef struct ChannelState {
* of line sequences in output? */
int inEofChar; /* If nonzero, use this as a signal of EOF on
* input. */
+#if TCL_MAJOR_VERSION < 9
int outEofChar; /* If nonzero, append this to the channel when
- * it is closed if it is open for writing. */
+ * it is closed if it is open for writing. For Tcl 8.x only */
+#endif
int unreportedError; /* Non-zero if an error report was deferred
* because it happened in the background. The
* value is the POSIX error code. */
diff --git a/tests/chan.test b/tests/chan.test
index 4155c36..280783f 100644
--- a/tests/chan.test
+++ b/tests/chan.test
@@ -61,7 +61,7 @@ test chan-4.5 {chan command: check valid inValue, invalid outValue} -body {
} -returnCodes error -match glob -result {bad value for -eofchar:*}
test chan-4.6 {chan command: check no inValue, valid outValue} -body {
chan configure stdout -eofchar [list {} \x27]
-} -result {} -cleanup {chan configure stdout -eofchar [list {} {}]}
+} -returnCodes error -result {bad value for -eofchar: must be non-NUL ASCII character} -cleanup {chan configure stdout -eofchar [list {} {}]}
test chan-5.1 {chan command: copy subcommand} -body {
chan copy foo
diff --git a/tests/chanio.test b/tests/chanio.test
index c1085f4..f9d272a 100644
--- a/tests/chanio.test
+++ b/tests/chanio.test
@@ -1895,7 +1895,7 @@ test chan-io-20.3 {Tcl_CreateChannel: initial settings} -constraints {unix} -bod
list [chan configure $f -eofchar] [chan configure $f -translation]
} -cleanup {
chan close $f
-} -result {{{} {}} {auto lf}}
+} -result {{{}} {auto lf}}
test chan-io-20.5 {Tcl_CreateChannel: install channel in empty slot} -setup {
set path(stdout) [makeFile {} stdout]
} -constraints {stdio notWinCI} -body {
@@ -4657,7 +4657,7 @@ test chan-io-35.6 {Tcl_Eof, eof char, lf write, auto read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {9 8 1}
+} -result {8 8 1}
test chan-io-35.7 {Tcl_Eof, eof char, lf write, lf read} -setup {
file delete $path(test1)
} -body {
@@ -4671,7 +4671,7 @@ test chan-io-35.7 {Tcl_Eof, eof char, lf write, lf read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {9 8 1}
+} -result {8 8 1}
test chan-io-35.8 {Tcl_Eof, eof char, cr write, auto read} -setup {
file delete $path(test1)
} -body {
@@ -4685,7 +4685,7 @@ test chan-io-35.8 {Tcl_Eof, eof char, cr write, auto read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {9 8 1}
+} -result {8 8 1}
test chan-io-35.9 {Tcl_Eof, eof char, cr write, cr read} -setup {
file delete $path(test1)
} -body {
@@ -4699,7 +4699,7 @@ test chan-io-35.9 {Tcl_Eof, eof char, cr write, cr read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {9 8 1}
+} -result {8 8 1}
test chan-io-35.10 {Tcl_Eof, eof char, crlf write, auto read} -setup {
file delete $path(test1)
} -body {
@@ -4713,7 +4713,7 @@ test chan-io-35.10 {Tcl_Eof, eof char, crlf write, auto read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {11 8 1}
+} -result {10 8 1}
test chan-io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} -setup {
file delete $path(test1)
} -body {
@@ -4727,7 +4727,7 @@ test chan-io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} -setup {
list $s [string length [chan read $f]] [chan eof $f]
} -cleanup {
chan close $f
-} -result {11 8 1}
+} -result {10 8 1}
test chan-io-35.12 {Tcl_Eof, eof char in middle, lf write, auto read} -setup {
file delete $path(test1)
} -body {
@@ -5288,26 +5288,26 @@ test chan-io-39.22 {Tcl_SetChannelOption, invariance} -setup {
} -constraints {unix} -body {
set f1 [open $path(test1) w+]
lappend l [chan configure $f1 -eofchar]
- chan configure $f1 -eofchar {ON GO}
+ chan configure $f1 -eofchar {ON {}}
lappend l [chan configure $f1 -eofchar]
chan configure $f1 -eofchar D
lappend l [chan configure $f1 -eofchar]
} -cleanup {
chan close $f1
-} -result {{{} {}} {O G} {D D}}
+} -result {{{}} O D}
test chan-io-39.22a {Tcl_SetChannelOption, invariance} -setup {
file delete $path(test1)
set l [list]
} -body {
set f1 [open $path(test1) w+]
- chan configure $f1 -eofchar {ON GO}
+ chan configure $f1 -eofchar {ON {}}
lappend l [chan configure $f1 -eofchar]
chan configure $f1 -eofchar D
lappend l [chan configure $f1 -eofchar]
lappend l [list [catch {chan configure $f1 -eofchar {1 2 3}} msg] $msg]
} -cleanup {
chan close $f1
-} -result {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
+} -result {O D {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
test chan-io-39.23 {Tcl_GetChannelOption, server socket is not readable or\
writeable, it should still have valid -eofchar and -translation options} -setup {
set l [list]
diff --git a/tests/io.test b/tests/io.test
index 3241625..15ce577 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -2099,7 +2099,7 @@ test io-20.3 {Tcl_CreateChannel: initial settings} {unix} {
set x [list [fconfigure $f -eofchar] [fconfigure $f -translation]]
close $f
set x
-} {{{} {}} {auto lf}}
+} {{{}} {auto lf}}
set path(stdout) [makeFile {} stdout]
test io-20.5 {Tcl_CreateChannel: install channel in empty slot} stdio {
set f [open $path(script) w]
@@ -5038,7 +5038,7 @@ test io-35.6 {Tcl_Eof, eof char, lf write, auto read} {
set e [eof $f]
close $f
list $s $l $e
-} {9 8 1}
+} {8 8 1}
test io-35.7 {Tcl_Eof, eof char, lf write, lf read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5052,7 +5052,7 @@ test io-35.7 {Tcl_Eof, eof char, lf write, lf read} {
set e [eof $f]
close $f
list $s $l $e
-} {9 8 1}
+} {8 8 1}
test io-35.8 {Tcl_Eof, eof char, cr write, auto read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5066,7 +5066,7 @@ test io-35.8 {Tcl_Eof, eof char, cr write, auto read} {
set e [eof $f]
close $f
list $s $l $e
-} {9 8 1}
+} {8 8 1}
test io-35.9 {Tcl_Eof, eof char, cr write, cr read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5080,7 +5080,7 @@ test io-35.9 {Tcl_Eof, eof char, cr write, cr read} {
set e [eof $f]
close $f
list $s $l $e
-} {9 8 1}
+} {8 8 1}
test io-35.10 {Tcl_Eof, eof char, crlf write, auto read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5094,7 +5094,7 @@ test io-35.10 {Tcl_Eof, eof char, crlf write, auto read} {
set e [eof $f]
close $f
list $s $l $e
-} {11 8 1}
+} {10 8 1}
test io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5108,7 +5108,7 @@ test io-35.11 {Tcl_Eof, eof char, crlf write, crlf read} {
set e [eof $f]
close $f
list $s $l $e
-} {11 8 1}
+} {10 8 1}
test io-35.12 {Tcl_Eof, eof char in middle, lf write, auto read} {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5226,7 +5226,7 @@ test io-35.18a {Tcl_Eof, eof char, cr write, crlf read} -body {
set e [eof $f]
close $f
list $s $l $e [scan [string index $in end] %c]
-} -result {9 8 1 13}
+} -result {8 8 1 13}
test io-35.18b {Tcl_Eof, eof char, cr write, crlf read} -body {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5240,7 +5240,7 @@ test io-35.18b {Tcl_Eof, eof char, cr write, crlf read} -body {
set e [eof $f]
close $f
list $s $l $e [scan [string index $in end] %c]
-} -result {2 1 1 13}
+} -result {1 1 1 13}
test io-35.18c {Tcl_Eof, eof char, cr write, crlf read} -body {
file delete $path(test1)
set f [open $path(test1) w]
@@ -5761,25 +5761,25 @@ test io-39.22 {Tcl_SetChannelOption, invariance} {unix} {
set f1 [open $path(test1) w+]
set l ""
lappend l [fconfigure $f1 -eofchar]
- fconfigure $f1 -eofchar {ON GO}
+ fconfigure $f1 -eofchar {ON {}}
lappend l [fconfigure $f1 -eofchar]
fconfigure $f1 -eofchar D
lappend l [fconfigure $f1 -eofchar]
close $f1
set l
-} {{{} {}} {O G} {D D}}
+} {{{}} O D}
test io-39.22a {Tcl_SetChannelOption, invariance} {
file delete $path(test1)
set f1 [open $path(test1) w+]
set l [list]
- fconfigure $f1 -eofchar {ON GO}
+ fconfigure $f1 -eofchar {ON {}}
lappend l [fconfigure $f1 -eofchar]
fconfigure $f1 -eofchar D
lappend l [fconfigure $f1 -eofchar]
lappend l [list [catch {fconfigure $f1 -eofchar {1 2 3}} msg] $msg]
close $f1
set l
-} {{O G} {D D} {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
+} {O D {1 {bad value for -eofchar: should be a list of zero, one, or two elements}}}
test io-39.23 {Tcl_GetChannelOption, server socket is not readable or
writeable, it should still have valid -eofchar and -translation options } {
set l [list]
diff --git a/tests/ioCmd.test b/tests/ioCmd.test
index 20418f3..c8daa96 100644
--- a/tests/ioCmd.test
+++ b/tests/ioCmd.test
@@ -1363,7 +1363,7 @@ test iocmd-25.1 {chan configure, cgetall, standard options} -match glob -body {
close $c
rename foo {}
set res
-} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -strictencoding 0 -translation {auto *}}}
+} -result {{-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {} -nocomplainencoding 0 -strictencoding 0 -translation {auto *}}}
test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body {
set res {}
proc foo {args} {oninit cget cgetall; onfinal; track; return ""}
@@ -1372,7 +1372,7 @@ test iocmd-25.2 {chan configure, cgetall, no options} -match glob -body {
close $c
rename foo {}
set res
-} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -strictencoding 0 -translation {auto *}}}
+} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {} -nocomplainencoding 0 -strictencoding 0 -translation {auto *}}}
test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body {
set res {}
proc foo {args} {
@@ -1384,7 +1384,7 @@ test iocmd-25.3 {chan configure, cgetall, regular result} -match glob -body {
close $c
rename foo {}
set res
-} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {{} {}} -nocomplainencoding 0 -strictencoding 0 -translation {auto *} -bar foo -snarf x}}
+} -result {{cgetall rc*} {-blocking 1 -buffering full -buffersize 4096 -encoding * -eofchar {} -nocomplainencoding 0 -strictencoding 0 -translation {auto *} -bar foo -snarf x}}
test iocmd-25.4 {chan configure, cgetall, bad result, list of uneven length} -match glob -body {
set res {}
proc foo {args} {