diff --git a/modules/standard/IO.chpl b/modules/standard/IO.chpl index a6a986796077..0db84865a4e0 100644 --- a/modules/standard/IO.chpl +++ b/modules/standard/IO.chpl @@ -7235,37 +7235,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 t == string { + sLocal.cachedNumCodepoints = 0; + sLocal.hasEscapes = false; } } + + 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..6f5c7462d994 --- /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