Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ The following bundled gems are promoted from default gems.
* pstore 0.2.0
* benchmark 0.5.0
* logger 1.7.0
* rdoc 6.16.1
* rdoc 6.17.0
* win32ole 1.9.2
* irb 1.15.3
* reline 0.6.3
Expand Down
4 changes: 2 additions & 2 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4841,11 +4841,11 @@ rb_raw_obj_info_buitin_type(char *const buff, const size_t buff_size, const VALU
APPEND_F("(too_complex) len:%zu", hash_len);
}
else {
APPEND_F("(embed) len:%d", ROBJECT_FIELDS_CAPACITY(obj));
APPEND_F("(embed) len:%d capa:%d", RSHAPE_LEN(RBASIC_SHAPE_ID(obj)), ROBJECT_FIELDS_CAPACITY(obj));
}
}
else {
APPEND_F("len:%d ptr:%p", ROBJECT_FIELDS_CAPACITY(obj), (void *)ROBJECT_FIELDS(obj));
APPEND_F("len:%d capa:%d ptr:%p", RSHAPE_LEN(RBASIC_SHAPE_ID(obj)), ROBJECT_FIELDS_CAPACITY(obj), (void *)ROBJECT_FIELDS(obj));
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion gems/bundled_gems
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ostruct 0.6.3 https://github.com/ruby/ostruct
pstore 0.2.0 https://github.com/ruby/pstore
benchmark 0.5.0 https://github.com/ruby/benchmark
logger 1.7.0 https://github.com/ruby/logger
rdoc 6.16.1 https://github.com/ruby/rdoc
rdoc 6.17.0 https://github.com/ruby/rdoc
win32ole 1.9.2 https://github.com/ruby/win32ole
irb 1.15.3 https://github.com/ruby/irb
reline 0.6.3 https://github.com/ruby/reline
Expand Down
17 changes: 10 additions & 7 deletions pathname_builtin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,12 @@ class Pathname

# :stopdoc:

SAME_PATHS = if File::FNM_SYSCASE.nonzero?
if File::FNM_SYSCASE.nonzero?
# Avoid #zero? here because #casecmp can return nil.
proc {|a, b| a.casecmp(b) == 0}
private def same_paths?(a, b) a.casecmp(b) == 0 end
else
proc {|a, b| a == b}
private def same_paths?(a, b) a == b end
end
SAME_PATHS.freeze
private_constant :SAME_PATHS

attr_reader :path
protected :path
Expand All @@ -215,8 +213,13 @@ class Pathname
#
def initialize(path)
@path = File.path(path).dup
rescue TypeError => e
raise e.class, "Pathname.new requires a String, #to_path or #to_str", cause: nil
end

#
# Freze self.
#
def freeze
super
@path.freeze
Expand Down Expand Up @@ -836,12 +839,12 @@ def relative_path_from(base_directory)
base_prefix, basename = r
base_names.unshift basename if basename != '.'
end
unless SAME_PATHS[dest_prefix, base_prefix]
unless same_paths?(dest_prefix, base_prefix)
raise ArgumentError, "different prefix: #{dest_prefix.inspect} and #{base_directory.inspect}"
end
while !dest_names.empty? &&
!base_names.empty? &&
SAME_PATHS[dest_names.first, base_names.first]
same_paths?(dest_names.first, base_names.first)
dest_names.shift
base_names.shift
end
Expand Down
2 changes: 1 addition & 1 deletion prism/srcs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ prism/$(HAVE_BASERUBY:yes=.srcs.mk.time): \

distclean-prism-srcs::
$(RM) prism/.srcs.mk.time
$(RMDIR) prism
$(RMDIRS) prism || $(NULLCMD)

distclean-srcs-local:: distclean-prism-srcs

Expand Down
2 changes: 1 addition & 1 deletion prism/srcs.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ prism/$(HAVE_BASERUBY:yes=.srcs.mk.time): \

distclean-prism-srcs::
$(RM) prism/.srcs.mk.time
$(RMDIR) prism
$(RMDIRS) prism || $(NULLCMD)

distclean-srcs-local:: distclean-prism-srcs

Expand Down
11 changes: 11 additions & 0 deletions test/pathname/test_pathname.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ def test_initialize
p2 = Pathname.new(p1)
assert_equal(p1, p2)

obj = Object.new
assert_raise_with_message(TypeError, /#to_path or #to_str/) { Pathname.new(obj) }

obj = Object.new
def obj.to_path; "a/path"; end
assert_equal("a/path", Pathname.new(obj).to_s)

obj = Object.new
def obj.to_str; "a/b"; end
assert_equal("a/b", Pathname.new(obj).to_s)
Expand All @@ -494,6 +501,10 @@ def test_initialize_nul
assert_raise(ArgumentError) { Pathname.new("a\0") }
end

def test_initialize_encoding
assert_raise(Encoding::CompatibilityError) { Pathname.new("a".encode(Encoding::UTF_32BE)) }
end

def test_global_constructor
p = Pathname.new('a')
assert_equal(p, Pathname('a'))
Expand Down
5 changes: 5 additions & 0 deletions test/pathname/test_ractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ class Ractor
x.join(Pathname("b"), Pathname("c"))
end
assert_equal(Pathname("a/b/c"), r.value)

r = Ractor.new Pathname("a") do |a|
Pathname("b").relative_path_from(a)
end
assert_equal(Pathname("../b"), r.value)
end;
end
end