summaryrefslogtreecommitdiffstats
path: root/generic/tclIO.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2015-07-02 08:17:50 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2015-07-02 08:17:50 (GMT)
commita6e73bdff10969ba7650f19309abf4a6ee9c041d (patch)
tree9b1ff6ff3db457ec452f61ebcb38c942c259dc7d /generic/tclIO.c
parent7f2e7b48d83365fd7bb943530df2e43ca61bea8d (diff)
downloadtcl-a6e73bdff10969ba7650f19309abf4a6ee9c041d.zip
tcl-a6e73bdff10969ba7650f19309abf4a6ee9c041d.tar.gz
tcl-a6e73bdff10969ba7650f19309abf4a6ee9c041d.tar.bz2
Another round of refCount consistancy improvements.
Diffstat (limited to 'generic/tclIO.c')
-rw-r--r--generic/tclIO.c57
1 files changed, 28 insertions, 29 deletions
diff --git a/generic/tclIO.c b/generic/tclIO.c
index b97f57a..eb924d1 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -578,11 +578,11 @@ TclFinalizeIOSubsystem(void)
int active = 1; /* Flag == 1 while there's still work to do */
int doflushnb;
- /* Fetch the pre-TIP#398 compatibility flag */
+ /* Fetch the pre-TIP#398 compatibility flag */
{
const char *s;
Tcl_DString ds;
-
+
s = TclGetEnv("TCL_FLUSH_NONBLOCKING_ON_EXIT", &ds);
doflushnb = ((s != NULL) && strcmp(s, "0"));
if (s != NULL) {
@@ -635,9 +635,9 @@ TclFinalizeIOSubsystem(void)
/* Set the channel back into blocking mode to ensure that we wait
* for all data to flush out.
*/
-
+
(void) Tcl_SetChannelOption(NULL, (Tcl_Channel) chanPtr,
- "-blocking", "on");
+ "-blocking", "on");
}
if ((chanPtr == (Channel *) tsdPtr->stdinChannel) ||
@@ -1022,8 +1022,7 @@ DeleteChannelTable(
Tcl_DeleteHashEntry(hPtr);
SetFlag(statePtr, CHANNEL_TAINTED);
- statePtr->refCount--;
- if (statePtr->refCount <= 0) {
+ if (statePtr->refCount-- <= 1) {
if (!GotFlag(statePtr, BG_FLUSH_SCHEDULED)) {
(void) Tcl_Close(interp, (Tcl_Channel) chanPtr);
}
@@ -1931,7 +1930,7 @@ TclChannelRelease(
if (chanPtr->refCount == 0) {
Tcl_Panic("Channel released more than preserved");
}
- if (--chanPtr->refCount) {
+ if (chanPtr->refCount-- > 1) {
return;
}
if (chanPtr->typePtr == NULL) {
@@ -2427,7 +2426,7 @@ static void
ReleaseChannelBuffer(
ChannelBuffer *bufPtr)
{
- if (--bufPtr->refCount) {
+ if (bufPtr->refCount-- > 1) {
return;
}
ckfree(bufPtr);
@@ -2657,7 +2656,7 @@ FlushChannel(
* the post-condition that on a successful return to caller we've
* left space in the current output buffer for more writing (the flush
* call was to make new room).
- * If the channel is blocking, then yes, so we guarantee that
+ * If the channel is blocking, then yes, so we guarantee that
* blocking flushes actually flush all pending data.
* Otherwise, no. Keep the current output buffer where it is so more
* can be written to it, possibly filling it, to promote more efficient
@@ -2844,7 +2843,7 @@ FlushChannel(
/*
* When we are calledFromAsyncFlush, that means a writable
* state on the channel triggered the call, so we should be
- * able to write something. Either we did write something
+ * able to write something. Either we did write something
* and wroteSome should be set, or there was nothing left to
* write in this call, and we've completed the BG flush.
* These are the two cases above. If we get here, that means
@@ -4224,7 +4223,7 @@ Write(
if (nextNewLine) {
srcLimit = nextNewLine - src;
}
-
+
/* Get space to write into */
bufPtr = statePtr->curOutPtr;
if (bufPtr == NULL) {
@@ -4252,7 +4251,7 @@ Write(
/* See chan-io-1.[89]. Tcl Bug 506297. */
statePtr->outputEncodingFlags &= ~TCL_ENCODING_START;
-
+
if ((result != TCL_OK) && (srcRead + dstWrote == 0)) {
/* We're reading from invalid/incomplete UTF-8 */
ReleaseChannelBuffer(bufPtr);
@@ -4292,7 +4291,7 @@ Write(
Tcl_Panic("unknown output translation requested");
break;
}
-
+
result |= Tcl_UtfToExternal(NULL, encoding, nl, nlLen,
statePtr->outputEncodingFlags,
&statePtr->outputEncodingState, dst,
@@ -5711,7 +5710,7 @@ DoReadChars(
int factor = UTF_EXPANSION_FACTOR;
binaryMode = (encoding == NULL)
- && (statePtr->inputTranslation == TCL_TRANSLATE_LF)
+ && (statePtr->inputTranslation == TCL_TRANSLATE_LF)
&& (statePtr->inEofChar == '\0');
if (appendFlag == 0) {
@@ -5981,7 +5980,7 @@ ReadChars(
* expand when converted to UTF-8 chars. This guess comes from analyzing
* how many characters were produced by the previous pass.
*/
-
+
int factor = *factorPtr;
int dstLimit = TCL_UTF_MAX - 1 + toRead * factor / UTF_EXPANSION_FACTOR;
@@ -6014,7 +6013,7 @@ ReadChars(
while (1) {
int dstDecoded, dstRead, dstWrote, srcRead, numChars, code;
int flags = statePtr->inputEncodingFlags | TCL_ENCODING_NO_TERMINATE;
-
+
if (charsToRead > 0) {
flags |= TCL_ENCODING_CHAR_LIMIT;
numChars = charsToRead;
@@ -6149,7 +6148,7 @@ ReadChars(
char buffer[TCL_UTF_MAX + 1];
int read, decoded, count;
- /*
+ /*
* Didn't get everything the buffer could offer
*/
@@ -6205,7 +6204,7 @@ ReadChars(
/* FALL THROUGH - get more data (dstWrote == 0) */
}
- /*
+ /*
* The translation transformation can only reduce the number
* of chars when it converts \r\n into \n. The reduction in
* the number of chars is the difference in bytes read and written.
@@ -6215,7 +6214,7 @@ ReadChars(
if (charsToRead > 0 && numChars > charsToRead) {
- /*
+ /*
* TODO: This cannot happen anymore.
*
* We read more chars than allowed. Reset limits to
@@ -6238,7 +6237,7 @@ ReadChars(
assert (numChars == 0);
- /*
+ /*
* There is one situation where this is the correct final
* result. If the src buffer contains only a single \n
* byte, and we are in TCL_TRANSLATE_AUTO mode, and
@@ -6331,7 +6330,7 @@ ReadChars(
*---------------------------------------------------------------------------
*/
-static void
+static void
TranslateInputEOL(
ChannelState *statePtr, /* Channel being read, for EOL translation and
* EOF character. */
@@ -6537,7 +6536,7 @@ Tcl_Ungets(
/*
* Clear the EOF flags, and clear the BLOCKED bit.
*/
-
+
if (GotFlag(statePtr, CHANNEL_EOF)) {
statePtr->inputEncodingFlags |= TCL_ENCODING_START;
}
@@ -6694,7 +6693,7 @@ GetInput(
ChannelState *statePtr = chanPtr->state;
/* State info for channel */
- /*
+ /*
* Verify that all callers know better than to call us when
* it's recorded that the next char waiting to be read is the
* eofchar.
@@ -9206,7 +9205,7 @@ MBEvent(
}
}
-static int
+static int
MBRead(
CopyState *csPtr)
{
@@ -9227,7 +9226,7 @@ MBRead(
}
}
-static int
+static int
MBWrite(
CopyState *csPtr)
{
@@ -9654,7 +9653,7 @@ CopyData(
* DoRead --
*
* Stores up to "bytesToRead" bytes in memory pointed to by "dst".
- * These bytes come from reading the channel "chanPtr" and
+ * These bytes come from reading the channel "chanPtr" and
* performing the configured translations. No encoding conversions
* are applied to the bytes being read.
*
@@ -9724,7 +9723,7 @@ DoRead(
TclChannelPreserve((Tcl_Channel)chanPtr);
while (bytesToRead) {
/*
- * Each pass through the loop is intended to process up to
+ * Each pass through the loop is intended to process up to
* one channel buffer.
*/
@@ -9732,13 +9731,13 @@ DoRead(
ChannelBuffer *bufPtr = statePtr->inQueueHead;
/*
- * Don't read more data if we have what we need.
+ * Don't read more data if we have what we need.
*/
while (!bufPtr || /* We got no buffer! OR */
(!IsBufferFull(bufPtr) && /* Our buffer has room AND */
(BytesLeft(bufPtr) < bytesToRead) ) ) {
- /* Not enough bytes in it
+ /* Not enough bytes in it
* yet to fill the dst */
int code;