diff --git a/ChangeLog b/ChangeLog index 5647a4caa9..c4b33554c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jun 26 22:43:20 2013 Nobuyoshi Nakada + + * include/ruby/intern.h (rb_enumerator_size_func): define strict + function declaration for rb_enumeratorize_with_size(). + Wed Jun 26 21:01:22 2013 Hiroshi Shirosaki * test/ruby/test_io.rb (TestIO#test_write_32bit_boundary): skip if diff --git a/array.c b/array.c index 269400b62e..b5518bbf16 100644 --- a/array.c +++ b/array.c @@ -1665,6 +1665,12 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary) static VALUE rb_ary_length(VALUE ary); +static VALUE +ary_enum_length(VALUE ary, VALUE args, VALUE eobj) +{ + return rb_ary_length(ary); +} + /* * call-seq: * ary.each { |item| block } -> ary @@ -1689,7 +1695,7 @@ rb_ary_each(VALUE array) long i; volatile VALUE ary = array; - RETURN_SIZED_ENUMERATOR(ary, 0, 0, rb_ary_length); + RETURN_SIZED_ENUMERATOR(ary, 0, 0, ary_enum_length); for (i=0; i 0)) ? NUM2LONG(RARRAY_AREF(args, 0)) : n; @@ -4699,7 +4705,7 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary) } static VALUE -rb_ary_combination_size(VALUE ary, VALUE args) +rb_ary_combination_size(VALUE ary, VALUE args, VALUE eobj) { long n = RARRAY_LEN(ary); long k = NUM2LONG(RARRAY_AREF(args, 0)); @@ -4822,7 +4828,7 @@ rpermute0(long n, long r, long *p, long index, VALUE values) } static VALUE -rb_ary_repeated_permutation_size(VALUE ary, VALUE args) +rb_ary_repeated_permutation_size(VALUE ary, VALUE args, VALUE eobj) { long n = RARRAY_LEN(ary); long k = NUM2LONG(RARRAY_AREF(args, 0)); @@ -4915,7 +4921,7 @@ rcombinate0(long n, long r, long *p, long index, long rest, VALUE values) } static VALUE -rb_ary_repeated_combination_size(VALUE ary, VALUE args) +rb_ary_repeated_combination_size(VALUE ary, VALUE args, VALUE eobj) { long n = RARRAY_LEN(ary); long k = NUM2LONG(RARRAY_AREF(args, 0)); diff --git a/enum.c b/enum.c index 2b9340fae7..a3cefe735f 100644 --- a/enum.c +++ b/enum.c @@ -312,7 +312,7 @@ find_all_i(VALUE i, VALUE ary, int argc, VALUE *argv) } static VALUE -enum_size(VALUE self, VALUE args) +enum_size(VALUE self, VALUE args, VALUE eobj) { VALUE r; r = rb_check_funcall(self, id_size, 0, 0); @@ -1795,13 +1795,13 @@ each_slice_i(VALUE i, VALUE m, int argc, VALUE *argv) } static VALUE -enum_each_slice_size(VALUE obj, VALUE args) +enum_each_slice_size(VALUE obj, VALUE args, VALUE eobj) { VALUE n, size; long slice_size = NUM2LONG(RARRAY_AREF(args, 0)); if (slice_size <= 0) rb_raise(rb_eArgError, "invalid slice size"); - size = enum_size(obj, 0); + size = enum_size(obj, 0, 0); if (size == Qnil) return Qnil; n = rb_funcall(size, '+', 1, LONG2NUM(slice_size-1)); @@ -1862,13 +1862,13 @@ each_cons_i(VALUE i, VALUE args, int argc, VALUE *argv) } static VALUE -enum_each_cons_size(VALUE obj, VALUE args) +enum_each_cons_size(VALUE obj, VALUE args, VALUE eobj) { VALUE n, size; long cons_size = NUM2LONG(RARRAY_AREF(args, 0)); if (cons_size <= 0) rb_raise(rb_eArgError, "invalid size"); - size = enum_size(obj, 0); + size = enum_size(obj, 0, 0); if (size == Qnil) return Qnil; n = rb_funcall(size, '+', 1, LONG2NUM(1 - cons_size)); @@ -2251,11 +2251,11 @@ cycle_i(VALUE i, VALUE ary, int argc, VALUE *argv) } static VALUE -enum_cycle_size(VALUE self, VALUE args) +enum_cycle_size(VALUE self, VALUE args, VALUE eobj) { long mul; VALUE n = Qnil; - VALUE size = enum_size(self, args); + VALUE size = enum_size(self, args, 0); if (size == Qnil) return Qnil; diff --git a/enumerator.c b/enumerator.c index 54fa49ff3c..0c45bf3d05 100644 --- a/enumerator.c +++ b/enumerator.c @@ -120,7 +120,7 @@ struct enumerator { VALUE feedvalue; VALUE stop_exc; VALUE size; - VALUE (*size_fn)(ANYARGS); + rb_enumerator_size_func *size_fn; }; static VALUE rb_cGenerator, rb_cYielder; @@ -474,6 +474,12 @@ enumerator_with_index_i(VALUE val, VALUE m, int argc, VALUE *argv) static VALUE enumerator_size(VALUE obj); +static VALUE +enumerator_enum_size(VALUE obj, VALUE args, VALUE eobj) +{ + return enumerator_size(obj); +} + /* * call-seq: * e.with_index(offset = 0) {|(*args), idx| ... } @@ -492,7 +498,7 @@ enumerator_with_index(int argc, VALUE *argv, VALUE obj) VALUE memo; rb_scan_args(argc, argv, "01", &memo); - RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_size); + RETURN_SIZED_ENUMERATOR(obj, argc, argv, enumerator_enum_size); if (NIL_P(memo)) memo = INT2FIX(0); else @@ -557,7 +563,7 @@ enumerator_with_object_i(VALUE val, VALUE memo, int argc, VALUE *argv) static VALUE enumerator_with_object(VALUE obj, VALUE memo) { - RETURN_SIZED_ENUMERATOR(obj, 1, &memo, enumerator_size); + RETURN_SIZED_ENUMERATOR(obj, 1, &memo, enumerator_enum_size); enumerator_block_call(obj, enumerator_with_object_i, memo); return memo; diff --git a/hash.c b/hash.c index dcd11d3cfe..903cca24a0 100644 --- a/hash.c +++ b/hash.c @@ -1014,6 +1014,12 @@ delete_if_i(VALUE key, VALUE value, VALUE hash) static VALUE rb_hash_size(VALUE hash); +static VALUE +hash_enum_size(VALUE hash, VALUE args, VALUE eobj) +{ + return rb_hash_size(hash); +} + /* * call-seq: * hsh.delete_if {| key, value | block } -> hsh @@ -1032,7 +1038,7 @@ static VALUE rb_hash_size(VALUE hash); VALUE rb_hash_delete_if(VALUE hash) { - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_modify_check(hash); if (RHASH(hash)->ntbl) rb_hash_foreach(hash, delete_if_i, hash); @@ -1053,7 +1059,7 @@ rb_hash_reject_bang(VALUE hash) { st_index_t n; - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_modify(hash); if (!RHASH(hash)->ntbl) return Qnil; @@ -1130,7 +1136,7 @@ rb_hash_select(VALUE hash) { VALUE result; - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); result = rb_hash_new(); rb_hash_foreach(hash, select_i, result); return result; @@ -1159,7 +1165,7 @@ rb_hash_select_bang(VALUE hash) { st_index_t n; - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_modify_check(hash); if (!RHASH(hash)->ntbl) return Qnil; @@ -1184,7 +1190,7 @@ rb_hash_select_bang(VALUE hash) VALUE rb_hash_keep_if(VALUE hash) { - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_modify_check(hash); if (RHASH(hash)->ntbl) rb_hash_foreach(hash, keep_if_i, hash); @@ -1424,7 +1430,7 @@ each_value_i(VALUE key, VALUE value) static VALUE rb_hash_each_value(VALUE hash) { - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_foreach(hash, each_value_i, 0); return hash; } @@ -1457,7 +1463,7 @@ each_key_i(VALUE key, VALUE value) static VALUE rb_hash_each_key(VALUE hash) { - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_foreach(hash, each_key_i, 0); return hash; } @@ -1494,7 +1500,7 @@ each_pair_i(VALUE key, VALUE value) static VALUE rb_hash_each_pair(VALUE hash) { - RETURN_SIZED_ENUMERATOR(hash, 0, 0, rb_hash_size); + RETURN_SIZED_ENUMERATOR(hash, 0, 0, hash_enum_size); rb_hash_foreach(hash, each_pair_i, 0); return hash; } @@ -2667,7 +2673,7 @@ env_keys(void) } static VALUE -rb_env_size(VALUE ehash) +rb_env_size(VALUE ehash, VALUE args, VALUE eobj) { char **env; long cnt = 0; diff --git a/include/ruby/intern.h b/include/ruby/intern.h index 25199dce7c..4794f563fa 100644 --- a/include/ruby/intern.h +++ b/include/ruby/intern.h @@ -198,7 +198,8 @@ VALUE rb_fiber_alive_p(VALUE); VALUE rb_enum_values_pack(int, VALUE*); /* enumerator.c */ VALUE rb_enumeratorize(VALUE, VALUE, int, VALUE *); -VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, VALUE *, VALUE (*)(ANYARGS)); +typedef VALUE rb_enumerator_size_func(VALUE, VALUE, VALUE); +VALUE rb_enumeratorize_with_size(VALUE, VALUE, int, VALUE *, rb_enumerator_size_func *); #define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn) do { \ if (!rb_block_given_p()) \ return rb_enumeratorize_with_size((obj), ID2SYM(rb_frame_this_func()),\ diff --git a/numeric.c b/numeric.c index 5a15e5b82e..79f8537fdd 100644 --- a/numeric.c +++ b/numeric.c @@ -1829,7 +1829,7 @@ ruby_num_interval_step_size(VALUE from, VALUE to, VALUE step, int excl) } static VALUE -num_step_size(VALUE from, VALUE args) +num_step_size(VALUE from, VALUE args, VALUE eobj) { VALUE to = RARRAY_AREF(args, 0); VALUE step = (RARRAY_LEN(args) > 1) ? RARRAY_AREF(args, 1) : INT2FIX(1); @@ -3473,7 +3473,7 @@ fix_size(VALUE fix) } static VALUE -int_upto_size(VALUE from, VALUE args) +int_upto_size(VALUE from, VALUE args, VALUE eobj) { return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(1), FALSE); } @@ -3520,7 +3520,7 @@ int_upto(VALUE from, VALUE to) } static VALUE -int_downto_size(VALUE from, VALUE args) +int_downto_size(VALUE from, VALUE args, VALUE eobj) { return ruby_num_interval_step_size(from, RARRAY_AREF(args, 0), INT2FIX(-1), FALSE); } @@ -3568,7 +3568,7 @@ int_downto(VALUE from, VALUE to) } static VALUE -int_dotimes_size(VALUE num) +int_dotimes_size(VALUE num, VALUE args, VALUE eobj) { if (FIXNUM_P(num)) { if (NUM2LONG(num) <= 0) return INT2FIX(0); diff --git a/range.c b/range.c index 280c333dc2..8fa7dcb3ba 100644 --- a/range.c +++ b/range.c @@ -327,7 +327,7 @@ discrete_object_p(VALUE obj) } static VALUE -range_step_size(VALUE range, VALUE args) +range_step_size(VALUE range, VALUE args, VALUE eobj) { VALUE b = RANGE_BEG(range), e = RANGE_END(range); VALUE step = INT2FIX(1); @@ -716,6 +716,12 @@ range_size(VALUE range) return Qnil; } +static VALUE +range_enum_size(VALUE range, VALUE args, VALUE eobj) +{ + return range_size(range); +} + /* * call-seq: * rng.each {| i | block } -> rng @@ -742,7 +748,7 @@ range_each(VALUE range) { VALUE beg, end; - RETURN_SIZED_ENUMERATOR(range, 0, 0, range_size); + RETURN_SIZED_ENUMERATOR(range, 0, 0, range_enum_size); beg = RANGE_BEG(range); end = RANGE_END(range); diff --git a/string.c b/string.c index 9cc8e1e54e..49adca7615 100644 --- a/string.c +++ b/string.c @@ -6291,7 +6291,7 @@ rb_str_lines(int argc, VALUE *argv, VALUE str) } static VALUE -rb_str_each_byte_size(VALUE str, VALUE args) +rb_str_each_byte_size(VALUE str, VALUE args, VALUE eobj) { return LONG2FIX(RSTRING_LEN(str)); } @@ -6371,7 +6371,7 @@ rb_str_bytes(VALUE str) } static VALUE -rb_str_each_char_size(VALUE str) +rb_str_each_char_size(VALUE str, VALUE args, VALUE eobj) { long len = RSTRING_LEN(str); if (!single_byte_optimizable(str)) { diff --git a/struct.c b/struct.c index dbfd406f72..5dc5e73ae8 100644 --- a/struct.c +++ b/struct.c @@ -460,6 +460,12 @@ rb_struct_new(VALUE klass, ...) static VALUE rb_struct_size(VALUE s); +static VALUE +struct_enum_size(VALUE s, VALUE args, VALUE eobj) +{ + return rb_struct_size(s); +} + /* * call-seq: * struct.each {|obj| block } -> struct @@ -484,7 +490,7 @@ rb_struct_each(VALUE s) { long i; - RETURN_SIZED_ENUMERATOR(s, 0, 0, rb_struct_size); + RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size); for (i=0; i