Skip to content

Commit e96ed64

Browse files
committed
Merge branch 'master-2.7' into dist/2.7/buster
2 parents c77bfed + feda9a2 commit e96ed64

File tree

114 files changed

+39574
-23431
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+39574
-23431
lines changed

ChangeLog

Lines changed: 25340 additions & 12161 deletions
Large diffs are not rendered by default.

array.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5149,7 +5149,7 @@ flatten(VALUE ary, int level)
51495149
{
51505150
long i;
51515151
VALUE stack, result, tmp, elt, vmemo;
5152-
st_table *memo;
5152+
st_table *memo = 0;
51535153
st_data_t id;
51545154

51555155
for (i = 0; i < RARRAY_LEN(ary); i++) {
@@ -5161,8 +5161,6 @@ flatten(VALUE ary, int level)
51615161
}
51625162
if (i == RARRAY_LEN(ary)) {
51635163
return ary;
5164-
} else if (tmp == ary) {
5165-
rb_raise(rb_eArgError, "tried to flatten recursive array");
51665164
}
51675165

51685166
result = ary_new(0, RARRAY_LEN(ary));
@@ -5173,12 +5171,14 @@ flatten(VALUE ary, int level)
51735171
rb_ary_push(stack, ary);
51745172
rb_ary_push(stack, LONG2NUM(i + 1));
51755173

5176-
vmemo = rb_hash_new();
5177-
RBASIC_CLEAR_CLASS(vmemo);
5178-
memo = st_init_numtable();
5179-
rb_hash_st_table_set(vmemo, memo);
5180-
st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
5181-
st_insert(memo, (st_data_t)tmp, (st_data_t)Qtrue);
5174+
if (level < 0) {
5175+
vmemo = rb_hash_new();
5176+
RBASIC_CLEAR_CLASS(vmemo);
5177+
memo = st_init_numtable();
5178+
rb_hash_st_table_set(vmemo, memo);
5179+
st_insert(memo, (st_data_t)ary, (st_data_t)Qtrue);
5180+
st_insert(memo, (st_data_t)tmp, (st_data_t)Qtrue);
5181+
}
51825182

51835183
ary = tmp;
51845184
i = 0;
@@ -5192,20 +5192,24 @@ flatten(VALUE ary, int level)
51925192
}
51935193
tmp = rb_check_array_type(elt);
51945194
if (RBASIC(result)->klass) {
5195-
RB_GC_GUARD(vmemo);
5196-
st_clear(memo);
5195+
if (memo) {
5196+
RB_GC_GUARD(vmemo);
5197+
st_clear(memo);
5198+
}
51975199
rb_raise(rb_eRuntimeError, "flatten reentered");
51985200
}
51995201
if (NIL_P(tmp)) {
52005202
rb_ary_push(result, elt);
52015203
}
52025204
else {
5203-
id = (st_data_t)tmp;
5204-
if (st_is_member(memo, id)) {
5205-
st_clear(memo);
5206-
rb_raise(rb_eArgError, "tried to flatten recursive array");
5205+
if (memo) {
5206+
id = (st_data_t)tmp;
5207+
if (st_is_member(memo, id)) {
5208+
st_clear(memo);
5209+
rb_raise(rb_eArgError, "tried to flatten recursive array");
5210+
}
5211+
st_insert(memo, id, (st_data_t)Qtrue);
52075212
}
5208-
st_insert(memo, id, (st_data_t)Qtrue);
52095213
rb_ary_push(stack, ary);
52105214
rb_ary_push(stack, LONG2NUM(i));
52115215
ary = tmp;
@@ -5215,14 +5219,18 @@ flatten(VALUE ary, int level)
52155219
if (RARRAY_LEN(stack) == 0) {
52165220
break;
52175221
}
5218-
id = (st_data_t)ary;
5219-
st_delete(memo, &id, 0);
5222+
if (memo) {
5223+
id = (st_data_t)ary;
5224+
st_delete(memo, &id, 0);
5225+
}
52205226
tmp = rb_ary_pop(stack);
52215227
i = NUM2LONG(tmp);
52225228
ary = rb_ary_pop(stack);
52235229
}
52245230

5225-
st_clear(memo);
5231+
if (memo) {
5232+
st_clear(memo);
5233+
}
52265234

52275235
RBASIC_SET_CLASS(result, rb_obj_class(ary));
52285236
return result;

class.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
#define id_attached id__attached__
3434

35+
#define METACLASS_OF(k) RBASIC(k)->klass
36+
#define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
37+
3538
void
3639
rb_class_subclass_add(VALUE super, VALUE klass)
3740
{
@@ -372,22 +375,35 @@ rb_singleton_class_clone(VALUE obj)
372375
return rb_singleton_class_clone_and_attach(obj, Qundef);
373376
}
374377

378+
// Clone and return the singleton class of `obj` if it has been created and is attached to `obj`.
375379
VALUE
376380
rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
377381
{
378382
const VALUE klass = RBASIC(obj)->klass;
379383

380-
if (!FL_TEST(klass, FL_SINGLETON))
381-
return klass;
384+
// Note that `rb_singleton_class()` can create situations where `klass` is
385+
// attached to an object other than `obj`. In which case `obj` does not have
386+
// a material singleton class attached yet and there is no singleton class
387+
// to clone.
388+
if (!(FL_TEST(klass, FL_SINGLETON) && rb_attr_get(klass, id_attached) == obj)) {
389+
// nothing to clone
390+
return klass;
391+
}
382392
else {
383393
/* copy singleton(unnamed) class */
394+
bool klass_of_clone_is_new;
384395
VALUE clone = class_alloc(RBASIC(klass)->flags, 0);
385396

386397
if (BUILTIN_TYPE(obj) == T_CLASS) {
398+
klass_of_clone_is_new = true;
387399
RBASIC_SET_CLASS(clone, clone);
388400
}
389401
else {
390-
RBASIC_SET_CLASS(clone, rb_singleton_class_clone(klass));
402+
VALUE klass_metaclass_clone = rb_singleton_class_clone(klass);
403+
// When `METACLASS_OF(klass) == klass_metaclass_clone`, it means the
404+
// recursive call did not clone `METACLASS_OF(klass)`.
405+
klass_of_clone_is_new = (METACLASS_OF(klass) != klass_metaclass_clone);
406+
RBASIC_SET_CLASS(clone, klass_metaclass_clone);
391407
}
392408

393409
RCLASS_SET_SUPER(clone, RCLASS_SUPER(klass));
@@ -411,7 +427,9 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
411427
arg.new_klass = clone;
412428
rb_id_table_foreach(RCLASS_M_TBL(klass), clone_method_i, &arg);
413429
}
414-
rb_singleton_class_attached(RBASIC(clone)->klass, clone);
430+
if (klass_of_clone_is_new) {
431+
rb_singleton_class_attached(RBASIC(clone)->klass, clone);
432+
}
415433
FL_SET(clone, FL_SINGLETON);
416434

417435
return clone;
@@ -433,11 +451,6 @@ rb_singleton_class_attached(VALUE klass, VALUE obj)
433451
}
434452
}
435453

