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

Commits on Nov 22, 2016

  1. Copy the full SHA
    34c811f View commit details
  2. Copy the full SHA
    c96a39f View commit details
  3. Copy the full SHA
    72f93cb View commit details
  4. Copy the full SHA
    08a7589 View commit details
  5. Copy the full SHA
    b0f3e36 View commit details
  6. Copy the full SHA
    ba0ad9e View commit details
2 changes: 2 additions & 0 deletions core/pom.rb
Original file line number Diff line number Diff line change
@@ -187,6 +187,7 @@
execute_goals( 'compile',
:id => 'default-compile',
:phase => 'compile',
'debug' => 'true',
'annotationProcessors' => [ 'org.jruby.anno.AnnotationBinder' ],
'generatedSourcesDirectory' => 'target/generated-sources',
'compilerArgs' => [ '-XDignore.symbol.file=true',
@@ -198,6 +199,7 @@
execute_goals( 'compile',
:id => 'populators',
:phase => 'process-classes',
'debug' => 'true',
'compilerArgs' => [ '-XDignore.symbol.file=true',
'-J-Duser.language=en',
'-J-Dfile.encoding=UTF-8',
2 changes: 2 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -488,6 +488,7 @@ DO NOT MODIFIY - GENERATED CODE
<goal>compile</goal>
</goals>
<configuration>
<debug>true</debug>
<annotationProcessors>
<annotationProcessor>org.jruby.anno.AnnotationBinder</annotationProcessor>
</annotationProcessors>
@@ -509,6 +510,7 @@ DO NOT MODIFIY - GENERATED CODE
<goal>compile</goal>
</goals>
<configuration>
<debug>true</debug>
<compilerArgs>
<compilerArg>-XDignore.symbol.file=true</compilerArg>
<compilerArg>-J-Duser.language=en</compilerArg>
33 changes: 28 additions & 5 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@

import org.jcodings.Encoding;
import org.jcodings.specific.UTF8Encoding;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.ir.interpreter.Interpreter;
import org.jruby.runtime.Constants;
import org.jruby.runtime.JavaSites;
@@ -953,21 +954,43 @@ static RubyString inspect(ThreadContext context, IRubyObject object) {

@Override
public IRubyObject rbClone() {
Ruby runtime = getRuntime();
return rbCloneInternal(getRuntime().getCurrentContext(), true);
}

public IRubyObject rbClone(ThreadContext context, IRubyObject maybeOpts) {
Ruby runtime = context.runtime;

boolean kwfreeze = true;
IRubyObject opts = ArgsUtil.getOptionsArg(runtime, maybeOpts);

if (!opts.isNil()) {
IRubyObject freeze = ((RubyHash) opts).fastARef(runtime.newSymbol("freeze"));
if (freeze != null) {
kwfreeze = freeze.isTrue();
}
}

return rbCloneInternal(context, kwfreeze);
}

private IRubyObject rbCloneInternal(ThreadContext context, boolean freeze) {
Ruby runtime = context.runtime;

if (isImmediate()) throw runtime.newTypeError("can't clone " + getMetaClass().getName());

// We're cloning ourselves, so we know the result should be a RubyObject
RubyBasicObject clone = (RubyBasicObject)getMetaClass().getRealClass().allocate();
RubyBasicObject clone = (RubyBasicObject) getMetaClass().getRealClass().allocate();
clone.setMetaClass(getSingletonClassCloneAndAttach(clone));
if (isTaint()) clone.setTaint(true);

initCopy(runtime.getCurrentContext(), clone, this, true);
initCopy(context, clone, this, true);

if (freeze && isFrozen()) clone.setFrozen(true);

if (isFrozen()) clone.setFrozen(true);
return clone;
}


protected RubyClass getSingletonClassClone() {
return getSingletonClassCloneAndAttach(UNDEF);
}
@@ -987,7 +1010,7 @@ protected RubyClass getSingletonClassCloneAndAttach(IRubyObject attach) {
}

RubyClass clone = new MetaClass(getRuntime(), klass.getSuperClass(), attach);
clone.flags = flags;
clone.flags = klass.flags;

if (this instanceof RubyClass) {
clone.setMetaClass(clone);
13 changes: 11 additions & 2 deletions core/src/main/java/org/jruby/RubyKernel.java
Original file line number Diff line number Diff line change
@@ -1880,8 +1880,13 @@ public static RubyClass type(IRubyObject self) {
}

@JRubyMethod(name = "clone")
public static IRubyObject rbClone(IRubyObject self) {
return ((RubyBasicObject)self).rbClone();
public static IRubyObject rbClone(ThreadContext context, IRubyObject self) {
return self.rbClone();
}

@JRubyMethod(name = "clone")
public static IRubyObject rbClone(ThreadContext context, IRubyObject self, IRubyObject opts) {
return ((RubyBasicObject) self).rbClone(context, opts);
}

@JRubyMethod
@@ -2066,6 +2071,10 @@ public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObj
return str;
}

public static IRubyObject rbClone(IRubyObject self) {
return rbClone(self.getRuntime().getCurrentContext(), self);
}

public static class LoopMethods {
@JRubyMethod(module = true, visibility = PRIVATE, reads = LASTLINE, writes = LASTLINE)
public static IRubyObject gsub(ThreadContext context, IRubyObject recv, IRubyObject arg0, Block block) {
121 changes: 120 additions & 1 deletion core/src/main/java/org/jruby/RubyMatchData.java
Original file line number Diff line number Diff line change
@@ -439,8 +439,29 @@ public RubyArray to_a() {
}

@JRubyMethod(rest = true)
public IRubyObject values_at(ThreadContext context, IRubyObject[] args) {
Ruby runtime = context.runtime;

RubyArray result = RubyArray.newArray(runtime, args.length);

for (IRubyObject arg : args) {
if (arg instanceof RubyFixnum) {
result.push(RubyRegexp.nth_match(arg.convertToInteger().getIntValue(), this));
} else {
int num = namevToBacktraceNumber(context, arg);
if (num >= 0) {
result.push(RubyRegexp.nth_match(num, this));
} else {
matchAryAref(context, arg, result);
}
}
}

return result;
}

public IRubyObject values_at(IRubyObject[] args) {
return to_a().values_at(args);
return values_at(getRuntime().getCurrentContext(), args);
}

/** match_captures
@@ -483,6 +504,76 @@ public static int backrefNumber(Ruby runtime, Regex pattern, Region regs, IRubyO
}
}

// MRI: namev_to_backref_number
private int namevToBacktraceNumber(ThreadContext context, IRubyObject name) {
int num = -1;

switch (name.getType().getClassIndex()) {
case SYMBOL:
name = name.asString();
/* fall through */
case STRING:
Ruby runtime = context.runtime;
if (regexp.isNil() || RubyEncoding.areCompatible(regexp, name) == null ||
(num = nameToBackrefNumber(runtime, regexp.getPattern(), regs, name.convertToString())) < 1) {
nameToBackrefError(runtime, name.toString());
}
return num;

default:
return -1;
}
}

private int nameToBackrefError(Ruby runtime, String name) {
throw runtime.newIndexError("undefined group name reference " + name);
}

// MRI: match_ary_subseq
private IRubyObject matchArySubseq(ThreadContext context, int beg, int len, RubyArray result) {
int olen = regs.numRegs;
int wantedEnd = beg + len;
int j, end = olen < wantedEnd ? olen : wantedEnd;

if (result == null) result = RubyArray.newArray(context.runtime);
if (len == 0) return result;

for (j = beg; j < end; j++) {
result.push(RubyRegexp.nth_match(j, this));
}

// if not enough groups, force length to be as wide as desired by setting last value to nil
if (wantedEnd > j) {
int newLength = result.size() + wantedEnd - j;
result.store(newLength - 1, context.nil);
}

return result;
}

// MRI: match_ary_aref
private IRubyObject matchAryAref(ThreadContext context, IRubyObject index, RubyArray result) {
int[] begLen = new int[2];
int numRegs = regs.numRegs;

/* check if idx is Range */
IRubyObject isRange = RubyRange.rangeBeginLength(context, index, numRegs, begLen, 1);

if (isRange.isNil()) return context.nil;

if (!isRange.isTrue()) {
IRubyObject nthMatch = RubyRegexp.nth_match(index.convertToInteger().getIntValue(), this);

// this should never happen here, but MRI allows any VALUE for result
if (result.isNil()) return nthMatch;

return result.push(nthMatch);
}

return matchArySubseq(context, begLen[0], begLen[1], result);
}


/** match_aref
*
*/
@@ -721,6 +812,34 @@ public RubyFixnum hash() {
return getRuntime().newFixnum( hashCode() );
}

@JRubyMethod
public RubyHash named_captures(ThreadContext context) {
Ruby runtime = context.runtime;

RubyHash hash = RubyHash.newHash(runtime);

if (regexp.getPattern().numberOfNames() > 0) {
Iterator<NameEntry> nameEntryIterator = regexp.getPattern().namedBackrefIterator();
while (nameEntryIterator.hasNext()) {
NameEntry entry = nameEntryIterator.next();
RubyString key = RubyString.newStringShared(runtime, new ByteList(entry.name, entry.nameP, entry.nameEnd - entry.nameP, regexp.getEncoding(), false));
boolean found = false;

for (int i : entry.getBackRefs()) {
IRubyObject value = RubyRegexp.nth_match(i, this);
if (value.isTrue()) {
hash.op_asetForString(runtime, key, value);
found = true;
}
}

if (!found) hash.op_asetForString(runtime, key, context.nil);
}
}

return hash;
}

/**
* Get the begin offset of the given region, or -1 if the region does not exist.
*
46 changes: 46 additions & 0 deletions core/src/main/java/org/jruby/RubyRange.java
Original file line number Diff line number Diff line change
@@ -932,6 +932,52 @@ public static boolean isRangeLike(ThreadContext context, IRubyObject obj, Respon
respond_to_end.respondsTo(context, obj, obj);
}

// MRI: rb_range_beg_len
public static IRubyObject rangeBeginLength(ThreadContext context, IRubyObject range, int len, int[] begLen, int err) {
JavaSites.RangeSites sites = sites(context);

if (!RubyRange.isRangeLike(context, range, sites.respond_to_begin, sites.respond_to_end)) return context.fals;

IRubyObject _beg = sites.begin.call(context, range, range);
IRubyObject _end = sites.end.call(context, range, range);
boolean excludeEnd = sites.exclude_end.call(context, range, range).isTrue();
int beg = _beg.convertToInteger().getIntValue();
int end = _end.convertToInteger().getIntValue();
int origBeg = beg;
int origEnd = end;

if (beg < 0) {
beg += len;
if (beg < 0) {
return rangeBeginLengthError(context, origBeg, origEnd, excludeEnd, err);
}
}

if (end < 0) {
end += len;
}

if (!excludeEnd) end++;

if (err == 0 || err == 2) { // CON: ???
if (beg > len) return rangeBeginLengthError(context, origBeg, origEnd, excludeEnd, err);
if (end > len) end = len;
}

len = end - beg;
if (len < 0) len = 0;

begLen[0] = beg;
begLen[1] = len;

return context.tru;
}

private static IRubyObject rangeBeginLengthError(ThreadContext context, int beg, int end, boolean excludeEnd, int err) {
if (err != 0) throw context.runtime.newRangeError(beg + ".." + (excludeEnd ? "." : "") + end + " out of range");
return context.nil;
}

private static JavaSites.RangeSites sites(ThreadContext context) {
return context.sites.Range;
}
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/runtime/JavaSites.java
Original file line number Diff line number Diff line change
@@ -371,6 +371,11 @@ public static class RationalSites {
public static class RangeSites {
public final RespondToCallSite respond_to_succ = new RespondToCallSite("succ");
public final CheckedSites to_int_checked = new CheckedSites("to_int");
public final RespondToCallSite respond_to_begin = new RespondToCallSite("begin");
public final RespondToCallSite respond_to_end = new RespondToCallSite("end");
public final CallSite begin = new FunctionalCachingCallSite("begin");
public final CallSite end = new FunctionalCachingCallSite("end");
public final CallSite exclude_end = new FunctionalCachingCallSite("exclude_end?");
}

public static class ZlibSites {
5 changes: 5 additions & 0 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@
import org.jcodings.Encoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyBoolean;
import org.jruby.RubyClass;
import org.jruby.RubyContinuation.Continuation;
import org.jruby.RubyInstanceConfig;
@@ -85,6 +86,8 @@ public static ThreadContext newContext(Ruby runtime) {
// runtime, nil, and runtimeCache cached here for speed of access from any thread
public final Ruby runtime;
public final IRubyObject nil;
public final RubyBoolean tru;
public final RubyBoolean fals;
public final RuntimeCache runtimeCache;

// Is this thread currently with in a function trace?
@@ -185,6 +188,8 @@ public SecureRandom getSecureRandom() {
private ThreadContext(Ruby runtime) {
this.runtime = runtime;
this.nil = runtime.getNil();
this.tru = runtime.getTrue();
this.fals = runtime.getFalse();
this.currentBlockType = Block.Type.NORMAL;
this.savedExcInLambda = null;