From ca662b77343c34cdc4c3aa3d433f1dcedb64401d Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Tue, 13 Mar 2018 15:07:34 +0100 Subject: [PATCH] Fix: RFFI ATTRIB function should return pairlist --- .../r/ffi/impl/nodes/AttributesAccessNodes.java | 16 +++++++++++++++- .../testrffi/testrffi/tests/simpleTests.R | 5 ++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java index 4cf867b273..fbe1b12be9 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/AttributesAccessNodes.java @@ -101,7 +101,21 @@ public final class AttributesAccessNodes { CompilerDirectives.transferToInterpreterAndInvalidate(); getAttributesNode = GetAttributesNode.create(); } - return getAttributesNode.execute(obj); + Object resultObj = getAttributesNode.execute(obj); + if (resultObj == RNull.instance) { + return resultObj; + } + assert resultObj instanceof RList : "GetAttributesNode should return RList or RNull"; + RList list = (RList) resultObj; + Object result = RNull.instance; + RStringVector names = list.getNames(); + assert names.getLength() == list.getLength(); + for (int i = list.getLength() - 1; i >= 0; i--) { + Object item = list.getDataAt(i); + RSymbol symbol = RDataFactory.createSymbol(names.getDataAt(i)); + result = RDataFactory.createPairList(item, result, symbol); + } + return result; } @Fallback diff --git a/com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/simpleTests.R b/com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/simpleTests.R index 208c28dece..a620c50095 100644 --- a/com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/simpleTests.R +++ b/com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/simpleTests.R @@ -145,4 +145,7 @@ rffi.RfFunctions() setAttrTarget <- c(1,2,3) attr(setAttrTarget, 'myattr2') <- 'some value'; api.SET_ATTRIB(setAttrTarget, as.pairlist(list(myattr=42))) -setAttrTarget \ No newline at end of file +setAttrTarget + +typeof(api.ATTRIB(mtcars)) +api.ATTRIB(structure(c(1,2,3), myattr3 = 33)) -- GitLab