Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
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
chrisseaton committed Apr 16, 2015
2 parents e13cf4b + 245cad9 commit 865c26c
Showing 78 changed files with 943 additions and 332 deletions.
6 changes: 6 additions & 0 deletions core/src/main/java/org/jruby/IncludedModuleWrapper.java
Original file line number Diff line number Diff line change
@@ -205,4 +205,10 @@ public Collection<String> getConstantNames(boolean includePrivate) {
public IRubyObject getAutoloadConstant(String name) {
return origin.getAutoloadConstant(name);
}

@Override
protected DynamicMethod searchMethodCommon(String name) {
// try us and superclasses (from prepend)
return origin.searchMethodInner(name);
}
}
24 changes: 1 addition & 23 deletions core/src/main/java/org/jruby/RubyIO.java
Original file line number Diff line number Diff line change
@@ -4476,29 +4476,7 @@ private static void checkValidOptions(IRubyObject options, Set<String> valid) {

// MRI: check_exec_env, w/ check_exec_env_i body in-line
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
Ruby runtime = context.runtime;
RubyArray env = runtime.newArray();
for (Map.Entry<IRubyObject, IRubyObject> entry : (Set<Map.Entry<IRubyObject, IRubyObject>>)hash.directEntrySet()) {
IRubyObject key = entry.getKey();
IRubyObject val = entry.getValue();
ByteList k;

k = StringSupport.checkEmbeddedNulls(runtime, key).getByteList();
if (k.indexOf('=') != -1)
throw runtime.newArgumentError("environment name contains a equal : " + k);

if (!val.isNil())
StringSupport.checkEmbeddedNulls(runtime, val);

if (Platform.IS_WINDOWS) {
key = ((RubyString)key).export(context);
}
if (!val.isNil()) val = ((RubyString)val).export(context);

env.push(runtime.newArray(key, val));
}

return env;
return PopenExecutor.checkExecEnv(context, hash);
}

/**
15 changes: 9 additions & 6 deletions core/src/main/java/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
@@ -3032,22 +3032,25 @@ public IRubyObject const_get_2_0(ThreadContext context, IRubyObject[] args) {
String symbol = fullName;
boolean inherit = args.length == 1 || (!args[1].isNil() && args[1].isTrue());

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

RubyModule mod = this;

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

int sep;
while((sep = symbol.indexOf("::")) != -1) {
while ((sep = symbol.indexOf("::")) != -1) {
String segment = symbol.substring(0, sep);
symbol = symbol.substring(sep + 2);
IRubyObject obj = mod.getConstant(validateConstant(segment, args[0]), inherit, inherit);
if(obj instanceof RubyModule) {
mod = (RubyModule)obj;
if (obj instanceof RubyModule) {
mod = (RubyModule) obj;
} else {
throw runtime.newTypeError(segment + " does not refer to class/module");
}
19 changes: 14 additions & 5 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@
import org.jruby.internal.runtime.methods.DynamicMethod;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.backtrace.BacktraceData;
import org.jruby.runtime.backtrace.BacktraceElement;
import org.jruby.runtime.backtrace.RubyStackTraceElement;
import org.jruby.runtime.backtrace.TraceType;
@@ -635,11 +636,18 @@ public IRubyObject getConstant(String internedName) {
return getCurrentStaticScope().getConstant(internedName);
}

private static void addBackTraceElement(Ruby runtime, RubyArray backtrace, RubyStackTraceElement element) {
RubyString str = RubyString.newString(runtime, element.mriStyleString());
backtrace.append(str);
/**
* Render the current backtrace as a string to the given StringBuilder. This will honor the currently-configured
* backtrace format and content.
*
* @param sb the StringBuilder to which to render the backtrace
*/
public void renderCurrentBacktrace(StringBuilder sb) {
TraceType traceType = runtime.getInstanceConfig().getTraceType();
BacktraceData backtraceData = traceType.getBacktrace(this, false);
traceType.getFormat().renderBacktrace(backtraceData.getBacktrace(runtime), sb, false);
}

