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

Commits on Jul 8, 2017

  1. Copy the full SHA
    98efb2f View commit details
  2. Copy the full SHA
    e437837 View commit details
  3. Copy the full SHA
    a5770fe View commit details
Showing with 26 additions and 4 deletions.
  1. +10 −2 core/src/main/java/org/jruby/RubyBasicObject.java
  2. +16 −2 core/src/main/java/org/jruby/RubyGlobal.java
12 changes: 10 additions & 2 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -508,6 +508,11 @@ public boolean isSpecialConst() {
return isImmediate() || !isTrue();
}

// MRI: special_object_p
public boolean isSpecialObject() {
return isImmediate() || this instanceof RubyBignum || this instanceof RubyFloat;
}

/**
* if exist return the meta-class else return the type of the object.
*
@@ -888,7 +893,7 @@ else if (target.isAssignableFrom(getClass())) {
public IRubyObject dup() {
Ruby runtime = getRuntime();

if (isImmediate()) {
if (isSpecialObject()) {
return this;
}

@@ -973,6 +978,9 @@ public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {

if (!opts.isNil()) {
IRubyObject freeze = ((RubyHash) opts).fastARef(runtime.newSymbol("freeze"));
if (freeze != null && freeze != runtime.getTrue() && freeze != runtime.getFalse()) {
throw runtime.newArgumentError("unexpected value for freeze: " + freeze.getType().getName());
}
if (freeze != null) {
kwfreeze = freeze.isTrue();
}
@@ -984,7 +992,7 @@ public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {
private IRubyObject rbCloneInternal(ThreadContext context, boolean freeze) {
Ruby runtime = context.runtime;

if (isImmediate()) {
if (isSpecialObject()) {
if (!freeze) {
throw runtime.newArgumentError("can't unfreeze " + getType().getName());
}
18 changes: 16 additions & 2 deletions core/src/main/java/org/jruby/RubyGlobal.java
Original file line number Diff line number Diff line change
@@ -177,9 +177,9 @@ public static void createGlobals(ThreadContext context, Ruby runtime) {
runtime.defineVariable(new NonEffectiveGlobalVariable(runtime, "$=", runtime.getFalse()), GLOBAL);

if(runtime.getInstanceConfig().getInputFieldSeparator() == null) {
runtime.defineVariable(new GlobalVariable(runtime, "$;", runtime.getNil()), GLOBAL);
runtime.defineVariable(new StringOrRegexpGlobalVariable(runtime, "$;", runtime.getNil()), GLOBAL);
} else {
runtime.defineVariable(new GlobalVariable(runtime, "$;", RubyRegexp.newRegexp(runtime, runtime.getInstanceConfig().getInputFieldSeparator(), new RegexpOptions())), GLOBAL);
runtime.defineVariable(new StringOrRegexpGlobalVariable(runtime, "$;", RubyRegexp.newRegexp(runtime, runtime.getInstanceConfig().getInputFieldSeparator(), new RegexpOptions())), GLOBAL);
}

RubyInstanceConfig.Verbosity verbose = runtime.getInstanceConfig().getVerbosity();
@@ -724,6 +724,20 @@ public IRubyObject set(IRubyObject value) {
}
}

public static class StringOrRegexpGlobalVariable extends GlobalVariable {
public StringOrRegexpGlobalVariable(Ruby runtime, String name, IRubyObject value) {
super(runtime, name, value);
}

@Override
public IRubyObject set(IRubyObject value) {
if (!value.isNil() && ! (value instanceof RubyString) && ! (value instanceof RubyRegexp)) {
throw runtime.newTypeError("value of " + name() + " must be String or Regexp");
}
return super.set(value);
}
}

public static class KCodeGlobalVariable extends GlobalVariable {
public KCodeGlobalVariable(Ruby runtime, String name, IRubyObject value) {
super(runtime, name, value);