diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java index 688c3aa6344d79d994cf23b3fb4546485e4fe627..f914d4c94eca2392c4a0a0998e2fc0943cce1a09 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java @@ -50,8 +50,6 @@ import com.oracle.truffle.r.runtime.env.REnvironment; * Encapsulated the access to the global grid state. */ public final class GridContext { - private static final GridContext INSTANCE = new GridContext(); - private RInternalCode internalCode; private final GridState gridState = new GridState(); /** @@ -65,7 +63,11 @@ public final class GridContext { } public static GridContext getContext() { - return INSTANCE; + RContext rCtx = RContext.getInstance(); + if (rCtx.gridContext == null) { + rCtx.gridContext = new GridContext(); + } + return (GridContext) rCtx.gridContext; } @TruffleBoundary diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/RGridGraphicsAdapter.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/RGridGraphicsAdapter.java index 651ec5ff1bdd5a59effb55fdf06d0fd1c2edac2c..709b772191ffea17cfc2b2e789a4d9f116dd103f 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/RGridGraphicsAdapter.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/graphics/RGridGraphicsAdapter.java @@ -24,6 +24,7 @@ import com.oracle.truffle.r.runtime.ROptions.OptionsException; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.context.RContext; import com.oracle.truffle.r.runtime.data.RDataFactory; +import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RNull; import com.oracle.truffle.r.runtime.data.RPairList; import com.oracle.truffle.r.runtime.env.REnvironment; @@ -81,14 +82,13 @@ public final class RGridGraphicsAdapter { } /** - * Fixup .Devices array as someone may have set it to something that is not a pair list nor - * RNull, which breaks dev.cur built-in R function and others. GNUR seems to have active binding - * for it. This is such special case that it doesn't seem necessary for now. + * Fixup .Devices array as someone may have set it to something that is not a (pair) list nor + * RNull, which breaks dev.cur built-in R function and others. */ @TruffleBoundary public static void fixupDevicesVariable() { Object devices = REnvironment.baseEnv().get(DOT_DEVICES); - if (devices == RNull.instance || !(devices instanceof RPairList)) { + if (!(devices instanceof RPairList || devices instanceof RList)) { // reset the .Devices and .Device variables to initial values REnvironment.baseEnv().safePut(DOT_DEVICES, RNull.instance); addDevice(NULL_DEVICE); diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java index 6de77baa7e43dbc7c86d6b2b19189aae6815a519..8af2341afbf9fb09911971519bb828c0cf4cb103 100644 --- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java +++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/RContext.java @@ -350,6 +350,10 @@ public final class RContext implements RTruffleObject { @CompilationFinal private RFFIContext stateRFFI; + // Context specific state required for libraries, the initialization is handled lazily by the + // concrete library. + public Object gridContext = null; + public final WeakHashMap<String, WeakReference<String>> stringMap = new WeakHashMap<>(); public final WeakHashMap<Source, REnvironment> sourceRefEnvironments = new WeakHashMap<>(); public final WeakHashMap<Path, REnvironment> srcfileEnvironments = new WeakHashMap<>();