From 6311d5a24d705de060e9a05efa7afd87fb56f5de Mon Sep 17 00:00:00 2001 From: Jeremiah Corrado Date: Tue, 20 Feb 2024 10:11:39 -0700 Subject: [PATCH 1/4] create a local string in IO.readStringBytesData when the string is not already local Signed-off-by: Jeremiah Corrado --- modules/standard/IO.chpl | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/modules/standard/IO.chpl b/modules/standard/IO.chpl index 2f951f42c892..b36c234ba38b 100644 --- a/modules/standard/IO.chpl +++ b/modules/standard/IO.chpl @@ -7063,37 +7063,41 @@ proc fileReader.readline(ref arg: ?t): bool throws where t==string || t==bytes { // Passing -1 to 'nCodepoints' tells this function to compute the number // of codepoints itself, and store the result in 'cachedNumCodepoints'. @chpldoc.nodoc -proc readStringBytesData(ref s /*: string or bytes*/, +proc readStringBytesData(ref s: ?t /*: string or bytes*/, _channel_internal:qio_channel_ptr_t, nBytes: int, nCodepoints: int): errorCode { import BytesStringCommon; + var sLoc: t; + ref sLocal = if s.locale == here then s else sLoc; - BytesStringCommon.resizeBuffer(s, nBytes); + BytesStringCommon.resizeBuffer(sLocal, nBytes); // TODO: if the fileReader is working with non-UTF-8 data // (which is a feature not yet implemented at all) - // this would need to call a read than can do character set conversion + // this would need to call a read that can do character set conversion // in the event that s.type == string. var len:c_ssize_t = nBytes.safeCast(c_ssize_t); - var err = qio_channel_read_amt(false, _channel_internal, s.buff, len); + var err = qio_channel_read_amt(false, _channel_internal, sLocal.buff, len); if !err { - s.buffLen = nBytes; - if nBytes != 0 then s.buff[nBytes] = 0; // include null-byte - if s.type == string { + sLocal.buffLen = nBytes; + if nBytes != 0 then sLocal.buff[nBytes] = 0; // include null-byte + if t == string { if nCodepoints == -1 - then s.cachedNumCodepoints = BytesStringCommon.countNumCodepoints(s); - else s.cachedNumCodepoints = nCodepoints; - s.hasEscapes = false; + then sLocal.cachedNumCodepoints = BytesStringCommon.countNumCodepoints(sLocal); + else sLocal.cachedNumCodepoints = nCodepoints; + sLocal.hasEscapes = false; } } else { - s.buffLen = 0; - if s.type == string { - s.cachedNumCodepoints = 0; - s.hasEscapes = false; + sLocal.buffLen = 0; + if sLocal.type == string { + sLocal.cachedNumCodepoints = 0; + sLocal.hasEscapes = false; } } + + if s.locale != here then s = sLoc; return err; } From e9c292ea4b86f8bcade3a998307c7c2a7a1665e8 Mon Sep 17 00:00:00 2001 From: Jeremiah Corrado Date: Tue, 20 Feb 2024 15:24:30 -0700 Subject: [PATCH 2/4] refactor fileReader.readLine to not create an extra temporary local string Signed-off-by: Jeremiah Corrado --- modules/standard/IO.chpl | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/modules/standard/IO.chpl b/modules/standard/IO.chpl index f26f95f332c3..c31d76401c6b 100644 --- a/modules/standard/IO.chpl +++ b/modules/standard/IO.chpl @@ -7340,12 +7340,10 @@ proc fileReader.readLine(ref s: string, nCodepoints -= 1; } - var sLoc: string; - // now read the data into the string // readStringBytesData will advance the fileReader by exactly `nBytes`. // This may consume or leave the newline based on the logic above. - err = readStringBytesData(sLoc, this._channel_internal, nBytes, nCodepoints); + err = readStringBytesData(s, this._channel_internal, nBytes, nCodepoints); if foundNewline && stripNewline && !err { // pass the newline in the input err = qio_channel_read_char(false, this._channel_internal, chr); @@ -7357,7 +7355,6 @@ proc fileReader.readLine(ref s: string, // return 'true' if we read anything ret = foundNewline || nBytes > 0; - s = sLoc; } return ret; @@ -7428,12 +7425,10 @@ proc fileReader.readLine(ref b: bytes, nBytes -= 1; } - var bLoc: bytes; - // now read the data into the bytes // readStringBytesData will advance the fileReader by exactly `nBytes`. // This may consume or leave the newline based on the logic above. - err = readStringBytesData(bLoc, this._channel_internal, nBytes, + err = readStringBytesData(b, this._channel_internal, nBytes, nCodepoints=-1); if foundNewline && stripNewline && !err { // pass the newline in the input @@ -7449,7 +7444,6 @@ proc fileReader.readLine(ref b: bytes, // return 'true' if we read anything ret = foundNewline || nBytes > 0; - b = bLoc; } return ret; From 711e8b9c339299e2c434861034aec01cefab47f8 Mon Sep 17 00:00:00 2001 From: jeremiah-corrado Date: Thu, 22 Feb 2024 09:51:47 -0600 Subject: [PATCH 3/4] fix string localization bug in readThrough/readTo. Add tests to lock in fix. Remove notests from openString/BytesReader multiloc tests Signed-off-by: jeremiah-corrado --- modules/standard/IO.chpl | 4 ++-- .../IO/readThrough/readThroughML.chpl | 20 +++++++++++++++++ .../IO/readThrough/readThroughML.good | 8 +++++++ .../IO/readThrough/readThroughML.numlocales | 1 + .../IO/readThrough/readThroughML.skipif | 1 + test/library/standard/IO/readTo/listInput.txt | 1 + test/library/standard/IO/readTo/readToML.chpl | 22 +++++++++++++++++++ test/library/standard/IO/readTo/readToML.good | 8 +++++++ .../standard/IO/readTo/readToML.numlocales | 1 + .../standard/IO/readTo/readToML.skipif | 1 + .../openBytesReaderML.notest | 0 .../openStringReaderML.notest | 0 12 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 test/library/standard/IO/readThrough/readThroughML.chpl create mode 100644 test/library/standard/IO/readThrough/readThroughML.good create mode 100644 test/library/standard/IO/readThrough/readThroughML.numlocales create mode 100644 test/library/standard/IO/readThrough/readThroughML.skipif create mode 100644 test/library/standard/IO/readTo/listInput.txt create mode 100644 test/library/standard/IO/readTo/readToML.chpl create mode 100644 test/library/standard/IO/readTo/readToML.good create mode 100644 test/library/standard/IO/readTo/readToML.numlocales create mode 100644 test/library/standard/IO/readTo/readToML.skipif delete mode 100644 test/library/standard/IO/stringBytesDirectReader/openBytesReaderML.notest delete mode 100644 test/library/standard/IO/stringBytesDirectReader/openStringReaderML.notest diff --git a/modules/standard/IO.chpl b/modules/standard/IO.chpl index c31d76401c6b..0db84865a4e0 100644 --- a/modules/standard/IO.chpl +++ b/modules/standard/IO.chpl @@ -7263,13 +7263,13 @@ proc readStringBytesData(ref s: ?t /*: string or bytes*/, } } else { sLocal.buffLen = 0; - if sLocal.type == string { + if t == string { sLocal.cachedNumCodepoints = 0; sLocal.hasEscapes = false; } } - if s.locale != here then s = sLoc; + if s.locale != here then s <=> sLoc; return err; } diff --git a/test/library/standard/IO/readThrough/readThroughML.chpl b/test/library/standard/IO/readThrough/readThroughML.chpl new file mode 100644 index 000000000000..ea2c287ace7a --- /dev/null +++ b/test/library/standard/IO/readThrough/readThroughML.chpl @@ -0,0 +1,20 @@ +use IO; + +var fr = openReader("listInput.txt", locking=false); + +test(fr, Locales[0], Locales[1]); +test(fr, Locales[1], Locales[0]); +test(fr, Locales[1], Locales[1]); +test(fr, Locales[1], Locales[2]); + +proc test(fr, L1: locale, L2: locale) { + on L1 { + var s = "", b = b""; + on L2 { + fr.readThrough(",", s); + fr.readThrough(b",", b); + } + writeln(s); + writeln(b); + } +} diff --git a/test/library/standard/IO/readThrough/readThroughML.good b/test/library/standard/IO/readThrough/readThroughML.good new file mode 100644 index 000000000000..98a3ebfd5bfa --- /dev/null +++ b/test/library/standard/IO/readThrough/readThroughML.good @@ -0,0 +1,8 @@ +1, +2, +3, +4, +5, +6, +7, +8, diff --git a/test/library/standard/IO/readThrough/readThroughML.numlocales b/test/library/standard/IO/readThrough/readThroughML.numlocales new file mode 100644 index 000000000000..00750edc07d6 --- /dev/null +++ b/test/library/standard/IO/readThrough/readThroughML.numlocales @@ -0,0 +1 @@ +3 diff --git a/test/library/standard/IO/readThrough/readThroughML.skipif b/test/library/standard/IO/readThrough/readThroughML.skipif new file mode 100644 index 000000000000..6f5c7462d994 --- /dev/null +++ b/test/library/standard/IO/readThrough/readThroughML.skipif @@ -0,0 +1 @@ +CHPL_COMM==none diff --git a/test/library/standard/IO/readTo/listInput.txt b/test/library/standard/IO/readTo/listInput.txt new file mode 100644 index 000000000000..e0cb5a0461ed --- /dev/null +++ b/test/library/standard/IO/readTo/listInput.txt @@ -0,0 +1 @@ +1,2,3,4,5,6,7,8, diff --git a/test/library/standard/IO/readTo/readToML.chpl b/test/library/standard/IO/readTo/readToML.chpl new file mode 100644 index 000000000000..7e809eb951fc --- /dev/null +++ b/test/library/standard/IO/readTo/readToML.chpl @@ -0,0 +1,22 @@ +use IO; + +var fr = openReader("listInput.txt", locking=false); + +test(fr, Locales[0], Locales[1]); +test(fr, Locales[1], Locales[0]); +test(fr, Locales[1], Locales[1]); +test(fr, Locales[1], Locales[2]); + +proc test(fr, L1: locale, L2: locale) { + on L1 { + var s = "", b = b""; + on L2 { + fr.readTo(",", s); + fr.matchLiteral(","); + fr.readTo(b",", b); + fr.matchLiteral(","); + } + writeln(s); + writeln(b); + } +} diff --git a/test/library/standard/IO/readTo/readToML.good b/test/library/standard/IO/readTo/readToML.good new file mode 100644 index 000000000000..535d2b01d339 --- /dev/null +++ b/test/library/standard/IO/readTo/readToML.good @@ -0,0 +1,8 @@ +1 +2 +3 +4 +5 +6 +7 +8 diff --git a/test/library/standard/IO/readTo/readToML.numlocales b/test/library/standard/IO/readTo/readToML.numlocales new file mode 100644 index 000000000000..00750edc07d6 --- /dev/null +++ b/test/library/standard/IO/readTo/readToML.numlocales @@ -0,0 +1 @@ +3 diff --git a/test/library/standard/IO/readTo/readToML.skipif b/test/library/standard/IO/readTo/readToML.skipif new file mode 100644 index 000000000000..91736d4010b4 --- /dev/null +++ b/test/library/standard/IO/readTo/readToML.skipif @@ -0,0 +1 @@ +CHPL_COMM=none diff --git a/test/library/standard/IO/stringBytesDirectReader/openBytesReaderML.notest b/test/library/standard/IO/stringBytesDirectReader/openBytesReaderML.notest deleted file mode 100644 index e69de29bb2d1..000000000000 diff --git a/test/library/standard/IO/stringBytesDirectReader/openStringReaderML.notest b/test/library/standard/IO/stringBytesDirectReader/openStringReaderML.notest deleted file mode 100644 index e69de29bb2d1..000000000000 From 6f42f566a7845a7e0494db39f0a8c3d26667ae9d Mon Sep 17 00:00:00 2001 From: Jeremiah Corrado Date: Thu, 22 Feb 2024 09:10:34 -0700 Subject: [PATCH 4/4] fix readToML skipif Signed-off-by: Jeremiah Corrado --- test/library/standard/IO/readTo/readToML.skipif | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/library/standard/IO/readTo/readToML.skipif b/test/library/standard/IO/readTo/readToML.skipif index 91736d4010b4..6f5c7462d994 100644 --- a/test/library/standard/IO/readTo/readToML.skipif +++ b/test/library/standard/IO/readTo/readToML.skipif @@ -1 +1 @@ -CHPL_COMM=none +CHPL_COMM==none