436-
437-
438-
#define METACLASS_OF(k) RBASIC(k)->klass
439-
#define SET_METACLASS_OF(k, cls) RBASIC_SET_CLASS(k, cls)
440-
441454
/*!
442455
* whether k is a meta^(n)-class of Class class
443456
* @retval 1 if \a k is a meta^(n)-class of Class class (n >= 0)

compile.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2737,15 +2737,13 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
27372737
goto again;
27382738
}
27392739
else if (IS_INSN_ID(diobj, leave)) {
2740-
INSN *pop;
27412740
/*
27422741
* jump LABEL
27432742
* ...
27442743
* LABEL:
27452744
* leave
27462745
* =>
27472746
* leave
2748-
* pop
27492747
* ...
27502748
* LABEL:
27512749
* leave
@@ -2755,9 +2753,6 @@ iseq_peephole_optimize(rb_iseq_t *iseq, LINK_ELEMENT *list, const int do_tailcal
27552753
iobj->insn_id = BIN(leave);
27562754
iobj->operand_size = 0;
27572755
iobj->insn_info = diobj->insn_info;
2758-
/* adjust stack depth */
2759-
pop = new_insn_body(iseq, diobj->insn_info.line_no, BIN(pop), 0);
2760-
ELEM_INSERT_NEXT(&iobj->link, &pop->link);
27612756
goto again;
27622757
}
27632758
else if (IS_INSN(iobj->link.prev) &&
@@ -5247,6 +5242,9 @@ compile_if(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int
52475242
branches);
52485243
end_label = NEW_LABEL(line);
52495244
ADD_INSNL(then_seq, line, jump, end_label);
5245+
if (!popped) {
5246+
ADD_INSN(then_seq, line, pop);
5247+
}
52505248
}
52515249
ADD_SEQ(ret, then_seq);
52525250
}
@@ -9849,14 +9847,13 @@ ibf_load_builtin(const struct ibf_load *load, ibf_offset_t *offset)
98499847
const char *name = (char *)ibf_load_ptr(load, offset, len);
98509848

