Skip to content

Commit 3d8ac37

Browse files
committed
Merge tag 'v2_1_3' into dbussink/ruby-2-1-3
Conflicts: ChangeLog gc.c string.c test/ruby/test_file_exhaustive.rb test/test_timeout.rb
2 parents 71c08a8 + 4cb2998 commit 3d8ac37

File tree

178 files changed

+4384
-1175
lines changed

Some content is hidden

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

178 files changed

+4384
-1175
lines changed

ChangeLog

Lines changed: 1052 additions & 0 deletions
Large diffs are not rendered by default.

README.EXT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ Here's the example of an initializing function.
650650
{
651651
/* define DBM class */
652652
cDBM = rb_define_class("DBM", rb_cObject);
653-
/* DBM includes Enumerate module */
653+
/* DBM includes Enumerable module */
654654
rb_include_module(cDBM, rb_mEnumerable);
655655

656656
/* DBM has class method open(): arguments are received as C array */

README.EXT.ja

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ Rubyは拡張ライブラリをロードする時に「Init_ライブラリ名
726726
{
727727
/* DBMクラスを定義する */
728728
cDBM = rb_define_class("DBM", rb_cObject);
729-
/* DBMはEnumerateモジュールをインクルードする */
729+
/* DBMはEnumerableモジュールをインクルードする */
730730
rb_include_module(cDBM, rb_mEnumerable);
731731

732732
/* DBMクラスのクラスメソッドopen(): 引数はCの配列で受ける */

array.c

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ rb_ary_modify(VALUE ary)
343343
ARY_SET_CAPA(ary, len);
344344
ARY_SET_PTR(ary, ptr);
345345
}
346+
347+
/* TODO: age2 promotion, OBJ_PROMOTED() checks not infant. */
348+
if (OBJ_PROMOTED(ary) && !OBJ_PROMOTED(shared)) {
349+
rb_gc_writebarrier_remember_promoted(ary);
350+
}
346351
}
347352
}
348353

@@ -898,19 +903,6 @@ rb_ary_push(VALUE ary, VALUE item)
898903
return ary;
899904
}
900905

