From 023ceb178da1d545717b455ee96184c481f20f5c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 13 Apr 2023 06:16:05 +0000 Subject: cherry-pick from trunk: Remove one unnecesary call to Tcl_SetErrno() in DoReadChars(). --- generic/tclIO.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 6ec93f2..92ad97e 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -6091,11 +6091,7 @@ DoReadChars( if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR) && !GotFlag(statePtr, CHANNEL_STICKY_EOF) - && !GotFlag(statePtr, CHANNEL_NONBLOCKING)) { - /* Channel is blocking. Return an error so that callers - * like [read] can return an error. - */ - Tcl_SetErrno(EILSEQ); + && (!GotFlag(statePtr, CHANNEL_NONBLOCKING))) { goto finish; } } @@ -6138,7 +6134,7 @@ finish: } /* - * Regenerate the top channel, in case it was changed due to + * Regenerate chanPtr in case it was changed due to * self-modifying reflected transforms. */ @@ -6160,8 +6156,14 @@ finish: assert(!(GotFlag(statePtr, CHANNEL_EOF|CHANNEL_BLOCKED) == (CHANNEL_EOF|CHANNEL_BLOCKED))); UpdateInterest(chanPtr); + + /* This must comes after UpdateInterest(), which may set errno */ if (GotFlag(statePtr, CHANNEL_ENCODING_ERROR) && (!copied || !GotFlag(statePtr, CHANNEL_NONBLOCKING))) { + /* Channel either is blocking or is nonblocking with no data + * succesfully red before the error. Return an error so that callers + * like [read] can also return an error. + */ Tcl_SetErrno(EILSEQ); copied = -1; } @@ -6200,7 +6202,7 @@ ReadBytes( * been allocated to hold data, not how many * bytes of data have been stored in the * object. */ - int bytesToRead) /* Maximum number of bytes to store, or < 0 to + int bytesToRead) /* Maximum number of bytes to store, or -1 to * get all available bytes. Bytes are obtained * from the first buffer in the queue - even * if this number is larger than the number of @@ -6597,7 +6599,7 @@ ReadChars( * precautions. */ - if (nextPtr->nextRemoved - srcLen < 0) { + if (nextPtr->nextRemoved < srcLen) { Tcl_Panic("Buffer Underflow, BUFFER_PADDING not enough"); } -- cgit v0.12