Skip to content
Snippets Groups Projects
Commit 0da13657 authored by stepan's avatar stepan
Browse files

Contents of NA CharSXPWrapper always return RRuntime.STRING_NA even when its...

Contents of NA CharSXPWrapper always return RRuntime.STRING_NA even when its native contents have been allocated
parent 9db7a10a
No related branches found
No related tags found
No related merge requests found
...@@ -43,6 +43,12 @@ public final class CharSXPWrapper extends RObject implements RTruffleObject { ...@@ -43,6 +43,12 @@ public final class CharSXPWrapper extends RObject implements RTruffleObject {
} }
public String getContents() { public String getContents() {
if (this == NA) {
// The NA string may have been moved to the native space if someone called R_CHAR on it,
// but on the Java side, it should still look like NA string, i.e. RRuntime.isNA should
// be true for its contents
return RRuntime.STRING_NA;
}
return NativeDataAccess.getData(this, contents); return NativeDataAccess.getData(this, contents);
} }
......
...@@ -173,6 +173,10 @@ rffi.getStringNA <- function() { ...@@ -173,6 +173,10 @@ rffi.getStringNA <- function() {
.Call("test_stringNA") .Call("test_stringNA")
} }
rffi.setStringElt <- function(x,y) {
.Call("test_setStringElt", x, y)
}
rffi.captureDotsWithSingleElement <- function(env) { rffi.captureDotsWithSingleElement <- function(env) {
.Call('test_captureDotsWithSingleElement', env) .Call('test_captureDotsWithSingleElement', env)
} }
...@@ -200,3 +204,7 @@ rffi.parseVector <- function(x) { ...@@ -200,3 +204,7 @@ rffi.parseVector <- function(x) {
rffi.RfEvalWithPromiseInPairList <- function() { rffi.RfEvalWithPromiseInPairList <- function() {
.Call('test_RfEvalWithPromiseInPairList') .Call('test_RfEvalWithPromiseInPairList')
} }
rffi.isNAString <- function(x) {
.Call('test_isNAString', x)
}
\ No newline at end of file
...@@ -82,6 +82,8 @@ static const R_CallMethodDef CallEntries[] = { ...@@ -82,6 +82,8 @@ static const R_CallMethodDef CallEntries[] = {
CALLDEF(test_createNativeConnection, 0), CALLDEF(test_createNativeConnection, 0),
CALLDEF(test_ParseVector, 1), CALLDEF(test_ParseVector, 1),
CALLDEF(test_RfEvalWithPromiseInPairList, 0), CALLDEF(test_RfEvalWithPromiseInPairList, 0),
CALLDEF(test_isNAString, 1),
CALLDEF(test_setStringElt, 2),
{NULL, NULL, 0} {NULL, NULL, 0}
}; };
......
...@@ -357,6 +357,19 @@ SEXP test_stringNA(void) { ...@@ -357,6 +357,19 @@ SEXP test_stringNA(void) {
return x; return x;
} }
SEXP test_setStringElt(SEXP vec, SEXP elt) {
SET_STRING_ELT(vec, 0, STRING_ELT(elt, 0));
return vec;
}
SEXP test_isNAString(SEXP vec) {
if (STRING_ELT(vec, 0) == NA_STRING) {
return ScalarLogical(1);
} else {
return ScalarLogical(0);
}
}
// This function is expected to be called only with environment that has single // This function is expected to be called only with environment that has single
// promise value in the '...' variable and this is asserted inside this function. // promise value in the '...' variable and this is asserted inside this function.
// The return value is list with the promises' expression and environment. // The return value is list with the promises' expression and environment.
......
...@@ -109,3 +109,7 @@ extern SEXP test_createNativeConnection(void); ...@@ -109,3 +109,7 @@ extern SEXP test_createNativeConnection(void);
extern SEXP test_ParseVector(SEXP src); extern SEXP test_ParseVector(SEXP src);
extern SEXP test_RfEvalWithPromiseInPairList(void); extern SEXP test_RfEvalWithPromiseInPairList(void);
extern SEXP test_isNAString(SEXP vec);
extern SEXP test_setStringElt(SEXP vec, SEXP elt);
\ No newline at end of file
...@@ -25,6 +25,14 @@ x <- "12345"; rffi.char_length(x) ...@@ -25,6 +25,14 @@ x <- "12345"; rffi.char_length(x)
strVec <- rffi.getStringNA(); strVec <- rffi.getStringNA();
stopifnot(anyNA(strVec)) stopifnot(anyNA(strVec))
stopifnot(rffi.isNAString(strVec))
rffi.LENGTH(strVec)
# this will call CHAR(x) on the NA string, which materializes it to native pointer...
rffi.char_length(strVec)
strVec <- rffi.setStringElt(c('hello'), as.character(NA))
stopifnot(anyNA(strVec))
stopifnot(rffi.isNAString(as.character(NA)))
x <- list(1) x <- list(1)
attr(x, 'myattr') <- 'hello'; attr(x, 'myattr') <- 'hello';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment