Skip to content

Commit 865c26c

Browse files
committed
Merge branch 'master' into truffle-head
Conflicts: truffle/src/main/java/org/jruby/truffle/nodes/core/ClassNodes.java truffle/src/main/java/org/jruby/truffle/nodes/core/KernelNodes.java truffle/src/main/java/org/jruby/truffle/nodes/core/ModuleNodes.java truffle/src/main/java/org/jruby/truffle/nodes/rubinius/FixnumPrimitiveNodes.java
2 parents e13cf4b + 245cad9 commit 865c26c

File tree

78 files changed

+943
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+943
-332
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,4 +205,10 @@ public Collection<String> getConstantNames(boolean includePrivate) {
205205
public IRubyObject getAutoloadConstant(String name) {
206206
return origin.getAutoloadConstant(name);
207207
}
208+
209+
@Override
210+
protected DynamicMethod searchMethodCommon(String name) {
211+
// try us and superclasses (from prepend)
212+
return origin.searchMethodInner(name);
213+
}
208214
}

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

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4476,29 +4476,7 @@ private static void checkValidOptions(IRubyObject options, Set<String> valid) {
44764476

44774477
// MRI: check_exec_env, w/ check_exec_env_i body in-line
44784478
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
4479-
Ruby runtime = context.runtime;
4480-
RubyArray env = runtime.newArray();
4481-
for (Map.Entry<IRubyObject, IRubyObject> entry : (Set<Map.Entry<IRubyObject, IRubyObject>>)hash.directEntrySet()) {
4482-
IRubyObject key = entry.getKey();
4483-
IRubyObject val = entry.getValue();
4484-
ByteList k;
4485-
4486-
k = StringSupport.checkEmbeddedNulls(runtime, key).getByteList();
4487-
if (k.indexOf('=') != -1)
4488-
throw runtime.newArgumentError("environment name contains a equal : " + k);
4489-
4490-
if (!val.isNil())
4491-
StringSupport.checkEmbeddedNulls(runtime, val);
4492-
4493-
if (Platform.IS_WINDOWS) {
4494-
key = ((RubyString)key).export(context);
4495-
}
4496-
if (!val.isNil()) val = ((RubyString)val).export(context);
4497-
4498-
env.push(runtime.newArray(key, val));
4499-
}
4500-
4501-
return env;
4479+
return PopenExecutor.checkExecEnv(context, hash);
45024480
}
45034481