98519849
if (0) {
9852-
for (int i=0; i<len; i++) fprintf(stderr, "%c", name[i]);
9853-
fprintf(stderr, "!!\n");
9850+
fprintf(stderr, "%.*s!!\n", len, name);
98549851
}
98559852

98569853
const struct rb_builtin_function *table = GET_VM()->builtin_function_table;
9857-
if (table == NULL) rb_bug("%s: table is not provided.", RUBY_FUNCTION_NAME_STRING);
9854+
if (table == NULL) rb_raise(rb_eArgError, "builtin function table is not provided");
98589855
if (strncmp(table[i].name, name, len) != 0) {
9859-
rb_bug("%s: index (%d) mismatch (expect %s but %s).", RUBY_FUNCTION_NAME_STRING, i, name, table[i].name);
9856+
rb_raise(rb_eArgError, "builtin function index (%d) mismatch (expect %s but %s)", i, name, table[i].name);
98609857
}
98619858
// fprintf(stderr, "load-builtin: name:%s(%d)\n", table[i].name, table[i].argc);
98629859

configure

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6521,7 +6521,7 @@ if test "x${ARCH_FLAG}" != x; then :
65216521
fi
65226522
# RUBY_UNIVERSAL_ARCH end
65236523

6524-
if test "$target_cpu" != "$host_cpu" -a "$GCC" = yes -a "$cross_compiling" = no -a "$universal_binary" = no; then :
6524+
if test "$target_cpu" != "$host_cpu" -a "$GCC" = yes -a "$cross_compiling" = no -a "${universal_binary:-no}" = no; then :
65256525

65266526

65276527
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking arch option" >&5
@@ -6540,6 +6540,11 @@ esac
65406540

65416541

65426542
fi
6543+
host_os=$target_os
6544+
host_vendor=$target_vendor
6545+
host_cpu=$target_cpu
6546+
host=$target
6547+
host_alias=$target_alias
65436548

65446549
case "$target_os" in #(
65456550
darwin*) :
@@ -18372,7 +18377,7 @@ else
1837218377

