diff options
author | mdejong <mdejong@noemail.net> | 2003-01-26 05:59:37 (GMT) |
---|---|---|
committer | mdejong <mdejong@noemail.net> | 2003-01-26 05:59:37 (GMT) |
commit | d4605f45baeb54c6320117b98dfc2c5e6728d78a (patch) | |
tree | 2e93369723b56eef9c19628901fb5aea461eeb5a /unix/tclUnixChan.c | |
parent | a723a185f7423882157f7844e7023ba4485410d5 (diff) | |
download | tcl-d4605f45baeb54c6320117b98dfc2c5e6728d78a.zip tcl-d4605f45baeb54c6320117b98dfc2c5e6728d78a.tar.gz tcl-d4605f45baeb54c6320117b98dfc2c5e6728d78a.tar.bz2 |
* generic/tclIO.c (Tcl_CutChannel, Tcl_SpliceChannel):
Invoke TclpCutFileChannel and TclpSpliceFileChannel.
* generic/tclInt.h: Declare TclpCutFileChannel
and TclpSpliceFileChannel.
* unix/tclUnixChan.c (FileCloseProc, TclpOpenFileChannel,
Tcl_MakeFileChannel, TclpCutFileChannel,
TclpSpliceFileChannel): Implement thread load data
cut and splice for file channels. This avoids
an invalid memory ref when compiled with -DDEPRECATED.
* win/tclWinChan.c (FileCloseProc, TclpCutFileChannel,
TclpSpliceFileChannel): Implement thread load data
cut and splice for file channels. This avoids
an invalid memory ref that was showing up in the
thread extension.
FossilOrigin-Name: 40bc638062775760b85fbf7679e73c0e285d1cb0
Diffstat (limited to 'unix/tclUnixChan.c')
-rw-r--r-- | unix/tclUnixChan.c | 118 |
1 files changed, 104 insertions, 14 deletions
diff --git a/unix/tclUnixChan.c b/unix/tclUnixChan.c index 4838c55..79dad86 100644 --- a/unix/tclUnixChan.c +++ b/unix/tclUnixChan.c @@ -10,11 +10,12 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixChan.c,v 1.40 2002/11/07 02:13:37 mdejong Exp $ + * RCS: @(#) $Id: tclUnixChan.c,v 1.41 2003/01/26 05:59:37 mdejong Exp $ */ #include "tclInt.h" /* Internal definitions for Tcl. */ #include "tclPort.h" /* Portability features for Tcl. */ +#include "tclIO.h" /* To get Channel type declaration. */ /* * sys/ioctl.h has already been included by tclPort.h. Including termios.h @@ -555,15 +556,6 @@ FileCloseProc(instanceData, interp) errorCode = errno; } } -#ifdef DEPRECATED - for (nextPtrPtr = &(tsdPtr->firstFilePtr); (*nextPtrPtr) != NULL; - nextPtrPtr = &((*nextPtrPtr)->nextPtr)) { - if ((*nextPtrPtr) == fsPtr) { - (*nextPtrPtr) = fsPtr->nextPtr; - break; - } - } -#endif /* DEPRECATED */ ckfree((char *) fsPtr); return errorCode; } @@ -1834,8 +1826,10 @@ TclpOpenFileChannel(interp, pathPtr, mode, permissions) } #ifdef DEPRECATED - fsPtr->nextPtr = tsdPtr->firstFilePtr; - tsdPtr->firstFilePtr = fsPtr; + if (channelTypePtr == &fileChannelType) { + fsPtr->nextPtr = tsdPtr->firstFilePtr; + tsdPtr->firstFilePtr = fsPtr; + } #endif /* DEPRECATED */ fsPtr->validMask = channelPermissions | TCL_EXCEPTION; fsPtr->fd = fd; @@ -1933,8 +1927,10 @@ Tcl_MakeFileChannel(handle, mode) } #ifdef DEPRECATED - fsPtr->nextPtr = tsdPtr->firstFilePtr; - tsdPtr->firstFilePtr = fsPtr; + if (channelTypePtr == &fileChannelType) { + fsPtr->nextPtr = tsdPtr->firstFilePtr; + tsdPtr->firstFilePtr = fsPtr; + } #endif /* DEPRECATED */ fsPtr->fd = fd; fsPtr->validMask = mode | TCL_EXCEPTION; @@ -3243,3 +3239,97 @@ TclUnixWaitForFile(fd, mask, timeout) } return result; } + +/* + *---------------------------------------------------------------------- + * + * TclpCutFileChannel -- + * + * Remove any thread local refs to this channel. See + * Tcl_CutChannel for more info. + * + * Results: + * None. + * + * Side effects: + * Changes thread local list of valid channels. + * + *---------------------------------------------------------------------- + */ + +void +TclpCutFileChannel(chan) + Tcl_Channel chan; /* The channel being removed. Must + * not be referenced in any + * interpreter. */ +{ +#ifdef DEPRECATED + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + Channel *chanPtr = (Channel *) chan; + FileState *fsPtr; + FileState **nextPtrPtr; + int removed = 0; + + if (chanPtr->typePtr != &fileChannelType) + return; + + fsPtr = (FileState *) chanPtr->instanceData; + + for (nextPtrPtr = &(tsdPtr->firstFilePtr); (*nextPtrPtr) != NULL; + nextPtrPtr = &((*nextPtrPtr)->nextPtr)) { + if ((*nextPtrPtr) == fsPtr) { + (*nextPtrPtr) = fsPtr->nextPtr; + removed = 1; + break; + } + } + + /* + * This could happen if the channel was created in one thread + * and then moved to another without updating the thread + * local data in each thread. + */ + + if (!removed) + panic("file info ptr not on thread channel list"); + +#endif /* DEPRECATED */ +} + +/* + *---------------------------------------------------------------------- + * + * TclpSpliceFileChannel -- + * + * Insert thread local ref for this channel. + * Tcl_SpliceChannel for more info. + * + * Results: + * None. + * + * Side effects: + * Changes thread local list of valid channels. + * + *---------------------------------------------------------------------- + */ + +void +TclpSpliceFileChannel(chan) + Tcl_Channel chan; /* The channel being removed. Must + * not be referenced in any + * interpreter. */ +{ +#ifdef DEPRECATED + ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); + Channel *chanPtr = (Channel *) chan; + FileState *fsPtr; + + if (chanPtr->typePtr != &fileChannelType) + return; + + fsPtr = (FileState *) chanPtr->instanceData; + + fsPtr->nextPtr = tsdPtr->firstFilePtr; + tsdPtr->firstFilePtr = fsPtr; +#endif /* DEPRECATED */ +} |