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: 63af7288e13f
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 07d3630a269b
Choose a head ref
  • 2 commits
  • 5 files changed
  • 1 contributor

Commits on Nov 7, 2016

  1. Allow creating a RubyInstanceConfig without loading the Ruby class

    * By providing isSecurityRestricted to the constructor.
    eregon committed Nov 7, 2016
    Copy the full SHA
    19ca0f8 View commit details
  2. Let KCode be independent of the Ruby runtime

    * Move logic to the only usage instead.
    * KCode.create does not need the runtime.
    * Loading KCode no longer requires loading the Ruby class.
    eregon committed Nov 7, 2016
    Copy the full SHA
    07d3630 View commit details
5 changes: 3 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
@@ -721,12 +721,13 @@ public KCodeGlobalVariable(Ruby runtime, String name, IRubyObject value) {

@Override
public IRubyObject get() {
return runtime.getKCode().kcode(runtime);
String kcode = runtime.getKCode().getKCode();
return kcode == null ? runtime.getNil() : runtime.newString(kcode);
}

@Override
public IRubyObject set(IRubyObject value) {
runtime.setKCode(KCode.create(runtime, value.convertToString().toString()));
runtime.setKCode(KCode.create(value.convertToString().toString()));
return value;
}
}
14 changes: 11 additions & 3 deletions core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -81,9 +81,14 @@
public class RubyInstanceConfig {

public RubyInstanceConfig() {
currentDirectory = Ruby.isSecurityRestricted() ? "/" : JRubyFile.getFileProperty("user.dir");
this(Ruby.isSecurityRestricted());
}

public RubyInstanceConfig(boolean isSecurityRestricted) {
this.isSecurityRestricted = isSecurityRestricted;
currentDirectory = isSecurityRestricted ? "/" : JRubyFile.getFileProperty("user.dir");

if (Ruby.isSecurityRestricted()) {
if (isSecurityRestricted) {
compileMode = CompileMode.OFF;
jitLogging = false;
jitDumping = false;
@@ -117,6 +122,7 @@ public RubyInstanceConfig() {
}

public RubyInstanceConfig(RubyInstanceConfig parentConfig) {
isSecurityRestricted = parentConfig.isSecurityRestricted;
currentDirectory = parentConfig.getCurrentDirectory();
compileMode = parentConfig.getCompileMode();
jitLogging = parentConfig.jitLogging;
@@ -301,7 +307,7 @@ private String calculateJRubyHome() {
String newJRubyHome = null;

// try the normal property first
if (!Ruby.isSecurityRestricted()) {
if (!isSecurityRestricted) {
newJRubyHome = SafePropertyAccessor.getProperty("jruby.home");
}

@@ -1496,6 +1502,8 @@ public static ClassLoader defaultClassLoader() {
// Configuration fields.
////////////////////////////////////////////////////////////////////////////

private final boolean isSecurityRestricted;

/**
* Indicates whether the script must be extracted from script source
*/
8 changes: 1 addition & 7 deletions core/src/main/java/org/jruby/util/KCode.java
Original file line number Diff line number Diff line change
@@ -29,8 +29,6 @@
package org.jruby.util;

import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.runtime.builtin.IRubyObject;

public enum KCode {
NIL(null, "ASCII", 0),
@@ -51,7 +49,7 @@ private KCode(String kcode, String encodingName, int code) {
this.code = code;
}

public static KCode create(Ruby runtime, String lang) {
public static KCode create(String lang) {
if (lang == null) return NIL;
if (lang.length() == 0) return NONE;

@@ -74,10 +72,6 @@ public static KCode create(Ruby runtime, String lang) {
return NIL;
}

public IRubyObject kcode(Ruby runtime) {
return kcode == null ? runtime.getNil() : runtime.newString(kcode);
}

public String getKCode() {
return kcode;
}
Original file line number Diff line number Diff line change
@@ -284,7 +284,7 @@ private void processArgument() {
case 'K': // @Deprecated TODO no longer relevant in Ruby 2.x
String eArg = grabValue(getArgumentError("provide a value for -K"));

config.setKCode(KCode.create(null, eArg));
config.setKCode(KCode.create(eArg));

// source encoding
config.setSourceEncoding(config.getKCode().getEncoding().toString());
2 changes: 1 addition & 1 deletion truffle/src/main/java/org/jruby/truffle/Main.java
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ public class Main {
public static void main(String[] args) {
printTruffleTimeMetric("before-main");

final RubyInstanceConfig config = new RubyInstanceConfig();
final RubyInstanceConfig config = new RubyInstanceConfig(false);
config.setHardExit(true);
config.processArguments(args);