Skip to content

Commit

Permalink
Merge branch 'master' into truffle-head
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Dec 29, 2014
2 parents 126a6e6 + 41bcacf commit ee07e39
Show file tree
Hide file tree
Showing 28 changed files with 307 additions and 129 deletions.
29 changes: 16 additions & 13 deletions core/src/main/java/org/jruby/embed/IsolatedScriptingContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.net.URL;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

import org.osgi.framework.Bundle;

Expand Down Expand Up @@ -64,21 +66,22 @@ public IsolatedScriptingContainer( LocalContextScope scope,
{
super(scope, behavior, lazy);

// get the right classloader
ClassLoader cl = this.getClass().getClassLoader();
if (cl == null) cl = Thread.currentThread().getContextClassLoader();
setClassLoader( cl );

setLoadPaths( Arrays.asList( "uri:classloader:" ) );

// set the right jruby home
setHomeDirectory( "uri:classloader:" + JRUBY_HOME );

// setup the isolated GEM_PATH, i.e. without $HOME/.gem/**
runScriptlet("require 'rubygems/defaults/jruby';"
+ "Gem::Specification.reset;"
+ "Gem::Specification.add_dir 'uri:classloader:" + JRUBY_HOME + "/lib/ruby/gems/shared';"
+ "Gem::Specification.add_dir 'uri:classloader:';");
setEnvironment(null);
}

@Override
public void setEnvironment(Map environment) {
if (environment == null || !environment.containsKey("GEM_PATH")) {
Map env = environment == null ? new HashMap() : new HashMap(environment);
env.put("GEM_PATH", "");
super.setEnvironment(env);
}
else {
super.setEnvironment(environment);
}
}

public void addLoadPath( ClassLoader cl ) {
Expand Down Expand Up @@ -140,6 +143,6 @@ private String createUri(ClassLoader cl, String ref) {
}

private void addGemPath(String uri) {
runScriptlet( "Gem::Specification.add_dir '" + uri + "' unless Gem::Specification.dirs.member?( '" + uri + "' )" );
runScriptlet( "require 'rubygems/defaults/jruby';Gem::Specification.add_dir '" + uri + "' unless Gem::Specification.dirs.member?( '" + uri + "' )" );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,9 @@ public static String findJRubyHome(Object instance) {
return jrubyhome;
} else if ((jrubyhome = SafePropertyAccessor.getProperty("jruby.home")) != null) {
return jrubyhome;
} else if (Thread.currentThread().getContextClassLoader() == null ||
Thread.currentThread().getContextClassLoader().equals(SystemPropertyCatcher.class.getClassLoader())) {
} else {
return "uri:classloader://META-INF/jruby.home";
}
else {
return "classpath:/META-INF/jruby.home";
}
}

public static String findFromJar(Object instance) {
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/jruby/truffle/TruffleBridgeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TimeNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrueClassNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TruffleDebugNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TrufflePrimitiveNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, EncodingConverterNodesFactory.getFactories());

Expand Down Expand Up @@ -134,6 +135,9 @@ public void init() {
// Libraries copied unmodified from MRI
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/mri").toString()));

// Shims
loadPath.slowPush(truffleContext.makeString(new File(home, "lib/ruby/truffle/shims").toString()));

// Hook

if (truffleContext.getHooks() != null) {
Expand Down
19 changes: 17 additions & 2 deletions core/src/main/java/org/jruby/truffle/nodes/core/BindingNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,23 @@ public LocalVariableSetNode(LocalVariableSetNode prev) {
public Object localVariableSetNode(RubyBinding binding, RubySymbol symbol, Object value) {
notDesignedForCompilation();

final MaterializedFrame frame = binding.getFrame();
frame.setObject(frame.getFrameDescriptor().findFrameSlot(symbol.toString()), value);
MaterializedFrame frame = binding.getFrame();

while (true) {
final FrameSlot frameSlot = frame.getFrameDescriptor().findFrameSlot(symbol.toString());

if (frameSlot != null) {
frame.setObject(frameSlot, value);
break;
}

frame = RubyArguments.getDeclarationFrame(frame.getArguments());

if (frame == null) {
throw new UnsupportedOperationException();
}
}

return value;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright (c) 2013, 2014 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.core;

import com.oracle.truffle.api.Truffle;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.frame.FrameInstance;
import com.oracle.truffle.api.frame.FrameInstanceVisitor;
import com.oracle.truffle.api.frame.MaterializedFrame;
import com.oracle.truffle.api.source.SourceSection;
import org.jruby.truffle.runtime.DebugOperations;
import org.jruby.truffle.runtime.RubyArguments;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.core.RubyBinding;
import org.jruby.util.Memo;

@CoreClass(name = "Truffle::Primitive")
public abstract class TrufflePrimitiveNodes {

@CoreMethod(names = "binding_of_caller", onSingleton = true)
public abstract static class BindingOfCallerNode extends CoreMethodNode {

public BindingOfCallerNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

public BindingOfCallerNode(BindingOfCallerNode prev) {
super(prev);
}

@Specialization
public RubyBinding bindingOfCaller() {
/*
* When you use this method you're asking for the binding of the caller at the call site. When we get into
* this method, that is then the binding of the caller of the caller.
*/

notDesignedForCompilation();

final Memo<Integer> frameCount = new Memo<>(0);

final MaterializedFrame frame = Truffle.getRuntime().iterateFrames(new FrameInstanceVisitor<MaterializedFrame>() {

@Override
public MaterializedFrame visitFrame(FrameInstance frameInstance) {
if (frameCount.get() == 1) {
return frameInstance.getFrame(FrameInstance.FrameAccess.READ_WRITE, false).materialize();
} else {
frameCount.set(frameCount.get() + 1);
return null;
}
}

});

return new RubyBinding(
getContext().getCoreLibrary().getBindingClass(),
RubyArguments.getSelf(frame.getArguments()),
frame);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,6 @@ protected Object singletonClass(double value) {
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(this));
}

@Specialization
protected Object singletonClass(RubyBignum value) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().typeErrorCantDefineSingleton(this));
}

@Specialization
protected RubyClass singletonClass(RubyBasicObject object) {
return object.getSingletonClass(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ public void initialize() {
trueClass = new RubyClass(context, objectClass, objectClass, "TrueClass");
truffleModule = new RubyModule(context, objectClass, "Truffle");
truffleDebugModule = new RubyModule(context, truffleModule, "Debug");
new RubyModule(context, truffleModule, "Primitive");
typeErrorClass = new RubyClass(context, objectClass, standardErrorClass, "TypeError");
typeErrorClass.setAllocator(new RubyException.ExceptionAllocator());
zeroDivisionErrorClass = new RubyClass(context, objectClass, standardErrorClass, "ZeroDivisionError");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ public RubyBignum(RubyClass rubyClass, BigInteger value) {
this.value = value;
}

@Override
public boolean hasNoSingleton() {
return true;
}

@CompilerDirectives.TruffleBoundary
public RubyBignum negate() {
return create(value.negate());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public boolean require(String feature, RubyNode currentNode) throws IOException
try {
// Some features are handled specially

if (feature.equals("stringio")) {
context.getCoreLibrary().loadRubyCore("jruby/truffle/standard/stringio.rb");
return true;
}

if (feature.equals("zlib")) {
context.getWarnings().warn("zlib not yet implemented");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ public class BodyTranslator extends Translator {
debugIgnoredCalls.add("upto");
}

public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$+", "$&", "$`", "$'"));
public static final Set<String> THREAD_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$~", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9"));
public static final Set<String> FRAME_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$_", "$+", "$&", "$`", "$'"));
public static final Set<String> THREAD_LOCAL_GLOBAL_VARIABLES = new HashSet<>(Arrays.asList("$~", "$1", "$2", "$3", "$4", "$5", "$6", "$7", "$8", "$9")); // "$_"

public BodyTranslator(RubyNode currentNode, RubyContext context, BodyTranslator parent, TranslatorEnvironment environment, Source source, boolean topLevel) {
super(currentNode, context, source);
Expand Down Expand Up @@ -1146,7 +1146,7 @@ public RubyNode visitGlobalAsgnNode(org.jruby.ast.GlobalAsgnNode node) {
return new WriteInstanceVariableNode(context, sourceSection, name, threadLocalVariablesObjectNode, rhs, true);
} else if (FRAME_LOCAL_GLOBAL_VARIABLES.contains(name)) {
if (environment.getNeverAssignInParentScope()) {
environment.declareVar(node.getName());
environment.declareVar(name);
}

RubyNode localVarNode = environment.findLocalVarNode(node.getName(), sourceSection);
Expand Down
1 change: 0 additions & 1 deletion core/src/main/ruby/jruby/truffle/standard/stringio.rb

This file was deleted.

2 changes: 1 addition & 1 deletion default.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ version.ruby=2.2.0
version.ruby.major=2.2
version.ruby.minor=0
version.ruby.patchlevel=0
version.ruby.revision=48765
version.ruby.revision=49005
21 changes: 17 additions & 4 deletions lib/ruby/stdlib/erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -797,8 +797,9 @@ def initialize(str, safe_level=nil, trim_mode=nil, eoutvar='_erbout')
@safe_level = safe_level
compiler = make_compiler(trim_mode)
set_eoutvar(compiler, eoutvar)
@src, @enc = *compiler.compile(str)
@src, @encoding = *compiler.compile(str)
@filename = nil
@lineno = 0
end

##
Expand All @@ -811,10 +812,22 @@ def make_compiler(trim_mode)
# The Ruby code generated by ERB
attr_reader :src

# The encoding to eval
attr_reader :encoding

# The optional _filename_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :filename

# The optional _lineno_ argument passed to Kernel#eval when the ERB code
# is run
attr_accessor :lineno

def location=((filename, lineno))
@filename = filename
@lineno = lineno if lineno
end

#
# Can be used to set _eoutvar_ as described in ERB::new. It's probably
# easier to just use the constructor though, since calling this method
Expand Down Expand Up @@ -844,10 +857,10 @@ def result(b=new_toplevel)
if @safe_level
proc {
$SAFE = @safe_level
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
}.call
else
eval(@src, b, (@filename || '(erb)'), 0)
eval(@src, b, (@filename || '(erb)'), @lineno)
end
end

Expand All @@ -869,7 +882,7 @@ def new_toplevel
# print MyClass.new.render('foo', 123)
def def_method(mod, methodname, fname='(ERB)')
src = self.src
magic_comment = "#coding:#{@enc}\n"
magic_comment = "#coding:#{@encoding}\n"
mod.module_eval do
eval(magic_comment + "def #{methodname}\n" + src + "\nend\n", binding, fname, -2)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ruby/stdlib/net/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_new(sock) #:nodoc: internal use only

def read_status_line(sock)
str = sock.readline
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)\s*(.*)\z/in.match(str) or
m = /\AHTTP(?:\/(\d+\.\d+))?\s+(\d\d\d)(?:\s+(.*))?\z/in.match(str) or
raise Net::HTTPBadResponse, "wrong status line: #{str.dump}"
m.captures
end
Expand Down
12 changes: 7 additions & 5 deletions lib/ruby/stdlib/open-uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,12 @@ def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
http.verify_mode = options[:ssl_verify_mode] || OpenSSL::SSL::VERIFY_PEER
store = OpenSSL::X509::Store.new
if options[:ssl_ca_cert]
if File.directory? options[:ssl_ca_cert]
store.add_path options[:ssl_ca_cert]
else
store.add_file options[:ssl_ca_cert]
Array(options[:ssl_ca_cert]).each do |cert|
if File.directory? cert
store.add_path cert
else
store.add_file cert
end
end
else
store.set_default_paths
Expand Down Expand Up @@ -680,7 +682,7 @@ module OpenRead
#
# [:ssl_ca_cert]
# Synopsis:
# :ssl_ca_cert=>filename
# :ssl_ca_cert=>filename or an Array of filenames
#
# :ssl_ca_cert is used to specify CA certificate for SSL.
# If it is given, default certificates are not used.
Expand Down
Loading

0 comments on commit ee07e39

Please sign in to comment.