Skip to content

Commit 25f0afc

Browse files
committed
[GR-13405] GitHub issue #49: dims attribute value is RDoubleVector, which causes ClassCastException when retrieving the dims.
PullRequest: fastr/1893
2 parents 3cef077 + 6336e09 commit 25f0afc

File tree

6 files changed

+29
-2
lines changed

6 files changed

+29
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Bug fixes:
2525
* `env2list` error for environments containing pairlists
2626
* `body<-` error for non-scalar values
2727
* `unlink` error for paths containing wildcard(s) but no path separator
28+
* dims attribute errorneously set to RDoubleVector; exception when retrieving the dims #49
2829

2930
# 1.0 RC 11
3031

com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/attributes/SetAttributeNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -144,11 +144,13 @@ protected void setSpecAttrInAttributable(RAttributable x, String name, Object va
144144
genericSpecialAttrNode.execute(x, name, value);
145145
}
146146

147-
@Specialization
147+
@Specialization(guards = "!isSpecialAttributeNode.execute(name)")
148+
@SuppressWarnings("unused")
148149
protected void setAttrInAttributable(RAttributable x, String name, Object value,
149150
@Cached("create()") BranchProfile attrNullProfile,
150151
@Cached("createBinaryProfile()") ConditionProfile attrStorageProfile,
151152
@Cached("createClassProfile()") ValueProfile xTypeProfile,
153+
@Cached("create()") SpecialAttributesFunctions.IsSpecialAttributeNode isSpecialAttributeNode,
152154
@Cached("create()") ShareObjectNode updateRefCountNode) {
153155
DynamicObject attributes;
154156
if (attrStorageProfile.profile(x instanceof RAttributeStorage)) {

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/R/testrffi.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,7 @@ rffi.shareListElement <- function(x, xi, y, yi) {
285285
rffi.test_setVar <- function(symbol, value, env) {
286286
.Call('test_Rf_setVar', symbol, value, env)
287287
}
288+
289+
rffi.test_setAttribDimDoubleVec <- function(vec, dimDoubleVec) {
290+
.Call('test_Rf_setAttribDimDoubleVec', vec, dimDoubleVec)
291+
}

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/src/testrffi.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -909,3 +909,12 @@ SEXP test_Rf_setVar(SEXP symbol, SEXP value, SEXP env) {
909909
Rf_setVar(symbol, value, env);
910910
return R_NilValue;
911911
}
912+
913+
SEXP test_Rf_setAttribDimDoubleVec(SEXP vec, SEXP dimDoubleVec) {
914+
Rf_setAttrib(vec, PROTECT(install("someNonSpecialAttrName")), PROTECT(allocVector(INTSXP, 42))); // Choose SetAttributeNode's non-special attr specialization
915+
Rf_setAttrib(vec, PROTECT(install("dim")), dimDoubleVec); // and remain on it (no guard was on it)
916+
UNPROTECT(3);
917+
return R_NilValue;
918+
}
919+
920+

com.oracle.truffle.r.test.native/packages/testrffi/testrffi/tests/simpleTests.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,8 @@ rffi.test_setVar(as.symbol('y'), 42, e)
374374
stopifnot(identical(e$y, NULL))
375375
stopifnot(identical(globalenv()$y, 42))
376376

377+
v <- c(1:6)
378+
d <- c(2.0, 3.0)
379+
rffi.test_setAttribDimDoubleVec(v, d)
380+
print(dim(v))
381+

com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/ExpectedTestOutput.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77583,6 +77583,12 @@ Error: unexpected '}' in "{ .Internal(strrep(, '') }"
7758377583
#{ strrep(c("A", "B", "C"), 1 : 3) }
7758477584
[1] "A" "BB" "CCC"
7758577585

77586+
##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit#
77587+
#strsplit('/some/path/to/somewhere' , '^(?=/)(?!//)|(?<!^)(?<!^/)/', perl = TRUE)
77588+
[[1]]
77589+
[1] "/" "some" "path" "to" "somewhere"
77590+
77591+
7758677592
##com.oracle.truffle.r.test.builtins.TestBuiltin_strsplit.testStrSplit#
7758777593
#strsplit('1', '1', fixed=FALSE)
7758877594
[[1]]

0 commit comments

Comments
 (0)