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

Commits on Aug 24, 2016

  1. Copy the full SHA
    14224e3 View commit details
  2. Revert "update getConstant lookup to avoid auto-loading constant on a…

    … const_defined? check"
    
    This reverts commit 5cdaa48.
    
    See #3920.
    headius committed Aug 24, 2016
    Copy the full SHA
    02c988a View commit details
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/IncludedModuleWrapper.java
Original file line number Diff line number Diff line change
@@ -230,8 +230,8 @@ public Collection<String> getConstantNames(boolean includePrivate) {
}

@Override
protected IRubyObject getAutoloadConstant(String name, boolean forceLoad) {
return delegate.getAutoloadConstant(name, forceLoad);
public IRubyObject getAutoloadConstant(String name) {
return delegate.getAutoloadConstant(name);
}

/** The module to which this include delegates. */
183 changes: 43 additions & 140 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -53,7 +53,6 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import org.jcodings.Encoding;
import org.jruby.anno.AnnotationBinder;
import org.jruby.anno.AnnotationHelper;
import org.jruby.anno.FrameField;
@@ -2616,49 +2615,10 @@ public RubyBoolean const_defined_p(ThreadContext context, IRubyObject symbol) {

@JRubyMethod(name = "const_defined?", required = 1, optional = 1, compat = RUBY1_9)
public RubyBoolean const_defined_p19(ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
boolean inherit = args.length == 1 || ( ! args[1].isNil() && args[1].isTrue() );

final IRubyObject symbol = args[0];
final String fullName = symbol.asJavaString();
String name = fullName;

int sep = name.indexOf("::");
// symbol form does not allow ::
if (symbol instanceof RubySymbol && sep != -1) {
throw runtime.newNameError("wrong constant name", name);
}

RubyModule mod = this;

if (sep == 0) { // ::Foo::Bar
mod = runtime.getObject();
name = name.substring(2);
}

// Bare ::
if (name.length() == 0) {
throw runtime.newNameError("wrong constant name ", fullName);
}

IRubyObject obj;
while ( ( sep = name.indexOf("::") ) != -1 ) {
final String segment = name.substring(0, sep);
if (segment.length() == 0) {
throw runtime.newNameError("wrong constant name " + fullName, name);
}
obj = mod.getConstantNoConstMissing(validateConstant(segment, symbol), inherit, inherit);
if (obj == null) return runtime.getFalse();
if (obj instanceof RubyModule) {
mod = (RubyModule) obj;
} else {
throw runtime.newTypeError(segment + " does not refer to class/module");
}
name = name.substring(sep + 2);
}
IRubyObject symbol = args[0];
boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());

obj = mod.getConstantSkipAutoload(validateConstant(name, symbol), inherit, inherit);
return runtime.newBoolean(obj != null);
return context.runtime.newBoolean(fastIsConstantDefined19(validateConstant(symbol.asJavaString()).intern(), inherit));
}

/** rb_mod_const_get
@@ -2680,36 +2640,17 @@ public IRubyObject const_get_1_9(ThreadContext context, IRubyObject[] args) {

@JRubyMethod(name = "const_get", required = 1, optional = 1, compat = CompatVersion.RUBY2_0)
public IRubyObject const_get_2_0(ThreadContext context, IRubyObject[] args) {
final Ruby runtime = context.runtime;
boolean inherit = args.length == 1 || ( ! args[1].isNil() && args[1].isTrue() );

final IRubyObject symbol = args[0];
final String fullName = symbol.asJavaString();
String name = fullName;

int sep = name.indexOf("::");
// symbol form does not allow ::
if (symbol instanceof RubySymbol && sep != -1) {
throw runtime.newNameError("wrong constant name", name);
}
String symbol = args[0].asJavaString();
boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());

RubyModule mod = this;

if (sep == 0) { // ::Foo::Bar
mod = runtime.getObject();
name = name.substring(2);
}

// Bare ::
if (name.length() == 0) {
throw runtime.newNameError("wrong constant name ", fullName);
}

while ( ( sep = name.indexOf("::") ) != -1 ) {
final String segment = name.substring(0, sep);
IRubyObject obj = mod.getConstant(validateConstant(segment, symbol), inherit, inherit);
if (obj instanceof RubyModule) {
mod = (RubyModule) obj;
int sep;
while((sep = symbol.indexOf("::")) != -1) {
String segment = symbol.substring(0, sep);
symbol = symbol.substring(sep + 2);
IRubyObject obj = mod.getConstant(validateConstant(segment), inherit, inherit);
if(obj instanceof RubyModule) {
mod = (RubyModule)obj;
} else {
throw getRuntime().newTypeError(segment + " does not refer to class/module");
}
@@ -3040,13 +2981,11 @@ public IRubyObject getConstant(String name, boolean inherit) {
}

public IRubyObject getConstant(String name, boolean inherit, boolean includeObject) {
assert IdUtil.isConstant(name);

IRubyObject value = getConstantNoConstMissing(name, inherit, includeObject);
Ruby runtime = getRuntime();

return value != null ? value :
callMethod(runtime.getCurrentContext(), "const_missing", runtime.newSymbol(name));
return value == null ? callMethod(runtime.getCurrentContext(), "const_missing",
runtime.newSymbol(name)) : value;
}

@Deprecated
@@ -3068,35 +3007,23 @@ public IRubyObject getConstantNoConstMissing(String name, boolean inherit) {
}

public IRubyObject getConstantNoConstMissing(String name, boolean inherit, boolean includeObject) {
IRubyObject constant = iterateConstantNoConstMissing(name, this, inherit, true);

if (constant == null && !isClass() && includeObject) {
constant = iterateConstantNoConstMissing(name, getRuntime().getObject(), inherit, true);
}

return constant;
}
assert IdUtil.isConstant(name);

// returns UNDEF for un-loaded autoload constants
private IRubyObject getConstantSkipAutoload(String name, boolean inherit, boolean includeObject) {
IRubyObject constant = iterateConstantNoConstMissing(name, this, inherit, false);
IRubyObject constant = iterateConstantNoConstMissing(name, this, inherit);

if (constant == null && !isClass() && includeObject) {
constant = iterateConstantNoConstMissing(name, getRuntime().getObject(), inherit, false);
constant = iterateConstantNoConstMissing(name, getRuntime().getObject(), inherit);
}

return constant;
}

private static IRubyObject iterateConstantNoConstMissing(String name,
RubyModule init, boolean inherit, boolean loadConstant) {
for (RubyModule mod = init; mod != null; mod = mod.getSuperClass()) {
final IRubyObject value = mod.fetchConstant(name, true);
private IRubyObject iterateConstantNoConstMissing(String name, RubyModule init, boolean inherit) {
for (RubyModule p = init; p != null; p = p.getSuperClass()) {
IRubyObject value = p.getConstantAt(name);

if ( value == UNDEF ) return mod.getAutoloadConstant(name, loadConstant);
if ( value != null ) return value;

if ( ! inherit ) break;
if (value != null) return value == UNDEF ? null : value;
if (!inherit) break;
}
return null;
}
@@ -3119,25 +3046,28 @@ public IRubyObject getConstantFromNoConstMissing(String name) {

public IRubyObject getConstantFromNoConstMissing(String name, boolean includePrivate) {
assert name == name.intern() : name + " is not interned";
assert IdUtil.isConstant(name);
Ruby runtime = getRuntime();
RubyClass objectClass = runtime.getObject();
IRubyObject value;

final Ruby runtime = getRuntime();
final RubyClass objectClass = runtime.getObject();

RubyModule mod = this; IRubyObject value;
RubyModule p = this;

while ( mod != null ) {
if ( ( value = mod.fetchConstant(name, includePrivate) ) != null ) {
if ( value == UNDEF ) return mod.resolveUndefConstant(name);
while (p != null) {
if ((value = p.fetchConstant(name, false)) != null) {
if (value == UNDEF) {
return p.resolveUndefConstant(name);
}

if ( mod == objectClass && this != objectClass ) {
if (p == objectClass && this != objectClass) {
String badCName = getName() + "::" + name;
runtime.getWarnings().warn(ID.CONSTANT_BAD_REFERENCE,
"toplevel constant " + name + " referenced by " + badCName);
runtime.getWarnings().warn(ID.CONSTANT_BAD_REFERENCE, "toplevel constant " +
name + " referenced by " + badCName);
}

return value;
}
mod = mod.getSuperClass();
p = p.getSuperClass();
}
return null;
}
@@ -3157,7 +3087,7 @@ public IRubyObject fastGetConstantFromConstMissing(String internedName) {
return getConstantFromConstMissing(internedName);
}

public final IRubyObject resolveUndefConstant(String name) {
public IRubyObject resolveUndefConstant(String name) {
return getAutoloadConstant(name);
}

@@ -3605,30 +3535,6 @@ protected final String validateConstant(String name) {
throw getRuntime().newNameError("wrong constant name " + name, name);
}

protected final String validateConstant(IRubyObject name) {
return validateConstant(name.asJavaString(), name);
}

protected final String validateConstant(String name, IRubyObject errorName) {
if (IdUtil.isValidConstantName19(name)) return name;

Ruby runtime = getRuntime();

Encoding resultEncoding = runtime.getDefaultInternalEncoding();
if (resultEncoding == null) resultEncoding = runtime.getDefaultExternalEncoding();

// MRI is more complicated than this and distinguishes between ID and non-ID.
RubyString nameString = errorName.asString();

// MRI does strlen to check for \0 vs Ruby string length.
if ((nameString.getEncoding() != resultEncoding && !nameString.isAsciiOnly()) ||
nameString.toString().indexOf('\0') > -1 ) {
nameString = (RubyString) nameString.inspect();
}

throw getRuntime().newNameError("wrong constant name " + nameString, name);
}

protected final void ensureConstantsSettable() {
if (isFrozen()) throw getRuntime().newFrozenError(ERR_FROZEN_CONST_TYPE);
}
@@ -3696,15 +3602,12 @@ protected IRubyObject finishAutoload(String name) {
* If it's first resolution for the constant, it tries to require the defined feature and returns the defined value.
* Multi-threaded accesses are blocked and processed sequentially except if the caller is the autoloading thread.
*/
public final IRubyObject getAutoloadConstant(String name) {
return getAutoloadConstant(name, true);
}

protected IRubyObject getAutoloadConstant(String name, boolean loadConstant) {
final Autoload autoload = getAutoloadMap().get(name);
if ( autoload == null ) return null;
if ( ! loadConstant ) return UNDEF;
return autoload.getConstant( getRuntime().getCurrentContext() );
public IRubyObject getAutoloadConstant(String name) {
Autoload autoload = getAutoloadMap().get(name);
if (autoload == null) {
return null;
}
return autoload.getConstant(getRuntime().getCurrentContext());
}

/**
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@
* rights and limitations under the License.
*
* Copyright (C) 2002 Jan Arne Petersen <jpetersen@uni-bonn.de>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
@@ -28,9 +28,10 @@
package org.jruby.runtime.load;

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

/**
*
*
* @author jpetersen
*/
public interface IAutoloadMethod {
11 changes: 11 additions & 0 deletions core/src/main/java/org/jruby/util/io/ChannelDescriptor.java
Original file line number Diff line number Diff line change
@@ -52,6 +52,8 @@
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;

import jnr.enxio.channels.NativeSelectableChannel;
import org.jruby.Ruby;
import org.jruby.RubyFile;

@@ -798,6 +800,15 @@ public void close() throws BadDescriptorException, IOException {

}

/**
* Attempt to sync the OS IO buffers (a la fsync(2)).
*/
public void fsync() throws IOException {
if (channel instanceof FileChannel) {
((FileChannel) channel).force(true);
}
}

void finish(boolean close) throws BadDescriptorException, IOException {
synchronized (refCounter) {
// if refcount is at or below zero, we're no longer valid
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/io/ChannelStream.java
Original file line number Diff line number Diff line change
@@ -824,6 +824,7 @@ public synchronized void lseek(long offset, int type) throws IOException, Invali

public synchronized void sync() throws IOException, BadDescriptorException {
flushWrite();
descriptor.fsync();
}

/**