summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorsebres <sebres@users.sourceforge.net>2018-03-05 17:37:21 (GMT)
committersebres <sebres@users.sourceforge.net>2018-03-05 17:37:21 (GMT)
commit6c0170972f57e3d1daf5684c55eccfb2d78b386f (patch)
tree353b752f4fb0906b3e00e35c92c1174a9b4b6a26 /generic/tclIO.c
parent85233a46935b192d7baf5fa81c9ad21bfebeca77 (diff)
downloadtcl-6c0170972f57e3d1daf5684c55eccfb2d78b386f.zip
tcl-6c0170972f57e3d1daf5684c55eccfb2d78b386f.tar.gz
tcl-6c0170972f57e3d1daf5684c55eccfb2d78b386f.tar.bz2
fixes [1873ea0ee4f01b26]: wrong initialization of std-channels, if no std-handles available at all (e. g. non-console application, like "tk")
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index 2e1569f..4d3df65 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -626,17 +626,18 @@ Tcl_SetStdChannel(
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ int init = channel ? 1 : -1;
switch (type) {
case TCL_STDIN:
- tsdPtr->stdinInitialized = 1;
+ tsdPtr->stdinInitialized = init;
tsdPtr->stdinChannel = channel;
break;
case TCL_STDOUT:
- tsdPtr->stdoutInitialized = 1;
+ tsdPtr->stdoutInitialized = init;
tsdPtr->stdoutChannel = channel;
break;
case TCL_STDERR:
- tsdPtr->stderrInitialized = 1;
+ tsdPtr->stderrInitialized = init;
tsdPtr->stderrChannel = channel;
break;
}
@@ -673,8 +674,8 @@ Tcl_GetStdChannel(
switch (type) {
case TCL_STDIN:
if (!tsdPtr->stdinInitialized) {
+ tsdPtr->stdinInitialized = -1;
tsdPtr->stdinChannel = TclpGetDefaultStdChannel(TCL_STDIN);
- tsdPtr->stdinInitialized = 1;
/*
* Artificially bump the refcount to ensure that the channel is
@@ -686,6 +687,7 @@ Tcl_GetStdChannel(
*/
if (tsdPtr->stdinChannel != NULL) {
+ tsdPtr->stdinInitialized = 1;
Tcl_RegisterChannel(NULL, tsdPtr->stdinChannel);
}
}
@@ -693,9 +695,10 @@ Tcl_GetStdChannel(
break;
case TCL_STDOUT:
if (!tsdPtr->stdoutInitialized) {
+ tsdPtr->stdoutInitialized = -1;
tsdPtr->stdoutChannel = TclpGetDefaultStdChannel(TCL_STDOUT);
- tsdPtr->stdoutInitialized = 1;
if (tsdPtr->stdoutChannel != NULL) {
+ tsdPtr->stdoutInitialized = 1;
Tcl_RegisterChannel(NULL, tsdPtr->stdoutChannel);
}
}
@@ -703,9 +706,10 @@ Tcl_GetStdChannel(
break;
case TCL_STDERR:
if (!tsdPtr->stderrInitialized) {
+ tsdPtr->stderrInitialized = -1;
tsdPtr->stderrChannel = TclpGetDefaultStdChannel(TCL_STDERR);
- tsdPtr->stderrInitialized = 1;
if (tsdPtr->stderrChannel != NULL) {
+ tsdPtr->stderrInitialized = 1;
Tcl_RegisterChannel(NULL, tsdPtr->stderrChannel);
}
}
@@ -975,7 +979,7 @@ CheckForStdChannelsBeingClosed(
ChannelState *statePtr = ((Channel *) chan)->state;
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
- if (tsdPtr->stdinInitialized
+ if (tsdPtr->stdinInitialized == 1
&& tsdPtr->stdinChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stdinChannel)->state) {
if (statePtr->refCount < 2) {
@@ -983,7 +987,7 @@ CheckForStdChannelsBeingClosed(
tsdPtr->stdinChannel = NULL;
return;
}
- } else if (tsdPtr->stdoutInitialized
+ } else if (tsdPtr->stdoutInitialized == 1
&& tsdPtr->stdoutChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stdoutChannel)->state) {
if (statePtr->refCount < 2) {
@@ -991,7 +995,7 @@ CheckForStdChannelsBeingClosed(
tsdPtr->stdoutChannel = NULL;
return;
}
- } else if (tsdPtr->stderrInitialized
+ } else if (tsdPtr->stderrInitialized == 1
&& tsdPtr->stderrChannel != NULL
&& statePtr == ((Channel *)tsdPtr->stderrChannel)->state) {
if (statePtr->refCount < 2) {