Skip to content

Commit

Permalink
Merge branch 'master' into symbol_love
Browse files Browse the repository at this point in the history
enebo committed Aug 7, 2017
2 parents 5e29f10 + 439f915 commit 2a27d1b
Showing 28 changed files with 445 additions and 719 deletions.
55 changes: 30 additions & 25 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -252,7 +252,18 @@ private Ruby(RubyInstanceConfig config) {

constant = OptoFactory.newConstantWrapper(Ruby.class, this);

getJRubyClassLoader(); // force JRubyClassLoader to init if possible
// force JRubyClassLoader to init if possible
if (!Ruby.isSecurityRestricted()) {
if (config.isClassloaderDelegate()){
jrubyClassLoader = new JRubyClassLoader(config.getLoader());
}
else {
jrubyClassLoader = new SelfFirstJRubyClassLoader(config.getLoader());
}
}
else {
jrubyClassLoader = null; // a NullClassLoader object would be better ...
}

this.staticScopeFactory = new StaticScopeFactory(this);
this.beanManager = BeanManagerFactory.create(this, config.isManagementEnabled());
@@ -2524,16 +2535,24 @@ public RubyClass getInvalidByteSequenceError() {
return invalidByteSequenceError;
}

private RubyRandom.RandomType defaultRand;
RubyRandom.RandomType defaultRand;

/**
* @deprecated internal API, to be hidden
*/
public RubyRandom.RandomType getDefaultRand() {
return defaultRand;
}

/**
* @deprecated internal API, to be hidden
*/
public void setDefaultRand(RubyRandom.RandomType defaultRand) {
this.defaultRand = defaultRand;
}

private RubyHash charsetMap;
@Deprecated // no longer used (internal API)
public RubyHash getCharsetMap() {
if (charsetMap == null) charsetMap = new RubyHash(this);
return charsetMap;
@@ -2595,24 +2614,7 @@ public static ClassLoader getClassLoader() {
return loader;
}

/**
* TODO the property {@link #jrubyClassLoader} will only be set in constructor. in the first call of
* {@link #getJRubyClassLoader() getJRubyClassLoader}. So the field {@link #jrubyClassLoader} can be final
* set in the constructor directly and we avoid the synchronized here.
*
* @return
*/
public synchronized JRubyClassLoader getJRubyClassLoader() {
// FIXME: Get rid of laziness and handle restricted access elsewhere
if (!Ruby.isSecurityRestricted() && jrubyClassLoader == null) {
if (config.isClassloaderDelegate()){
jrubyClassLoader = new JRubyClassLoader(config.getLoader());
}
else {
jrubyClassLoader = new SelfFirstJRubyClassLoader(config.getLoader());
}
}

public JRubyClassLoader getJRubyClassLoader() {
return jrubyClassLoader;
}

@@ -3345,9 +3347,9 @@ public void tearDown(boolean systemExit) {
* release the runtime loader but not otherwise - you should do that manually.
*/
public void releaseClassLoader() {
if ( jrubyClassLoader != null ) {
getJRubyClassLoader().close();
jrubyClassLoader = null;
if (jrubyClassLoader != null) {
jrubyClassLoader.close();
//jrubyClassLoader = null;
}
}

@@ -4590,6 +4592,9 @@ public CoverageData getCoverageData() {
return coverageData;
}

/**
* @deprecated internal API, to be removed
*/
public Random getRandom() {
return random;
}
@@ -4979,7 +4984,7 @@ public StructLayout.FieldIO getStructLayoutDefaultIO() {

// Java support
private JavaSupport javaSupport;
private JRubyClassLoader jrubyClassLoader;
private final JRubyClassLoader jrubyClassLoader;

// Management/monitoring
private BeanManager beanManager;
@@ -5115,7 +5120,7 @@ public StructLayout.FieldIO getStructLayoutDefaultIO() {
private static ThreadLocal<Ruby> threadLocalRuntime = new ThreadLocal<Ruby>();

/** The runtime-local random number generator. Uses SecureRandom if permissions allow. */
private final Random random;
final Random random;

/** The runtime-local seed for hash randomization */
private final long hashSeedK0;
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/RubyBasicObject.java
Original file line number Diff line number Diff line change
@@ -260,6 +260,7 @@ protected RubyBasicObject(Ruby runtime, RubyClass metaClass, boolean useObjectSp
runtime.addToObjectSpace(useObjectSpace, this);
}

@Deprecated
protected void taint(Ruby runtime) {
if (!isTaint()) {
testFrozen();
81 changes: 22 additions & 59 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
@@ -982,51 +982,18 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {
return real.callMethod(context, "rationalize", args);
}

@JRubyMethod(name = "finite?")
@Override
public IRubyObject finite_p(ThreadContext context) {
IRubyObject magnitude = magnitude(context);

if (magnitude instanceof RubyInteger || magnitude instanceof RubyRational) {
return context.runtime.getTrue();
}

if (magnitude instanceof RubyFloat) {
return context.runtime.newBoolean(!((RubyFloat) magnitude).infinite_p().isTrue());
}

return sites(context).finite.call(context, magnitude, magnitude);
}

@JRubyMethod(name = "infinite?")
@Override
public IRubyObject infinite_p(ThreadContext context) {
IRubyObject magnitude = magnitude(context);

if (magnitude instanceof RubyInteger || magnitude instanceof RubyRational) {
return context.nil;
}

if (magnitude instanceof RubyFloat) {
RubyFloat flote = (RubyFloat) magnitude;
if (flote.infinite_p().isTrue()) {
return context.runtime.newFixnum(flote.getDoubleValue() < 0 ? -1 : 1);
}
return context.nil;
}
private static final ByteList SEP = RubyFile.SLASH;
private static final ByteList _eE = new ByteList(new byte[] { '.', 'e', 'E' }, false);

return sites(context).infinite.call(context, magnitude, magnitude);
}

static RubyArray str_to_c_internal(ThreadContext context, IRubyObject recv) {
RubyString s = recv.convertToString();
ByteList bytes = s.getByteList();

Ruby runtime = context.runtime;
if (bytes.getRealSize() == 0) return runtime.newArray(runtime.getNil(), recv);
if (bytes.getRealSize() == 0) return runtime.newArray(context.nil, recv);

IRubyObject sr, si, re;
sr = si = re = runtime.getNil();
sr = si = re = context.nil;
boolean po = false;
IRubyObject m = RubyRegexp.newDummyRegexp(runtime, Numeric.ComplexPatterns.comp_pat0).match_m(context, s, false);

@@ -1056,15 +1023,15 @@ static RubyArray str_to_c_internal(ThreadContext context, IRubyObject recv) {

if (m.isNil()) {
m = RubyRegexp.newDummyRegexp(runtime, Numeric.ComplexPatterns.comp_pat2).match_m(context, s, false);
if (m.isNil()) return runtime.newArray(runtime.getNil(), recv);
if (m.isNil()) return runtime.newArray(context.nil, recv);
RubyMatchData match = (RubyMatchData)m;
sr = match.at(1);
if (match.at(2).isNil()) {
si = runtime.getNil();
si = context.nil;
} else {
si = match.at(3);
IRubyObject t = match.at(4);
if (t.isNil()) t = runtime.newString(RubyFixnum.SINGLE_CHAR_BYTELISTS19['1']);
if (t.isNil()) t = runtime.newString(RubyInteger.singleCharByteList((byte) '1'));
si.convertToString().cat(t.convertToString().getByteList());
}
re = match.post_match(context);
@@ -1074,28 +1041,24 @@ static RubyArray str_to_c_internal(ThreadContext context, IRubyObject recv) {
IRubyObject r = RubyFixnum.zero(runtime);
IRubyObject i = r;

if (!sr.isNil()) {
if (sr.callMethod(context, "include?", runtime.newString(new ByteList(new byte[]{'/'}))).isTrue()) {
r = f_to_r(context, sr);
} else if (f_gt_p(context, sr.callMethod(context, "count", runtime.newString(".eE")), RubyFixnum.zero(runtime)).isTrue()) {
r = f_to_f(context, sr);
} else {
r = f_to_i(context, sr);
}
}
r = convertString(context, sr, r);
i = convertString(context, si, i);

if (!si.isNil()) {
if (si.callMethod(context, "include?", runtime.newString(new ByteList(new byte[]{'/'}))).isTrue()) {
i = f_to_r(context, si);
} else if (f_gt_p(context, si.callMethod(context, "count", runtime.newString(".eE")), RubyFixnum.zero(runtime)).isTrue()) {
i = f_to_f(context, si);
} else {
i = f_to_i(context, si);
}
}
return runtime.newArray(po ? newComplexPolar(context, r, i) : newComplexCanonicalize(context, r, i), re);
}


private static IRubyObject convertString(ThreadContext context, final IRubyObject s, IRubyObject def) {
if (s == context.nil) return def;
final Ruby runtime = context.runtime;
if (s.callMethod(context, "include?", RubyString.newStringShared(runtime, SEP)).isTrue()) {
return f_to_r(context, s);
}
if (f_gt_p(context, s.callMethod(context, "count", RubyString.newStringShared(runtime, _eE)), RubyFixnum.zero(runtime)).isTrue()) {
return f_to_f(context, s);
}
return f_to_i(context, s);
}

private static IRubyObject str_to_c_strict(ThreadContext context, IRubyObject recv) {
RubyArray a = str_to_c_internal(context, recv);
if (a.eltInternal(0).isNil() || a.eltInternal(1).convertToString().getByteList().length() > 0) {
10 changes: 7 additions & 3 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -92,6 +92,10 @@
**/
@JRubyClass(name="File", parent="IO", include="FileTest")
public class RubyFile extends RubyIO implements EncodingCapable {

static final ByteList SLASH = new ByteList(new byte[] { '/' }, false);
static final ByteList BACKSLASH = new ByteList(new byte[] { '\\' }, false);

public static RubyClass createFileClass(Ruby runtime) {
ThreadContext context = runtime.getCurrentContext();

@@ -107,13 +111,13 @@ public static RubyClass createFileClass(Ruby runtime) {
fileClass.kindOf = new RubyModule.JavaClassKindOf(RubyFile.class);

// file separator constants
RubyString separator = RubyString.newString(runtime, new ByteList(new byte[] { '/' }, false));
RubyString separator = RubyString.newString(runtime, SLASH);
separator.freeze(context);
fileClass.defineConstant("SEPARATOR", separator);
fileClass.defineConstant("Separator", separator);

if (File.separatorChar == '\\') {
RubyString altSeparator = RubyString.newString(runtime, new ByteList(new byte[] { '\\' }, false));
RubyString altSeparator = RubyString.newString(runtime, BACKSLASH);
altSeparator.freeze(context);
fileClass.defineConstant("ALT_SEPARATOR", altSeparator);
} else {
@@ -1153,7 +1157,7 @@ public static IRubyObject utime(ThreadContext context, IRubyObject recv, IRubyOb
long[] atimeval = null;
long[] mtimeval = null;

if (args[0] != runtime.getNil() || args[1] != runtime.getNil()) {
if (args[0] != context.nil || args[1] != context.nil) {
atimeval = extractTimeval(context, args[0]);
mtimeval = extractTimeval(context, args[1]);
}
5 changes: 2 additions & 3 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -183,9 +183,8 @@ public RubyFloat convertToFloat() {
return this;
}

protected int compareValue(RubyNumeric other) {
double otherVal = other.getDoubleValue();
return getValue() > otherVal ? 1 : getValue() < otherVal ? -1 : 0;
public int signum() {
return (int) Math.signum(value); // NOTE: (int) NaN ?
}

public static RubyFloat newFloat(Ruby runtime, double value) {
16 changes: 5 additions & 11 deletions core/src/main/java/org/jruby/RubyGenerator.java
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ public RubyGenerator(Ruby runtime, RubyClass klass) {
public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block block) {
Ruby runtime = context.runtime;

IRubyObject proc;
final IRubyObject proc;

if (args.length == 0) {
proc = RubyProc.newProc(runtime, block, Block.Type.PROC);
@@ -76,7 +76,9 @@ public IRubyObject initialize(ThreadContext context, IRubyObject[] args, Block b
}
}

return init(runtime, proc);
// generator_init
this.proc = proc;
return this;
}

// generator_init_copy
@@ -96,15 +98,7 @@ public IRubyObject initialize_copy(ThreadContext context, IRubyObject other) {
// generator_each
@JRubyMethod(rest = true)
public IRubyObject each(ThreadContext context, IRubyObject[] args, Block block) {
return ((RubyProc) proc).call19(context, ArraySupport.newCopy(RubyYielder.newYielder(context, block), args), Block.NULL_BLOCK);
}


// generator_init
private IRubyObject init(Ruby runtime, IRubyObject proc) {
this.proc = proc;

return this;
return ((RubyProc) proc).call(context, ArraySupport.newCopy(RubyYielder.newYielder(context, block), args), Block.NULL_BLOCK);
}

private IRubyObject proc;
14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -1073,7 +1073,7 @@ public IRubyObject internal_encoding(ThreadContext context) {
public IRubyObject set_encoding(ThreadContext context, IRubyObject encodingObj) {
setEncoding(context, encodingObj, context.nil, context.nil);

return context.nil;
return this;
}

@JRubyMethod
@@ -1085,14 +1085,14 @@ public IRubyObject set_encoding(ThreadContext context, IRubyObject encodingStrin
setEncoding(context, encodingString, internalEncoding, context.nil);
}

return context.nil;
return this;
}

@JRubyMethod
public IRubyObject set_encoding(ThreadContext context, IRubyObject encodingString, IRubyObject internalEncoding, IRubyObject options) {
setEncoding(context, encodingString, internalEncoding, options);

return context.nil;
return this;
}

// mri: io_encoding_set
@@ -1642,9 +1642,9 @@ public IRubyObject printf(ThreadContext context, IRubyObject[] args) {
public IRubyObject putc(ThreadContext context, IRubyObject ch) {
IRubyObject str;
if (ch instanceof RubyString) {
str = ((RubyString)ch).substr(context.runtime, 0, 1);
str = ((RubyString) ch).substr(context.runtime, 0, 1);
} else {
str = RubyString.newStringShared(context.runtime, RubyFixnum.SINGLE_CHAR_BYTELISTS19[RubyNumeric.num2chr(ch) & 0xFF]);
str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList(RubyNumeric.num2chr(ch)));
}

sites(context).write.call(context, this, this, str);
@@ -1654,10 +1654,10 @@ public IRubyObject putc(ThreadContext context, IRubyObject ch) {

public static IRubyObject putc(ThreadContext context, IRubyObject maybeIO, IRubyObject object) {
if (maybeIO instanceof RubyIO) {
((RubyIO)maybeIO).putc(context, object);
((RubyIO) maybeIO).putc(context, object);
} else {
byte c = RubyNumeric.num2chr(object);
IRubyObject str = RubyString.newStringShared(context.runtime, RubyFixnum.SINGLE_CHAR_BYTELISTS19[c & 0xFF]);
IRubyObject str = RubyString.newStringShared(context.runtime, RubyInteger.singleCharByteList(c));
sites(context).write.call(context, maybeIO, maybeIO, str);
}

Loading

0 comments on commit 2a27d1b

Please sign in to comment.