From 68057f056b7f7d72675892d8ac84ba059550fffb Mon Sep 17 00:00:00 2001 From: Miloslav Metelka <miloslav.metelka@oracle.com> Date: Mon, 2 Jul 2018 16:01:39 +0200 Subject: [PATCH] Fix of "not implemented: handle unexpected eof" internal error. --- .../r/runtime/conn/FileConnections.java | 9 ++++-- .../truffle/r/test/ExpectedTestOutput.test | 29 +++++++++++++++++++ .../r/test/library/base/TestConnections.java | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) 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 b1717cbd09..548dc1d937 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 @@ -229,9 +229,14 @@ public class FileConnections { */ final RCompression.Type cTypeActual; if (!raw && (openMode == AbstractOpenMode.Read || openMode == AbstractOpenMode.ReadBinary)) { - cTypeActual = RCompression.getCompressionType(base.path); - if (cTypeActual != cType) { + RCompression.Type cTypeFound = RCompression.getCompressionType(base.path); + // For binary reading force file's compression type if compression exists + // and it conflicts with requested compression type. + if (cTypeFound != cType && (openMode != AbstractOpenMode.ReadBinary || cType != RCompression.Type.NONE)) { + cTypeActual = cTypeFound; base.updateConnectionClass(mapConnectionClass(cTypeActual)); + } else { + cTypeActual = cType; } } else { cTypeActual = cType; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test index b6eaccf56c..7c7844eec5 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test @@ -72277,6 +72277,25 @@ Error: unexpected '}' in "{ .Internal(strrep(, '') }" [1] "" +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', '[[]') +[[1]] +[1] "a" "1]" "1]=x11&a" "1]" "2]=x12" + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', '[][]') +[[1]] +[1] "a" "1" "" "1" "=x11&a" "1" "" "2" +[9] "=x12" + + +##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# +#strsplit('a[1][1]=x11&a[1][2]=x12', ']') +[[1]] +[1] "a[1" "[1" "=x11&a[1" "[2" "=x12" + + ##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit# #strsplit('foo bar baz', '[f z]', perl=TRUE) [[1]] @@ -85262,6 +85281,10 @@ Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"), : [126] 00 00 02 00 04 00 09 00 00 00 01 61 00 04 00 09 00 00 00 01 62 00 00 00 fe [151] 00 00 00 fe +##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary# +#f <- tempfile(); unlink(f); x <- 1:10; save(x, file=f); con <- file(f, 'rb'); dput(class(con)) +c("file", "connection") + ##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.ImplementationError# #{ s <- "äöüß"; rc <- rawConnection(raw(0), "wb"); write(charToRaw(s), rc); res <- rawConnectionValue(rc); close(rc); res } [1] 63 33 20 61 34 20 63 33 20 62 36 20 63 33 0a 62 63 20 63 33 20 39 66 0a @@ -85461,6 +85484,12 @@ In readLines(zz, 2, warn = T, skipNul = F) : Warning message: In open.connection(con, "rb") : connection is already open +##com.oracle.truffle.r.test.library.base.TestConnections.testSeek# +#f1 <- file(open='w+b', encoding='UTF-8'); writeBin(charToRaw("abcd"), f1); seek(f1); seek(f1,0); seek(f1) +[1] 4 +[1] 4 +[1] 0 + ##com.oracle.truffle.r.test.library.base.TestConnections.testSeekTextConnection# #{ zz <- textConnection("Hello, World!"); res <- isSeekable(zz); close(zz); res } [1] FALSE diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java index 9129f3984c..55b38976ab 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/base/TestConnections.java @@ -247,6 +247,7 @@ public class TestConnections extends TestRBase { assertEval("conn <- rawConnection(raw(0), \"wb\"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn)"); // ignored because save refuses to write to a rawConnection that is not configured to binary assertEval(Ignored.ImplementationError, "conn <- rawConnection(raw(0), \"w\"); value <- c(1,2,3); save(value, file=conn); rawConnectionValue(conn)"); + assertEval("f <- tempfile(); unlink(f); x <- 1:10; save(x, file=f); con <- file(f, 'rb'); dput(class(con))"); } @Test -- GitLab