901-
static VALUE
902-
rb_ary_push_1(VALUE ary, VALUE item)
903-
{
904-
long idx = RARRAY_LEN(ary);
905-
906-
if (idx >= ARY_CAPA(ary)) {
907-
ary_double_capa(ary, idx);
908-
}
909-
RARRAY_ASET(ary, idx, item);
910-
ARY_SET_LEN(ary, idx + 1);
911-
return ary;
912-
}
913-
914906
VALUE
915907
rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
916908
{
@@ -3077,7 +3069,7 @@ ary_reject(VALUE orig, VALUE result)
30773069
for (i = 0; i < RARRAY_LEN(orig); i++) {
30783070
VALUE v = RARRAY_AREF(orig, i);
30793071
if (!RTEST(rb_yield(v))) {
3080-
rb_ary_push_1(result, v);
3072+
rb_ary_push(result, v);
30813073
}
30823074
}
30833075
return result;
@@ -4690,6 +4682,25 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
46904682
#define tmpary(n) rb_ary_tmp_new(n)
46914683
#define tmpary_discard(a) (ary_discard(a), RBASIC_SET_CLASS_RAW(a, rb_cArray))
46924684

4685+
/*
4686+
* Build a ruby array of the corresponding values and yield it to the
4687+
* associated block.
4688+
* Return the class of +values+ for reentry check.
4689+
*/
4690+
static int
4691+
yield_indexed_values(const VALUE values, const long r, const long *const p)
4692+
{
4693+
const VALUE result = rb_ary_new2(r);
4694+
VALUE *const result_array = RARRAY_PTR(result);
4695+
const VALUE *const values_array = RARRAY_CONST_PTR(values);
4696+
long i;
4697+
4698+
for (i = 0; i < r; i++) result_array[i] = values_array[p[i]];
4699+
ARY_SET_LEN(result, r);
4700+
rb_yield(result);
4701+
return !RBASIC(values)->klass;
4702+
}
4703+
46934704
/*
46944705
* Recursively compute permutations of +r+ elements of the set
46954706
* <code>[0..n-1]</code>.
@@ -4707,7 +4718,7 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
47074718
static void
47084719
permute0(long n, long r, long *p, long index, char *used, VALUE values)
47094720
{
4710-
long i,j;
4721+
long i;
47114722
for (i = 0; i < n; i++) {
47124723
if (used[i] == 0) {
47134724
p[index] = i;
@@ -4718,17 +4729,7 @@ permute0(long n, long r, long *p, long index, char *used, VALUE values)
47184729
used[i] = 0; /* index unused */
47194730
}
47204731
else {
4721-
/* We have a complete permutation of array indexes */
4722-
/* Build a ruby array of the corresponding values */
4723-
/* And yield it to the associated block */
4724-
VALUE result = rb_ary_new2(r);
4725-
VALUE *result_array = RARRAY_PTR(result);
4726-
const VALUE *values_array = RARRAY_PTR(values);
4727-
4728-
for (j = 0; j < r; j++) result_array[j] = values_array[p[j]];
4729-
ARY_SET_LEN(result, r);
4730-
rb_yield(result);
4731-
if (RBASIC(values)->klass) {
4732+
if (!yield_indexed_values(values, r, p)) {
47324733
rb_raise(rb_eRuntimeError, "permute reentered");
47334734
}
47344735
}
@@ -4826,7 +4827,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
48264827
}
48274828
}
48284829
else { /* this is the general case */
4829-
volatile VALUE t0 = tmpbuf(n,sizeof(long));
4830+
volatile VALUE t0 = tmpbuf(r,sizeof(long));
48304831
long *p = (long*)RSTRING_PTR(t0);
48314832
volatile VALUE t1 = tmpbuf(n,sizeof(char));
48324833
char *used = (char*)RSTRING_PTR(t1);
@@ -4897,21 +4898,19 @@ rb_ary_combination(VALUE ary, VALUE num)
48974898
}
48984899
}
48994900
else {
4900-
volatile VALUE t0 = tmpbuf(n+1, sizeof(long));
4901-
long *stack = (long*)RSTRING_PTR(t0);
4902-
volatile VALUE cc = tmpary(n);
4903-
VALUE *chosen = RARRAY_PTR(cc);
4901+
VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */
4902+
volatile VALUE t0;
4903+
long *stack = ALLOCV_N(long, t0, n+1);
49044904
long lev = 0;
49054905

4906-
MEMZERO(stack, long, n);
4906+
RBASIC_CLEAR_CLASS(ary0);
4907+
MEMZERO(stack+1, long, n);
49074908
stack[0] = -1;
49084909
for (;;) {
4909-
chosen[lev] = RARRAY_AREF(ary, stack[lev+1]);
49104910
for (lev++; lev < n; lev++) {
4911-
chosen[lev] = RARRAY_AREF(ary, stack[lev+1] = stack[lev]+1);
4911+
stack[lev+1] = stack[lev]+1;
49124912
}
4913-
rb_yield(rb_ary_new4(n, chosen));
4914-
if (RBASIC(t0)->klass) {
4913+
if (!yield_indexed_values(ary0, n, stack+1)) {
49154914
rb_raise(rb_eRuntimeError, "combination reentered");
49164915
}
49174916
do {
@@ -4920,8 +4919,8 @@ rb_ary_combination(VALUE ary, VALUE num)
49204919
} while (stack[lev+1]+n == len+lev+1);
49214920
}
49224921
done:
4923-
tmpbuf_discard(t0);
4924-
tmpary_discard(cc);
4922+
ALLOCV_END(t0);
4923+
RBASIC_SET_CLASS_RAW(ary0, rb_cArray);
49254924
}
49264925
return ary;
49274926
}
@@ -4942,24 +4941,14 @@ rb_ary_combination(VALUE ary, VALUE num)
49424941
static void
49434942
rpermute0(long n, long r, long *p, long index, VALUE values)
49444943
{
4945-
long i, j;
4944+
long i;
49464945
for (i = 0; i < n; i++) {
49474946
p[index] = i;
49484947
if (index < r-1) { /* if not done yet */
49494948
rpermute0(n, r, p, index+1, values); /* recurse */
49504949
}
49514950
else {
4952-
/* We have a complete permutation of array indexes */
4953-
/* Build a ruby array of the corresponding values */
4954-
/* And yield it to the associated block */
4955-
VALUE result = rb_ary_new2(r);
4956-
VALUE *result_array = RARRAY_PTR(result);
4957-
const VALUE *values_array = RARRAY_PTR(values);
4958-
4959-
for (j = 0; j < r; j++) result_array[j] = values_array[p[j]];
4960-
ARY_SET_LEN(result, r);
4961-
rb_yield(result);
4962-
if (RBASIC(values)->klass) {
4951+
if (!yield_indexed_values(values, r, p)) {
49634952
rb_raise(rb_eRuntimeError, "repeated permute reentered");
49644953
}
49654954
}
@@ -5040,22 +5029,14 @@ rb_ary_repeated_permutation(VALUE ary, VALUE num)
50405029
static void
50415030
rcombinate0(long n, long r, long *p, long index, long rest, VALUE values)
50425031
{
5043-
long j;
50445032
if (rest > 0) {
50455033
for (; index < n; ++index) {
50465034
p[r-rest] = index;
50475035
rcombinate0(n, r, p, index, rest-1, values);
50485036
}
50495037
}
50505038
else {
5051-
VALUE result = rb_ary_new2(r);
5052-
VALUE *result_array = RARRAY_PTR(result);
5053-
const VALUE *values_array = RARRAY_PTR(values);
5054-
5055-
for (j = 0; j < r; ++j) result_array[j] = values_array[p[j]];
5056-
ARY_SET_LEN(result, r);
5057-
rb_yield(result);
5058-
if (RBASIC(values)->klass) {
5039+
if (!yield_indexed_values(values, r, p)) {
50595040
rb_raise(rb_eRuntimeError, "repeated combination reentered");
50605041
}
50615042
}

bignum.c

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ end
218218
219219
*/
220220

221-
#ifdef HAVE_UINT16_T
221+
#if SIZEOF_BDIGIT_DBL == 2
222222
static const int maxpow16_exp[35] = {
223223
15, 10, 7, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3,
224224
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
@@ -234,8 +234,7 @@ static const uint16_t maxpow16_num[35] = {
234234
U16(0x00006978), U16(0x0000745f), U16(0x00008000), U16(0x00008c61),
235235
U16(0x00009988), U16(0x0000a77b), U16(0x0000b640),
236236
};
237-
#endif
238-
#ifdef HAVE_UINT32_T
237+
#elif SIZEOF_BDIGIT_DBL == 4
239238
static const int maxpow32_exp[35] = {
240239
31, 20, 15, 13, 12, 11, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
241240
7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
@@ -251,8 +250,7 @@ static const uint32_t maxpow32_num[35] = {
251250
U32(0x2b73a840), U32(0x34e63b41), U32(0x40000000), U32(0x4cfa3cc1),
252251
U32(0x5c13d840), U32(0x6d91b519), U32(0x81bf1000),
253252
};
254-
#endif
255-
#ifdef HAVE_UINT64_T
253+
#elif SIZEOF_BDIGIT_DBL == 8 && defined HAVE_UINT64_T
256254
static const int maxpow64_exp[35] = {
257255
63, 40, 31, 27, 24, 22, 21, 20, 19, 18, 17, 17, 16, 16, 15, 15, 15,
258256
15, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
@@ -278,8 +276,7 @@ static const uint64_t maxpow64_num[35] = {
278276
U64(0x211e44f7,0xd02c1000), U64(0x2ee56725,0xf06e5c71),
279277
U64(0x41c21cb8,0xe1000000),
280278
};
281-
#endif
282-
#ifdef HAVE_UINT128_T
279+
#elif SIZEOF_BDIGIT_DBL == 16 && defined HAVE_UINT128_T
283280
static const int maxpow128_exp[35] = {
284281
127, 80, 63, 55, 49, 45, 42, 40, 38, 37, 35, 34, 33, 32, 31, 31, 30,
285282
30, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26, 25, 25, 25, 25, 24,

class.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ rb_class_subclass_add(VALUE super, VALUE klass)
4242
rb_subclass_entry_t *entry, *head;
4343

4444
if (super && super != Qundef) {
45-
entry = malloc(sizeof(*entry));
45+
entry = xmalloc(sizeof(*entry));
4646
entry->klass = klass;
4747
entry->next = NULL;
4848

@@ -62,7 +62,7 @@ rb_module_add_to_subclasses_list(VALUE module, VALUE iclass)
6262
{
6363
rb_subclass_entry_t *entry, *head;
6464

65-
entry = malloc(sizeof(*entry));
65+
entry = xmalloc(sizeof(*entry));
6666
entry->klass = iclass;
6767
entry->next = NULL;
6868

@@ -88,7 +88,7 @@ rb_class_remove_from_super_subclasses(VALUE klass)
8888
if (entry->next) {
8989
RCLASS_EXT(entry->next->klass)->parent_subclasses = RCLASS_EXT(klass)->parent_subclasses;
9090
}
91-
free(entry);
91+
xfree(entry);
9292
}
9393

9494
RCLASS_EXT(klass)->parent_subclasses = NULL;
@@ -107,7 +107,7 @@ rb_class_remove_from_module_subclasses(VALUE klass)
107107
RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
108108
}
109109

110-
free(entry);
110+
xfree(entry);
111111
}
112112

113113
RCLASS_EXT(klass)->module_subclasses = NULL;
@@ -329,12 +329,21 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
329329
}
330330
RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig));
331331
RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
332+
if (RCLASS_IV_TBL(clone)) {
333+
st_free_table(RCLASS_IV_TBL(clone));
334+
RCLASS_IV_TBL(clone) = 0;
335+
}
336+
if (RCLASS_CONST_TBL(clone)) {
337+
rb_free_const_table(RCLASS_CONST_TBL(clone));
338+
RCLASS_CONST_TBL(clone) = 0;
339+
}
340+
if (RCLASS_M_TBL_WRAPPER(clone)) {
341+
rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
342+
RCLASS_M_TBL_WRAPPER(clone) = 0;
343+
}
332344
if (RCLASS_IV_TBL(orig)) {
333345
st_data_t id;
334346

335-
if (RCLASS_IV_TBL(clone)) {
336-
st_free_table(RCLASS_IV_TBL(clone));
337-
}
338347
RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig));
339348
CONST_ID(id, "__tmp_classpath__");
340349
st_delete(RCLASS_IV_TBL(clone), &id, 0);
@@ -345,18 +354,13 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
345354
}
346355
if (RCLASS_CONST_TBL(orig)) {
347356
struct clone_const_arg arg;
348-
if (RCLASS_CONST_TBL(clone)) {
349-
rb_free_const_table(RCLASS_CONST_TBL(clone));
350-
}
357+
351358
RCLASS_CONST_TBL(clone) = st_init_numtable();
352359
arg.klass = clone;
353360
arg.tbl = RCLASS_CONST_TBL(clone);
354361
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
355362
}
356363
if (RCLASS_M_TBL(orig)) {
357-
if (RCLASS_M_TBL_WRAPPER(clone)) {
358-
rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
359-
}
360364
RCLASS_M_TBL_INIT(clone);
361365
st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
362366
}

common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ $(CAPIOUT)/.timestamp: Doxyfile $(PREP)
204204
Doxyfile: $(srcdir)/template/Doxyfile.tmpl $(PREP) $(srcdir)/tool/generic_erb.rb $(RBCONFIG)
205205
$(ECHO) generating $@
206206
$(Q) $(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ $(srcdir)/template/Doxyfile.tmpl \
207-
--srcdir="$(srcdir)" --miniruby="$(BASERUBY)"
207+
--srcdir="$(srcdir)" --miniruby="$(MINIRUBY)"
208208

209209
program: showflags $(PROGRAM)
210210
wprogram: showflags $(WPROGRAM)

compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,8 @@ rb_iseq_compile_node(VALUE self, NODE *node)
478478
LABEL *start = iseq->compile_data->start_label = NEW_LABEL(0);
479479
LABEL *end = iseq->compile_data->end_label = NEW_LABEL(0);
480480

481-
ADD_LABEL(ret, start);
482481
ADD_TRACE(ret, FIX2INT(iseq->location.first_lineno), RUBY_EVENT_B_CALL);
482+
ADD_LABEL(ret, start);
483483
COMPILE(ret, "block body", node->nd_body);
484484
ADD_LABEL(ret, end);
485485
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_B_RETURN);
@@ -2479,6 +2479,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
24792479
if (i > 0 || !first) ADD_INSN(ret, line, swap);
24802480
COMPILE(ret, "keyword splat", kw);
24812481
ADD_SEND(ret, line, ID2SYM(id_core_hash_merge_kwd), nhash);
2482+
if (nhash == INT2FIX(1)) ADD_SEND(ret, line, ID2SYM(rb_intern("dup")), INT2FIX(0));
24822483
}
24832484
first = 0;
24842485
break;

0 commit comments

Comments
 (0)