8000 Merge pull request #20 from github/dbussink/ruby-2-1-3 · github/ruby@5d491fe · GitHub
[go: up one dir, main page]

Skip to content

Commit 5d491fe

Browse files
committed
Merge pull request #20 from github/dbussink/ruby-2-1-3
Update to upstream 2.1.3
2 parents 71c08a8 + 741436c commit 5d491fe

File tree

180 files changed

+4454
-1202
lines changed

Some content is hidden

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

180 files changed

+4454
-1202
lines changed

ChangeLog

Lines changed: 1063 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: 41 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
{
@@ -1593,6 +1585,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
15931585
MEMMOVE(RARRAY_PTR(ary) + beg, RARRAY_CONST_PTR(rpl), VALUE, rlen);
15941586
}
15951587
}
1588+
RB_GC_GUARD(rpl);
15961589
}
15971590

15981591
void
@@ -3077,7 +3070,7 @@ ary_reject(VALUE orig, VALUE result)
30773070
for (i = 0; i < RARRAY_LEN(orig); i++) {
30783071
VALUE v = RARRAY_AREF(orig, i);
30793072
if (!RTEST(rb_yield(v))) {
3080-
rb_ary_push_1(result, v);
3073+
rb_ary_push(result, v);
30813074
}
30823075
}
30833076
return result;
@@ -4690,6 +4683,25 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
46904683
#define tmpary(n) rb_ary_tmp_new(n)
46914684
#define tmpary_discard(a) (ary_discard(a), RBASIC_SET_CLASS_RAW(a, rb_cArray))
46924685

4686+
/*
4687+
* Build a ruby array of the corresponding values and yield it to the
4688+
* associated block.
4689+
* Return the class of +values+ for reentry check.
4690+
*/
4691+
static int
4692+
yield_indexed_values(const VALUE values, const long r, const long *const p)
4693+
{
4694+
const VALUE result = rb_ary_new2(r);
4695+
VALUE *const result_array = RARRAY_PTR(result);
4696+
const VALUE *const values_array = RARRAY_CONST_PTR(values);
4697+
long i;
4698+
4699+
for (i = 0; i < r; i++) result_array[i] = values_array[p[i]];
4700+
ARY_SET_LEN(result, r);
4701+
rb_yield(result);
4702+
return !RBASIC(values)->klass;
4703+
}
4704+
46934705
/*
46944706
* Recursively compute permutations of +r+ elements of the set
46954707
* <code>[0..n-1]</code>.
@@ -4707,7 +4719,7 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
47074719
static void
47084720
permute0(long n, long r, long *p, long index, char *used, VALUE values)
47094721
{
4710-
long i,j;
4722+
long i;
47114723
for (i = 0; i < n; i++) {
47124724
if (used[i] == 0) {
47134725
p[index] = i;
@@ -4718,17 +4730,7 @@ permute0(long n, long r, long *p, long index, char *used, VALUE values)
47184730
used[i] = 0; /* index unused */
47194731
}
47204732
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) {
4733+
if (!yield_indexed_values(values, r, p)) {
47324734
rb_raise(rb_eRuntimeError, "permute reentered");
47334735
}
47344736
}
@@ -4826,7 +4828,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
48264828
}
48274829
}
48284830
else { /* this is the general case */
4829-
volatile VALUE t0 = tmpbuf(n,sizeof(long));
4831+
volatile VALUE t0 = tmpbuf(r,sizeof(long));
48304832
long *p = (long*)RSTRING_PTR(t0);
48314833
volatile VALUE t1 = tmpbuf(n,sizeof(char));
48324834
char *used = (char*)RSTRING_PTR(t1);
@@ -4897,21 +4899,19 @@ rb_ary_combination(VALUE ary, VALUE num)
48974899
}
48984900
}
48994901
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);
4902+
VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */
4903+
volatile VALUE t0;
4904+
long *stack = ALLOCV_N(long, t0, n+1);
49044905
long lev = 0;
49054906

4906-
MEMZERO(stack, long, n);
4907+
RBASIC_CLEAR_CLASS(ary0);
4908+
MEMZERO(stack+1, long, n);
49074909
stack[0] = -1;
49084910
for (;;) {
4909-
chosen[lev] = RARRAY_AREF(ary, stack[lev+1]);
49104911
for (lev++; lev < n; lev++) {
4911-
chosen[lev] = RARRAY_AREF(ary, stack[lev+1] = stack[lev]+1);
4912+
stack[lev+1] = stack[lev]+1;
49124913
}
4913-
rb_yield(rb_ary_new4(n, chosen));
4914-
if (RBASIC(t0)->klass) {
4914+
if (!yield_indexed_values(ary0, n, stack+1)) {
49154915
rb_raise(rb_eRuntimeError, "combination reentered");
49164916
}
49174917
do {
@@ -4920,8 +4920,8 @@ rb_ary_combination(VALUE ary, VALUE num)
49204920
} while (stack[lev+1]+n == len+lev+1);
49214921
}
49224922
done:
4923-
tmpbuf_discard(t0);
4924-
tmpary_discard(cc);
4923+
ALLOCV_END(t0);
4924+
RBASIC_SET_CLASS_RAW(ary0, rb_cArray);
49254925
}
49264926
return ary;
49274927
}
@@ -4942,24 +4942,14 @@ rb_ary_combination(VALUE ary, VALUE num)
49424942
static void
49434943
rpermute0(long n, long r, long *p, long index, VALUE values)
49444944
{
4945-
long i, j;
4945+
long i;
49464946
for (i = 0; i < n; i++) {
49474947
p[index] = i;
49484948
if (index < r-1) { /* if not done yet */
49494949
rpermute0(n, r, p, index+1, values); /* recurse */
49504950
}
49514951
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) {
4952+
if (!yield_indexed_values(values, r, p)) {
49634953
rb_raise(rb_eRuntimeError, "repeated permute reentered");
49644954
}
49654955
}
@@ -5040,22 +5030,14 @@ rb_ary_repeated_permutation(VALUE ary, VALUE num)
50405030
static void
50415031
rcombinate0(long n, long r, long *p, long index, long rest, VALUE values)
50425032
{
5043-
long j;
50445033
if (rest > 0) {
50455034
for (; index < n; ++index) {
50465035
p[r-rest] = index;
50475036
rcombinate0(n, r, p, index, rest-1, values);
50485037
}
50495038
}
50505039
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) {
5040+
if (!yield_indexed_values(values, r, p)) {
50595041
rb_raise(rb_eRuntimeError, "repeated combination reentered");
50605042
}
50615043
}

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)
0