Skip to content

Commit

Permalink
Showing 22 changed files with 301 additions and 146 deletions.
20 changes: 13 additions & 7 deletions core/src/main/java/org/jruby/RubyEnumerator.java
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@
/**
* Implementation of Ruby's Enumerator module.
*/
@JRubyModule(name="Enumerable::Enumerator", include="Enumerable")
@JRubyModule(name="Enumerator", include="Enumerable")
public class RubyEnumerator extends RubyObject {
/** target for each operation */
private IRubyObject object;
@@ -75,7 +75,7 @@ public static void defineEnumerator(Ruby runtime) {
final RubyModule Enumerable = runtime.getModule("Enumerable");

final RubyClass Enumerator;
Enumerator = runtime.defineClass("Enumerator", runtime.getObject(), ENUMERATOR_ALLOCATOR);
Enumerator = runtime.defineClass("Enumerator", runtime.getObject(), ALLOCATOR);

Enumerator.includeModule(Enumerable);
Enumerator.defineAnnotatedMethods(RubyEnumerator.class);
@@ -85,7 +85,7 @@ public static void defineEnumerator(Ruby runtime) {
RubyYielder.createYielderClass(runtime);
}

private static ObjectAllocator ENUMERATOR_ALLOCATOR = new ObjectAllocator() {
private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@Override
public IRubyObject allocate(Ruby runtime, RubyClass klass) {
return new RubyEnumerator(runtime, klass);
@@ -477,20 +477,26 @@ public IRubyObject each_with_index(ThreadContext context, final Block block) {
return with_index_common(context, block, "each_with_index", context.nil);
}

@JRubyMethod(name = "with_index")
public IRubyObject with_index(ThreadContext context, final Block block) {
return with_index19(context, block);
return with_index_common(context, block, "with_index", context.nil);
}

@JRubyMethod(name = "with_index")
@Deprecated
public IRubyObject with_index19(ThreadContext context, final Block block) {
return with_index_common(context, block, "with_index", context.nil);
return with_index(context, block);
}

@JRubyMethod(name = "with_index")
public IRubyObject with_index19(ThreadContext context, IRubyObject arg, final Block block) {
public IRubyObject with_index(ThreadContext context, IRubyObject arg, final Block block) {
return with_index_common(context, block, "with_index", arg);
}

@Deprecated
public IRubyObject with_index19(ThreadContext context, IRubyObject arg, final Block block) {
return with_index(context, arg, block);
}

private volatile Nexter nexter = null;

@JRubyMethod
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
---
IntegrationProcessTest:
- test_cookie_persist_to_next_request
- test_https_and_port_via_host_and_https!
- test_https_and_port_via_process
- test_port_via_host!
- test_port_via_process
- test_cookie_persist_to_next_request_on_another_domain
- test_get
- test_get_with_parameters
- test_get_with_query_string
- test_get_xml_rss_atom
- test_head
- test_post
- test_redirect
- test_request_with_bad_format
- test_respect_removal_of_default_headers_by_a_controller_action
- test_response_cookies_are_added_to_the_cookie_jar_for_the_next_request
- test_xml_http_request_get
ExpiresInRenderTest:
- test_dynamic_render_with_file
- test_permitted_dynamic_render_file_hash
17 changes: 13 additions & 4 deletions mx.jruby/mx_jruby.py
Original file line number Diff line number Diff line change
@@ -193,14 +193,19 @@ def clean(self, forBuild=False):
def extractArguments(args):
vmArgs = []
rubyArgs = []
for i in range(len(args)):
arg = args[i]
if arg.startswith('-J-'):
while args:
arg = args.pop(0)
if arg == '-J-cp' or arg == '-J-classpath':
vmArgs.append(arg[2:])
vmArgs.append(args.pop(0))
elif arg.startswith('-J-'):
vmArgs.append(arg[2:])
elif arg.startswith('-X'):
vmArgs.append('-Djruby.' + arg[2:])
else:
rubyArgs.append(arg)
rubyArgs.extend(args)
break
return vmArgs, rubyArgs

def extractTarball(file, target_dir):
@@ -228,7 +233,11 @@ def setup_jruby_home():
def ruby_command(args):
"""runs Ruby"""
vmArgs, rubyArgs = extractArguments(args)
vmArgs += ['-cp', mx.classpath(['TRUFFLE_API', 'RUBY'])]
classpath = mx.classpath(['TRUFFLE_API', 'RUBY']).split(':')
truffle_api, classpath = classpath[0], classpath[1:]
assert os.path.basename(truffle_api) == "truffle-api.jar"
vmArgs += ['-Xbootclasspath/p:' + truffle_api]
vmArgs += ['-cp', ':'.join(classpath)]
vmArgs += ['org.jruby.Main', '-X+T']
env = setup_jruby_home()
mx.run_java(vmArgs + rubyArgs, env=env)
5 changes: 3 additions & 2 deletions spec/java_integration/extensions/iterable_spec.rb
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
ret = path.each { |p| paths << p.to_s }
expect( paths ).to_not be_empty
expect( paths.last ).to eq 'iterable_spec.rb'
expect( ret ).to eq path
expect( ret ).to be path
end

it 'iterates with an Enumerator on #each' do
@@ -29,14 +29,15 @@
expect( paths ).to_not be_empty
expect( paths[-1][0].to_s ).to eq 'iterable_spec.rb'
expect( paths[-1][1] ).to eq paths.size - 1
expect( ret ).to eq path
expect( ret ).to eql path

paths = []; idxs = []
ret = path.each_with_index { |p, i| paths << p; idxs << i }
expect( paths ).to_not be_empty
expect( paths[-1].to_s ).to eq 'iterable_spec.rb'
expect( idxs[0] ).to eq 0
expect( idxs[-1] ).to eq paths.size - 1
expect( ret ).to be path
end

it 'iterates with an Enumerator on #each_with_index' do
7 changes: 0 additions & 7 deletions spec/truffle/tags/core/enumerable/slice_after_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/enumerable/slice_before_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/file/mkfifo_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/read_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:File.read raises an Errno::EISDIR when passed a path that is a directory
fails(windows):File.read raises an Errno::EACCES when passed a path that is a directory
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/unlink_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/kernel/backtick_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
fails:Kernel#` produces a String in the default external encoding
fails:Kernel#` sets $? to the exit status of the executed sub-process
fails:Kernel#` raises an Errno::ENOENT if the command is not executable
fails:Kernel.` tries to convert the given argument to String using #to_str
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/instance_variables_tags.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tool/jruby_eclipse
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ parse_options = lambda do |args|
extra_classpath << args.shift
when /^-J/
java_flags << arg[2..-1]
when /^-Xtruffle./
when /^-Xtruffle\./
java_flags << "-Djruby.#{arg[2..-1]}"
else
rest << arg
63 changes: 63 additions & 0 deletions tool/jruby_mx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env ruby

JRUBY = File.expand_path('../..', __FILE__)

GRAAL_OPTIONS_PREFIX = "graal."

java = ENV["JAVACMD"] || "java"

java_flags = []
ruby_flags = []

print_command = false

# Separate java and ruby flags from JRUBY_OPTS and ARGV.
# Also translate shortcuts like -J-G:, -J and -Xtruffle.
parse_options = lambda do |args|
until args.empty?
case arg = args.shift
when "-X+T"
# Just drop it
when "-X-T"
abort "Can only run JRuby+Truffle with mx"
when "-J-cmd"
print_command = true
when /^-J-G:\+/
java_flags << "-J-D#{GRAAL_OPTIONS_PREFIX}#{$'}=true"
when /^-J-G:-/
java_flags << "-J-D#{GRAAL_OPTIONS_PREFIX}#{$'}=false"
when /^-J-G:/
java_flags << "-J-D#{GRAAL_OPTIONS_PREFIX}#{$'}"
when /^-J-(cp|classpath)$/
java_flags << arg << args.shift
when /^-J/
java_flags << arg
when /^-Xtruffle\./
java_flags << "-J-Djruby.#{arg[2..-1]}"
else # Not a VM argument, leave untouched
ruby_flags << arg
break
end
end
ruby_flags += args
end

parse_options.call(ENV["JRUBY_OPTS"].to_s.split(' '))
parse_options.call(ARGV)

args = ["mx"]
unless java == "java"
java_home = java[%r{^(.+)/bin/java$}, 1]
args << '--java-home' << java_home
end
args << "ruby"
args << "-J-Xss2048k"
args += java_flags
args += ruby_flags

if print_command
args.insert(1, '-v')
puts "$ " + args.join(' ')
end

exec(*args)
195 changes: 103 additions & 92 deletions tool/jt.rb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -239,10 +239,10 @@ public Object instanceExec(Object receiver, Object[] arguments, NotProvided bloc
@CoreMethod(names = "__instance_variables__")
public abstract static class InstanceVariablesNode extends CoreMethodArrayArgumentsNode {

public abstract DynamicObject executeObject(DynamicObject self);
public abstract DynamicObject execute(Object self);

@TruffleBoundary
@Specialization
@Specialization(guards = {"!isNil(self)", "!isRubySymbol(self)"})
public DynamicObject instanceVariables(DynamicObject self) {
List<Object> keys = self.getShape().getKeyList();

@@ -259,6 +259,31 @@ public DynamicObject instanceVariables(DynamicObject self) {
return ArrayHelpers.createArray(getContext(), names.toArray(new Object[size]), size);
}

@Specialization
public DynamicObject instanceVariables(int self) {
return ArrayHelpers.createArray(getContext(), null, 0);
}

@Specialization
public DynamicObject instanceVariables(long self) {
return ArrayHelpers.createArray(getContext(), null, 0);
}

@Specialization
public DynamicObject instanceVariables(boolean self) {
return ArrayHelpers.createArray(getContext(), null, 0);
}

@Specialization(guards = "isNil(object)")
public DynamicObject instanceVariablesNil(DynamicObject object) {
return ArrayHelpers.createArray(getContext(), null, 0);
}

@Specialization(guards = "isRubySymbol(object)")
public DynamicObject instanceVariablesSymbol(DynamicObject object) {
return ArrayHelpers.createArray(getContext(), null, 0);
}

}

@CoreMethod(names = "method_missing", needsBlock = true, rest = true, optional = 1, visibility = Visibility.PRIVATE)
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@
import org.jruby.truffle.core.cast.NameToSymbolOrStringNodeGen;
import org.jruby.truffle.core.cast.TaintResultNode;
import org.jruby.truffle.core.cast.ToPathNodeGen;
import org.jruby.truffle.core.cast.ToStrNode;
import org.jruby.truffle.core.cast.ToStrNodeGen;
import org.jruby.truffle.core.encoding.EncodingOperations;
import org.jruby.truffle.core.format.BytesResult;
@@ -153,6 +154,17 @@ public abstract class KernelNodes {
public abstract static class BacktickNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode toHashNode;
@Child private ToStrNode toStrNode;

@Specialization(guards = "!isRubyString(command)")
public DynamicObject backtickCoerce(VirtualFrame frame, DynamicObject command) {
// TODO BJF Aug 4, 2016 Needs SafeStringValue here
if (toStrNode == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();
toStrNode = insert(ToStrNodeGen.create(getContext(), getSourceSection(), null));
}
return backtick(frame, toStrNode.executeToStr(frame, command));
}

@Specialization(guards = "isRubyString(command)")
public DynamicObject backtick(VirtualFrame frame, DynamicObject command) {
@@ -1050,8 +1062,8 @@ public InstanceVariablesNode(RubyContext context, SourceSection sourceSection) {
}

@Specialization
public DynamicObject instanceVariables(VirtualFrame frame, DynamicObject self) {
return instanceVariablesNode.executeObject(self);
public DynamicObject instanceVariables(VirtualFrame frame, Object self) {
return instanceVariablesNode.execute(self);
}

}
Original file line number Diff line number Diff line change
@@ -318,7 +318,10 @@ public RubyConstant removeConstant(RubyContext context, Node currentNode, String
@TruffleBoundary
public void addMethod(RubyContext context, Node currentNode, InternalMethod method) {
assert ModuleOperations.canBindMethodTo(method.getDeclaringModule(), rubyModuleObject) ||
ModuleOperations.assignableTo(context.getCoreLibrary().getObjectClass(), method.getDeclaringModule());
ModuleOperations.assignableTo(context.getCoreLibrary().getObjectClass(), method.getDeclaringModule()) ||
// TODO (pitr-ch 24-Jul-2016): find out why undefined methods sometimes do not match above assertion
// e.g. "block in _routes route_set.rb:525" in rails/actionpack/lib/action_dispatch/routing/
(method.isUndefined() && methods.get(method.getName()) != null);

if (context.getCoreLibrary().isLoadingRubyCore()) {
final InternalMethod currentMethod = methods.get(method.getName());
Original file line number Diff line number Diff line change
@@ -259,6 +259,17 @@ public DynamicObject memset(DynamicObject pointer, int c, long length) {

}

@CoreMethod(names = "mkfifo", isModuleFunction = true, required = 2, unsafe = UnsafeGroup.IO)
public abstract static class MkfifoNode extends CoreMethodArrayArgumentsNode {

@TruffleBoundary
@Specialization(guards = "isRubyString(path)")
public int mkfifo(DynamicObject path, int mode) {
return posix().mkfifo(StringOperations.getString(path), mode);
}

}

@CoreMethod(names = "putenv", isModuleFunction = true, required = 1, unsafe = UnsafeGroup.PROCESSES)
public abstract static class PutenvNode extends CoreMethodArrayArgumentsNode {

Original file line number Diff line number Diff line change
@@ -414,4 +414,9 @@ public int fsync(int fd) {
public int isatty(int fd) {
return posix.libc().isatty(fd);
}

@Override
public int mkfifo(String path, int mode) {
return posix.mkfifo(path, mode);
}
}
Original file line number Diff line number Diff line change
@@ -100,5 +100,6 @@ public interface TrufflePosix {
String getcwd();
int fsync(int fd);
int isatty(int fd);
int mkfifo(String path, int mode);

}
32 changes: 31 additions & 1 deletion truffle/src/main/ruby/core/enumerable.rb
Original file line number Diff line number Diff line change
@@ -162,17 +162,47 @@ def group_by
h
end

def slice_after(arg = undefined, &block)
has_arg = !(undefined.equal? arg)
if block_given?
raise ArgumentError, "both pattern and block are given" if has_arg
else
raise ArgumentError, "wrong number of arguments (0 for 1)" unless has_arg
block = Proc.new{ |elem| arg === elem }
end
Enumerator.new do |yielder|
accumulator = nil
each do |*elem|
elem = elem[0] if elem.size == 1
end_slice = block.yield(elem)
accumulator ||= []
if end_slice
accumulator << elem
yielder.yield accumulator
accumulator = nil
else
accumulator << elem
end
end
yielder.yield accumulator if accumulator
end
end

def slice_before(arg = undefined, &block)
if block_given?
has_init = !(undefined.equal? arg)
if has_init
raise ArgumentError, "both pattern and block are given"
end
else
raise ArgumentError, "wrong number of arguments (0 for 1)" if undefined.equal? arg
block = Proc.new{ |elem| arg === elem }
end
Enumerator.new do |yielder|
init = arg.dup if has_init
accumulator = nil
each do |elem|
each do |*elem|
elem = elem[0] if elem.size == 1
start_new = has_init ? block.yield(elem, init) : block.yield(elem)
if start_new
yielder.yield accumulator if accumulator
12 changes: 12 additions & 0 deletions truffle/src/main/ruby/core/file.rb
Original file line number Diff line number Diff line change
@@ -345,6 +345,18 @@ def self.lchown(owner, group, *paths)
paths.size
end

def self.mkfifo(path, mode = undefined)
mode = if undefined.equal?(mode)
0666
else
Rubinius::Type.coerce_to mode, Integer, :to_int
end
path = Rubinius::Type.coerce_to_path(path)
status = Truffle::POSIX.mkfifo(path, mode)
Errno.handle path if status != 0
status
end

##
# Returns the change time for the named file (the
# time at which directory information about the

0 comments on commit 9be0bad

Please sign in to comment.