diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | generic/tclIO.c | 16 | ||||
-rw-r--r-- | generic/tclTest.c | 39 |
3 files changed, 37 insertions, 36 deletions
@@ -1,5 +1,23 @@ 2003-03-06 Mo DeJong <mdejong@users.sourceforge.net> + * generic/tclIO.c (Tcl_Seek, Tcl_OutputBuffered): + If there is data buffered in the statePtr->curOutPtr + member then set the BUFFER_READY flag in Tcl_Seek. + This is needed so that the next call to FlushChannel + will write any buffered bytes before doing the seek. + The existing code would set the BUFFER_READY flag + inside the Tcl_OutputBuffered function. This was a + programming error made when Tcl_OutputBuffered + was originally created in CVS revision 1.35. The + setting of the BUFFER_READY flag should not have + been included in the Tcl_OutputBuffered function. + * generic/tclTest.c (TestChannelCmd): Use the + Tcl_InputBuffered and Tcl_OutputBuffered + util methods to query the amount of buffered + input and output. + +2003-03-06 Mo DeJong <mdejong@users.sourceforge.net> + * generic/tclIO.c (Tcl_Flush): Compare the nextAdded member of the ChannelBuffer to the nextRemoved member to determine if any output diff --git a/generic/tclIO.c b/generic/tclIO.c index 9f992f0..accf020 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.65 2003/03/06 10:10:24 mdejong Exp $ + * RCS: @(#) $Id: tclIO.c,v 1.66 2003/03/06 20:14:51 mdejong Exp $ */ #include "tclInt.h" @@ -5464,7 +5464,18 @@ Tcl_Seek(chan, offset, mode) statePtr->flags &= (~(BG_FLUSH_SCHEDULED)); } } - + + /* + * If there is data buffered in statePtr->curOutPtr then mark + * the channel as ready to flush before invoking FlushChannel. + */ + + if ((statePtr->curOutPtr != (ChannelBuffer *) NULL) && + (statePtr->curOutPtr->nextAdded > + statePtr->curOutPtr->nextRemoved)) { + statePtr->flags |= BUFFER_READY; + } + /* * If the flush fails we cannot recover the original position. In * that case the seek is not attempted because we do not know where @@ -5880,7 +5891,6 @@ Tcl_OutputBuffered(chan) } if ((statePtr->curOutPtr != (ChannelBuffer *) NULL) && (statePtr->curOutPtr->nextAdded > statePtr->curOutPtr->nextRemoved)) { - statePtr->flags |= BUFFER_READY; bytesBuffered += (statePtr->curOutPtr->nextAdded - statePtr->curOutPtr->nextRemoved); } diff --git a/generic/tclTest.c b/generic/tclTest.c index ed7e0ad..41d420e 100644 --- a/generic/tclTest.c +++ b/generic/tclTest.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclTest.c,v 1.62 2003/02/18 10:13:25 vincentdarley Exp $ + * RCS: @(#) $Id: tclTest.c,v 1.63 2003/03/06 20:14:58 mdejong Exp $ */ #define TCL_TEST @@ -5324,28 +5324,15 @@ TestChannelCmd(clientData, interp, argc, argv) } else if (statePtr->outputTranslation == TCL_TRANSLATE_CRLF) { Tcl_AppendElement(interp, "crlf"); } - for (IOQueued = 0, bufPtr = statePtr->inQueueHead; - bufPtr != (ChannelBuffer *) NULL; - bufPtr = bufPtr->nextPtr) { - IOQueued += bufPtr->nextAdded - bufPtr->nextRemoved; - } + IOQueued = Tcl_InputBuffered(chan); TclFormatInt(buf, IOQueued); Tcl_AppendElement(interp, buf); - IOQueued = 0; - if (statePtr->curOutPtr != (ChannelBuffer *) NULL) { - IOQueued = statePtr->curOutPtr->nextAdded - - statePtr->curOutPtr->nextRemoved; - } - for (bufPtr = statePtr->outQueueHead; - bufPtr != (ChannelBuffer *) NULL; - bufPtr = bufPtr->nextPtr) { - IOQueued += (bufPtr->nextAdded - bufPtr->nextRemoved); - } + IOQueued = Tcl_OutputBuffered(chan); TclFormatInt(buf, IOQueued); Tcl_AppendElement(interp, buf); - TclFormatInt(buf, (int)Tcl_Tell((Tcl_Channel) chanPtr)); + TclFormatInt(buf, (int)Tcl_Tell(chan)); Tcl_AppendElement(interp, buf); TclFormatInt(buf, statePtr->refCount); @@ -5361,12 +5348,7 @@ TestChannelCmd(clientData, interp, argc, argv) (char *) NULL); return TCL_ERROR; } - - for (IOQueued = 0, bufPtr = statePtr->inQueueHead; - bufPtr != (ChannelBuffer *) NULL; - bufPtr = bufPtr->nextPtr) { - IOQueued += bufPtr->nextAdded - bufPtr->nextRemoved; - } + IOQueued = Tcl_InputBuffered(chan); TclFormatInt(buf, IOQueued); Tcl_AppendResult(interp, buf, (char *) NULL); return TCL_OK; @@ -5457,16 +5439,7 @@ TestChannelCmd(clientData, interp, argc, argv) return TCL_ERROR; } - IOQueued = 0; - if (statePtr->curOutPtr != (ChannelBuffer *) NULL) { - IOQueued = statePtr->curOutPtr->nextAdded - - statePtr->curOutPtr->nextRemoved; - } - for (bufPtr = statePtr->outQueueHead; - bufPtr != (ChannelBuffer *) NULL; - bufPtr = bufPtr->nextPtr) { - IOQueued += (bufPtr->nextAdded - bufPtr->nextRemoved); - } + IOQueued = Tcl_OutputBuffered(chan); TclFormatInt(buf, IOQueued); Tcl_AppendResult(interp, buf, (char *) NULL); return TCL_OK; |