summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2004-07-15 20:46:49 (GMT)
committerandreas_kupries <akupries@shaw.ca>2004-07-15 20:46:49 (GMT)
commitd030c083e5dd7913feb8736f3727f316fe525876 (patch)
tree57898ba81f1e08b32a243a13819f2637f6435d74 /generic/tclIO.c
parentac5258caba03972be43bafc65a38ad4571af178f (diff)
downloadtcl-d030c083e5dd7913feb8736f3727f316fe525876.zip
tcl-d030c083e5dd7913feb8736f3727f316fe525876.tar.gz
tcl-d030c083e5dd7913feb8736f3727f316fe525876.tar.bz2
* generic/tclIO.h (CHANNEL_INCLOSE): New flag. Set in
* generic/tclIO.c (Tcl_UnregisterChannel): 'Tcl_Close' while the * generic/tclIO.c (Tcl_Close): close callbacks are run. Checked in 'Tcl_Close' and 'Tcl_Unregister' to prevent recursive call of 'close' in the close-callbacks. This is a possible error made by implementors of virtual filesystems based on 'tclvfs', thinking that they have to close the channel in the close handler for the filesystem. * generic/tclIO.c: * generic/tclIO.h: * Not reverting, but #ifdef'ing the changes from May 19, 2004 out of the core. This removes the ***POTENTIAL INCOMPATIBILITY*** for channel drivers it introduced. This has become possible due to Expect gaining a BlockModeProc and now handling blockingg and non-blocking modes correctly. Thus [SF Tcl Bug 943274] is still fixed if a recent enough version of Expect is used. * doc/CrtChannel.3: Added warning about usage of a channel without a BlockModeProc.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c46
1 files changed, 45 insertions, 1 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 919dfef..295225c 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIO.c,v 1.76 2004/06/01 18:44:16 davygrvy Exp $
+ * RCS: @(#) $Id: tclIO.c,v 1.77 2004/07/15 20:46:49 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -807,6 +807,17 @@ Tcl_UnregisterChannel(interp, chan)
{
ChannelState *statePtr; /* State of the real channel. */
+ statePtr = ((Channel *) chan)->state->bottomChanPtr->state;
+
+ if (statePtr->flags & CHANNEL_INCLOSE) {
+ if (interp != (Tcl_Interp*) NULL) {
+ Tcl_AppendResult(interp,
+ "Illegal recursive call to close through close-handler of channel",
+ (char *) NULL);
+ }
+ return TCL_ERROR;
+ }
+
if (DetachChannel(interp, chan) != TCL_OK) {
return TCL_OK;
}
@@ -2529,6 +2540,14 @@ Tcl_Close(interp, chan)
Tcl_Panic("called Tcl_Close on channel with refCount > 0");
}
+ if (statePtr->flags & CHANNEL_INCLOSE) {
+ Tcl_AppendResult(interp,
+ "Illegal recursive call to close through close-handler of channel",
+ (char *) NULL);
+ return TCL_ERROR;
+ }
+ statePtr->flags |= CHANNEL_INCLOSE;
+
/*
* When the channel has an escape sequence driven encoding such as
* iso2022, the terminated escape sequence must write to the buffer.
@@ -2552,6 +2571,8 @@ Tcl_Close(interp, chan)
ckfree((char *) cbPtr);
}
+ statePtr->flags &= ~CHANNEL_INCLOSE;
+
/*
* Ensure that the last output buffer will be flushed.
*/
@@ -4237,6 +4258,7 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
statePtr->flags &= (~(CHANNEL_BLOCKED));
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]. Better emulation of non-blocking
* channels for channels without BlockModeProc, by keeping
* track of true fileevents generated by the OS == Data
@@ -4252,6 +4274,7 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
nread = -1;
result = EWOULDBLOCK;
} else {
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
/*
* Now go to the driver to get as much as is possible to
* fill the remaining request. Do all the error handling
@@ -4263,7 +4286,9 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
nread = (chanPtr->typePtr->inputProc)(chanPtr->instanceData,
bufPtr + copied, bytesToRead - copied, &result);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
if (nread > 0) {
/*
* If we get a short read, signal up that we may be
@@ -4277,11 +4302,13 @@ Tcl_ReadRaw(chan, bufPtr, bytesToRead)
statePtr->flags |= CHANNEL_BLOCKED;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (nread <= (bytesToRead - copied)) {
/* [SF Tcl Bug 943274] We have read the available
* data, clear flag */
statePtr->flags &= ~CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
} else if (nread == 0) {
statePtr->flags |= CHANNEL_EOF;
statePtr->inputEncodingFlags |= TCL_ENCODING_END;
@@ -5323,6 +5350,7 @@ GetInput(chanPtr)
return 0;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]. Better emulation of non-blocking channels
* for channels without BlockModeProc, by keeping track of true
* fileevents generated by the OS == Data waiting and reading if
@@ -5337,9 +5365,12 @@ GetInput(chanPtr)
nread = -1;
result = EWOULDBLOCK;
} else {
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
nread = (chanPtr->typePtr->inputProc)(chanPtr->instanceData,
bufPtr->buf + bufPtr->nextAdded, toRead, &result);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
if (nread > 0) {
bufPtr->nextAdded += nread;
@@ -5355,11 +5386,13 @@ GetInput(chanPtr)
statePtr->flags |= CHANNEL_BLOCKED;
}
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (nread <= toRead) {
/* [SF Tcl Bug 943274] We have read the available data,
* clear flag */
statePtr->flags &= ~CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
} else if (nread == 0) {
statePtr->flags |= CHANNEL_EOF;
@@ -6764,6 +6797,7 @@ Tcl_NotifyChannel(channel, mask)
Channel* upChanPtr;
Tcl_ChannelType* upTypePtr;
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* [SF Tcl Bug 943274]
* For a non-blocking channel without blockmodeproc we keep track
* of actual input coming from the OS so that we can do a credible
@@ -6777,6 +6811,7 @@ Tcl_NotifyChannel(channel, mask)
statePtr->flags |= CHANNEL_HAS_MORE_DATA;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
/*
* In contrast to the other API functions this procedure walks towards
@@ -7017,6 +7052,7 @@ ChannelTimerProc(clientData)
statePtr->timer = Tcl_CreateTimerHandler(0, ChannelTimerProc,
(ClientData) chanPtr);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
/* Set the TIMER flag to notify the higher levels that the
* driver might have no data for us. We do this only if we are
* in non-blocking mode and the driver has no BlockModeProc
@@ -7028,10 +7064,15 @@ ChannelTimerProc(clientData)
(Tcl_ChannelBlockModeProc(chanPtr->typePtr) == NULL)) {
statePtr->flags |= CHANNEL_TIMER_FEV;
}
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+
Tcl_Preserve((ClientData) statePtr);
Tcl_NotifyChannel((Tcl_Channel)chanPtr, TCL_READABLE);
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
statePtr->flags &= ~CHANNEL_TIMER_FEV;
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+
Tcl_Release((ClientData) statePtr);
} else {
statePtr->timer = NULL;
@@ -9263,8 +9304,11 @@ DumpFlags (str, flags)
if (flags & INPUT_NEED_NL) {buf[i] = '*';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_DEAD) {buf[i] = 'D';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_RAW_MODE) {buf[i] = 'R';} else {buf [i]='_';}; i++;
+#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING
if (flags & CHANNEL_TIMER_FEV) {buf[i] = 'T';} else {buf [i]='_';}; i++;
if (flags & CHANNEL_HAS_MORE_DATA) {buf[i] = 'H';} else {buf [i]='_';}; i++;
+#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */
+ if (flags & CHANNEL_INCLOSE) {buf[i] = 'x';} else {buf [i]='_';}; i++;
buf [i] ='\0';
fprintf (stderr,"%s: %s\n", str, buf); fflush(stderr);