From 439a4360b3125b8917bb1d1ef0157d2c2f88de21 Mon Sep 17 00:00:00 2001 From: pointsman Date: Mon, 24 Apr 2023 09:41:04 +0000 Subject: Fixes the examples given in [0306a5563c]. Still more to do for a full fix. --- generic/tclIO.c | 1 + 1 file changed, 1 insertion(+) diff --git a/generic/tclIO.c b/generic/tclIO.c index 4e2e37d..387d56e 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -4273,6 +4273,7 @@ Tcl_WriteObj( } totalWritten += written; srcLen -= chunkSize; + src += written; } while (srcLen); return totalWritten; } -- cgit v0.12 From 1ddccee9d333130c931c56373c0bddd89cd2d5fa Mon Sep 17 00:00:00 2001 From: pointsman Date: Mon, 24 Apr 2023 20:21:42 +0000 Subject: Added a test for the initial problem and another for the known remaining problem. --- tests/bigdata.test | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/bigdata.test b/tests/bigdata.test index c02d8e3..bb6d269 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -1069,6 +1069,43 @@ bigtestRO concat-bigdata-1 "concat" {4294967296 {0 1 2 3 4} {6 7 0 1 2} {3 4 5 6 set l [bigList 0x80000000] } +tcltest::test puts-bigdata-1 "puts" -setup { + set fpath [tcltest::makeFile {} bug-0306a5563.data] +} -constraints { + bug0306a5563 + bigdata +} -body { + set fd [open $fpath w] + puts -nonewline $fd [testbigdata string 0x80000001] + close $fd + set fd [open $fpath] + seek $fd 0x7FFFFFFA + set written [read $fd] + close $fd + set written +} -result {2345678} + +tcltest::test puts-bigdata-2 "puts" -setup { + set fpath [tcltest::makeFile {} bug-0306a5563.data] +} -constraints { + bug0306a5563 + bigdata + knownBug +} -body { + set fd [open $fpath w] + set s [testbigdata string 0x7FFFFFFE] + # The character to append in the next line is EM DASH, + # code point 0x2014 (decimal 8212, UTF-8 #xE2 #x80 #x94) + append s — + puts -nonewline$fd $s + close $fd + set fd [open $fpath] + seek $fd 0x7FFFFFFA + set written [read $fd] + close $fd + set written +} -result {23456—} + # # TODO # lremove -- cgit v0.12 From 84d939b69af55bedc3276066cd8db61bb79dfc39 Mon Sep 17 00:00:00 2001 From: pointsman Date: Tue, 2 May 2023 21:50:48 +0000 Subject: Fix for [0306a5563c]. --- generic/tclIO.c | 50 +++++++++++++++++++------------------------------- tests/bigdata.test | 7 +++---- 2 files changed, 22 insertions(+), 35 deletions(-) diff --git a/generic/tclIO.c b/generic/tclIO.c index 387d56e..a7014e2 100644 --- a/generic/tclIO.c +++ b/generic/tclIO.c @@ -223,8 +223,8 @@ static void StopCopy(CopyState *csPtr); static void TranslateInputEOL(ChannelState *statePtr, char *dst, const char *src, int *dstLenPtr, int *srcLenPtr); static void UpdateInterest(Channel *chanPtr); -static int Write(Channel *chanPtr, const char *src, - int srcLen, Tcl_Encoding encoding); +static Tcl_Size Write(Channel *chanPtr, const char *src, + Tcl_Size srcLen, Tcl_Encoding encoding); static Tcl_Obj * FixLevelCode(Tcl_Obj *msg); static void SpliceChannel(Tcl_Channel chan); static void CutChannel(Tcl_Channel chan); @@ -4240,6 +4240,7 @@ Tcl_WriteObj( Channel *chanPtr; ChannelState *statePtr; /* State info for channel */ const char *src; + Tcl_Size srcLen = 0; statePtr = ((Channel *) chan)->state; chanPtr = statePtr->topChanPtr; @@ -4247,35 +4248,21 @@ Tcl_WriteObj( if (CheckChannelErrors(statePtr, TCL_WRITABLE) != 0) { return TCL_INDEX_NONE; } - - Tcl_Size srcLen; if (statePtr->encoding == NULL) { + Tcl_Size result; + src = (char *) Tcl_GetByteArrayFromObj(objPtr, &srcLen); if (src == NULL) { Tcl_SetErrno(EILSEQ); - return TCL_INDEX_NONE; + result = TCL_INDEX_NONE; + } else { + result = WriteBytes(chanPtr, src, srcLen); } + return result; } else { src = Tcl_GetStringFromObj(objPtr, &srcLen); + return WriteChars(chanPtr, src, srcLen); } - - size_t totalWritten = 0; - /* - * Note original code always called WriteChars even if srcLen 0 - * so we will too. - */ - do { - int chunkSize = srcLen > INT_MAX ? INT_MAX : srcLen; - int written; - written = WriteChars(chanPtr, src, chunkSize); - if (written < 0) { - return TCL_INDEX_NONE; - } - totalWritten += written; - srcLen -= chunkSize; - src += written; - } while (srcLen); - return totalWritten; } static void @@ -4346,20 +4333,21 @@ WillRead( *---------------------------------------------------------------------- */ -static int +static Tcl_Size Write( Channel *chanPtr, /* The channel to buffer output for. */ const char *src, /* UTF-8 string to write. */ - int srcLen, /* Length of UTF-8 string in bytes. */ + Tcl_Size srcLen, /* Length of UTF-8 string in bytes. */ Tcl_Encoding encoding) { ChannelState *statePtr = chanPtr->state; /* State info for channel */ char *nextNewLine = NULL; - int endEncoding, saved = 0, total = 0, flushed = 0, needNlFlush = 0; + int endEncoding, needNlFlush = 0; + Tcl_Size saved = 0, total = 0, flushed = 0; char safe[BUFFER_PADDING]; int encodingError = 0; - + if (srcLen) { WillWrite(chanPtr); } @@ -4369,7 +4357,6 @@ Write( */ endEncoding = ((statePtr->outputEncodingFlags & TCL_ENCODING_END) != 0); - if (GotFlag(statePtr, CHANNEL_LINEBUFFERED) || (statePtr->outputTranslation != TCL_TRANSLATE_LF)) { nextNewLine = (char *)memchr(src, '\n', srcLen); @@ -4378,7 +4365,8 @@ Write( while (srcLen + saved + endEncoding > 0 && !encodingError) { ChannelBuffer *bufPtr; char *dst; - int result, srcRead, dstLen, dstWrote, srcLimit = srcLen; + int result, srcRead, dstLen, dstWrote; + Tcl_Size srcLimit = srcLen; if (nextNewLine) { srcLimit = nextNewLine - src; @@ -4650,7 +4638,7 @@ Tcl_GetsObj( if (statePtr->encoding == GetBinaryEncoding() && ((statePtr->inputTranslation == TCL_TRANSLATE_LF) || (statePtr->inputTranslation == TCL_TRANSLATE_CR)) - && Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL) != NULL) { + && Tcl_GetByteArrayFromObj(objPtr, (Tcl_Size *)NULL) != NULL) { return TclGetsObjBinary(chan, objPtr); } @@ -5991,7 +5979,7 @@ DoReadChars( && (statePtr->inEofChar == '\0'); if (appendFlag) { - if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (size_t *)NULL))) { + if (binaryMode && (NULL == Tcl_GetByteArrayFromObj(objPtr, (Tcl_Size *)NULL))) { binaryMode = 0; } } else { diff --git a/tests/bigdata.test b/tests/bigdata.test index 0538528..c477238 100644 --- a/tests/bigdata.test +++ b/tests/bigdata.test @@ -1090,13 +1090,12 @@ test puts-bigdata-2 "puts" -setup { } -constraints { bug0306a5563 bigdata - knownBug } -body { set fd [open $fpath w] set s [testbigdata string 0x7FFFFFFE] - # The character to append in the next line is EM DASH, + # The character to append in the next line is —, EM DASH, # code point 0x2014 (decimal 8212, UTF-8 #xE2 #x80 #x94) - append s — + append s \u2014 puts -nonewline $fd $s close $fd set fd [open $fpath] @@ -1104,7 +1103,7 @@ test puts-bigdata-2 "puts" -setup { set written [read $fd] close $fd set written -} -result {23456—} +} -result {2345—} # # TODO -- cgit v0.12