diff options
author | andreas_kupries <akupries@shaw.ca> | 2004-07-15 20:46:17 (GMT) |
---|---|---|
committer | andreas_kupries <akupries@shaw.ca> | 2004-07-15 20:46:17 (GMT) |
commit | 597bb3236aba9dbe1c799b8bde917c1228fd21a1 (patch) | |
tree | 6b9b7f812be710b6ab81f81e35ba63a056c6926f /generic | |
parent | 3c87843ad32da0db04bc580121a56049ad5cb367 (diff) | |
download | tcl-597bb3236aba9dbe1c799b8bde917c1228fd21a1.zip tcl-597bb3236aba9dbe1c799b8bde917c1228fd21a1.tar.gz tcl-597bb3236aba9dbe1c799b8bde917c1228fd21a1.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')
-rw-r--r-- | generic/tclIO.c | 49 | ||||
-rw-r--r-- | generic/tclIO.h | 11 |
2 files changed, 58 insertions, 2 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c index f1a3266..154bec0 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.61.2.6 2004/05/19 19:23:58 andreas_kupries Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.61.2.7 2004/07/15 20:46:18 andreas_kupries Exp $ */ #include "tclInt.h" @@ -772,6 +772,7 @@ Tcl_RegisterChannel(interp, chan) } Tcl_SetHashValue(hPtr, (ClientData) chanPtr); } + statePtr->refCount++; } @@ -808,6 +809,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; } @@ -2527,6 +2539,14 @@ Tcl_Close(interp, chan) if (statePtr->refCount > 0) { 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 @@ -2551,6 +2571,8 @@ Tcl_Close(interp, chan) ckfree((char *) cbPtr); } + statePtr->flags &= ~CHANNEL_INCLOSE; + /* * Ensure that the last output buffer will be flushed. */ @@ -4225,6 +4247,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 @@ -4240,6 +4263,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 @@ -4251,7 +4275,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 @@ -4265,11 +4291,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; @@ -5310,6 +5338,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 @@ -5324,9 +5353,14 @@ 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; @@ -5342,11 +5376,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; @@ -6740,6 +6776,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 @@ -6753,6 +6790,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 @@ -6993,6 +7031,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 @@ -7004,10 +7043,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; @@ -9239,8 +9283,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); diff --git a/generic/tclIO.h b/generic/tclIO.h index 7f2c421..ea3c6e4 100644 --- a/generic/tclIO.h +++ b/generic/tclIO.h @@ -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.h,v 1.5.4.1 2004/05/19 19:16:24 andreas_kupries Exp $ + * RCS: @(#) $Id: tclIO.h,v 1.5.4.2 2004/07/15 20:46:19 andreas_kupries Exp $ */ /* @@ -296,6 +296,7 @@ typedef struct ChannelState { * the state of the channel changes. */ #define CHANNEL_RAW_MODE (1<<16) /* When set, notes that the Raw API is * being used. */ +#ifdef TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING #define CHANNEL_TIMER_FEV (1<<17) /* When set the event we are * notified by is a fileevent * generated by a timer. We @@ -323,6 +324,14 @@ typedef struct ChannelState { * will be performed if the * flag is set. This will * reset the flag as well. */ +#endif /* TCL_IO_TRACK_OS_FOR_DRIVER_WITH_BAD_BLOCKING */ + +#define CHANNEL_INCLOSE (1<<19) /* Channel is currently being + * closed. Its structures are + * still live and usable, but + * it may not be closed again + * from within the close handler. + */ /* * For each channel handler registered in a call to Tcl_CreateChannelHandler, |