Skip to content

Commit

Permalink
Showing 8 changed files with 27 additions and 10 deletions.
6 changes: 6 additions & 0 deletions spec/ruby/language/fixtures/dollar_zero.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
puts $0
puts __FILE__

if $0 == __FILE__
print "OK"
end
7 changes: 7 additions & 0 deletions spec/ruby/language/predefined_spec.rb
Original file line number Diff line number Diff line change
@@ -906,6 +906,13 @@ def obj.foo2; yield; end
$0 = @orig_program_name
end

it "is the path given as the main script and the same as __FILE__" do
script = "fixtures/dollar_zero.rb"
Dir.chdir(File.dirname(__FILE__)) do
ruby_exe(script).should == "#{script}\n#{script}\nOK"
end
end

it "returns the program name" do
$0 = "rbx"
$0.should == "rbx"
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/sub_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails(regexp):String#sub! with pattern and block raises a RuntimeError if the string is modified while substituting
fails:String#sub with pattern, replacement returns a copy of self when no modification is made
1 change: 1 addition & 0 deletions spec/truffle/tags/language/predefined_tags.txt
Original file line number Diff line number Diff line change
@@ -4,3 +4,4 @@ slow:The predefined global constant STDIN has the encodings set by #set_encoding
slow:The predefined global constant STDOUT has the encodings set by #set_encoding
slow:The predefined global constant ARGV contains Strings encoded in locale Encoding
linux:Global variable $0 actually sets the program name
slow:Global variable $0 is the path given as the main script and the same as __FILE__
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ public RubyContext context() {
public abstract static class RunJRubyRootNode extends CoreMethodArrayArgumentsNode {

@Specialization
public Object runJRubyRootNode(VirtualFrame frame, @Cached("create()")IndirectCallNode callNode) {
public Object runJRubyRootNode(VirtualFrame frame, @Cached("create()") IndirectCallNode callNode) {
coreLibrary().getGlobalVariables().put(
"$0",
StringOperations.createString(getContext(),
@@ -100,10 +100,6 @@ public Object runJRubyRootNode(VirtualFrame frame, @Cached("create()")IndirectCa
final Source source;

try {
if (!inputFile.equals("-e")) {
inputFile = new File(inputFile).getCanonicalPath();
}

source = getContext().getSourceCache().getSource(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
Original file line number Diff line number Diff line change
@@ -44,7 +44,6 @@ public Source load(String canonicalPath) throws IOException {
if (!file.canRead()) {
throw new IOException("Can't read file " + canonicalPath);
}
assert file.getCanonicalPath().equals(canonicalPath) : canonicalPath;
return Source.fromFileName(canonicalPath);
}
}
10 changes: 9 additions & 1 deletion truffle/src/main/ruby/core/splitter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Copyright (c) 2016 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
#
# Copyright (c) 2007-2015, Evan Phoenix and contributors
# All rights reserved.
#
@@ -28,7 +36,7 @@ module Rubinius
class Splitter
def self.split_characters(string, pattern, limit, tail_empty)
if limit
string.chars.take(limit - 1) << (string.chars.size > (limit - 1) ? string[(limit - 1)..-1] : "")
string.chars.take(limit - 1) << (string.size > (limit - 1) ? string[(limit - 1)..-1] : "")
else
ret = string.chars.to_a
# Use #byteslice because it returns the right class and taints
5 changes: 3 additions & 2 deletions truffle/src/main/ruby/core/string.rb
Original file line number Diff line number Diff line change
@@ -744,6 +744,7 @@ def upto(stop, exclusive=false)
def sub(pattern, replacement=undefined)
# Because of the behavior of $~, this is duplicated from sub! because
# if we call sub! from sub, the last_match can't be updated properly.
dup = self.dup

unless valid_encoding?
raise ArgumentError, "invalid byte sequence in #{encoding}"
@@ -769,7 +770,7 @@ def sub(pattern, replacement=undefined)
end

pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
match = pattern.match_from(self, 0)
match = pattern.match_from(dup, 0)

Regexp.last_match = match

@@ -799,7 +800,7 @@ def sub(pattern, replacement=undefined)
ret.append(match.post_match)
tainted ||= val.tainted?
else
return self
return dup
end

ret.taint if tainted

0 comments on commit 970e06d

Please sign in to comment.