summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2014-05-02 15:06:57 (GMT)
committerdgp <dgp@users.sourceforge.net>2014-05-02 15:06:57 (GMT)
commit7404b09c618ba2e4af7bb1cd0f043d50eff6f484 (patch)
treed528a3109e1018a322a650e31f17730c564df04e
parentcf5a2fcdb5b8dd834e530641922f7ba5c841553f (diff)
parentab2c4a52f1dbcc67939ad86233d21cf7fc38a5cd (diff)
downloadtcl-7404b09c618ba2e4af7bb1cd0f043d50eff6f484.zip
tcl-7404b09c618ba2e4af7bb1cd0f043d50eff6f484.tar.gz
tcl-7404b09c618ba2e4af7bb1cd0f043d50eff6f484.tar.bz2
Backport channel self restacking support. (Test iogt-2.4).
-rw-r--r--generic/tclIO.c61
-rw-r--r--tests/iogt.test2
2 files changed, 60 insertions, 3 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index cd28a0e..46a17f5 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -1654,6 +1654,10 @@ Tcl_StackChannel(
csPtrW = statePtr->csPtrW;
statePtr->csPtrW = NULL;
+ /*
+ * TODO: Examine what can go wrong if Tcl_Flush() call disturbs
+ * the stacking state of this channel during its operations.
+ */
if (Tcl_Flush((Tcl_Channel) prevChanPtr) != TCL_OK) {
statePtr->csPtrR = csPtrR;
statePtr->csPtrW = csPtrW;
@@ -1786,6 +1790,13 @@ Tcl_UnstackChannel(
* structure.
*/
+ /*
+ * TODO: Figure out how to handle the situation where the chan
+ * operations called below by this unstacking operation cause
+ * another unstacking recursively. In that case the downChanPtr
+ * value we're holding on to will not be the right thing.
+ */
+
Channel *downChanPtr = chanPtr->downChanPtr;
/*
@@ -1906,7 +1917,7 @@ Tcl_UnstackChannel(
*/
Tcl_EventuallyFree(chanPtr, TCL_DYNAMIC);
- UpdateInterest(downChanPtr);
+ UpdateInterest(statePtr->topChanPtr);
if (result != 0) {
Tcl_SetErrno(result);
@@ -4134,6 +4145,17 @@ Tcl_GetsObj(
*/
gotEOL:
+ /*
+ * Regenerate the top channel, in case it was changed due to
+ * self-modifying reflected transforms.
+ */
+
+ if (chanPtr != statePtr->topChanPtr) {
+ Tcl_Release(chanPtr);
+ chanPtr = statePtr->topChanPtr;
+ Tcl_Preserve(chanPtr);
+ }
+
bufPtr = gs.bufPtr;
if (bufPtr == NULL) {
Tcl_Panic("Tcl_GetsObj: gotEOL reached with bufPtr==NULL");
@@ -4162,6 +4184,15 @@ Tcl_GetsObj(
*/
restore:
+ /*
+ * Regenerate the top channel, in case it was changed due to
+ * self-modifying reflected transforms.
+ */
+ if (chanPtr != statePtr->topChanPtr) {
+ Tcl_Release(chanPtr);
+ chanPtr = statePtr->topChanPtr;
+ Tcl_Preserve(chanPtr);
+ }
bufPtr = statePtr->inQueueHead;
if (bufPtr != NULL) {
bufPtr->nextRemoved = oldRemoved;
@@ -4197,6 +4228,15 @@ Tcl_GetsObj(
*/
done:
+ /*
+ * Regenerate the top channel, in case it was changed due to
+ * self-modifying reflected transforms.
+ */
+ if (chanPtr != statePtr->topChanPtr) {
+ Tcl_Release(chanPtr);
+ chanPtr = statePtr->topChanPtr;
+ Tcl_Preserve(chanPtr);
+ }
UpdateInterest(chanPtr);
Tcl_Release(chanPtr);
return copiedTotal;
@@ -5201,6 +5241,11 @@ DoReadChars(
ResetFlag(statePtr, CHANNEL_BLOCKED);
}
result = GetInput(chanPtr);
+ if (chanPtr != statePtr->topChanPtr) {
+ Tcl_Release(chanPtr);
+ chanPtr = statePtr->topChanPtr;
+ Tcl_Preserve(chanPtr);
+ }
if (result != 0) {
if (result == EAGAIN) {
break;
@@ -5227,6 +5272,15 @@ DoReadChars(
*/
done:
+ /*
+ * Regenerate the top channel, in case it was changed due to
+ * self-modifying reflected transforms.
+ */
+ if (chanPtr != statePtr->topChanPtr) {
+ Tcl_Release(chanPtr);
+ chanPtr = statePtr->topChanPtr;
+ Tcl_Preserve(chanPtr);
+ }
UpdateInterest(chanPtr);
Tcl_Release(chanPtr);
return copied;
@@ -9341,12 +9395,15 @@ StackSetBlockMode(
{
int result = 0;
Tcl_DriverBlockModeProc *blockModeProc;
+ ChannelState *statePtr = chanPtr->state;
/*
* Start at the top of the channel stack
+ * TODO: Examine what can go wrong when blockModeProc calls
+ * disturb the stacking state of the channel.
*/
- chanPtr = chanPtr->state->topChanPtr;
+ chanPtr = statePtr->topChanPtr;
while (chanPtr != NULL) {
blockModeProc = Tcl_ChannelBlockModeProc(chanPtr->typePtr);
if (blockModeProc != NULL) {
diff --git a/tests/iogt.test b/tests/iogt.test
index d54ae04..d81acd6 100644
--- a/tests/iogt.test
+++ b/tests/iogt.test
@@ -250,7 +250,7 @@ proc id_torture {chan op data} {
delete/read -
clear_read {;#ignore}
flush/write -
- flush/read -
+ flush/read {}
write -
read {
testchannel unstack $chan