From f18c38c2e8657adaa5c89929df3cdc1427344e11 Mon Sep 17 00:00:00 2001
From: Lukas Stadler <lukas.stadler@oracle.com>
Date: Thu, 23 Mar 2017 09:32:25 +0100
Subject: [PATCH] remove unnecessary "0x00" byte during save

---
 .../nodes/builtin/base/LoadSaveFunctions.java |  2 +-
 .../truffle/r/test/ExpectedTestOutput.test    | 19 ++++++++++++++++++-
 .../r/test/library/base/TestConnections.java  |  6 +++++-
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java
index 027d33bbf8..01788ee13c 100644
--- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java
+++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/LoadSaveFunctions.java
@@ -236,7 +236,7 @@ public class LoadSaveFunctions {
                 if (!ascii && openConn.isTextMode()) {
                     throw error(RError.Message.CONN_XDR);
                 }
-                openConn.writeChar(ascii ? ASCII_HEADER : XDR_HEADER, 0, "", false);
+                openConn.writeChar(ascii ? ASCII_HEADER : XDR_HEADER, 0, null, false);
                 RSerialize.serialize(openConn, toSave, ascii ? RSerialize.ASCII : RSerialize.XDR, RSerialize.DEFAULT_VERSION, null);
             } catch (IOException ex) {
                 throw error(RError.Message.GENERIC, ex.getMessage());
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 7543a2447f..0f04b19455 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
@@ -76896,7 +76896,24 @@ Error in cat(x, file = file, sep = c(rep.int(sep, ncolumns - 1), "\n"),  :
 #{ rv <- charToRaw("Hello"); rc <- rawConnection(rv, "r+"); writeChar(", World", rc); res <- rawToChar(rawConnectionValue(rc)); close(rc); res }
 [1] ", World"
 
-##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.Unknown#
+##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.ImplementationError#
+#conn <- rawConnection(raw(0), "w"); value <- c(1,2,3); save(value, file=conn); rawConnectionValue(conn)
+ [1] 52 44 58 32 0a 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 04 02 00 00
+[26] 00 01 00 04 00 09 00 00 00 05 76 61 6c 75 65 00 00 00 0e 00 00 00 03 3f f0
+[51] 00 00 00 00 00 00 40 00 00 00 00 00 00 00 40 08 00 00 00 00 00 00 00 00 00
+[76] fe
+
+##com.oracle.truffle.r.test.library.base.TestConnections.testRawWriteBinary#Ignored.ImplementationError#
+#conn <- rawConnection(raw(0), "wb"); value <- list(a=c(1,2,3), b='foo'); save(value, file=conn); rawConnectionValue(conn)
+  [1] 52 44 58 32 0a 58 0a 00 00 00 02 00 03 03 02 00 02 03 00 00 00 04 02 00 00
+ [26] 00 01 00 04 00 09 00 00 00 05 76 61 6c 75 65 00 00 02 13 00 00 00 02 00 00
+ [51] 00 0e 00 00 00 03 3f f0 00 00 00 00 00 00 40 00 00 00 00 00 00 00 40 08 00
+ [76] 00 00 00 00 00 00 00 00 10 00 00 00 01 00 04 00 09 00 00 00 03 66 6f 6f 00
+[101] 00 04 02 00 00 00 01 00 04 00 09 00 00 00 05 6e 61 6d 65 73 00 00 00 10 00
+[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#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
 
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 7ef2680d0a..a727d532ef 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
@@ -241,8 +241,12 @@ public class TestConnections extends TestRBase {
     public void testRawWriteBinary() {
 
         // this test is currently ignored, since 'charToRaw' is not compliant
-        assertEval(Ignored.Unknown, "{ s <- \"äöüß\"; rc <- rawConnection(raw(0), \"wb\"); write(charToRaw(s), rc); res <- rawConnectionValue(rc); close(rc); res }");
+        assertEval(Ignored.ImplementationError, "{ s <- \"äöüß\"; rc <- rawConnection(raw(0), \"wb\"); write(charToRaw(s), rc); res <- rawConnectionValue(rc); close(rc); res }");
         assertEval("{ zz <- rawConnection(raw(0), \"wb\"); x <- c(\"a\", \"this will be truncated\", \"abc\"); nc <- c(3, 10, 3); writeChar(x, zz, nc, eos = NULL); writeChar(x, zz, eos = \"\\r\\n\"); res <- rawConnectionValue(zz); close(zz); res }");
+
+        assertEval(Ignored.ImplementationError, "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)");
     }
 
     @Test
-- 
GitLab