Skip to content

Commit 4156a35

Browse files
committed
Merge remote-tracking branch 'origin/jruby-9.4'
2 parents a80335b + 8828f3a commit 4156a35

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

core/src/main/java/org/jruby/RubyModule.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
46254625
int patternIndex;
46264626
int index = 0;
46274627
RubyModule mod = this;
4628+
boolean includeObject = true;
46284629

46294630
if (value.startsWith(pattern)) {
46304631
mod = objectClass(context);
@@ -4658,6 +4659,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
46584659

46594660
mod = (RubyModule) obj;
46604661
currentOffset = patternIndex + pattern.getRealSize();
4662+
includeObject = false;
46614663
}
46624664

46634665
if (mod == null) mod = this; // Bare 'Foo'
@@ -4666,7 +4668,7 @@ private boolean constDefined(ThreadContext context, IRubyObject name, boolean in
46664668

46674669
String id = RubySymbol.newConstantSymbol(context, fullName, lastSegment).idString();
46684670

4669-
return mod.getConstantSkipAutoload(context, id, inherit, inherit) != null;
4671+
return mod.getConstantSkipAutoload(context, id, inherit, inherit && includeObject, false) != null;
46704672
}
46714673

46724674
// MRI: rb_mod_const_get
@@ -5370,10 +5372,10 @@ public IRubyObject getConstantNoConstMissing(String name, boolean inherit, boole
53705372
}
53715373

53725374
public IRubyObject getConstantNoConstMissing(ThreadContext context, String name, boolean inherit, boolean includeObject) {
5373-
IRubyObject constant = iterateConstantNoConstMissing(context, name, this, inherit, true);
5375+
IRubyObject constant = iterateConstantNoConstMissing(context, name, this, inherit, true, true);
53745376

53755377
if (constant == null && !isClass() && includeObject) {
5376-
constant = iterateConstantNoConstMissing(context, name, objectClass(context), inherit, true);
5378+
constant = iterateConstantNoConstMissing(context, name, objectClass(context), inherit, true, true);
53775379
}
53785380

53795381
return constant;
@@ -5385,20 +5387,20 @@ public final IRubyObject getConstantNoConstMissingSkipAutoload(String name) {
53855387
}
53865388

53875389
public final IRubyObject getConstantNoConstMissingSkipAutoload(ThreadContext context, String name) {
5388-
return getConstantSkipAutoload(context, name, true, true);
5390+
return getConstantSkipAutoload(context, name, true, true, true);
53895391
}
53905392

53915393
@Deprecated
53925394
public IRubyObject getConstantNoConstMissingSKipAutoload(String name) {
5393-
return getConstantSkipAutoload(getCurrentContext(), name, true, true);
5395+
return getConstantSkipAutoload(getCurrentContext(), name, true, true, true);
53945396
}
53955397

53965398
// returns null for autoloads that have failed
5397-
private IRubyObject getConstantSkipAutoload(ThreadContext context, String name, boolean inherit, boolean includeObject) {
5398-
IRubyObject constant = iterateConstantNoConstMissing(context, name, this, inherit, false);
5399+
private IRubyObject getConstantSkipAutoload(ThreadContext context, String name, boolean inherit, boolean searchObject, boolean inheritObject) {
5400+
IRubyObject constant = iterateConstantNoConstMissing(context, name, this, inherit, false, inheritObject);
53995401

5400-
if (constant == null && !isClass() && includeObject) {
5401-
constant = iterateConstantNoConstMissing(context, name, objectClass(context), inherit, false);
5402+
if (constant == null && !isClass() && searchObject) {
5403+
constant = iterateConstantNoConstMissing(context, name, getRuntime().getObject(), inherit, false, true);
54025404
}
54035405

54045406
return constant;
@@ -5423,7 +5425,8 @@ private static SourceLocation iterateConstantEntryNoConstMissing(String name, Ru
54235425
}
54245426

54255427
private static IRubyObject iterateConstantNoConstMissing(ThreadContext context, String name,
5426-
RubyModule init, boolean inherit, boolean loadConstant) {
5428+
RubyModule init, boolean inherit, boolean loadConstant, boolean includeObject) {
5429+
RubyClass objectClass = init.getRuntime().getObject();
54275430
for (RubyModule mod = init; mod != null; mod = mod.getSuperClass()) {
54285431
IRubyObject value = loadConstant ?
54295432
mod.getConstantWithAutoload(context, name, null, true) :
@@ -5434,6 +5437,8 @@ private static IRubyObject iterateConstantNoConstMissing(ThreadContext context,
54345437
if (value != null) return value;
54355438

54365439
if (!inherit) break;
5440+
5441+
if (!includeObject && mod.getSuperClass() == objectClass) break;
54375442
}
54385443
return null;
54395444
}

core/src/main/java/org/jruby/ext/rbconfig/RbConfigLibrary.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,13 @@ public void load(Ruby runtime, boolean wrap) {
250250
setConfig(context, CONFIG, "TEENY", teeny);
251251
setConfig(context, CONFIG, "PATCHLEVEL", "0");
252252
setConfig(context, CONFIG, "ruby_version", major + '.' + minor + ".0");
253+
254+
// normalize Java version 1.8 to 8
255+
String javaSpecVersion = System.getProperty("java.specification.version");
256+
if (javaSpecVersion.equals("1.8")) javaSpecVersion = "8";
257+
253258
// Rubygems is too specific on host cpu so until we have real need lets default to universal
254-
//setConfig(CONFIG, "arch", System.getProperty("os.arch") + "-java" + System.getProperty("java.specification.version"));
255-
setConfig(context, CONFIG, "arch", "universal-java" + System.getProperty("java.specification.version"));
259+
setConfig(context, CONFIG, "arch", "universal-java-" + javaSpecVersion);
256260

257261
// Use property for binDir if available, otherwise fall back to common bin default
258262
String binDir = SafePropertyAccessor.getProperty("jruby.bindir");

spec/ruby/core/module/const_defined_spec.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,4 +166,11 @@
166166
name.should_receive(:to_str).and_return(123)
167167
-> { ConstantSpecs.const_defined? name }.should raise_error(TypeError)
168168
end
169+
170+
it "does not search Object for a scoped constant name" do
171+
Object.const_defined?("ConstantSpecs::ModueA::String").should == false
172+
Object.const_defined?("ConstantSpecs::ClassA::String").should == false
173+
ConstantSpecs.const_defined?("ModuleA::String").should == false
174+
ConstantSpecs.const_defined?("ClassA::String").should == false
175+
end
169176
end

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy