From b05c4f11943883efe95f9ef5f5bab155f505ba3d Mon Sep 17 00:00:00 2001
From: Mick Jordan <mick.jordan@oracle.com>
Date: Tue, 5 Jan 2016 15:52:40 -0800
Subject: [PATCH] backout bf70ed59b8ca; increase max graphics systems

---
 .../com/oracle/truffle/r/engine/REngine.java  | 47 +------------------
 com.oracle.truffle.r.native/include/Makefile  | 13 +++--
 .../include/ed_GraphicsEngine                 |  3 ++
 .../include/src/R_ext/GraphicsDevice.h.stub   |  6 ---
 .../include/src/R_ext/GraphicsEngine.h.stub   |  7 ---
 .../truffle/r/runtime/context/Engine.java     |  2 +-
 .../com/oracle/truffle/r/runtime/ffi/DLL.java |  5 +-
 7 files changed, 16 insertions(+), 67 deletions(-)
 create mode 100644 com.oracle.truffle.r.native/include/ed_GraphicsEngine
 delete mode 100644 com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub
 delete mode 100644 com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub

diff --git a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
index 267eeca2a9..0dfb0b7e4d 100644
--- a/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
+++ b/com.oracle.truffle.r.engine/src/com/oracle/truffle/r/engine/REngine.java
@@ -82,7 +82,6 @@ import com.oracle.truffle.r.runtime.RCmdOptions.RCmdOption;
 import com.oracle.truffle.r.runtime.RError;
 import com.oracle.truffle.r.runtime.RErrorHandling;
 import com.oracle.truffle.r.runtime.RInternalError;
-import com.oracle.truffle.r.runtime.ROptions;
 import com.oracle.truffle.r.runtime.RProfile;
 import com.oracle.truffle.r.runtime.RRuntime;
 import com.oracle.truffle.r.runtime.ReturnException;
@@ -101,7 +100,6 @@ import com.oracle.truffle.r.runtime.data.RNull;
 import com.oracle.truffle.r.runtime.data.RPromise;
 import com.oracle.truffle.r.runtime.data.RPromise.Closure;
 import com.oracle.truffle.r.runtime.data.RShareable;
-import com.oracle.truffle.r.runtime.data.RStringVector;
 import com.oracle.truffle.r.runtime.data.RTypedValue;
 import com.oracle.truffle.r.runtime.data.model.RAbstractVector;
 import com.oracle.truffle.r.runtime.env.REnvironment;
@@ -109,7 +107,6 @@ import com.oracle.truffle.r.runtime.env.frame.FrameSlotChangeMonitor;
 import com.oracle.truffle.r.runtime.nodes.RBaseNode;
 import com.oracle.truffle.r.runtime.nodes.RNode;
 import com.oracle.truffle.r.runtime.nodes.RSyntaxNode;
