Skip to content

Commit 5f44059

Browse files
authored
Merge branch 'master' into mb-array-min
2 parents 4701392 + b78a84e commit 5f44059

37 files changed

Lines changed: 2664 additions & 2224 deletions

bootstraptest/test_method.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,3 +1434,9 @@ def x = [1]
14341434
def forwarder(...) = target(*x, 2, ...)
14351435
forwarder(3).inspect
14361436
}, '[Bug #21832] post-splat args before forwarding'
1437+
1438+
assert_equal '[nil, nil]', %q{
1439+
def self_reading(a = a, kw:) = a
1440+
def through_binding(a = binding.local_variable_get(:a), kw:) = a
1441+
[self_reading(kw: 1), through_binding(kw: 1)]
1442+
}, 'nil initialization of optional parameters'

class.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,7 @@ class_boot_boxable(VALUE super, bool boxable)
786786

787787
class_associate_super(klass, super, true);
788788
if (super && !UNDEF_P(super)) {
789+
RCLASS_SET_ALLOCATOR(klass, RCLASS_ALLOCATOR(super));
789790
rb_class_set_initialized(klass);
790791
}
791792

@@ -1428,6 +1429,8 @@ void
14281429
Init_class_hierarchy(void)
14291430
{
14301431
rb_cBasicObject = boot_defclass("BasicObject", 0);
1432+
RCLASS_SET_ALLOCATOR(rb_cBasicObject, rb_class_allocate_instance);
1433+
FL_SET_RAW(rb_cBasicObject, RCLASS_ALLOCATOR_DEFINED);
14311434
rb_cObject = boot_defclass("Object", rb_cBasicObject);
14321435
rb_vm_register_global_object(rb_cObject);
14331436

gc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,7 @@ rb_gc_register_pinning_obj(VALUE obj)
10861086
static inline void
10871087
rb_data_object_check(VALUE klass)
10881088
{
1089+
RUBY_ASSERT(!RCLASS_SINGLETON_P(klass));
10891090
if (klass != rb_cObject && (rb_get_alloc_func(klass) == rb_class_allocate_instance)) {
10901091
rb_undef_alloc_func(klass);
10911092
rb_warn("undefining the allocator of T_DATA class %"PRIsVALUE, klass);

insns.def

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ opt_new
926926
// The bookkeeping slot should be empty.
927927
RUBY_ASSERT(TOPN(argc + 1) == Qnil);
928928

929-
if (vm_method_cfunc_is(GET_ISEQ(), cd, val, rb_class_new_instance_pass_kw)) {
929+
if (vm_method_cfunc_is(GET_CFP(), cd, val, rb_class_new_instance_pass_kw)) {
930930
RB_DEBUG_COUNTER_INC(opt_new_hit);
931931
val = rb_obj_alloc(val);
932932
TOPN(argc) = val;
@@ -947,7 +947,7 @@ objtostring
947947
// attr bool leaf = false;
948948
// attr bool zjit_profile = true;
949949
{
950-
val = vm_objtostring(GET_ISEQ(), recv, cd);
950+
val = vm_objtostring(GET_CFP(), recv, cd);
951951

952952
if (UNDEF_P(val)) {
953953
CALL_SIMPLE_METHOD();
@@ -1006,7 +1006,7 @@ opt_nil_p
10061006
(VALUE val)
10071007
// attr bool zjit_profile = true;
10081008
{
1009-
val = vm_opt_nil_p(GET_ISEQ(), cd, recv);
1009+
val = vm_opt_nil_p(GET_CFP(), cd, recv);
10101010

10111011
if (UNDEF_P(val)) {
10121012
CALL_SIMPLE_METHOD();
@@ -1435,7 +1435,7 @@ opt_eq
14351435
(VALUE val)
14361436
// attr bool zjit_profile = true;
14371437
{
1438-
val = opt_equality(GET_ISEQ(), recv, obj, cd);
1438+
val = opt_equality(GET_CFP(), recv, obj, cd);
14391439

14401440
if (UNDEF_P(val)) {
14411441
CALL_SIMPLE_METHOD();
@@ -1450,7 +1450,7 @@ opt_neq
14501450
(VALUE val)
14511451
// attr bool zjit_profile = true;
14521452
{
1453-
val = vm_opt_neq(GET_ISEQ(), cd, cd_eq, recv, obj);
1453+
val = vm_opt_neq(GET_CFP(), cd, cd_eq, recv, obj);
14541454

14551455
if (UNDEF_P(val)) {
14561456
CALL_SIMPLE_METHOD();
@@ -1672,7 +1672,7 @@ opt_not
16721672
(VALUE val)
16731673
// attr bool zjit_profile = true;
16741674
{
1675-
val = vm_opt_not(GET_ISEQ(), cd, recv);
1675+
val = vm_opt_not(GET_CFP(), cd, recv);
16761676

16771677
if (UNDEF_P(val)) {
16781678
CALL_SIMPLE_METHOD();

internal/class.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ static inline void RCLASS_WRITE_CLASSPATH(VALUE klass, VALUE classpath, bool per
255255
#define RCLASS_IS_INITIALIZED FL_USER3
256256
// 3 is RMODULE_IS_REFINEMENT for RMODULE
257257
#define RCLASS_BOXABLE FL_USER4
258+
#define RCLASS_ALLOCATOR_DEFINED FL_USER5
258259

259260
static inline st_table *
260261
RCLASS_CLASSEXT_TBL(VALUE klass)
@@ -619,9 +620,7 @@ static inline rb_alloc_func_t
619620
RCLASS_ALLOCATOR(VALUE klass)
620621
{
621622
RBIMPL_ASSERT_TYPE(klass, T_CLASS);
622-
if (RCLASS_SINGLETON_P(klass)) {
623-
return 0;
624-
}
623+
RUBY_ASSERT(!RCLASS_SINGLETON_P(klass));
625624
return RCLASS_EXT_PRIME(klass)->as.class.allocator;
626625
}
627626

lib/bundler/resolver/strategy.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ class Resolver
55
class Strategy
66
def initialize(source)
77
@source = source
8+
@package_priority_cache = {}
89
end
910

1011
def next_package_and_version(unsatisfied)
@@ -17,10 +18,12 @@ def next_package_and_version(unsatisfied)
1718

1819
def next_term_to_try_from(unsatisfied)
1920
unsatisfied.min_by do |package, range|
20-
matching_versions = @source.versions_for(package, range)
21-
higher_versions = @source.versions_for(package, range.upper_invert)
21+
@package_priority_cache[[package, range]] ||= begin
22+
matching_versions = @source.versions_for(package, range)
23+
higher_versions = @source.versions_for(package, range.upper_invert)
2224

23-
[matching_versions.count <= 1 ? 0 : 1, higher_versions.count]
25+
[matching_versions.count <= 1 ? 0 : 1, higher_versions.count]
26+
end
2427
end
2528
end
2629

lib/rubygems/package.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ def extract_tar_gz(io, destination_dir, pattern = "*") # :nodoc:
470470

471471
symlinks.each do |name, target, destination, real_destination|
472472
if File.exist?(real_destination)
473-
File.symlink(target, destination)
473+
create_symlink(target, destination)
474474
else
475475
alert_warning "#{@spec.full_name} ships with a dangling symlink named #{name} pointing to missing #{target} file. Ignoring"
476476
end
@@ -725,6 +725,21 @@ def limit_read(io, name, limit)
725725
raise Gem::Package::FormatError, "#{name} is too big (over #{limit} bytes)" if bytes.size > limit
726726
bytes
727727
end
728+
729+
if Gem.win_platform?
730+
# Create a symlink and fallback to copy the file or directory on Windows,
731+
# where symlink creation needs special privileges in form of the Developer Mode.
732+
def create_symlink(old_name, new_name)
733+
File.symlink(old_name, new_name)
734+
rescue Errno::EACCES
735+
from = File.expand_path(old_name, File.dirname(new_name))
736+
FileUtils.cp_r(from, new_name)
737+
end
738+
else
739+
def create_symlink(old_name, new_name)
740+
File.symlink(old_name, new_name)
741+
end
742+
end
728743
end
729744

730745
require_relative "package/digest_io"

lib/rubygems/version.rb

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -345,60 +345,58 @@ def approximate_recommendation
345345
# other types may raise an exception.
346346

347347
def <=>(other)
348-
if String === other
349-
return unless self.class.correct?(other)
350-
return self <=> self.class.new(other)
351-
end
352-
353-
return unless Gem::Version === other
354-
355-
# Fast path for comparison when available.
356-
if @sort_key && other.sort_key
357-
return @sort_key <=> other.sort_key
358-
end
359-
360-
return 0 if @version == other.version || canonical_segments == other.canonical_segments
348+
if Gem::Version === other
349+
# Fast path for comparison when available.
350+
if @sort_key && other.sort_key
351+
return @sort_key <=> other.sort_key
352+
end
361353

362-
lhsegments = canonical_segments
363-
rhsegments = other.canonical_segments
354+
return 0 if @version == other.version || canonical_segments == other.canonical_segments
364355

365-
lhsize = lhsegments.size
366-
rhsize = rhsegments.size
367-
limit = (lhsize > rhsize ? rhsize : lhsize)
356+
lhsegments = canonical_segments
357+
rhsegments = other.canonical_segments
368358

369-
i = 0
359+
lhsize = lhsegments.size
360+
rhsize = rhsegments.size
361+
limit = (lhsize > rhsize ? rhsize : lhsize)
370362

371-
while i < limit
372-
lhs = lhsegments[i]
373-
rhs = rhsegments[i]
374-
i += 1
363+
i = 0
375364

376-
next if lhs == rhs
377-
return -1 if String === lhs && Numeric === rhs
378-
return 1 if Numeric === lhs && String === rhs
365+
while i < limit
366+
lhs = lhsegments[i]
367+
rhs = rhsegments[i]
368+
i += 1
379369

380-
return lhs <=> rhs
381-
end
370+
next if lhs == rhs
371+
return -1 if String === lhs && Numeric === rhs
372+
return 1 if Numeric === lhs && String === rhs
382373

383-
lhs = lhsegments[i]
374+
return lhs <=> rhs
375+
end
384376

385-
if lhs.nil?
386-
rhs = rhsegments[i]
377+
lhs = lhsegments[i]
387378

388-
while i < rhsize
389-
return 1 if String === rhs
390-
return -1 unless rhs.zero?
391-
rhs = rhsegments[i += 1]
392-
end
393-
else
394-
while i < lhsize
395-
return -1 if String === lhs
396-
return 1 unless lhs.zero?
397-
lhs = lhsegments[i += 1]
379+
if lhs.nil?
380+
rhs = rhsegments[i]
381+
382+
while i < rhsize
383+
return 1 if String === rhs
384+
return -1 unless rhs.zero?
385+
rhs = rhsegments[i += 1]
386+
end
387+
else
388+
while i < lhsize
389+
return -1 if String === lhs
390+
return 1 unless lhs.zero?
391+
lhs = lhsegments[i += 1]
392+
end
398393
end
399-
end
400394

401-
0
395+
0
396+
elsif String === other
397+
return unless self.class.correct?(other)
398+
self <=> self.class.new(other)
399+
end
402400
end
403401

404402
# remove trailing zeros segments before first letter or at the end of the version

marshal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,9 @@ w_object(VALUE obj, struct dump_arg *arg, int limit)
947947
hasiv = has_ivars(obj, (encname = encoding_name(obj, arg)), &ivobj);
948948
{
949949
st_data_t compat_data;
950-
rb_alloc_func_t allocator = rb_get_alloc_func(RBASIC(obj)->klass);
951-
if (st_lookup(compat_allocator_tbl,
950+
VALUE klass = CLASS_OF(obj);
951+
rb_alloc_func_t allocator = RCLASS_SINGLETON_P(klass) ? 0 : rb_get_alloc_func(klass);
952+
if (allocator && st_lookup(compat_allocator_tbl,
952953
(st_data_t)allocator,
953954
&compat_data)) {
954955
marshal_compat_t *compat = (marshal_compat_t*)compat_data;

object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2253,6 +2253,7 @@ rb_class_initialize(int argc, VALUE *argv, VALUE klass)
22532253
}
22542254
}
22552255
rb_class_set_super(klass, super);
2256+
RCLASS_SET_ALLOCATOR(klass, RCLASS_ALLOCATOR(super));
22562257
rb_make_metaclass(klass, RBASIC(super)->klass);
22572258
rb_class_inherited(super, klass);
22582259
rb_mod_initialize_exec(klass);
@@ -4448,7 +4449,6 @@ InitVM_Object(void)
44484449
#endif
44494450

44504451
rb_define_private_method(rb_cBasicObject, "initialize", rb_obj_initialize, 0);
4451-
rb_define_alloc_func(rb_cBasicObject, rb_class_allocate_instance);
44524452
rb_define_method(rb_cBasicObject, "==", rb_obj_equal, 1);
44534453
rb_define_method(rb_cBasicObject, "equal?", rb_obj_equal, 1);
44544454
rb_define_method(rb_cBasicObject, "!", rb_obj_not, 0);

0 commit comments

Comments
 (0)