Skip to content

Commit

Permalink
Merge branch 'master' into rbx-2.5.6-upgrade
Browse files Browse the repository at this point in the history
Conflicts:
	truffle/src/main/java/org/jruby/truffle/nodes/core/RangeNodes.java
	truffle/src/main/java/org/jruby/truffle/nodes/rubinius/PosixNodes.java
	truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
nirvdrum committed Jun 18, 2015
2 parents acec36b + 7b22490 commit 1da2096
Showing 109 changed files with 1,284 additions and 1,179 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -75,8 +75,6 @@ matrix:
fast_finish: true
allow_failures:
- env: COMMAND=test/truffle/run.sh
- env: PHASE='-Ptruffle-mri-tests'


branches:
only:
@@ -85,8 +83,9 @@ branches:
- /^test-.*$/
- /^ha-feature/

script: if [[ -v COMMAND ]]; then $COMMAND; else travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip=false $PHASE | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]; fi
install: /bin/true
script: if [[ -v COMMAND ]]; then $COMMAND; else ./mvnw install -Dinvoker.skip=false $PHASE | egrep -v 'Download|\\[exec\\] [[:digit:]]+/[[:digit:]]+|^[[:space:]]*\\[exec\\][[:space:]]*$' ; [ ${PIPESTATUS[0]} == 0 ]; fi
install: travis_retry ./mvnw -Pbootstrap clean install -Dinvoker.skip -Dmaven.test.skip

notifications:
irc:
channels:
5 changes: 2 additions & 3 deletions bin/jruby.bash
Original file line number Diff line number Diff line change
@@ -146,9 +146,8 @@ for j in "$JRUBY_HOME"/lib/jruby.jar "$JRUBY_HOME"/lib/jruby-complete.jar; do
JRUBY_ALREADY_ADDED=true
done

# The Truffle jar always needs to be on the boot classpath so that the VM can
# substitute classes. We add it even if the jar isn't necessarily available,
# but this doesn't cause any problems.
# The Truffle jar always needs to be on the boot classpath, if it exists, so
# that the VM can substitute classes.
if [ -e "$JRUBY_HOME/lib/jruby-truffle.jar" ]; then
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
fi
5 changes: 2 additions & 3 deletions bin/jruby.sh
Original file line number Diff line number Diff line change
@@ -107,9 +107,8 @@ for j in "$JRUBY_HOME"/lib/jruby.jar "$JRUBY_HOME"/lib/jruby-complete.jar; do
JRUBY_ALREADY_ADDED=true
done

# The Truffle jar always needs to be on the boot classpath so that the VM can
# substitute classes. We add it even if the jar isn't necessarily available,
# but this doesn't cause any problems.
# The Truffle jar always needs to be on the boot classpath, if it exists, so
# that the VM can substitute classes.
if [ -e "$JRUBY_HOME/lib/jruby-truffle.jar" ]; then
JRUBY_CP="$JRUBY_CP$CP_DELIMITER$JRUBY_HOME/lib/jruby-truffle.jar"
fi
23 changes: 11 additions & 12 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -692,25 +692,24 @@ public IRubyObject runWithGetsLoop(Node scriptNode, boolean printing, boolean pr
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) {
ISourcePosition pos = oldRoot.getPosition();
BlockNode newBody = new BlockNode(pos);
newBody.add(new GlobalAsgnNode(pos, "$/", new StrNode(pos, new ByteList(getInstanceConfig().getRecordSeparator().getBytes()))));

if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/")));

BlockNode whileBody;
if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
whileBody = (BlockNode) oldRoot.getBodyNode();
} else { // single expr script
whileBody = new BlockNode(pos);
whileBody.add(oldRoot.getBodyNode());
}

newBody.prepend(new GlobalAsgnNode(pos, "$/", new StrNode(pos, new ByteList(getInstanceConfig().getRecordSeparator().getBytes()))));
GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_");

BlockNode whileBody = new BlockNode(pos);
newBody.add(new WhileNode(pos, new VCallNode(pos, "gets"), whileBody));

if (printing) whileBody.prepend(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));
if (split) whileBody.prepend(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
if (processLineEndings) whileBody.prepend(new CallNode(pos, dollarUnderscore, "chop!", null, null));
if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, "chop!", null, null));
if (split) whileBody.add(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
if (printing) whileBody.add(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));

if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
whileBody.addAll(oldRoot.getBodyNode());
} else { // single expr script
whileBody.add(oldRoot.getBodyNode());
}

return new RootNode(pos, oldRoot.getScope(), newBody);
}
16 changes: 16 additions & 0 deletions core/src/main/java/org/jruby/RubyFile.java
Original file line number Diff line number Diff line change
@@ -628,6 +628,7 @@ public static IRubyObject dirname(ThreadContext context, IRubyObject recv, IRuby
return runtime.newString(dirname(context, jfilename)).infectBy(filename);
}

