Skip to content

Commit

Permalink
Merge pull request #20 from github/dbussink/ruby-2-1-3
Browse files Browse the repository at this point in the history
Update to upstream 2.1.3
  • Loading branch information
dbussink committed Nov 11, 2014
2 parents 71c08a8 + 741436c commit 5d491fe
Show file tree
Hide file tree
Showing 180 changed files with 4,454 additions and 1,202 deletions.
1,063 changes: 1,063 additions & 0 deletions ChangeLog

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.EXT
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ Here's the example of an initializing function.
{
/* define DBM class */
cDBM = rb_define_class("DBM", rb_cObject);
/* DBM includes Enumerate module */
/* DBM includes Enumerable module */
rb_include_module(cDBM, rb_mEnumerable);

/* DBM has class method open(): arguments are received as C array */
Expand Down
2 changes: 1 addition & 1 deletion README.EXT.ja
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ Rubyは拡張ライブラリをロードする時に「Init_ライブラリ名
{
/* DBMクラスを定義する */
cDBM = rb_define_class("DBM", rb_cObject);
/* DBMはEnumerateモジュールをインクルードする */
/* DBMはEnumerableモジュールをインクルードする */
rb_include_module(cDBM, rb_mEnumerable);

/* DBMクラスのクラスメソッドopen(): 引数はCの配列で受ける */
Expand Down
100 changes: 41 additions & 59 deletions array.c
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ rb_ary_modify(VALUE ary)
ARY_SET_CAPA(ary, len);
ARY_SET_PTR(ary, ptr);
}

/* TODO: age2 promotion, OBJ_PROMOTED() checks not infant. */
if (OBJ_PROMOTED(ary) && !OBJ_PROMOTED(shared)) {
rb_gc_writebarrier_remember_promoted(ary);
}
}
}

Expand Down Expand Up @@ -898,19 +903,6 @@ rb_ary_push(VALUE ary, VALUE item)
return ary;
}

static VALUE
rb_ary_push_1(VALUE ary, VALUE item)
{
long idx = RARRAY_LEN(ary);

if (idx >= ARY_CAPA(ary)) {
ary_double_capa(ary, idx);
}
RARRAY_ASET(ary, idx, item);
ARY_SET_LEN(ary, idx + 1);
return ary;
}

VALUE
rb_ary_cat(VALUE ary, const VALUE *ptr, long len)
{
Expand Down Expand Up @@ -1593,6 +1585,7 @@ rb_ary_splice(VALUE ary, long beg, long len, VALUE rpl)
MEMMOVE(RARRAY_PTR(ary) + beg, RARRAY_CONST_PTR(rpl), VALUE, rlen);
}
}
RB_GC_GUARD(rpl);
}

void
Expand Down Expand Up @@ -3077,7 +3070,7 @@ ary_reject(VALUE orig, VALUE result)
for (i = 0; i < RARRAY_LEN(orig); i++) {
VALUE v = RARRAY_AREF(orig, i);
if (!RTEST(rb_yield(v))) {
rb_ary_push_1(result, v);
rb_ary_push(result, v);
}
}
return result;
Expand Down Expand Up @@ -4690,6 +4683,25 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
#define tmpary(n) rb_ary_tmp_new(n)
#define tmpary_discard(a) (ary_discard(a), RBASIC_SET_CLASS_RAW(a, rb_cArray))

/*
* Build a ruby array of the corresponding values and yield it to the
* associated block.
* Return the class of +values+ for reentry check.
*/
static int
yield_indexed_values(const VALUE values, const long r, const long *const p)
{
const VALUE result = rb_ary_new2(r);
VALUE *const result_array = RARRAY_PTR(result);
const VALUE *const values_array = RARRAY_CONST_PTR(values);
long i;

for (i = 0; i < r; i++) result_array[i] = values_array[p[i]];
ARY_SET_LEN(result, r);
rb_yield(result);
return !RBASIC(values)->klass;
}