1837318378
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1837418379
/* end confdefs.h. */
18375-
unsigned char atomic_var;
18380+
unsigned int atomic_var;
1837618381
int
1837718382
main ()
1837818383
{
@@ -18412,7 +18417,7 @@ else
1841218417

1841318418
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
1841418419
/* end confdefs.h. */
18415-
unsigned char atomic_var;
18420+
unsigned int atomic_var;
1841618421
int
1841718422
main ()
1841818423
{
@@ -23627,6 +23632,28 @@ _ACEOF
2362723632
fi
2362823633
done
2362923634

23635+
for ac_func in getlogin
23636+
do :
23637+
ac_fn_c_check_func "$LINENO" "getlogin" "ac_cv_func_getlogin"
23638+
if test "x$ac_cv_func_getlogin" = xyes; then :
23639+
cat >>confdefs.h <<_ACEOF
23640+
#define HAVE_GETLOGIN 1
23641+
_ACEOF
23642+
23643+
fi
23644+
done
23645+
23646+
for ac_func in getlogin_r
23647+
do :
23648+
ac_fn_c_check_func "$LINENO" "getlogin_r" "ac_cv_func_getlogin_r"
23649+
if test "x$ac_cv_func_getlogin_r" = xyes; then :
23650+
cat >>confdefs.h <<_ACEOF
23651+
#define HAVE_GETLOGIN_R 1
23652+
_ACEOF
23653+
23654+
fi
23655+
done
23656+
2363023657
for ac_func in getpgid
2363123658
do :
2363223659
ac_fn_c_check_func "$LINENO" "getpgid" "ac_cv_func_getpgid"
@@ -23660,6 +23687,17 @@ _ACEOF
2366023687
fi
2366123688
done
2366223689

23690+
for ac_func in getpwnam
23691+
do :
23692+
ac_fn_c_check_func "$LINENO" "getpwnam" "ac_cv_func_getpwnam"
23693+
if test "x$ac_cv_func_getpwnam" = xyes; then :
23694+
cat >>confdefs.h <<_ACEOF
23695+
#define HAVE_GETPWNAM 1
23696+
_ACEOF
23697+
23698+
fi
23699+
done
23700+
2366323701
for ac_func in getpwnam_r
2366423702
do :
2366523703
ac_fn_c_check_func "$LINENO" "getpwnam_r" "ac_cv_func_getpwnam_r"
@@ -23671,6 +23709,28 @@ _ACEOF
2367123709
fi
2367223710
done
2367323711

23712+
for ac_func in getpwuid
23713+
do :
23714+
ac_fn_c_check_func "$LINENO" "getpwuid" "ac_cv_func_getpwuid"
23715+
if test "x$ac_cv_func_getpwuid" = xyes; then :
23716+
cat >>confdefs.h <<_ACEOF
23717+
#define HAVE_GETPWUID 1
23718+
_ACEOF
23719+
23720+
fi
23721+
done
23722+
23723+
for ac_func in getpwuid_r
23724+
do :
23725+
ac_fn_c_check_func "$LINENO" "getpwuid_r" "ac_cv_func_getpwuid_r"
23726+
if test "x$ac_cv_func_getpwuid_r" = xyes; then :
23727+
cat >>confdefs.h <<_ACEOF
23728+
#define HAVE_GETPWUID_R 1
23729+
_ACEOF
23730+
23731+
fi
23732+
done
23733+
2367423734
for ac_func in getrandom
2367523735
do :
2367623736
ac_fn_c_check_func "$LINENO" "getrandom" "ac_cv_func_getrandom"
@@ -26824,11 +26884,11 @@ if ${rb_cv_func_pthread_setname_np_arguments+:} false; then :
2682426884
else
2682526885
rb_cv_func_pthread_setname_np_arguments=
2682626886
# Linux,AIX, (pthread_self(), name)
26827-
# NetBSD (pthread_self(), name, \"%s\")
26887+
# NetBSD (pthread_self(), \"%s\", name)
2682826888
# Darwin (name)
2682926889
for mac in \
2683026890
"(pthread_self(), name)" \
26831-
"(pthread_self(), name, \"%s\")" \
26891+
"(pthread_self(), \"%s\", name)" \
2683226892
"(name)" \
2683326893
; do
2683426894
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -27974,12 +28034,12 @@ main(void)
2797428034
stack_t ss;
2797528035
struct sigaction sa;
2797628036

27977-
ss.ss_sp = malloc(SIGSTKSZ);
28037+
ss.ss_sp = malloc(16*1024);
2797828038
if (ss.ss_sp == NULL) {
2797928039
fprintf(stderr, "cannot allocate memory for sigaltstack\n");
2798028040
return EXIT_FAILURE;
2798128041
}
27982-
ss.ss_size = SIGSTKSZ;
28042+
ss.ss_size = 16*1024;
2798328043
ss.ss_flags = 0;
2798428044
if (sigaltstack(&ss, NULL) == -1) {
2798528045
fprintf(stderr, "sigaltstack failed\n");

0 commit comments

Comments
 (0)