diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java index 4039b565c5716f0f804e4da332dcbbeb7095477c..ecb9e560802612488835d5b901897d3d8403830b 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/common/JavaUpCallsRFFIImpl.java @@ -1589,6 +1589,11 @@ public abstract class JavaUpCallsRFFIImpl implements UpCallsRFFI { return new DotSymbol(name, new SymbolHandle(fun), numArgs); } + @Override + public Object getEmbeddingDLLInfo() { + return DLL.getEmbeddingDLLInfo(); + } + protected abstract Object setSymbol(DLLInfo dllInfo, int nstOrd, Object routines, int index); @Override diff --git a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/DLLUpCallsRFFI.java b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/DLLUpCallsRFFI.java index 336062d6f09c01b5b1d83d6506610ab78bcd0eee..3064448d1d7ac885ba5276918b88d1c7f0440699 100644 --- a/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/DLLUpCallsRFFI.java +++ b/com.oracle.truffle.r.ffi.impl/src/com/oracle/truffle/r/ffi/impl/upcalls/DLLUpCallsRFFI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 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 @@ -71,4 +71,11 @@ public interface DLLUpCallsRFFI { @RFFICpointer Object getCCallable(@RFFICstring String pkgName, @RFFICstring String functionName); + /** + * Returns special {@link com.oracle.truffle.r.runtime.ffi.DLL.DLLInfo} instance that is + * supposed to be used when registering symbols from within code embedding R, i.e. code that + * cannot have its init method called by R runtime and must call {@code R_registerRoutines} + * itself. + */ + Object getEmbeddingDLLInfo(); } diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h index f483086b448e76dfc39b4f18b41f8ebe5311de1b..307b1d2fcd52091e8055fa8d94262cfc8684ea77 100644 --- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h +++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcalls.h @@ -315,6 +315,7 @@ typedef void * (*call_setDotSymbolValues)(DllInfo *dllInfo, char *name, DL_FUNC typedef int (*call_forceSymbols)(DllInfo *dllInfo, Rboolean value); typedef int (*call_registerCCallable)(const char *pkgname, const char *name, void *fun); typedef void* (*call_getCCallable)(const char *pkgname, const char *name); +typedef DllInfo* (*call_getEmbeddingDLLInfo)(void); // memory diff --git a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h index afa389d701d376db9b7f23622ef494ceddd381af..fa00c66c35468ba9f1eb3121de1530d15e29cb57 100644 --- a/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h +++ b/com.oracle.truffle.r.native/fficall/src/common/rffi_upcallsindex.h @@ -181,17 +181,18 @@ #define forceSymbols_x 176 #define getCCallable_x 177 #define getConnectionClassString_x 178 -#define getOpenModeString_x 179 -#define getSummaryDescription_x 180 -#define isSeekable_x 181 -#define octsize_x 182 -#define registerCCallable_x 183 -#define registerRoutines_x 184 -#define restoreHandlerStacks_x 185 -#define setDotSymbolValues_x 186 -#define unif_rand_x 187 -#define useDynamicSymbols_x 188 +#define getEmbeddingDLLInfo_x 179 +#define getOpenModeString_x 180 +#define getSummaryDescription_x 181 +#define isSeekable_x 182 +#define octsize_x 183 +#define registerCCallable_x 184 +#define registerRoutines_x 185 +#define restoreHandlerStacks_x 186 +#define setDotSymbolValues_x 187 +#define unif_rand_x 188 +#define useDynamicSymbols_x 189 -#define UPCALLS_TABLE_SIZE 189 +#define UPCALLS_TABLE_SIZE 190 #endif // RFFI_UPCALLSINDEX_H diff --git a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h index 7d361d1da12e6d16e81dedbe7b9541b8f5db11a4..d512182aafb05d94efc7cc48c9539372b29ca8e4 100644 --- a/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h +++ b/com.oracle.truffle.r.native/fficall/src/truffle_common/Rinternals_truffle_common.h @@ -1664,6 +1664,13 @@ R_registerRoutines(DllInfo *info, const R_CMethodDef * const croutines, return 1; } +DllInfo *R_getEmbeddingDllInfo() { + TRACE0(); + DllInfo *result = ((call_getEmbeddingDLLInfo) callbacks[getEmbeddingDLLInfo_x])(); + checkExitCall(); + return result; +} + Rboolean R_useDynamicSymbols(DllInfo *dllInfo, Rboolean value) { TRACE0(); Rboolean result = ((call_useDynamicSymbols) callbacks[useDynamicSymbols_x])(dllInfo, value); diff --git a/com.oracle.truffle.r.native/version.source b/com.oracle.truffle.r.native/version.source index 82cced27d7be32719d009707139bd949ad6263c9..0691f67b202a873c99bdb9b99e15a667cb916a5b 100644 --- a/com.oracle.truffle.r.native/version.source +++ b/com.oracle.truffle.r.native/version.source @@ -1 +1 @@ -51 +52 diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java index 07b6aeba98290ab63ad0ee0bd7cb834ca8575171..ce08cd08089df9aadf00819b673c56f4cce2a236 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/ffi/DLL.java @@ -217,6 +217,14 @@ public class DLL { return result; } + /** + * Embedding {@link DLLInfo} is just a placeholder. It does not represent any concrete dll + * and thus we e.g. cannot find any symbols in it. + */ + public boolean isEmbeddingDllInfo() { + return handle == null; + } + public void setNativeSymbols(int nstOrd, DotSymbol[] symbols) { nativeSymbols[nstOrd] = symbols; } @@ -758,6 +766,7 @@ public class DLL { */ public static SymbolHandle findSymbol(String name, DLLInfo dllInfo) { if (dllInfo != null) { + assert !dllInfo.isEmbeddingDllInfo() : "Dynamic symbols lookup is not supported for the embedding DLLInfo"; return (SymbolHandle) DLLRFFI.DLSymRootNode.create(RContext.getInstance()).call(dllInfo.handle, name); } else { return (SymbolHandle) RFindSymbolRootNode.create(RContext.getInstance()).call(name, null, RegisteredNativeSymbol.any());