/**
* Create an Array with backtrace information for Kernel#caller
* @param level
@@ -656,7 +664,8 @@ public IRubyObject createCallerBacktrace(int level, Integer length, StackTraceEl
RubyArray newTrace = runtime.newArray(trace.length);

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

if (RubyInstanceConfig.LOG_CALLERS) TraceType.dumpCaller(newTrace);
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jruby.runtime.backtrace;

import org.jruby.Ruby;
import org.jruby.compiler.JITCompiler;
import org.jruby.util.JavaNameMangler;

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

public RubyStackTraceElement[] getBacktrace(Ruby runtime) {
if (backtraceElements == null) {
backtraceElements = transformBacktrace(runtime.getBoundMethods());
backtraceElements = constructBacktrace(runtime.getBoundMethods());
}
return backtraceElements;
}

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

// used for duplicating the previous Ruby frame when masking native calls
63 changes: 49 additions & 14 deletions core/src/main/java/org/jruby/runtime/backtrace/TraceType.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,14 @@ public TraceType(Gather gather, Format format) {
this.format = format;
}

public Gather getGather() {
return gather;
}

public Format getFormat() {
return format;
}

/**
* Get a normal Ruby backtrace, using the current Gather type.
*
@@ -214,6 +222,10 @@ public enum Format {
public String printBacktrace(RubyException exception, boolean console) {
return printBacktraceMRI(exception, console);
}

public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
renderBacktraceMRI(elts, buffer, color);
}
},

/**
@@ -223,9 +235,14 @@ public String printBacktrace(RubyException exception, boolean console) {
public String printBacktrace(RubyException exception, boolean console) {
return printBacktraceJRuby(exception, console);
}

public void renderBacktrace(RubyStackTraceElement[] elts, StringBuilder buffer, boolean color) {
renderBacktraceJRuby(elts, buffer, color);
}
};

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

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

protected static String printBacktraceJRuby(RubyException exception, boolean console) {
Ruby runtime = exception.getRuntime();
RubyStackTraceElement[] frames = exception.getBacktraceElements();
if (frames == null) frames = new RubyStackTraceElement[0];

// find longest method name
int longestMethod = 0;
for (RubyStackTraceElement frame : frames) {
longestMethod = Math.max(longestMethod, frame.getMethodName().length());
}

StringBuilder buffer = new StringBuilder();
boolean color = console && runtime.getInstanceConfig().getBacktraceColor();

// exception line
String message = exception.message(runtime.getCurrentContext()).toString();
@@ -325,8 +335,21 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
.append(": ")
.append(message)
.append('\n');

boolean color = console && runtime.getInstanceConfig().getBacktraceColor();

RubyStackTraceElement[] frames = exception.getBacktraceElements();
if (frames == null) frames = RubyStackTraceElement.EMPTY_ARRAY;
renderBacktraceJRuby(frames, buffer, color);


return buffer.toString();
}

private static void renderBacktraceJRuby(RubyStackTraceElement[] frames, StringBuilder buffer, boolean color) {
// find longest method name
int longestMethod = 0;
for (RubyStackTraceElement frame : frames) {
longestMethod = Math.max(longestMethod, frame.getMethodName().length());
}

// backtrace lines
boolean first = true;
@@ -341,7 +364,7 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
}
first = false;
}

buffer.append(" ");

// method name
@@ -355,16 +378,28 @@ protected static String printBacktraceJRuby(RubyException exception, boolean con
.append(frame.getFileName())
.append(':')
.append(frame.getLineNumber());

if (color) {
buffer.append(CLEAR_COLOR);
}

buffer
.append('\n');
}
}

return buffer.toString();
private static void renderBacktraceMRI(RubyStackTraceElement[] trace, StringBuilder buffer, boolean color) {
for (int i = 0; i < trace.length; i++) {
RubyStackTraceElement element = trace[i];

buffer
.append(element.getFileName())
.append(':')
.append(element.getLineNumber())
.append(":in `")
.append(element.getMethodName())
.append("'\n");
}
}

public static IRubyObject generateMRIBacktrace(Ruby runtime, RubyStackTraceElement[] trace) {
11 changes: 5 additions & 6 deletions core/src/main/java/org/jruby/runtime/load/LoadService.java
Original file line number Diff line number Diff line change
@@ -461,13 +461,12 @@ private void unlock(String requireName) {
}

protected void warnCircularRequire(String requireName) {
StringBuilder sb = new StringBuilder();

runtime.getCurrentContext().renderCurrentBacktrace(sb);

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

/**
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.builtin.IRubyObject;
import org.jruby.util.ByteList;
import org.jruby.util.SafePropertyAccessor;
import org.jruby.util.ShellLauncher;
import org.jruby.util.StringSupport;
import org.jruby.util.TypeConverter;
@@ -314,10 +313,11 @@ public static IRubyObject popen(ThreadContext context, IRubyObject[] argv, RubyC
}

static void execargSetenv(ThreadContext context, Ruby runtime, ExecArg eargp, IRubyObject env) {
eargp.env_modification = !env.isNil() ? checkExecEnv(context, runtime, (RubyHash)env) : null;
eargp.env_modification = !env.isNil() ? checkExecEnv(context, (RubyHash)env) : null;
}

static RubyArray checkExecEnv(ThreadContext context, Ruby runtime, RubyHash hash) {
public static RubyArray checkExecEnv(ThreadContext context, RubyHash hash) {
Ruby runtime = context.runtime;
RubyArray env;

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

if (!env.isNil()) {
eargp.env_modification = RubyIO.checkExecEnv(context, (RubyHash)env);
eargp.env_modification = checkExecEnv(context, (RubyHash) env);
}

prog = prog.export(context);
4 changes: 2 additions & 2 deletions lib/pom.rb
Original file line number Diff line number Diff line change
@@ -20,12 +20,12 @@ def version
# the versions are declared in ../pom.xml
default_gems =
[
ImportedGem.new( 'jruby-openssl', '0.9.6', true ),
ImportedGem.new( 'jruby-openssl', '0.9.7', true ),
ImportedGem.new( 'jruby-readline', '1.0', false ),
ImportedGem.new( 'rake', 'rake.version', true ),
ImportedGem.new( 'rdoc', 'rdoc.version', true ),
ImportedGem.new( 'json', 'json.version', true ),
ImportedGem.new( 'jar-dependencies', '0.1.10', true ),
ImportedGem.new( 'jar-dependencies', '0.1.12', true ),
ImportedGem.new( 'minitest', 'minitest.version', true ),
ImportedGem.new( 'test-unit', 'test-unit.version', true ),
ImportedGem.new( 'power_assert', 'power_assert.version', true ),
4 changes: 2 additions & 2 deletions lib/pom.xml
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@
<dependency>
<groupId>rubygems</groupId>
<artifactId>jruby-openssl</artifactId>
<version>0.9.6</version>
<version>0.9.7</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
@@ -93,7 +93,7 @@
<dependency>
<groupId>rubygems</groupId>
<artifactId>jar-dependencies</artifactId>
<version>0.1.10</version>
<version>0.1.12</version>
<type>gem</type>
<scope>provided</scope>
<exclusions>
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/delegate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../stdlib/delegate'
1 change: 1 addition & 0 deletions lib/ruby/truffle/mri/tmpdir.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require_relative '../../stdlib/tmpdir'
1 change: 1 addition & 0 deletions lib/ruby/truffle/rubysl/README.md
Original file line number Diff line number Diff line change
@@ -9,3 +9,4 @@ Commits for each library are:
* rubysl-stringio `4b2977296eceef83084146c73d9ddef8d7e8f1af`
* rubysl-complex `ccdb6e86aed5eaada64808f85d03d08d2834294a`
* rubysl-pathname `cdf215804c4349353a60226b5c1d71f695d45570`
* rubysl-tempfile `97c4464b4d235f773aab537fbc80608a730a58fc`
25 changes: 25 additions & 0 deletions lib/ruby/truffle/rubysl/rubysl-tempfile/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2013, Brian Shirai
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. Neither the name of the library nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "rubysl/tempfile/version"
require "rubysl/tempfile/tempfile"
Loading

0 comments on commit 865c26c

Please sign in to comment.