From 4abd46c49a3a7063c14f968d98e40cb459961e72 Mon Sep 17 00:00:00 2001 From: stepan <stepan.sindelar@oracle.com> Date: Tue, 6 Mar 2018 15:14:11 +0100 Subject: [PATCH] RPairList: make sure tag is always RSymbol or RNull --- .../oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java | 3 ++- .../truffle/r/runtime/data/RArgsValuesAndNames.java | 4 ++-- .../com/oracle/truffle/r/runtime/data/RPairList.java | 12 ++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java index bc51d6d45c..b3007b211c 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/nodes/CoerceNodes.java @@ -51,6 +51,7 @@ import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RPairList; import com.oracle.truffle.r.runtime.data.RShareable; import com.oracle.truffle.r.runtime.data.RStringVector; +import com.oracle.truffle.r.runtime.data.RSymbol; import com.oracle.truffle.r.runtime.data.RTypedValue; import com.oracle.truffle.r.runtime.data.model.RAbstractIntVector; import com.oracle.truffle.r.runtime.data.model.RAbstractVector; @@ -75,7 +76,7 @@ public final class CoerceNodes { for (int i = 0; i < v.getLength(); i++) { Object element = v.getDataAtAsObject(i); adjustSharing(v, element); - RPairList cur = RDataFactory.createPairList(element, RNull.instance, names != null ? names.getDataAt(i) : RNull.instance, gnurType); + RPairList cur = RDataFactory.createPairList(element, RNull.instance, names != null ? RDataFactory.createSymbol(names.getDataAt(i)) : RNull.instance, gnurType); if (prev == null) { assert head == null; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RArgsValuesAndNames.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RArgsValuesAndNames.java index fee0ee0e9f..f018216085 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RArgsValuesAndNames.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RArgsValuesAndNames.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -108,7 +108,7 @@ public final class RArgsValuesAndNames extends RObject implements RTypedValue { assert signature.getLength() == getLength(); for (int i = 0; i < getLength(); i++) { String name = signature.getName(i); - RPairList cur = RDataFactory.createPairList(getArgument(i), RNull.instance, name != null ? name : RNull.instance, SEXPTYPE.DOTSXP); + RPairList cur = RDataFactory.createPairList(getArgument(i), RNull.instance, name != null ? RDataFactory.createSymbol(name) : RNull.instance, SEXPTYPE.DOTSXP); if (head == null) { head = cur; diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java index 8ba6f70a6a..b729095f5d 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/data/RPairList.java @@ -45,7 +45,13 @@ import com.oracle.truffle.r.runtime.gnur.SEXPTYPE; * {@code null} is never allowed as a value for the tag, car or cdr, only the type. */ public final class RPairList extends RSharingAttributeStorage implements RAbstractContainer, Iterable<RPairList> { + /** + * Data of the current pair list cell. + */ private Object car = RNull.instance; + /** + * Link to the next {@link RPairList} cell or {@link RNull} if last. + */ private Object cdr = RNull.instance; /** * Externally, i.e., when serialized, this is either a SYMSXP ({@link RSymbol}) or an @@ -336,9 +342,7 @@ public final class RPairList extends RSharingAttributeStorage implements RAbstra int i = 0; while (true) { data[i] = Utils.toString(pl.tag); - if (pl.tag == RRuntime.STRING_NA) { - complete = false; - } + complete &= data[i] != RRuntime.STRING_NA; if (isNull(pl.cdr)) { break; } @@ -353,7 +357,7 @@ public final class RPairList extends RSharingAttributeStorage implements RAbstra Object p = this; for (int i = 0; i < newNames.getLength() && !isNull(p); i++) { RPairList pList = (RPairList) p; - pList.tag = newNames.getDataAt(i); + pList.tag = RDataFactory.createSymbol(newNames.getDataAt(i)); p = pList.cdr; } } -- GitLab