diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java index 3d388a9b646160e68d67bfdea9c4941f655c6251..0d76a622a5513c3382bc9ac7b55d3fd5b011fff7 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ConnectionFunctions.java @@ -390,13 +390,21 @@ public abstract class ConnectionFunctions { @RBuiltin(name = "readLines", kind = INTERNAL, parameterNames = {"con", "n", "ok", "warn", "encoding", "skipNul"}) public abstract static class ReadLines extends InternalCloseHelper { + + @Override + protected void createCasts(CastBuilder casts) { + casts.toLogical(2); + casts.toLogical(3); + casts.toLogical(5); + } + @Specialization @TruffleBoundary - protected Object readLines(RConnection con, int n, byte ok, @SuppressWarnings("unused") byte warn, @SuppressWarnings("unused") String encoding, @SuppressWarnings("unused") byte skipNul) { + protected Object readLines(RConnection con, int n, byte ok, byte warn, @SuppressWarnings("unused") String encoding, byte skipNul) { // TODO implement all the arguments controlVisibility(); try (RConnection openConn = con.forceOpen("rt")) { - String[] lines = openConn.readLines(n); + String[] lines = openConn.readLines(n, RRuntime.fromLogical(warn), RRuntime.fromLogical(skipNul)); if (n > 0 && lines.length < n && ok == RRuntime.LOGICAL_FALSE) { throw RError.error(this, RError.Message.TOO_FEW_LINES_READ_LINES); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java index f465111a0e5e9fa53ab902e4b914b5fd2aacb86d..69932ef9049694493792163810c8d3720a13637e 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Parse.java @@ -121,7 +121,7 @@ public abstract class Parse extends RBuiltinNode { throw RError.nyi(this, "parse from stdin not implemented"); } try (RConnection openConn = conn.forceOpen("r")) { - lines = openConn.readLines(0); + lines = openConn.readLines(0, false, false); } catch (IOException ex) { throw RError.error(this, RError.Message.PARSE_ERROR); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java index e4cefc681c14e4221ed7f714759a27d9fce6e53d..6f59d3e35a42235e37d74bb7bf9826ca4d946a88 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/ReadDCF.java @@ -52,7 +52,7 @@ public abstract class ReadDCF extends RBuiltinNode { keepWhiteSet.add(keepWhite.getDataAt(i)); } } - dcf = DCF.read(openConn.readLines(0), keepWhiteSet); + dcf = DCF.read(openConn.readLines(0, true, false), keepWhiteSet); } catch (IOException ex) { throw RError.error(this, RError.Message.ERROR_READING_CONNECTION, ex.getMessage()); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Scan.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Scan.java index ee0095a55da34e6eb85110e8b202e5042a7d4b92..1e208c89b9f1926d6912a7921dc8a41ea7d5f725 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Scan.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Scan.java @@ -225,7 +225,7 @@ public abstract class Scan extends RBuiltinNode { try (RConnection openConn = data.con.forceOpen("r")) { if (nskip > 0) { - openConn.readLines(nskip); + openConn.readLines(nskip, true, RRuntime.fromLogical(skipNull)); } if (what instanceof RList) { return scanFrame((RList) what, nmax, nlines, flush == RRuntime.LOGICAL_TRUE, fill == RRuntime.LOGICAL_TRUE, strip == RRuntime.LOGICAL_TRUE, blSkip == RRuntime.LOGICAL_TRUE, @@ -335,7 +335,7 @@ public abstract class Scan extends RBuiltinNode { private static String[] getItems(LocalData data, boolean blSkip) throws IOException { while (true) { - String[] str = data.con.readLines(1); + String[] str = data.con.readLines(1, true, false); if (str == null || str.length == 0) { return null; } else { diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/ReadTableHead.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/ReadTableHead.java index 03f7edb9750ab695025b1aed7d38d66bf3ef3f73..562d03ee71f151c4c01ac82856b645b8974bfbab 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/ReadTableHead.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/foreign/ReadTableHead.java @@ -27,7 +27,7 @@ public final class ReadTableHead extends RExternalBuiltinNode { RConnection conn = (RConnection) argValues[0]; int nlines = castInt(castVector(argValues[1])); try (RConnection openConn = conn.forceOpen("r")) { - return RDataFactory.createStringVector(openConn.readLines(nlines), RDataFactory.COMPLETE_VECTOR); + return RDataFactory.createStringVector(openConn.readLines(nlines, true, false), RDataFactory.COMPLETE_VECTOR); } catch (IOException ex) { errorProfile.enter(); throw RError.error(this, RError.Message.ERROR_READING_CONNECTION, ex.getMessage()); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java index b7729ed8564d19da5e0d66ada11ecbf14be8e2a8..83a92ea99a6779fdbf92c8769a6483516fa247c2 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/ConnectionSupport.java @@ -342,12 +342,12 @@ public class ConnectionSupport { private static final int INVALID_DESCRIPTOR = -1; @Override - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { throw RInternalError.shouldNotReachHere("INVALID CONNECTION"); } @Override - public String[] readLines(int n) throws IOException { + public String[] readLines(int n, boolean warn, boolean skipNul) throws IOException { throw RInternalError.shouldNotReachHere("INVALID CONNECTION"); } @@ -633,9 +633,9 @@ public class ConnectionSupport { } @Override - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { checkOpen(); - return theConnection.readLinesInternal(n); + return theConnection.readLinesInternal(n, warn, skipNul); } @Override @@ -789,8 +789,11 @@ public class ConnectionSupport { * {@code readLines} from an {@link InputStream}. It would be convenient to use a * {@link BufferedReader} but mixing binary and text operations, which is a requirement, * would then be difficult. + * + * @param warn TODO + * @param skipNul TODO */ - default String[] readLinesHelper(InputStream in, int n) throws IOException { + default String[] readLinesHelper(InputStream in, int n, boolean warn, boolean skipNul) throws IOException { ArrayList<String> lines = new ArrayList<>(); int totalRead = 0; byte[] buffer = new byte[64]; @@ -813,7 +816,9 @@ public class ConnectionSupport { * "name" for the warning. */ lines.add(new String(buffer, 0, totalRead)); - RError.warning(RError.SHOW_CALLER2, RError.Message.INCOMPLETE_FINAL_LINE, "TODO: connection path"); + if (warn) { + RError.warning(RError.SHOW_CALLER2, RError.Message.INCOMPLETE_FINAL_LINE, "TODO: connection path"); + } } break; } @@ -1031,7 +1036,7 @@ public class ConnectionSupport { } @Override - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { throw new IOException(RError.Message.CANNOT_READ_CONNECTION.message); } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java index 732a23f795f1731f9152bd8c7ffe1d0afe14765e..37f44c12ed5a329e7b1ac07ec8a28cc0e98fc602 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/FileConnections.java @@ -120,8 +120,8 @@ public class FileConnections { @TruffleBoundary @Override - public String[] readLinesInternal(int n) throws IOException { - return readLinesHelper(inputStream, n); + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { + return readLinesHelper(inputStream, n, warn, skipNul); } @Override @@ -223,8 +223,8 @@ public class FileConnections { @TruffleBoundary @Override - public String[] readLinesInternal(int n) throws IOException { - return readLinesHelper(inputStream, n); + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { + return readLinesHelper(inputStream, n, warn, skipNul); } @Override @@ -382,9 +382,9 @@ public class FileConnections { } @Override - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { raf.seek(readOffset); - return readLinesHelper(inputStream, n); + return readLinesHelper(inputStream, n, warn, skipNul); } @Override diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/GZIPConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/GZIPConnections.java index 01592b2d8442cc10dd58814b568f374651473cc9..d5e4582c3c03e984c0da95086b9bbee14f33d03c 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/GZIPConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/GZIPConnections.java @@ -128,8 +128,8 @@ public class GZIPConnections { } @Override - public String[] readLinesInternal(int n) throws IOException { - return readLinesHelper(inputStream, n); + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { + return readLinesHelper(inputStream, n, warn, skipNul); } @Override diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java index bf6656c84688daf14cb40c7490c6ffccbb466a5d..67af8beb9fedfa13105b1939c278b8255dc1cb1f 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/RConnection.java @@ -45,13 +45,13 @@ public abstract class RConnection extends RAttributeStorage implements RTypedVal private LinkedList<String> pushBack; - public abstract String[] readLinesInternal(int n) throws IOException; + public abstract String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException; public RType getRType() { return RType.Integer; } - private String readOneLineWithPushBack(String[] res, int ind) { + private String readOneLineWithPushBack(String[] res, int ind, @SuppressWarnings("unused") boolean warn, @SuppressWarnings("unused") boolean skipNul) { String s = pushBack.pollLast(); if (s == null) { return null; @@ -93,14 +93,14 @@ public abstract class RConnection extends RAttributeStorage implements RTypedVal } @TruffleBoundary - private String[] readLinesWithPushBack(int n) throws IOException { + private String[] readLinesWithPushBack(int n, boolean warn, boolean skipNul) throws IOException { String[] res = new String[n]; for (int i = 0; i < n; i++) { - String s = readOneLineWithPushBack(res, i); + String s = readOneLineWithPushBack(res, i, warn, skipNul); if (s == null) { if (res[i] == null) { // no more push back value - System.arraycopy(readLinesInternal(n - i), 0, res, i, n - i); + System.arraycopy(readLinesInternal(n - i, warn, skipNul), 0, res, i, n - i); pushBack = null; break; } @@ -108,7 +108,7 @@ public abstract class RConnection extends RAttributeStorage implements RTypedVal } else { // reached the last push back value without reaching and of line assert pushBack.size() == 0; - System.arraycopy(readLinesInternal(n - i), 0, res, i, n - i); + System.arraycopy(readLinesInternal(n - i, warn, skipNul), 0, res, i, n - i); res[i] = s + res[i]; pushBack = null; break; @@ -119,16 +119,17 @@ public abstract class RConnection extends RAttributeStorage implements RTypedVal /** * Read (n > 0 up to n else unlimited) lines on the connection. + * */ @TruffleBoundary - public String[] readLines(int n) throws IOException { + public String[] readLines(int n, boolean warn, boolean skipNul) throws IOException { if (pushBack == null) { - return readLinesInternal(n); + return readLinesInternal(n, warn, skipNul); } else if (pushBack.size() == 0) { pushBack = null; - return readLinesInternal(n); + return readLinesInternal(n, warn, skipNul); } else { - return readLinesWithPushBack(n); + return readLinesWithPushBack(n, warn, skipNul); } } diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/SocketConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/SocketConnections.java index 4c3dad02c987e3250a9c5084c54945368ad252d7..bd347d3e427d038df5134732ae4ba8acb2e7d4c1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/SocketConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/SocketConnections.java @@ -97,8 +97,8 @@ public class SocketConnections { } @Override - public String[] readLinesInternal(int n) throws IOException { - return readLinesHelper(inputStream, n); + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { + return readLinesHelper(inputStream, n, warn, skipNul); } @Override diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/StdConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/StdConnections.java index e4d8ab0574e519df7325349a547f7094eeff6d59..a1c74e8f6b99fadc54c95cf88af547411b73bbf7 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/StdConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/StdConnections.java @@ -193,7 +193,7 @@ public class StdConnections { @Override @TruffleBoundary - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { ConsoleHandler console = RContext.getInstance().getConsoleHandler(); ArrayList<String> lines = new ArrayList<>(); String line; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/TextConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/TextConnections.java index 8e045d5e415f9452c6b5977f75134aa81ee6ca72..e1943b9a83597322952fa4283865258665a25de1 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/TextConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/TextConnections.java @@ -93,7 +93,7 @@ public class TextConnections { } @Override - public String[] readLinesInternal(int n) throws IOException { + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { int nleft = lines.length - index; int nlines = nleft; if (n > 0) { diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/URLConnections.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/URLConnections.java index b5d14c9f6b1a8675f74872b92ad2d394112c34f0..1af709c10436c1a42e07aa05089f7110b9d6e9ea 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/URLConnections.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/conn/URLConnections.java @@ -79,8 +79,8 @@ public class URLConnections { } @Override - public String[] readLinesInternal(int n) throws IOException { - return readLinesHelper(inputStream, n); + public String[] readLinesInternal(int n, boolean warn, boolean skipNul) throws IOException { + return readLinesHelper(inputStream, n, warn, skipNul); } @Override