private static Pattern PROTOCOL_PATTERN = Pattern.compile("^([a-z]+:)?[a-z]+:/.*");
public static String dirname(ThreadContext context, String jfilename) {
String name = jfilename.replace('\\', '/');
int minPathLength = 1;
@@ -639,6 +640,21 @@ public static String dirname(ThreadContext context, String jfilename) {
minPathLength = 3;
}

// jar like paths
if (name.contains("!/")) {
int start = name.indexOf("!/") + 1;
String path = dirname(context, name.substring(start));
if (path.equals(".") || path.equals("/")) path = "";
return name.substring(0, start) + path;
}
// address all the url like paths first
if (PROTOCOL_PATTERN.matcher(name).matches()) {
int start = name.indexOf(":/") + 2;
String path = dirname(context, name.substring(start));
if (path.equals(".")) path = "";
return name.substring(0, start) + path;
}

while (name.length() > minPathLength && name.charAt(name.length() - 1) == '/') {
trimmedSlashes = true;
name = name.substring(0, name.length() - 1);
2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyInstanceConfig.java
Original file line number Diff line number Diff line change
@@ -391,7 +391,7 @@ public InputStream getScriptSource() {
return getInput();
} else {
final String script = getScriptFileName();
FileResource resource = JRubyFile.createResource(null, getCurrentDirectory(), getScriptFileName());
FileResource resource = JRubyFile.createRestrictedResource(getCurrentDirectory(), getScriptFileName());
if (resource != null && resource.exists()) {
if (resource.isFile() || resource.isSymLink()) {
if (isXFlag()) {
10 changes: 3 additions & 7 deletions core/src/main/java/org/jruby/ast/ArgsNode.java
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@

import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
import org.jruby.runtime.Helpers;

/**
* Represents the argument declarations of a method. The fields:
@@ -225,16 +226,11 @@ public int getRequiredKeywordCount() {
if (keywords == null) return 0;

int count = 0;
for (Node keyWordNode :getKeywords().childNodes()) {
for (Node keyWordNode : getKeywords().children()) {
for (Node asgnNode : keyWordNode.childNodes()) {
if (isRequiredKeywordArgumentValueNode(asgnNode)) count++;
if (Helpers.isRequiredKeywordArgumentValueNode(asgnNode)) count++;
}
}
return count;
}

private boolean isRequiredKeywordArgumentValueNode(Node asgnNode) {
return asgnNode.childNodes().get(0) instanceof RequiredKeywordArgumentValueNode;
}

}
73 changes: 48 additions & 25 deletions core/src/main/java/org/jruby/ast/ListNode.java
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@
***** END LICENSE BLOCK *****/
package org.jruby.ast;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jruby.ast.visitor.NodeVisitor;
import org.jruby.lexer.yacc.ISourcePosition;
@@ -41,7 +41,10 @@
* the editor projects who want position info saved.
*/
public class ListNode extends Node {
private List<Node> list;
private static final Node[] EMPTY = new Node[0];
private static final int INITIAL_SIZE = 4;
private Node[] list;
private int size = 0;

/**
* Create a new ListNode.
@@ -52,49 +55,62 @@ public class ListNode extends Node {
public ListNode(ISourcePosition position, Node firstNode) {
super(position, firstNode != null && firstNode.containsVariableAssignment);

list = new ArrayList<>(4);
list.add(firstNode);
list = new Node[INITIAL_SIZE];
addInternal(firstNode);
}

public ListNode(ISourcePosition position) {
super(position, false);

list = new ArrayList<>(0);
list = EMPTY;
}

public NodeType getNodeType() {
return NodeType.LISTNODE;
}

protected void growList(int mustBeDelta) {
int newSize = list.length * 2;
// Fairly arbitrary to scale 1.5 here but this means we are adding a lot so I think
// we can taper the multiplier
if (size + mustBeDelta >= newSize) newSize = (int) ((size + mustBeDelta) * 1.5);

Node[] newList = new Node[newSize];
System.arraycopy(list, 0, newList, 0, size);
list = newList;
}

protected void addInternal(Node node) {
if (size >= list.length) growList(1);

list[size++] = node;
}

protected void addAllInternal(ListNode other) {
if (size + other.size() >= list.length) growList(other.size);

System.arraycopy(other.list, 0, list, size, other.size);
size += other.size;
}

public ListNode add(Node node) {
// Ruby Grammar productions return plenty of nulls.
if (node == null || node == NilImplicitNode.NIL) {
list.add(NilImplicitNode.NIL);
addInternal(NilImplicitNode.NIL);

return this;
}

if (node.containsVariableAssignment()) containsVariableAssignment = true;
list.add(node);
addInternal(node);

if (getPosition() == null) setPosition(node.getPosition());

return this;
}

public ListNode prepend(Node node) {
// Ruby Grammar productions return plenty of nulls.
if (node == null) return this;

if (node.containsVariableAssignment()) containsVariableAssignment = true;
list.add(0, node);

setPosition(node.getPosition());
return this;
}

public int size() {
return list.size();
return size;
}


@@ -107,7 +123,7 @@ public int size() {
public ListNode addAll(ListNode other) {
if (other != null && other.size() > 0) {
if (other.containsVariableAssignment()) containsVariableAssignment = true;
list.addAll(other.list);
addAllInternal(other);

if (getPosition() == null) setPosition(other.getPosition());
}
@@ -125,22 +141,29 @@ public ListNode addAll(Node other) {
}

public Node getLast() {
return list.size() == 0 ? null : list.get(list.size() - 1);
return size == 0 ? null : list[size - 1];
}

public boolean isEmpty() {
return list.isEmpty();
return size == 0;
}


public Node[] children() {
Node[] properList = new Node[size];
System.arraycopy(list, 0, properList, 0, size);
return properList;
}

@Deprecated
public List<Node> childNodes() {
return list;
return Arrays.asList(children());
}

public <T> T accept(NodeVisitor<T> visitor) {
return visitor.visitListNode(this);
}

public Node get(int idx) {
return list.get(idx);
return list[idx];
}
}
9 changes: 3 additions & 6 deletions core/src/main/java/org/jruby/ast/ZArrayNode.java
Original file line number Diff line number Diff line change
@@ -41,9 +41,9 @@
* zero length list
*
*/
public class ZArrayNode extends Node implements ILiteralNode {
public class ZArrayNode extends ListNode implements ILiteralNode {
public ZArrayNode(ISourcePosition position) {
super(position, false);
super(position);
}

public NodeType getNodeType() {
@@ -52,13 +52,10 @@ public NodeType getNodeType() {

/**
* Accept for the visitor pattern.
*
* @param iVisitor the visitor
**/
public <T> T accept(NodeVisitor<T> iVisitor) {
return iVisitor.visitZArrayNode(this);
}

public List<Node> childNodes() {
return EMPTY_LIST;
}
}
20 changes: 7 additions & 13 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
@@ -5,11 +5,6 @@
import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.wiring.BundleWiring;

/**
* the IsolatedScriptingContainer does set GEM_HOME and GEM_PATH and JARS_HOME
* in such a way that it uses only resources which can be reached with classloader.
@@ -75,10 +70,10 @@ public void setEnvironment(Map environment) {
}
}

private Bundle toBundle(String symbolicName) {
BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
Bundle bundle = null;
for (Bundle b : context.getBundles()) {
private org.osgi.framework.Bundle toBundle(String symbolicName) {
org.osgi.framework.BundleContext context = org.osgi.framework.FrameworkUtil.getBundle(getClass()).getBundleContext();
org.osgi.framework.Bundle bundle = null;
for (org.osgi.framework.Bundle b : context.getBundles()) {
if (b.getSymbolicName().equals(symbolicName)) {
bundle = b;
break;
@@ -90,22 +85,21 @@ private Bundle toBundle(String symbolicName) {
return bundle;
}

private String createUri(Bundle cl, String ref) {
private String createUri(org.osgi.framework.Bundle cl, String ref) {
URL url = cl.getResource( ref );
if ( url == null && ref.startsWith( "/" ) ) {
url = cl.getResource( ref.substring( 1 ) );
}
if ( url == null ) {
throw new RuntimeException( "reference " + ref + " not found on classloader " + cl );
}
System.err.println("=---" + url.toString().replaceFirst( ref + "$", "" ));
return "uri:" + url.toString().replaceFirst( ref + "$", "" );
}
/**
* add the classloader from the given bundle to the LOAD_PATH
* @param bundle
*/
public void addBundleToLoadPath(Bundle bundle) {
public void addBundleToLoadPath(org.osgi.framework.Bundle bundle) {
addLoadPath(createUri(bundle, "/.jrubydir"));
}

@@ -123,7 +117,7 @@ public void addBundleToLoadPath(String symbolicName) {
* add the classloader from the given bundle to the GEM_PATH
* @param bundle
*/
public void addBundleToGemPath(Bundle bundle) {
public void addBundleToGemPath(org.osgi.framework.Bundle bundle) {
addGemPath(createUri(bundle, "/specifications/.jrubydir"));
}

Loading

0 comments on commit 1da2096

Please sign in to comment.