-import java.util.ArrayList;
 
 /**
  * The engine for the FastR implementation. Handles parsing and evaluation. There is one instance of
@@ -164,15 +161,7 @@ final class REngine implements Engine, Engine.Timings {
         MaterializedFrame baseFrame = RRuntime.createNonFunctionFrame("base");
         REnvironment.baseInitialize(baseFrame, globalFrame);
         RBuiltinPackages.loadBase(baseFrame);
-        boolean isInitial = !RContext.isInitialContextInitialized();
-        // TODO support per-context graphics?
-        if (isInitial) {
-            RGraphics.initialize();
-        } else {
-            /* Have to remove grDevices/graphics from the default set.
-               The system profile
-            */
-        }
+        RGraphics.initialize();
         /*
          * eval the system/site/user profiles. Experimentally GnuR does not report warnings during
          * system profile evaluation, but does for the site/user profiles.
@@ -182,11 +171,6 @@ final class REngine implements Engine, Engine.Timings {
         } catch (ParseException e) {
             throw new RInternalError(e, "error while parsing system profile from %s", RProfile.systemProfile().getName());
         }
-
-        if (!isInitial) {
-            removeGraphicsPackages();
-        }
-
         checkAndRunStartupShutdownFunction(".OptRequireMethods");
 
         suppressWarnings = false;
@@ -215,35 +199,6 @@ final class REngine implements Engine, Engine.Timings {
         RBuiltinPackages.loadDefaultPackageOverrides();
     }
 
-    /**
-     * The system profile sets the defaultPackages option which is then
-     * used in .First.sys (invoked below) to 'require' the packages.
-     * Until we support graphics in multiple contexts, we have to
-     * remove grDevices and graphics.
-     */
-    private void removeGraphicsPackages() {
-        RStringVector dp = (RStringVector) context.stateROptions.getValue("defaultPackages");
-        ArrayList<String> newDpList = new ArrayList<>();
-        for (int i = 0; i < dp.getLength(); i++) {
-            String pkg = dp.getDataAt(i);
-            if (pkg.equals("grDevices") || pkg.equals("graphics")) {
-                continue;
-            }
-            newDpList.add(pkg);
-        }
-        if (newDpList.size() != dp.getLength()) {
-            String[] data = new String[newDpList.size()];
-            newDpList.toArray(data);
-            RStringVector newDp = RDataFactory.createStringVector(data, RDataFactory.COMPLETE_VECTOR);
-            try {
-                context.stateROptions.setValue("defaultPackages", newDp);
-            } catch (ROptions.OptionsException ex) {
-                throw RInternalError.shouldNotReachHere(ex);
-            }
-        }
-
-    }
-
     public void checkAndRunStartupShutdownFunction(String name, String... args) {
         Object func = REnvironment.globalEnv().findFunction(name);
         if (func != null) {
diff --git a/com.oracle.truffle.r.native/include/Makefile b/com.oracle.truffle.r.native/include/Makefile
index fd396a5530..c65a01a741 100644
--- a/com.oracle.truffle.r.native/include/Makefile
+++ b/com.oracle.truffle.r.native/include/Makefile
@@ -1,5 +1,5 @@
 #
-# Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2016, 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
@@ -21,7 +21,7 @@
 # questions.
 #
 
-# links to the standard R header files with some modifications for JNI-based RFFI
+# links to the standard R header files with some minor modifications for FASTR
 
 .PHONY: all clean
 
@@ -30,7 +30,7 @@ SRC=src
 R_EXT_HEADERS := $(wildcard $(GNUR_HOME)/include/R_ext/*.h)
 #$(info R_EXT_HEADERS=$(R_EXT_HEADERS))
 R_EXT_HEADERS_FILENAMES := $(notdir $(R_EXT_HEADERS))
-R_EXT_HEADERS_LOCAL := $(wildcard $(SRC)/R_ext/*.h)
+R_EXT_HEADERS_LOCAL := src/R_ext/GraphicsEngine.h
 #$(info R_EXT_HEADERS_LOCAL=$(R_EXT_HEADERS_LOCAL))
 R_EXT_HEADERS_TO_LINK := $(filter-out $(notdir $(R_EXT_HEADERS_LOCAL)),$(R_EXT_HEADERS_FILENAMES))
 #$(info R_EXT_HEADERS_TO_LINK=$(R_EXT_HEADERS_TO_LINK))
@@ -38,21 +38,24 @@ R_HEADERS := $(wildcard $(GNUR_HOME)/include/*.h)
 R_HEADERS_FILENAMES := $(notdir $(R_HEADERS))
 #$(info R_HEADERS_FILENAMES=$(R_HEADERS_FILENAMES))
 R_HEADERS_LOCAL := src/libintl.h src/Rinternals.h src/Rinterface.h
-#$(info R_HEADERS_LOCAL=$(R_HEADERS_LOCAL))
+#$(info R_HEADERS_LOCAL=$(R_HEADERS_LOCAL))>
 R_HEADERS_TO_LINK := $(filter-out $(notdir $(R_HEADERS_LOCAL)),$(R_HEADERS_FILENAMES))
 #$(info R_HEADERS_TO_LINK=$(R_HEADERS_TO_LINK))
 
 all: linked
 
-linked: ed_Rinternals
+linked: ed_Rinternals ed_Rinterface ed_GraphicsEngine
 	mkdir -p R_ext
 	$(foreach file,$(R_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/$(file) $(file);)
 	ln -sf src/libintl.h
 	ed $(GNUR_HOME)/include/Rinternals.h < ed_Rinternals
 	ed $(GNUR_HOME)/include/Rinterface.h < ed_Rinterface
+	ed $(GNUR_HOME)/include/R_ext/GraphicsEngine.h < ed_GraphicsEngine
 	$(foreach file,$(R_EXT_HEADERS_TO_LINK),ln -sf $(GNUR_HOME)/include/R_ext/$(file) R_ext/$(file);)
 #	cp $(R_EXT_HEADERS_LOCAL) R_ext
 	touch linked
 
 clean:
 	rm -rf include linked
+	$(foreach file,$(R_HEADERS_FILENAMES),rm -f $(file);)
+	$(foreach file,$(R_EXT_HEADERS_FILENAMES),rm -f R_ext/$(file);)
diff --git a/com.oracle.truffle.r.native/include/ed_GraphicsEngine b/com.oracle.truffle.r.native/include/ed_GraphicsEngine
new file mode 100644
index 0000000000..6481419d09
--- /dev/null
+++ b/com.oracle.truffle.r.native/include/ed_GraphicsEngine
@@ -0,0 +1,3 @@
+/MAX_GRAPHICS_SYSTEMS/
+s/24/256/
+w R_ext/GraphicsEngine.h
diff --git a/com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub b/com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub
deleted file mode 100644
index 2baba2672f..0000000000
--- a/com.oracle.truffle.r.native/include/src/R_ext/GraphicsDevice.h.stub
+++ /dev/null
@@ -1,6 +0,0 @@
-// Stubs to allow packages to build in FastR
-#ifndef R_GRAPHICSDEVICE_H_
-#define R_GRAPHICSDEVICE_H_
-
-typedef void *pDevDesc;
-#endif
diff --git a/com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub b/com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub
deleted file mode 100644
index ac2501facf..0000000000
--- a/com.oracle.truffle.r.native/include/src/R_ext/GraphicsEngine.h.stub
+++ /dev/null
@@ -1,7 +0,0 @@
-// Stubs to allow packages to build in FastR
-#ifndef R_GRAPHICSENGINE_H_
-#define R_GRAPHICSENGINE_H_
-
-#include <R_ext/GraphicsDevice.h> /* needed for DevDesc */
-#endif
-
diff --git a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
index f549c639e5..1bcf01c632 100644
--- a/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
+++ b/com.oracle.truffle.r.runtime/src/com/oracle/truffle/r/runtime/context/Engine.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, 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
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 2e5366f96c..fca322e254 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
@@ -5,7 +5,7 @@
  *
  * Copyright (c) 1995-2012, The R Core Team
  * Copyright (c) 2003, The R Foundation
- * Copyright (c) 2015, Oracle and/or its affiliates
+ * Copyright (c) 2015, 2016, Oracle and/or its affiliates
  *
  * All rights reserved.
  */
@@ -278,7 +278,8 @@ public class DLL {
                 try {
                     RFFIFactory.getRFFI().getCallRFFI().invokeVoidCall(symbolInfo.address, symbolInfo.symbol, new Object[]{dllInfo});
                 } catch (ReturnException ex) {
-                    // An error call can, due to condition handling, throw this which we must propogate
+                    // An error call can, due to condition handling, throw this which we must
+// propogate
                     throw ex;
                 } catch (Throwable ex) {
                     if (RContext.isInitialContextInitialized()) {
-- 
GitLab