/*
* Recursively compute permutations of +r+ elements of the set
* <code>[0..n-1]</code>.
Expand All @@ -4707,7 +4719,7 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
static void
permute0(long n, long r, long *p, long index, char *used, VALUE values)
{
long i,j;
long i;
for (i = 0; i < n; i++) {
if (used[i] == 0) {
p[index] = i;
Expand All @@ -4718,17 +4730,7 @@ permute0(long n, long r, long *p, long index, char *used, VALUE values)
used[i] = 0; /* index unused */
}
else {
/* We have a complete permutation of array indexes */
/* Build a ruby array of the corresponding values */
/* And yield it to the associated block */
VALUE result = rb_ary_new2(r);
VALUE *result_array = RARRAY_PTR(result);
const VALUE *values_array = RARRAY_PTR(values);

for (j = 0; j < r; j++) result_array[j] = values_array[p[j]];
ARY_SET_LEN(result, r);
rb_yield(result);
if (RBASIC(values)->klass) {
if (!yield_indexed_values(values, r, p)) {
rb_raise(rb_eRuntimeError, "permute reentered");
}
}
Expand Down Expand Up @@ -4826,7 +4828,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
}
}
else { /* this is the general case */
volatile VALUE t0 = tmpbuf(n,sizeof(long));
volatile VALUE t0 = tmpbuf(r,sizeof(long));
long *p = (long*)RSTRING_PTR(t0);
volatile VALUE t1 = tmpbuf(n,sizeof(char));
char *used = (char*)RSTRING_PTR(t1);
Expand Down Expand Up @@ -4897,21 +4899,19 @@ rb_ary_combination(VALUE ary, VALUE num)
}
}
else {
volatile VALUE t0 = tmpbuf(n+1, sizeof(long));
long *stack = (long*)RSTRING_PTR(t0);
volatile VALUE cc = tmpary(n);
VALUE *chosen = RARRAY_PTR(cc);
VALUE ary0 = ary_make_shared_copy(ary); /* private defensive copy of ary */
volatile VALUE t0;
long *stack = ALLOCV_N(long, t0, n+1);
long lev = 0;

MEMZERO(stack, long, n);
RBASIC_CLEAR_CLASS(ary0);
MEMZERO(stack+1, long, n);
stack[0] = -1;
for (;;) {
chosen[lev] = RARRAY_AREF(ary, stack[lev+1]);
for (lev++; lev < n; lev++) {
chosen[lev] = RARRAY_AREF(ary, stack[lev+1] = stack[lev]+1);
stack[lev+1] = stack[lev]+1;
}
rb_yield(rb_ary_new4(n, chosen));
if (RBASIC(t0)->klass) {
if (!yield_indexed_values(ary0, n, stack+1)) {
rb_raise(rb_eRuntimeError, "combination reentered");
}
do {
Expand All @@ -4920,8 +4920,8 @@ rb_ary_combination(VALUE ary, VALUE num)
} while (stack[lev+1]+n == len+lev+1);
}
done:
tmpbuf_discard(t0);
tmpary_discard(cc);
ALLOCV_END(t0);
RBASIC_SET_CLASS_RAW(ary0, rb_cArray);
}
return ary;
}
Expand All @@ -4942,24 +4942,14 @@ rb_ary_combination(VALUE ary, VALUE num)
static void
rpermute0(long n, long r, long *p, long index, VALUE values)
{
long i, j;
long i;
for (i = 0; i < n; i++) {
p[index] = i;
if (index < r-1) { /* if not done yet */
rpermute0(n, r, p, index+1, values); /* recurse */
}
else {
/* We have a complete permutation of array indexes */
/* Build a ruby array of the corresponding values */
/* And yield it to the associated block */
VALUE result = rb_ary_new2(r);
VALUE *result_array = RARRAY_PTR(result);
const VALUE *values_array = RARRAY_PTR(values);

for (j = 0; j < r; j++) result_array[j] = values_array[p[j]];
ARY_SET_LEN(result, r);
rb_yield(result);
if (RBASIC(values)->klass) {
if (!yield_indexed_values(values, r, p)) {
rb_raise(rb_eRuntimeError, "repeated permute reentered");
}
}
Expand Down Expand Up @@ -5040,22 +5030,14 @@ rb_ary_repeated_permutation(VALUE ary, VALUE num)
static void
rcombinate0(long n, long r, long *p, long index, long rest, VALUE values)
{
long j;
if (rest > 0) {
for (; index < n; ++index) {
p[r-rest] = index;
rcombinate0(n, r, p, index, rest-1, values);
}
}
else {
VALUE result = rb_ary_new2(r);
VALUE *result_array = RARRAY_PTR(result);
const VALUE *values_array = RARRAY_PTR(values);

for (j = 0; j < r; ++j) result_array[j] = values_array[p[j]];
ARY_SET_LEN(result, r);
rb_yield(result);
if (RBASIC(values)->klass) {
if (!yield_indexed_values(values, r, p)) {
rb_raise(rb_eRuntimeError, "repeated combination reentered");
}
}
Expand Down
11 changes: 4 additions & 7 deletions bignum.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ end
*/

#ifdef HAVE_UINT16_T
#if SIZEOF_BDIGIT_DBL == 2
static const int maxpow16_exp[35] = {
15, 10, 7, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3,
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
Expand All @@ -234,8 +234,7 @@ static const uint16_t maxpow16_num[35] = {
U16(0x00006978), U16(0x0000745f), U16(0x00008000), U16(0x00008c61),
U16(0x00009988), U16(0x0000a77b), U16(0x0000b640),
};
#endif
#ifdef HAVE_UINT32_T
#elif SIZEOF_BDIGIT_DBL == 4
static const int maxpow32_exp[35] = {
31, 20, 15, 13, 12, 11, 10, 10, 9, 9, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7,
7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
Expand All @@ -251,8 +250,7 @@ static const uint32_t maxpow32_num[35] = {
U32(0x2b73a840), U32(0x34e63b41), U32(0x40000000), U32(0x4cfa3cc1),
U32(0x5c13d840), U32(0x6d91b519), U32(0x81bf1000),
};
#endif
#ifdef HAVE_UINT64_T
#elif SIZEOF_BDIGIT_DBL == 8 && defined HAVE_UINT64_T
static const int maxpow64_exp[35] = {
63, 40, 31, 27, 24, 22, 21, 20, 19, 18, 17, 17, 16, 16, 15, 15, 15,
15, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13, 13, 12, 12, 12, 12, 12,
Expand All @@ -278,8 +276,7 @@ static const uint64_t maxpow64_num[35] = {
U64(0x211e44f7,0xd02c1000), U64(0x2ee56725,0xf06e5c71),
U64(0x41c21cb8,0xe1000000),
};
#endif
#ifdef HAVE_UINT128_T
#elif SIZEOF_BDIGIT_DBL == 16 && defined HAVE_UINT128_T
static const int maxpow128_exp[35] = {
127, 80, 63, 55, 49, 45, 42, 40, 38, 37, 35, 34, 33, 32, 31, 31, 30,
30, 29, 29, 28, 28, 27, 27, 27, 26, 26, 26, 26, 25, 25, 25, 25, 24,
Expand Down
30 changes: 17 additions & 13 deletions class.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ rb_class_subclass_add(VALUE super, VALUE klass)
rb_subclass_entry_t *entry, *head;

if (super && super != Qundef) {
entry = malloc(sizeof(*entry));
entry = xmalloc(sizeof(*entry));
entry->klass = klass;
entry->next = NULL;

Expand All @@ -62,7 +62,7 @@ rb_module_add_to_subclasses_list(VALUE module, VALUE iclass)
{
rb_subclass_entry_t *entry, *head;

entry = malloc(sizeof(*entry));
entry = xmalloc(sizeof(*entry));
entry->klass = iclass;
entry->next = NULL;

Expand All @@ -88,7 +88,7 @@ rb_class_remove_from_super_subclasses(VALUE klass)
if (entry->next) {
RCLASS_EXT(entry->next->klass)->parent_subclasses = RCLASS_EXT(klass)->parent_subclasses;
}
free(entry);
xfree(entry);
}

RCLASS_EXT(klass)->parent_subclasses = NULL;
Expand All @@ -107,7 +107,7 @@ rb_class_remove_from_module_subclasses(VALUE klass)
RCLASS_EXT(entry->next->klass)->module_subclasses = RCLASS_EXT(klass)->module_subclasses;
}

free(entry);
xfree(entry);
}

RCLASS_EXT(klass)->module_subclasses = NULL;
Expand Down Expand Up @@ -329,12 +329,21 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
}
RCLASS_SET_SUPER(clone, RCLASS_SUPER(orig));
RCLASS_EXT(clone)->allocator = RCLASS_EXT(orig)->allocator;
if (RCLASS_IV_TBL(clone)) {
st_free_table(RCLASS_IV_TBL(clone));
RCLASS_IV_TBL(clone) = 0;
}
if (RCLASS_CONST_TBL(clone)) {
rb_free_const_table(RCLASS_CONST_TBL(clone));
RCLASS_CONST_TBL(clone) = 0;
}
if (RCLASS_M_TBL_WRAPPER(clone)) {
rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
RCLASS_M_TBL_WRAPPER(clone) = 0;
}
if (RCLASS_IV_TBL(orig)) {
st_data_t id;

if (RCLASS_IV_TBL(clone)) {
st_free_table(RCLASS_IV_TBL(clone));
}
RCLASS_IV_TBL(clone) = rb_st_copy(clone, RCLASS_IV_TBL(orig));
CONST_ID(id, "__tmp_classpath__");
st_delete(RCLASS_IV_TBL(clone), &id, 0);
Expand All @@ -345,18 +354,13 @@ rb_mod_init_copy(VALUE clone, VALUE orig)
}
if (RCLASS_CONST_TBL(orig)) {
struct clone_const_arg arg;
if (RCLASS_CONST_TBL(clone)) {
rb_free_const_table(RCLASS_CONST_TBL(clone));
}

RCLASS_CONST_TBL(clone) = st_init_numtable();
arg.klass = clone;
arg.tbl = RCLASS_CONST_TBL(clone);
st_foreach(RCLASS_CONST_TBL(orig), clone_const_i, (st_data_t)&arg);
}
if (RCLASS_M_TBL(orig)) {
if (RCLASS_M_TBL_WRAPPER(clone)) {
rb_free_m_tbl_wrapper(RCLASS_M_TBL_WRAPPER(clone));
}
RCLASS_M_TBL_INIT(clone);
st_foreach(RCLASS_M_TBL(orig), clone_method_i, (st_data_t)clone);
}
Expand Down
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ $(CAPIOUT)/.timestamp: Doxyfile $(PREP)
Doxyfile: $(srcdir)/template/Doxyfile.tmpl $(PREP) $(srcdir)/tool/generic_erb.rb $(RBCONFIG)
$(ECHO) generating $@
$(Q) $(MINIRUBY) $(srcdir)/tool/generic_erb.rb -o $@ $(srcdir)/template/Doxyfile.tmpl \
--srcdir="$(srcdir)" --miniruby="$(BASERUBY)"
--srcdir="$(srcdir)" --miniruby="$(MINIRUBY)"

program: showflags $(PROGRAM)
wprogram: showflags $(WPROGRAM)
Expand Down
3 changes: 2 additions & 1 deletion compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ rb_iseq_compile_node(VALUE self, NODE *node)
LABEL *start = iseq->compile_data->start_label = NEW_LABEL(0);
LABEL *end = iseq->compile_data->end_label = NEW_LABEL(0);

ADD_LABEL(ret, start);
ADD_TRACE(ret, FIX2INT(iseq->location.first_lineno), RUBY_EVENT_B_CALL);
ADD_LABEL(ret, start);
COMPILE(ret, "block body", node->nd_body);
ADD_LABEL(ret, end);
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_B_RETURN);
Expand Down Expand Up @@ -2479,6 +2479,7 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
if (i > 0 || !first) ADD_INSN(ret, line, swap);
COMPILE(ret, "keyword splat", kw);
ADD_SEND(ret, line, ID2SYM(id_core_hash_merge_kwd), nhash);
if (nhash == INT2FIX(1)) ADD_SEND(ret, line, ID2SYM(rb_intern("dup")), INT2FIX(0));
}
first = 0;
break;
Expand Down
Loading

0 comments on commit 5d491fe

Please sign in to comment.