45044482
/**

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,22 +3032,25 @@ public IRubyObject const_get_2_0(ThreadContext context, IRubyObject[] args) {
30323032
String symbol = fullName;
30333033
boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());
30343034

3035+
int sep = symbol.indexOf("::");
30353036
// symbol form does not allow ::
3036-
if (args[0] instanceof RubySymbol && symbol.indexOf("::") != -1) {
3037+
if (args[0] instanceof RubySymbol && sep != -1) {
30373038
throw context.runtime.newNameError("wrong constant name", symbol);
30383039
}
30393040

30403041
RubyModule mod = this;
30413042

3042-
if (symbol.startsWith("::")) mod = runtime.getObject();
3043+
if (sep == 0) { // ::Foo::Bar
3044+
mod = runtime.getObject();
3045+
symbol = symbol.substring(2);
3046+
}
30433047

3044-
int sep;
3045-
while((sep = symbol.indexOf("::")) != -1) {
3048+
while ((sep = symbol.indexOf("::")) != -1) {
30463049
String segment = symbol.substring(0, sep);
30473050
symbol = symbol.substring(sep + 2);
30483051
IRubyObject obj = mod.getConstant(validateConstant(segment, args[0]), inherit, inherit);
3049-
if(obj instanceof RubyModule) {
3050-
mod = (RubyModule)obj;
3052+
if (obj instanceof RubyModule) {
3053+
mod = (RubyModule) obj;
30513054
} else {
30523055
throw runtime.newTypeError(segment + " does not refer to class/module");
30533056
}

core/src/main/java/org/jruby/runtime/ThreadContext.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.jruby.internal.runtime.methods.DynamicMethod;
4949
import org.jruby.lexer.yacc.ISourcePosition;
5050
import org.jruby.parser.StaticScope;
51+
import org.jruby.runtime.backtrace.BacktraceData;
5152
import org.jruby.runtime.backtrace.BacktraceElement;
5253
import org.jruby.runtime.backtrace.RubyStackTraceElement;
5354
import org.jruby.runtime.backtrace.TraceType;
@@ -635,11 +636,18 @@ public IRubyObject getConstant(String internedName) {
635636
return getCurrentStaticScope().getConstant(internedName);
636637
}
637638

638-
private static void addBackTraceElement(Ruby runtime, RubyArray backtrace, RubyStackTraceElement element) {
639-
RubyString str = RubyString.newString(runtime, element.mriStyleString());
640-
backtrace.append(str);
639+
/**
640+
* Render the current backtrace as a string to the given StringBuilder. This will honor the currently-configured
641+
* backtrace format and content.
642+
*
643+
* @param sb the StringBuilder to which to render the backtrace
644+
*/
645+
public void renderCurrentBacktrace(StringBuilder sb) {
646+
TraceType traceType = runtime.getInstanceConfig().getTraceType();
647+
BacktraceData backtraceData = traceType.getBacktrace(this, false);
648+
traceType.getFormat().renderBacktrace(backtraceData.getBacktrace(runtime), sb, false);
641649
}
642-
650+
643651
/**
644652
* Create an Array with backtrace information for Kernel#caller
645653
* @param level
@@ -656,7 +664,8 @@ public IRubyObject createCallerBacktrace(int level, Integer length, StackTraceEl
656664
RubyArray newTrace = runtime.newArray(trace.length);
657665

658666
for (int i = level; i - level < trace.length; i++) {
659-
addBackTraceElement(runtime, newTrace, trace[i - level]);
667+
RubyString str = RubyString.newString(runtime, trace[i - level].mriStyleString());
668+
newTrace.append(str);
660669
}
661670

662671
if (RubyInstanceConfig.LOG_CALLERS) TraceType.dumpCaller(newTrace);

core/src/main/java/org/jruby/runtime/backtrace/BacktraceData.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jruby.runtime.backtrace;
22

33
import org.jruby.Ruby;
4-
import org.jruby.compiler.JITCompiler;
54
import org.jruby.util.JavaNameMangler;
65

76
import java.io.Serializable;
@@ -37,12 +36,12 @@ public BacktraceData(StackTraceElement[] javaTrace, BacktraceElement[] rubyTrace
3736

3837
public RubyStackTraceElement[] getBacktrace(Ruby runtime) {
3938
if (backtraceElements == null) {
40-
backtraceElements = transformBacktrace(runtime.getBoundMethods());
39+
backtraceElements = constructBacktrace(runtime.getBoundMethods());
4140
}
4241
return backtraceElements;
4342
}
4443

45-
private RubyStackTraceElement[] transformBacktrace(Map<String, Map<String, String>> boundMethods) {
44+
private RubyStackTraceElement[] constructBacktrace(Map<String, Map<String, String>> boundMethods) {
4645
List<RubyStackTraceElement> trace = new ArrayList<RubyStackTraceElement>(javaTrace.length);
4746

4847
// used for duplicating the previous Ruby frame when masking native calls

core/src/main/java/org/jruby/runtime/backtrace/TraceType.java

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ public TraceType(Gather gather, Format format) {
2828
this.format = format;
2929
}
3030

31+
public Gather getGather() {
32+
return gather;
33+
}
34+
35+
public Format getFormat() {
36+
return format;
37+
}
38+
3139
/**
3240
* Get a normal Ruby backtrace, using the current Gather type.
3341
*
@@ -214,6 +222,10 @@ public enum Format {
214222
public String printBacktrace(RubyException exception, boolean console) {
215223
return printBacktraceMRI(exception, console);
216224
}
225+
226+
public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
227+
renderBacktraceMRI(elts, buffer, color);
228+
}
217229
},
218230

219231
/**
@@ -223,9 +235,14 @@ public String printBacktrace(RubyException exception, boolean console) {
223235
public String printBacktrace(RubyException exception, boolean console) {
224236
return printBacktraceJRuby(exception, console);
225237
}
238+
239+
public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
240+
renderBacktraceJRuby(elts, buffer, color);
241+
}
226242
};
227243

228244
public abstract String printBacktrace(RubyException exception, boolean console);
245+
public abstract void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color);
229246
}
230247

231248
protected static String printBacktraceMRI(RubyException exception, boolean console) {
@@ -304,16 +321,9 @@ protected static String printBacktraceMRI(RubyException exception, boolean conso
304321

305322
protected static String printBacktraceJRuby(RubyException exception, boolean console) {
306323
Ruby runtime = exception.getRuntime();
307-
RubyStackTraceElement[] frames = exception.getBacktraceElements();
308-
if (frames == null) frames = new RubyStackTraceElement[0];
309-
310-
// find longest method name
311-
int longestMethod = 0;
312-
for (RubyStackTraceElement frame : frames) {
313-
longestMethod = Math.max(longestMethod, frame.getMethodName().length());
314-
}
315324

316325
StringBuilder buffer = new StringBuilder();
326+
boolean color = console && runtime.getInstanceConfig().getBacktraceColor();
317327

318328
// exception line
319329
String message = exception.message(runtime.getCurrentContext()).toString();
@@ -325,8 +335,21 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
325335
.append(": ")
326336
.append(message)
327337
.append('\n');
328-
329-
boolean color = console && runtime.getInstanceConfig().getBacktraceColor();
338+
339+
RubyStackTraceElement[] frames = exception.getBacktraceElements();
340+
if (frames == null) frames = RubyStackTraceElement.EMPTY_ARRAY;
341+
renderBacktraceJRuby(frames, buffer, color);
342+
343+
344+
return buffer.toString();
345+
}
346+
347+
private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color) {
348+
// find longest method name
349+
int longestMethod = 0;
350+
for (RubyStackTraceElement frame : frames) {
351+
longestMethod = Math.max(longestMethod, frame.getMethodName().length());
352+
}
330353

331354
// backtrace lines
332355
boolean first = true;
@@ -341,7 +364,7 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
341364
}
342365
first = false;
343366
}
344-
367+
345368
buffer.append(" ");
346369

347370
// method name
@@ -355,16 +378,28 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
355378
.append(frame.getFileName())
356379
.append(':')
357380
.append(frame.getLineNumber());
358-
381+
359382
if (color) {
360383
buffer.append(CLEAR_COLOR);
361384
}
362-
385+
363386
buffer
364387
.append('\n');
365388
}
389+
}
366390

367-
return buffer.toString();
391+
private static void renderBacktraceMRI(RubyStackTraceElement[] trace, StringBuilder buffer, boolean color) {
392+
for (int i = 0; i < trace.length; i++) {
393+
RubyStackTraceElement element = trace[i];
394+
395+
buffer
396+
.append(element.getFileName())
397+
.append(':')
398+
.append(element.getLineNumber())
399+
.append(":in `")
400+
.append(element.getMethodName())
401+
.append("'\n");
402+
}
368403
}
369404

370405
public static IRubyObject generateMRIBacktrace(Ruby runtime, RubyStackTraceElement[] trace) {

core/src/main/java/org/jruby/runtime/load/LoadService.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,13 +461,12 @@ private void unlock(String requireName) {
461461
}
462462

463463
protected void warnCircularRequire(String requireName) {
464+
StringBuilder sb = new StringBuilder();
465+
466+
runtime.getCurrentContext().renderCurrentBacktrace(sb);
467+
464468
runtime.getWarnings().warn("loading in progress, circular require considered harmful - " + requireName);
465-
// it's a hack for c:rb_backtrace impl.
466-
// We should introduce new method to Ruby.TraceType when rb_backtrace is widely used not only for this purpose.
467-
RaiseException ex = new RaiseException(runtime, runtime.getRuntimeError(), null, false);
468-
String trace = runtime.getInstanceConfig().getTraceType().printBacktrace(ex.getException(), runtime.getPosix().isatty(FileDescriptor.err));
469-
// rb_backtrace dumps to stderr directly.
470-
System.err.print(trace.replaceFirst("[^\n]*\n", ""));
469+
runtime.getErr().print(sb.toString());
471470
}
472471

473472
/**

core/src/main/java/org/jruby/util/io/PopenExecutor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.jruby.runtime.ThreadContext;
2424
import org.jruby.runtime.builtin.IRubyObject;
2525
import org.jruby.util.ByteList;
26-
import org.jruby.util.SafePropertyAccessor;
2726
import org.jruby.util.ShellLauncher;
2827
import org.jruby.util.StringSupport;
2928
import org.jruby.util.TypeConverter;
@@ -314,10 +313,11 @@ public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyC
314313
}
315314

316315
static void execargSetenv(ThreadContext context, Ruby runtime, ExecArg eargp, IRubyObject env) {
317-
eargp.env_modification = !env.isNil() ? checkExecEnv(context, runtime, (RubyHash)env) : null;
316+
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env) : null;
318317
}
319318

320-
static RubyArray checkExecEnv(ThreadContext context, Ruby runtime, RubyHash hash) {
319+
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
320+
Ruby runtime = context.runtime;
321321
RubyArray env;
322322

323323
env = runtime.newArray();
@@ -1769,7 +1769,7 @@ private static void execFillarg(ThreadContext context, RubyString prog, IRubyObj
17691769
}
17701770

17711771
if (!env.isNil()) {
1772-
eargp.env_modification = RubyIO.checkExecEnv(context, (RubyHash)env);
1772+
eargp.env_modification = checkExecEnv(context, (RubyHash) env);
17731773
}
17741774

17751775
prog = prog.export(context);

lib/pom.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ def version
2020
# the versions are declared in ../pom.xml
2121
default_gems =
2222
[
23-
ImportedGem.new( 'jruby-openssl', '0.9.6', true ),
23+
ImportedGem.new( 'jruby-openssl', '0.9.7', true ),
2424
ImportedGem.new( 'jruby-readline', '1.0', false ),
2525
ImportedGem.new( 'rake', 'rake.version', true ),
2626
ImportedGem.new( 'rdoc', 'rdoc.version', true ),
2727
ImportedGem.new( 'json', 'json.version', true ),
28-
ImportedGem.new( 'jar-dependencies', '0.1.10', true ),
28+
ImportedGem.new( 'jar-dependencies', '0.1.12', true ),
2929
ImportedGem.new( 'minitest', 'minitest.version', true ),
3030
ImportedGem.new( 'test-unit', 'test-unit.version', true ),
3131
ImportedGem.new( 'power_assert', 'power_assert.version', true ),

lib/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<dependency>
2929
<groupId>rubygems</groupId>
3030
<artifactId>jruby-openssl</artifactId>
31-
<version>0.9.6</version>
31+
<version>0.9.7</version>
3232
<type>gem</type>
3333
<scope>provided</scope>
3434
<exclusions>
@@ -93,7 +93,7 @@
9393
<dependency>
9494
<groupId>rubygems</groupId>
9595
<artifactId>jar-dependencies</artifactId>
96-
<version>0.1.10</version>
96+
<version>0.1.12</version>
9797
<type>gem</type>
9898
<scope>provided</scope>
9999
<exclusions>

lib/ruby/truffle/mri/delegate.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require_relative '../../stdlib/delegate'

lib/ruby/truffle/mri/tmpdir.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require_relative '../../stdlib/tmpdir'

lib/ruby/truffle/rubysl/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ Commits for each library are:
99
* rubysl-stringio `4b2977296eceef83084146c73d9ddef8d7e8f1af`
1010
* rubysl-complex `ccdb6e86aed5eaada64808f85d03d08d2834294a`
1111
* rubysl-pathname `cdf215804c4349353a60226b5c1d71f695d45570`
12+
* rubysl-tempfile `97c4464b4d235f773aab537fbc80608a730a58fc`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2013, Brian Shirai
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
1. Redistributions of source code must retain the above copyright notice, this
8+
list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright notice,
10+
this list of conditions and the following disclaimer in the documentation
11+
and/or other materials provided with the distribution.
12+
3. Neither the name of the library nor the names of its contributors may be
13+
used to endorse or promote products derived from this software without
14+
specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
20+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25+
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "rubysl/tempfile/version"
2+
require "rubysl/tempfile/tempfile"

0 commit comments

Comments
 (0)