Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1dc3b6e43276
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 727f65bc0daf
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 19, 2015

  1. [Truffle] Fix line-wrapping.

    eregon committed Jun 19, 2015
    Copy the full SHA
    a14075f View commit details
  2. Copy the full SHA
    45aee57 View commit details
  3. Copy the full SHA
    bf831a9 View commit details
  4. Copy the full SHA
    727f65b View commit details
12 changes: 5 additions & 7 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -528,16 +528,14 @@ public void runFromMain(InputStream inputStream, String filename) {
getGlobalVariables().define("$PROGRAM_NAME", d, GLOBAL);
getGlobalVariables().define("$0", d, GLOBAL);

for (Iterator i = config.getOptionGlobals().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
Object value = entry.getValue();
IRubyObject varvalue;
if (value != null) {
varvalue = newString(value.toString());
for (Map.Entry<String, String> entry : config.getOptionGlobals().entrySet()) {
final IRubyObject varvalue;
if (entry.getValue() != null) {
varvalue = newString(entry.getValue());
} else {
varvalue = getTrue();
}
getGlobalVariables().set("$" + entry.getKey().toString(), varvalue);
getGlobalVariables().set("$" + entry.getKey(), varvalue);
}

if (filename.endsWith(".class")) {
29 changes: 9 additions & 20 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@

import jnr.enxio.channels.NativeDeviceChannel;
import jnr.posix.POSIX;

import org.jcodings.Encoding;
import org.jruby.anno.JRubyMethod;
import org.jruby.common.IRubyWarnings.ID;
@@ -56,21 +57,16 @@
import org.jruby.util.KCode;
import org.jruby.util.OSEnvironment;
import org.jruby.util.RegexpOptions;
import org.jruby.util.ShellLauncher;
import org.jruby.util.cli.OutputStrings;
import org.jruby.util.io.BadDescriptorException;
import org.jruby.util.io.OpenFile;
import org.jruby.util.io.STDIO;

import static org.jruby.internal.runtime.GlobalVariable.Scope.*;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channel;
import java.nio.channels.Channels;
import java.util.HashMap;
import java.util.Map;

/** This class initializes global variables and constants.
@@ -296,14 +292,8 @@ private static Channel prepareStdioChannel(Ruby runtime, STDIO stdio, Object str
}

private static void defineGlobalEnvConstants(Ruby runtime) {
Map environmentVariableMap = null;
OSEnvironment environment = new OSEnvironment();
environmentVariableMap = environment.getEnvironmentVariableMap(runtime);

if (environmentVariableMap == null) {
// if the environment variables can't be obtained, define an empty ENV
environmentVariableMap = new HashMap();
}
Map<RubyString, RubyString> environmentVariableMap = environment.getEnvironmentVariableMap(runtime);

CaseInsensitiveStringOnlyRubyHash env = new CaseInsensitiveStringOnlyRubyHash(runtime,
environmentVariableMap,
@@ -315,9 +305,8 @@ private static void defineGlobalEnvConstants(Ruby runtime) {
runtime.setENV(env);

// Define System.getProperties() in ENV_JAVA
Map systemProps = environment.getSystemPropertiesMap(runtime);
RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(
runtime, systemProps, runtime.getNil());
Map<RubyString, RubyString> systemProps = environment.getSystemPropertiesMap(runtime);
RubyHash systemPropsHash = new ReadOnlySystemPropertiesHash(runtime, systemProps, runtime.getNil());
systemPropsHash.setFrozen(true);
runtime.defineGlobalConstant("ENV_JAVA", systemPropsHash);
}
@@ -329,7 +318,7 @@ private static void defineGlobalEnvConstants(Ruby runtime) {
*/
public static class CaseInsensitiveStringOnlyRubyHash extends StringOnlyRubyHash {

public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public CaseInsensitiveStringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue, updateRealENV);
}

@@ -363,12 +352,12 @@ public static class StringOnlyRubyHash extends RubyHash {
// the op_aset to also update the real ENV map via setenv/unsetenv.
private boolean updateRealENV;

public StringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public StringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue);
this.updateRealENV = updateRealENV;
}

public StringOnlyRubyHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) {
public StringOnlyRubyHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue) {
this(runtime, valueMap, defaultValue, false);
}

@@ -470,11 +459,11 @@ private IRubyObject normalizeEnvString(IRubyObject str) {
}

private static class ReadOnlySystemPropertiesHash extends StringOnlyRubyHash {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map valueMap, IRubyObject defaultValue, boolean updateRealENV) {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue, boolean updateRealENV) {
super(runtime, valueMap, defaultValue, updateRealENV);
}

public ReadOnlySystemPropertiesHash(Ruby runtime, Map valueMap, IRubyObject defaultValue) {
public ReadOnlySystemPropertiesHash(Ruby runtime, Map<RubyString, RubyString> valueMap, IRubyObject defaultValue) {
this(runtime, valueMap, defaultValue, false);
}

11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@
package org.jruby;

import jnr.posix.util.Platform;

import org.jruby.embed.util.SystemPropertyCatcher;
import org.jruby.exceptions.MainExitException;
import org.jruby.runtime.Constants;
@@ -661,7 +662,7 @@ public boolean isSiphashEnabled() {
return siphashEnabled;
}

public void setEnvironment(Map newEnvironment) {
public void setEnvironment(Map<String, String> newEnvironment) {
environment = new HashMap<String, String>();
if (newEnvironment != null) {
environment.putAll(newEnvironment);
@@ -677,7 +678,7 @@ private void setupEnvironment(String jrubyHome) {
}
}

public Map getEnvironment() {
public Map<String, String> getEnvironment() {
return environment;
}

@@ -1055,15 +1056,15 @@ public String getInPlaceBackupExtension() {
return inPlaceBackupExtension;
}

public Map getOptionGlobals() {
public Map<String, String> getOptionGlobals() {
return optionGlobals;
}

public boolean isManagementEnabled() {
return managementEnabled;
}

public Set getExcludedMethods() {
public Set<String> getExcludedMethods() {
return excludedMethods;
}

@@ -1465,7 +1466,7 @@ public ClassLoader getCurrentThreadClassLoader() {
private boolean argvGlobalsOn = false;
private boolean assumeLoop = Options.CLI_ASSUME_LOOP.load();
private boolean assumePrinting = Options.CLI_ASSUME_PRINT.load();
private Map optionGlobals = new HashMap();
private Map<String, String> optionGlobals = new HashMap<String, String>();
private boolean processLineEnds = Options.CLI_PROCESS_LINE_ENDS.load();
private boolean split = Options.CLI_AUTOSPLIT.load();
private Verbosity verbosity = Options.CLI_WARNING_LEVEL.load();
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/util/NailMain.java
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public int run(NGContext context) {
Main main = new Main(config);

config.setCurrentDirectory(context.getWorkingDirectory());
config.setEnvironment(context.getEnv());
config.setEnvironment(OSEnvironment.propertiesToStringMap(context.getEnv()));

return main.run(context.getArgs()).getStatus();
}
43 changes: 27 additions & 16 deletions core/src/main/java/org/jruby/util/OSEnvironment.java
Original file line number Diff line number Diff line change
@@ -30,12 +30,14 @@

import org.jcodings.Encoding;
import org.jruby.Ruby;

import jnr.posix.util.Platform;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

import org.jruby.RubyString;

public class OSEnvironment {
@@ -44,19 +46,18 @@ public class OSEnvironment {
*
* @param runtime
*/
public Map getEnvironmentVariableMap(Ruby runtime) {
Map envs = null;

public Map<RubyString, RubyString> getEnvironmentVariableMap(Ruby runtime) {
if (runtime.getInstanceConfig().getEnvironment() != null) {
return getAsMapOfRubyStrings(runtime, runtime.getInstanceConfig().getEnvironment().entrySet());
return getAsMapOfRubyStrings(runtime, runtime.getInstanceConfig().getEnvironment());
}

final Map<RubyString, RubyString> envs;
// fall back on empty env when security disallows environment var access (like in an applet)
if (Ruby.isSecurityRestricted()) {
envs = new HashMap();
envs = new HashMap<RubyString, RubyString>();
} else {
Map variables = System.getenv();
envs = getAsMapOfRubyStrings(runtime, variables.entrySet());
Map<String, String> variables = System.getenv();
envs = getAsMapOfRubyStrings(runtime, variables);
}

return envs;
@@ -68,19 +69,29 @@ public Map getEnvironmentVariableMap(Ruby runtime) {
* @param runtime
* @return the java system properties as a Map<RubyString,RubyString>.
*/
public Map getSystemPropertiesMap(Ruby runtime) {
public Map<RubyString, RubyString> getSystemPropertiesMap(Ruby runtime) {
if (Ruby.isSecurityRestricted()) {
return new HashMap();
return new HashMap<RubyString, RubyString>();
} else {
return getAsMapOfRubyStrings(runtime, ((Properties)System.getProperties().clone()).entrySet());
return getAsMapOfRubyStrings(runtime, propertiesToStringMap(System.getProperties()));
}
}

public static Map<String, String> propertiesToStringMap(Properties properties) {
Map<String, String> map = new HashMap<String, String>();
for (Entry<Object, Object> entry : properties.entrySet()) {
if (entry.getKey() instanceof String && entry.getValue() instanceof String) {
map.put((String) entry.getKey(), (String) entry.getValue());
}
}
return map;
}

private static Map getAsMapOfRubyStrings(Ruby runtime, Set<Map.Entry<Object, Object>> entrySet) {
Map envs = new HashMap();
private static Map<RubyString, RubyString> getAsMapOfRubyStrings(Ruby runtime, Map<String, String> map) {
Map<RubyString, RubyString> envs = new HashMap<RubyString, RubyString>();
Encoding encoding = runtime.getEncodingService().getLocaleEncoding();

// On Windows, entrySet doesn't have corresponding keys for these
// On Windows, map doesn't have corresponding keys for these
if (Platform.IS_WINDOWS) {
// these may be null when in a restricted environment (JRUBY-6514)
String home = SafePropertyAccessor.getProperty("user.home");
@@ -89,7 +100,7 @@ private static Map getAsMapOfRubyStrings(Ruby runtime, Set<Map.Entry<Object, Obj
addRubyKeyValuePair(runtime, envs, "USER", user == null ? "" : user, encoding);
}

for (Map.Entry<Object, Object> entry : entrySet) {
for (Entry<String, String> entry : map.entrySet()) {
Object tmp = entry.getKey();

if (!(tmp instanceof String)) continue; // Java devs can stuff non-string objects into env
@@ -106,7 +117,7 @@ private static Map getAsMapOfRubyStrings(Ruby runtime, Set<Map.Entry<Object, Obj
return envs;
}

private static void addRubyKeyValuePair(Ruby runtime, Map map, String key, String value, Encoding encoding) {
private static void addRubyKeyValuePair(Ruby runtime, Map<RubyString, RubyString> map, String key, String value, Encoding encoding) {
ByteList keyBytes = new ByteList(key.getBytes(), encoding);
ByteList valueBytes = new ByteList(value.getBytes(), encoding);

30 changes: 12 additions & 18 deletions truffle/src/main/java/org/jruby/truffle/Main.java
Original file line number Diff line number Diff line change
@@ -40,8 +40,7 @@ public static void main(String[] args) {
config.setCompileMode(RubyInstanceConfig.CompileMode.TRUFFLE);

if (config.isHardExit()) {
// We're the command-line JRuby, and should set a shutdown hook for
// teardown.
// We're the command-line JRuby, and should set a shutdown hook for teardown.
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
if (didTeardown.compareAndSet(false, true)) {
@@ -55,27 +54,22 @@ public void run() {
return;
} else {
// Global variables
IAccessor d = new ValueAccessor(runtime.newString(filename));
runtime.getGlobalVariables().define("$PROGRAM_NAME", d,
GlobalVariable.Scope.GLOBAL);
runtime.getGlobalVariables().define("$0", d,
GlobalVariable.Scope.GLOBAL);

for (Iterator i = config.getOptionGlobals().entrySet().iterator(); i.hasNext();) {
Map.Entry entry = (Map.Entry) i.next();
Object value = entry.getValue();
IRubyObject varvalue;
if (value != null) {
varvalue = runtime.newString(value.toString());
IAccessor programName = new ValueAccessor(runtime.newString(filename));
runtime.getGlobalVariables().define("$PROGRAM_NAME", programName, GlobalVariable.Scope.GLOBAL);
runtime.getGlobalVariables().define("$0", programName, GlobalVariable.Scope.GLOBAL);

for (Map.Entry<String, String> entry : config.getOptionGlobals().entrySet()) {
final IRubyObject varvalue;
if (entry.getValue() != null) {
varvalue = runtime.newString(entry.getValue());
} else {
varvalue = runtime.getTrue();
}
runtime.getGlobalVariables().set(
"$" + entry.getKey().toString(), varvalue);

runtime.getGlobalVariables().set("$" + entry.getKey(), varvalue);
}

RootNode scriptNode = (RootNode) runtime
.parseFromMain(filename, in);
RootNode scriptNode = (RootNode) runtime.parseFromMain(filename, in);

// If no DATA, we're done with the stream, shut it down
if (runtime.fetchGlobalConstant("DATA") == null) {