Skip to content

Commit 3d498e2

Browse files
committed
[GR-9827] Allow RStringVector to contain CharSXPWrappers or Strings, support for DATAPTR(characterVector).
PullRequest: fastr/1493
2 parents 77217f6 + 438ecb3 commit 3d498e2

File tree

20 files changed

+531
-355
lines changed

20 files changed

+531
-355
lines changed

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.concurrent.atomic.AtomicInteger;
3636
import java.util.function.Function;
3737

38+
import com.oracle.truffle.api.CompilerDirectives;
3839
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
3940
import com.oracle.truffle.api.frame.Frame;
4041
import com.oracle.truffle.api.frame.FrameInstance.FrameAccess;
@@ -51,6 +52,7 @@
5152
import com.oracle.truffle.r.runtime.RCleanUp;
5253
import com.oracle.truffle.r.runtime.REnvVars;
5354
import com.oracle.truffle.r.runtime.RError;
55+
import com.oracle.truffle.r.runtime.RError.Message;
5456
import com.oracle.truffle.r.runtime.RErrorHandling;
5557
import com.oracle.truffle.r.runtime.RInternalError;
5658
import com.oracle.truffle.r.runtime.RRuntime;
@@ -2280,6 +2282,15 @@ public Object octsize(Object size) {
22802282
throw implementedAsNode();
22812283
}
22822284

2285+
@Override
2286+
public Object FASTR_DATAPTR(Object x) {
2287+
if (x instanceof RStringVector) {
2288+
return VectorRFFIWrapper.get((RStringVector) x);
2289+
}
2290+
CompilerDirectives.transferToInterpreter();
2291+
throw RError.error(RError.NO_CALLER, Message.GENERIC, "DATAPTR not implemented for type " + Utils.getTypeName(x));
2292+
}
2293+
22832294
@Override
22842295
public Object INTEGER(Object x) {
22852296
// also handles LOGICAL

com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/FastRUpCalls.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
*/
2323
package com.oracle.truffle.r.ffi.impl.upcalls;
2424

25+
import com.oracle.truffle.r.ffi.processor.RFFICpointer;
26+
2527
/**
2628
* Up-calls specific to FastR used in FastR native code and not exported as part of any API.
2729
*/
@@ -41,4 +43,11 @@ public interface FastRUpCalls {
4143
boolean isSeekable(Object x);
4244

4345
void restoreHandlerStacks(Object savedHandlerStack);
46+
47+
/**
48+
* Implements {@code DATAPTR} for types that do not have specialized API function for accessing
49+
* the underlying data such as {@link com.oracle.truffle.r.runtime.data.RStringVector}.
50+
*/
51+
@RFFICpointer
52+
Object FASTR_DATAPTR(Object x);
4453
}

com.oracle.truffle.r.native/fficall/src/common/Rinternals_common.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
* questions.
2222
*/
2323
#include <Rinternals.h>
24+
extern void* FASTR_DATAPTR(SEXP x);
2425

2526
// This file includes all implementations that arise from Rinternals.h that
2627
// are independent, or largely independent, of the RFFI implementation.
@@ -117,13 +118,8 @@ void *DATAPTR(SEXP x) {
117118
return COMPLEX(x);
118119
} else if (type == CHARSXP) {
119120
return R_CHAR(x);
120-
} else if (type == STRSXP) {
121-
printf("FastR does not support DATAPTR macro with character vectors, please use SET_STRING_ELT or STRING_ELT.\n");
122-
exit(1);
123121
} else {
124-
printf("DATAPTR macro with SEXPTYPE %d is not supported.\n", type);
125-
exit(1);
126-
return NULL;
122+
return FASTR_DATAPTR(x);
127123
}
128124
}
129125

com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ typedef int (*call_LEVELS)(SEXP x);
171171
typedef int (*call_SETLEVELS)(SEXP x, int v);
172172
typedef int *(*call_LOGICAL)(SEXP x);
173173
typedef int *(*call_INTEGER)(SEXP x);
174+
typedef void *(*call_FASTR_DATAPTR)(SEXP x);
174175
typedef Rbyte *(*call_RAW)(SEXP x);
175176
typedef double *(*call_REAL)(SEXP x);
176177
typedef Rcomplex *(*call_COMPLEX)(SEXP x);

0 commit comments

Comments
 (0)