diff --git a/lib/cext/ABI_check.txt b/lib/cext/ABI_check.txt index 7f8f011eb73..ec635144f60 100644 --- a/lib/cext/ABI_check.txt +++ b/lib/cext/ABI_check.txt @@ -1 +1 @@ -7 +9 diff --git a/lib/truffle/truffle/cext.rb b/lib/truffle/truffle/cext.rb index d6dc582036e..f582529e06c 100644 --- a/lib/truffle/truffle/cext.rb +++ b/lib/truffle/truffle/cext.rb @@ -2336,7 +2336,7 @@ def rb_eval_cmd_kw(cmd, args, kw_splat) def rb_tr_warn(message) location = caller_locations(1, 1)[0] - message_with_prefix = location.label + ': warning: ' + message + message_with_prefix = "#{location.label}: warning: #{message}" Warning.warn(message_with_prefix) end @@ -2346,7 +2346,7 @@ def rb_warning_category_enabled_p(category) def rb_tr_warn_category(message, category) location = caller_locations(1, 1)[0] - message_with_prefix = location.label + ': warning: ' + message + message_with_prefix = "#{location.label}: warning: #{message}" Warning.warn(message_with_prefix, category: category) end diff --git a/spec/ruby/core/dir/chdir_spec.rb b/spec/ruby/core/dir/chdir_spec.rb index 69a8b40415b..b1fe06c2eb1 100644 --- a/spec/ruby/core/dir/chdir_spec.rb +++ b/spec/ruby/core/dir/chdir_spec.rb @@ -95,10 +95,10 @@ def to_str; DirSpecs.mock_dir; end end it "raises an Errno::ENOENT if the original directory no longer exists" do - dir1 = tmp('/testdir1') - dir2 = tmp('/testdir2') - File.should_not.exist?(dir1) - File.should_not.exist?(dir2) + dir1 = tmp('testdir1') + dir2 = tmp('testdir2') + Dir.should_not.exist?(dir1) + Dir.should_not.exist?(dir2) Dir.mkdir dir1 Dir.mkdir dir2 begin @@ -108,8 +108,8 @@ def to_str; DirSpecs.mock_dir; end end }.should raise_error(Errno::ENOENT) ensure - Dir.unlink dir1 if File.exist?(dir1) - Dir.unlink dir2 if File.exist?(dir2) + Dir.unlink dir1 if Dir.exist?(dir1) + Dir.unlink dir2 if Dir.exist?(dir2) end end @@ -177,28 +177,27 @@ def to_str; DirSpecs.mock_dir; end dir.close end - it "raises an Errno::ENOENT if the original directory no longer exists" do - dir_name1 = tmp('/testdir1') - dir_name2 = tmp('/testdir2') - File.should_not.exist?(dir_name1) - File.should_not.exist?(dir_name2) + it "does not raise an Errno::ENOENT if the original directory no longer exists" do + dir_name1 = tmp('testdir1') + dir_name2 = tmp('testdir2') + Dir.should_not.exist?(dir_name1) + Dir.should_not.exist?(dir_name2) Dir.mkdir dir_name1 Dir.mkdir dir_name2 - dir1 = Dir.new(dir_name1) + dir2 = Dir.new(dir_name2) begin - -> { - dir1.chdir do - Dir.chdir(dir_name2) { Dir.unlink dir_name1 } - end - }.should raise_error(Errno::ENOENT) + Dir.chdir(dir_name1) do + dir2.chdir { Dir.unlink dir_name1 } + end + Dir.pwd.should == @original ensure - Dir.unlink dir_name1 if File.exist?(dir_name1) - Dir.unlink dir_name2 if File.exist?(dir_name2) + Dir.unlink dir_name1 if Dir.exist?(dir_name1) + Dir.unlink dir_name2 if Dir.exist?(dir_name2) end ensure - dir1.close + dir2.close end it "always returns to the original directory when given a block" do diff --git a/spec/ruby/core/dir/for_fd_spec.rb b/spec/ruby/core/dir/for_fd_spec.rb index eeda26754ac..d809f921182 100644 --- a/spec/ruby/core/dir/for_fd_spec.rb +++ b/spec/ruby/core/dir/for_fd_spec.rb @@ -42,8 +42,8 @@ it "calls #to_int to convert a value to an Integer" do dir = Dir.new(DirSpecs.mock_dir) - obj = Object.new - obj.singleton_class.define_method(:to_int) { dir.fileno } + obj = mock("fd") + obj.should_receive(:to_int).and_return(dir.fileno) dir_new = Dir.for_fd(obj) dir_new.fileno.should == dir.fileno diff --git a/spec/ruby/core/proc/clone_spec.rb b/spec/ruby/core/proc/clone_spec.rb index 26f031334f7..730dc421a87 100644 --- a/spec/ruby/core/proc/clone_spec.rb +++ b/spec/ruby/core/proc/clone_spec.rb @@ -15,7 +15,7 @@ end ruby_version_is "3.3" do - it "calls #initialize_copy on subclass" do + it "calls #initialize_clone on subclass" do obj = ProcSpecs::MyProc2.new(:a, 2) { } dup = obj.clone @@ -24,7 +24,7 @@ dup.first.should == :a dup.second.should == 2 - dup.initializer.should == :copy + dup.initializer.should == :clone end end end diff --git a/spec/ruby/core/proc/fixtures/common.rb b/spec/ruby/core/proc/fixtures/common.rb index 204acde597b..dfe67d7ba80 100644 --- a/spec/ruby/core/proc/fixtures/common.rb +++ b/spec/ruby/core/proc/fixtures/common.rb @@ -47,6 +47,13 @@ def initialize_dup(other) @first = other.first @second = other.second end + + def initialize_clone(other, **options) + super + @initializer = :clone + @first = other.first + @second = other.second + end end class Arity diff --git a/src/main/c/cext/error.c b/src/main/c/cext/error.c index abc17d66179..4438118011e 100644 --- a/src/main/c/cext/error.c +++ b/src/main/c/cext/error.c @@ -45,3 +45,7 @@ bool rb_warning_category_enabled_p(rb_warning_category_t category) { return true; } } + +void rb_tr_warn_va_list(const char *fmt, va_list args) { + RUBY_CEXT_INVOKE("rb_tr_warn", rb_vsprintf(fmt, args)); +} diff --git a/src/main/c/cext/truffleruby.c b/src/main/c/cext/truffleruby.c index 8ddf279a2f8..fc07b1019cd 100644 --- a/src/main/c/cext/truffleruby.c +++ b/src/main/c/cext/truffleruby.c @@ -34,10 +34,6 @@ int rb_tr_obj_equal(VALUE first, VALUE second) { return RTEST(RUBY_CEXT_INVOKE("rb_tr_obj_equal", first, second)); } -void rb_tr_warn_va_list(const char *fmt, va_list args) { - RUBY_CEXT_INVOKE("rb_tr_warn", rb_vsprintf(fmt, args)); -} - VALUE rb_tr_zlib_crc_table(void) { return RUBY_CEXT_INVOKE("zlib_get_crc_table"); } diff --git a/src/main/java/org/truffleruby/core/proc/ProcNodes.java b/src/main/java/org/truffleruby/core/proc/ProcNodes.java index 5a961702fda..4eb72836f37 100644 --- a/src/main/java/org/truffleruby/core/proc/ProcNodes.java +++ b/src/main/java/org/truffleruby/core/proc/ProcNodes.java @@ -86,7 +86,7 @@ RubyProc procSpecial(VirtualFrame frame, RubyClass procClass, Object[] args, Rub @Cached DispatchNode initialize) { // Instantiate a new instance of procClass as classes do not correspond - final RubyProc proc = ProcOperations.duplicate(procClass, getLanguage().procShape, block, this); + final RubyProc proc = block.duplicate(procClass, getLanguage().procShape, this); initialize.callWithDescriptor(proc, "initialize", block, RubyArguments.getDescriptor(frame), args); return proc; } @@ -101,9 +101,9 @@ public abstract static class CloneNode extends CoreMethodArrayArgumentsNode { @Specialization RubyProc clone(RubyProc proc, - @Cached DispatchNode initializeCopyNode) { - final RubyProc copy = ProcOperations.duplicate(proc.getLogicalClass(), getLanguage().procShape, proc, this); - initializeCopyNode.call(copy, "initialize_copy", proc); + @Cached DispatchNode initializeCloneNode) { + final RubyProc copy = proc.duplicate(getLanguage().procShape, this); + initializeCloneNode.call(copy, "initialize_clone", proc); return copy; } } @@ -114,7 +114,7 @@ public abstract static class DupNode extends CoreMethodArrayArgumentsNode { @Specialization RubyProc dup(RubyProc proc, @Cached DispatchNode initializeDupNode) { - final RubyProc copy = ProcOperations.duplicate(proc.getLogicalClass(), getLanguage().procShape, proc, this); + final RubyProc copy = proc.duplicate(getLanguage().procShape, this); initializeDupNode.call(copy, "initialize_dup", proc); return copy; } diff --git a/src/main/java/org/truffleruby/core/proc/ProcOperations.java b/src/main/java/org/truffleruby/core/proc/ProcOperations.java index f2293896cfc..9ff8fa7ad0c 100644 --- a/src/main/java/org/truffleruby/core/proc/ProcOperations.java +++ b/src/main/java/org/truffleruby/core/proc/ProcOperations.java @@ -10,7 +10,6 @@ package org.truffleruby.core.proc; import com.oracle.truffle.api.CompilerDirectives; -import com.oracle.truffle.api.nodes.Node; import com.oracle.truffle.api.object.Shape; import org.truffleruby.RubyContext; import org.truffleruby.RubyLanguage; @@ -21,7 +20,6 @@ import org.truffleruby.language.methods.DeclarationContext; import org.truffleruby.language.methods.InternalMethod; import org.truffleruby.language.methods.SharedMethodInfo; -import org.truffleruby.language.objects.AllocationTracing; import org.truffleruby.language.threadlocal.SpecialVariableStorage; import com.oracle.truffle.api.RootCallTarget; @@ -125,24 +123,6 @@ public static RubyProc createProcFromBlock(RubyContext context, RubyLanguage lan return convertBlock(context, language, block, ProcType.PROC); } - public static RubyProc duplicate(RubyClass procClass, Shape shape, RubyProc proc, Node node) { - final RubyProc copy = new RubyProc( - procClass, - shape, - proc.type, - proc.arity, - proc.argumentDescriptors, - proc.callTargets, - proc.callTarget, - proc.declarationFrame, - proc.declarationVariables, - proc.declaringMethod, - proc.frameOnStackMarker, - proc.declarationContext); - AllocationTracing.trace(copy, node); - return copy; - } - public static Object getSelf(RubyProc proc) { return RubyArguments.getSelf(proc.declarationFrame); } diff --git a/src/main/java/org/truffleruby/core/proc/RubyProc.java b/src/main/java/org/truffleruby/core/proc/RubyProc.java index 706d0ddcfe4..d32756f8e97 100644 --- a/src/main/java/org/truffleruby/core/proc/RubyProc.java +++ b/src/main/java/org/truffleruby/core/proc/RubyProc.java @@ -22,6 +22,7 @@ import org.truffleruby.language.methods.DeclarationContext; import org.truffleruby.language.methods.InternalMethod; import org.truffleruby.language.methods.SharedMethodInfo; +import org.truffleruby.language.objects.AllocationTracing; import org.truffleruby.language.objects.ObjectGraph; import org.truffleruby.language.objects.ObjectGraphNode; import org.truffleruby.language.threadlocal.SpecialVariableStorage; @@ -98,6 +99,28 @@ public RubyProc withArity(Arity newArity, ArgumentDescriptor[] newArgumentDescri declarationContext); } + public RubyProc duplicate(RubyClass procClass, Shape shape, Node node) { + final RubyProc copy = new RubyProc( + procClass, + shape, + this.type, + this.arity, + this.argumentDescriptors, + this.callTargets, + this.callTarget, + this.declarationFrame, + this.declarationVariables, + this.declaringMethod, + this.frameOnStackMarker, + this.declarationContext); + AllocationTracing.trace(copy, node); + return copy; + } + + public RubyProc duplicate(Shape shape, Node node) { + return duplicate(this.getLogicalClass(), shape, node); + } + @Override public void getAdjacentObjects(Set reachable) { ObjectGraph.getObjectsInFrame(declarationFrame, reachable); diff --git a/src/main/java/org/truffleruby/core/range/RangeNodes.java b/src/main/java/org/truffleruby/core/range/RangeNodes.java index c514d3e83a8..9cc65324a46 100644 --- a/src/main/java/org/truffleruby/core/range/RangeNodes.java +++ b/src/main/java/org/truffleruby/core/range/RangeNodes.java @@ -418,70 +418,6 @@ public RubyNode cloneUninitialized() { } } - @CoreMethod(names = "reverse_each", needsBlock = true, enumeratorSize = "size") - public abstract static class ReverseEachNode extends CoreMethodArrayArgumentsNode { - - @Child private DispatchNode reverseEachInternalCall; - - @Specialization - RubyIntRange reverseEachInt(RubyIntRange range, RubyProc block, - @Cached @Shared InlinedConditionProfile excludedEndProfile, - @Cached @Exclusive InlinedLoopConditionProfile loopProfile, - @Cached @Shared CallBlockNode yieldNode) { - final int end; - if (excludedEndProfile.profile(this, range.excludedEnd)) { - end = range.end - 1; - } else { - end = range.end; - } - - int n = end; - try { - for (; loopProfile.inject(this, n >= range.begin); n--) { - yieldNode.yield(this, block, n); - } - } finally { - profileAndReportLoopCount(this, loopProfile, end - range.begin + 1); - } - - return range; - } - - @Specialization - RubyLongRange reverseEachLong(RubyLongRange range, RubyProc block, - @Cached @Shared InlinedConditionProfile excludedEndProfile, - @Cached @Exclusive InlinedLoopConditionProfile loopProfile, - @Cached @Shared CallBlockNode yieldNode) { - final long end; - if (excludedEndProfile.profile(this, range.excludedEnd)) { - end = range.end - 1; - } else { - end = range.end; - } - - long n = end; - try { - for (; loopProfile.inject(this, n >= range.begin); n--) { - yieldNode.yield(this, block, n); - } - } finally { - profileAndReportLoopCount(this, loopProfile, end - range.begin + 1); - } - - return range; - } - - @Specialization - Object reverseEachObject(RubyObjectRange range, RubyProc block) { - if (reverseEachInternalCall == null) { - CompilerDirectives.transferToInterpreterAndInvalidate(); - reverseEachInternalCall = insert(DispatchNode.create()); - } - - return reverseEachInternalCall.callWithBlock(range, "reverse_each_internal", block); - } - } - @GenerateCached(false) @GenerateInline public abstract static class NewRangeNode extends RubyBaseNode { diff --git a/src/main/ruby/truffleruby/core/dir.rb b/src/main/ruby/truffleruby/core/dir.rb index 9e006cdd579..66fc503d995 100644 --- a/src/main/ruby/truffleruby/core/dir.rb +++ b/src/main/ruby/truffleruby/core/dir.rb @@ -373,10 +373,14 @@ def fchdir(fd) begin yield ensure - Primitive.dir_set_truffle_working_directory(original_path) - ret = Truffle::POSIX.fchdir original_dir.fileno - Errno.handle('fchdir') if ret != 0 - original_dir.close + begin + ret = Truffle::POSIX.fchdir original_dir.fileno + Errno.handle('fchdir') if ret != 0 + + Primitive.dir_set_truffle_working_directory(original_path) + ensure + original_dir.close + end end else ret = Truffle::POSIX.fchdir fd diff --git a/src/main/ruby/truffleruby/core/range.rb b/src/main/ruby/truffleruby/core/range.rb index 80b4ca85117..696863ef256 100644 --- a/src/main/ruby/truffleruby/core/range.rb +++ b/src/main/ruby/truffleruby/core/range.rb @@ -460,8 +460,8 @@ def %(n) Truffle::RangeOperations.step_no_block(self, n) end - private def reverse_each_internal(&block) - return to_enum { size } unless block_given? + def reverse_each(&block) + return to_enum(:reverse_each) { size } unless block_given? if Primitive.nil?(self.end) raise TypeError, "can't iterate from NilClass" diff --git a/test/mri/excludes/TestRange.rb b/test/mri/excludes/TestRange.rb index da751e46b92..1c63b318700 100644 --- a/test/mri/excludes/TestRange.rb +++ b/test/mri/excludes/TestRange.rb @@ -19,7 +19,6 @@ exclude :test_reverse_each_for_beginless_range, "TypeError: can't iterate from NilClass" exclude :test_reverse_each_for_empty_range, "RangeError: long too big to convert into `int'" exclude :test_reverse_each_for_endless_range, "[TypeError] exception expected, not #." -exclude :test_reverse_each_for_single_point_range, " (java.lang.NegativeArraySizeException)" exclude :test_size, "<3> expected but was <(31/10)>." exclude :test_step, "ArgumentError expected but nothing was raised." exclude :test_step_with_succ, "NoMethodError: undefined method `i' for nil:NilClass"