summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/refchan.n4
-rw-r--r--generic/tclIORChan.c21
-rw-r--r--tests/ioCmd.test10
3 files changed, 17 insertions, 18 deletions
diff --git a/doc/refchan.n b/doc/refchan.n
index c17117d..77e742c 100644
--- a/doc/refchan.n
+++ b/doc/refchan.n
@@ -53,8 +53,8 @@ here, then the \fBfinalize\fR subcommand will not be called.
.PP
The \fImode\fR argument tells the handler whether the channel was
opened for reading, writing, or both. It is a list containing any of
-the strings \fBread\fR or \fBwrite\fR. The list will always
-contain at least one element.
+the strings \fBread\fR or \fBwrite\fR. The list may be empty, but
+will usually contain at least one element.
.PP
The subcommand must throw an error if the chosen mode is not
supported by the \fIcmdPrefix\fR.
diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c
index ba2d2cb..2f4f91d 100644
--- a/generic/tclIORChan.c
+++ b/generic/tclIORChan.c
@@ -549,7 +549,7 @@ TclChanCreateObjCmd(
/*
* First argument is a list of modes. Allowed entries are "read", "write".
- * Expect at least one list element. Abbreviations are ok.
+ * Empty list is uncommon, but allowed. Abbreviations are ok.
*/
modeObj = objv[MODE];
@@ -922,6 +922,11 @@ TclChanPostEventObjCmd(
if (EncodeEventMask(interp, "event", objv[EVENT], &events) != TCL_OK) {
return TCL_ERROR;
}
+ if (events == 0) {
+ Tcl_SetObjResult(interp,
+ Tcl_NewStringObj("bad event list: is empty", -1));
+ return TCL_ERROR;
+ }
/*
* Check that the channel is actually interested in the provided events.
@@ -2111,10 +2116,10 @@ ReflectTruncate(
* EncodeEventMask --
*
* This function takes a list of event items and constructs the
- * equivalent internal bitmask. The list must contain at least one
- * element. Elements are "read", "write", or any unique abbreviation of
- * them. Note that the bitmask is not changed if problems are
- * encountered.
+ * equivalent internal bitmask. The list may be empty but will usually
+ * contain at least one element. Valid elements are "read", "write", or
+ * any unique abbreviation of them. Note that the bitmask is not changed
+ * if problems are encountered.
*
* Results:
* A standard Tcl error code. A bitmask where TCL_READABLE and/or
@@ -2144,12 +2149,6 @@ EncodeEventMask(
return TCL_ERROR;
}
- if (listc < 1) {
- Tcl_SetObjResult(interp, Tcl_ObjPrintf(
- "bad %s list: is empty", objName));
- return TCL_ERROR;
- }
-
events = 0;
while (listc > 0) {
if (Tcl_GetIndexFromObj(interp, listv[listc-1], eventOptions,
diff --git a/tests/ioCmd.test b/tests/ioCmd.test
index 89c6e76..cab4745 100644
--- a/tests/ioCmd.test
+++ b/tests/ioCmd.test
@@ -698,12 +698,12 @@ test iocmd-21.1 {chan create, wrong#args, too many} {
catch {chan create a b c} msg
set msg
} {wrong # args: should be "chan create mode cmdprefix"}
-test iocmd-21.2 {chan create, invalid r/w mode, empty} {
- proc foo {} {}
- catch {chan create {} foo} msg
+test iocmd-21.2 {chan create, r/w mode empty} {
+ proc foo {cmd args} { return {initialize finalize watch} }
+ set chan [chan create {} foo]
+ close $chan
rename foo {}
- set msg
-} {bad mode list: is empty}
+} {}
test iocmd-21.3 {chan create, invalid r/w mode, bad string} {
proc foo {} {}
catch {chan create {c} foo} msg