From f595d5b0d24d9b0323aba79ae07a6e1c9dbfbe36 Mon Sep 17 00:00:00 2001 From: matz Date: Sun, 4 May 2003 16:03:24 +0000 Subject: * array.c (rb_ary_values_at): new method to replace select(index..). * hash.c (rb_hash_values_at,env_values_at): ditto. * re.c (match_values_at): ditto. * struct.c (rb_struct_values_at): ditto. * re.c (match_select): add iterator behavior. * ext/curses/curses.c, ext/digest/sha2/sha2.c, ext/iconv/iconv.c, ext/racc/cparse/cparse.c: include "ruby.h" at the top to shut up "_FILE_OFFSET_BITS redefined" warning on Solaris. * class.c (rb_class_protected_instance_methods): now gives warnings to show migration path. The default will be reversed on Jan 2004. * numeric.c (num_step): "1.1.step(1.5,0.1)" to work. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 29 ++++++++++++++- array.c | 44 ++++++++++++++-------- class.c | 29 ++++++++++++--- ext/curses/curses.c | 3 +- ext/digest/sha2/sha2.c | 2 +- ext/iconv/iconv.c | 2 +- ext/racc/cparse/cparse.c | 2 +- hash.c | 95 +++++++++++++++++++++++++++++++----------------- numeric.c | 2 +- object.c | 61 ++++++++++++++++++++----------- re.c | 31 +++++++++++++++- struct.c | 39 +++++++++++++------- 12 files changed, 241 insertions(+), 98 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b20e1160b..036f198a7d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon May 5 00:46:10 2003 Yukihiro Matsumoto + + * array.c (rb_ary_values_at): new method to replace select(index..). + + * hash.c (rb_hash_values_at,env_values_at): ditto. + + * re.c (match_values_at): ditto. + + * struct.c (rb_struct_values_at): ditto. + + * re.c (match_select): add iterator behavior. + Sun May 4 19:08:53 2003 Tadayoshi Funaba * lib/date/format.rb: synchronized with date2 3.3.2. @@ -10,10 +22,23 @@ Sun May 4 15:06:37 2003 Minero Aoki * lib/net/pop.rb: APOP did not work. [ruby-dev:20149] -Sat May 3 00:58:53 2003 Yukihiro Matsumoto +Sat May 3 21:14:29 2003 Johan Holmberg + + * ext/curses/curses.c, ext/digest/sha2/sha2.c, ext/iconv/iconv.c, + ext/racc/cparse/cparse.c: include "ruby.h" at the top to shut up + "_FILE_OFFSET_BITS redefined" warning on Solaris. + +Sat May 3 11:00:12 2003 Yukihiro Matsumoto * class.c (rb_class_protected_instance_methods): now gives - warnings to show migration path. + warnings to show migration path. The default will be reversed + on Jan 2004. + + * numeric.c (num_step): "1.1.step(1.5,0.1)" to work. + +Sat May 3 00:58:53 2003 Yukihiro Matsumoto + + * object.c (rb_obj_methods): now accepts recurse parameter. * lib/delegate.rb (Delegator::initialize): instance_methods etc. now recurse by default. need to specify false. diff --git a/array.c b/array.c index 8deeaf6ac7..adb511311e 100644 --- a/array.c +++ b/array.c @@ -616,7 +616,7 @@ rb_ary_indexes(argc, argv, ary) VALUE new_ary; long i; - rb_warn("Array#%s is deprecated; use Array#select", + rb_warn("Array#%s is deprecated; use Array#values_at", rb_id2name(rb_frame_last_func())); new_ary = rb_ary_new2(argc); for (i=0; i 0) { - rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc); - } - result = rb_ary_new2(RARRAY(ary)->len); - for (i = 0; i < RARRAY(ary)->len; i++) { - if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) { - rb_ary_push(result, RARRAY(ary)->ptr[i]); - } - } + if (!rb_block_given_p()) { + rb_warn("Array#select(index..) is deprecated; use Array#values_at"); + return rb_ary_values_at(argc, argv, ary); } - else { - result = rb_ary_new2(argc); - for (i=0; i 0) { + rb_raise(rb_eArgError, "wrong number arguments (%d for 0)", argc); + } + result = rb_ary_new2(RARRAY(ary)->len); + for (i = 0; i < RARRAY(ary)->len; i++) { + if (RTEST(rb_yield(RARRAY(ary)->ptr[i]))) { + rb_ary_push(result, RARRAY(ary)->ptr[i]); } } return result; @@ -1954,9 +1965,10 @@ Init_Array() rb_define_method(rb_cArray, "sort!", rb_ary_sort_bang, 0); rb_define_method(rb_cArray, "collect", rb_ary_collect, 0); rb_define_method(rb_cArray, "collect!", rb_ary_collect_bang, 0); - rb_define_method(rb_cArray, "select", rb_ary_select, -1); rb_define_method(rb_cArray, "map", rb_ary_collect, 0); rb_define_method(rb_cArray, "map!", rb_ary_collect_bang, 0); + rb_define_method(rb_cArray, "select", rb_ary_select, -1); + rb_define_method(rb_cArray, "values_at", rb_ary_values_at, -1); rb_define_method(rb_cArray, "delete", rb_ary_delete, 1); rb_define_method(rb_cArray, "delete_at", rb_ary_delete_at_m, 1); rb_define_method(rb_cArray, "delete_if", rb_ary_delete_if, 0); diff --git a/class.c b/class.c index be2be7e5ae..c0d7c1ed5f 100644 --- a/class.c +++ b/class.c @@ -564,8 +564,11 @@ rb_class_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { - rb_warn("instance_methods() default to true; specify false explicitly"); +#if RUBY_RELEASE_CODE < 20040101 + rb_warn("instance_methods parameter will default to 'true' in Jan 2004"); +#else recur = Qtrue; +#endif } return method_list(mod, RTEST(recur), ins_methods_i); } @@ -580,8 +583,11 @@ rb_class_protected_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { - rb_warn("protected_instance_methods() default to true; specify false explicitly"); +#if RUBY_RELEASE_CODE < 20040101 + rb_warn("protected_instance_methods parameter will default to 'true' in Jan 2004"); +#else recur = Qtrue; +#endif } if (argc == 0) recur = Qtrue; return method_list(mod, RTEST(recur), ins_methods_prot_i); @@ -597,8 +603,11 @@ rb_class_private_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { - rb_warn("private_instance_methods() default to true; specify false explicitly"); +#if RUBY_RELEASE_CODE < 20040101 + rb_warn("private_instance_methods parameter will default to 'true' in Jan 2004"); +#else recur = Qtrue; +#endif } if (argc == 0) recur = Qtrue; return method_list(mod, RTEST(recur), ins_methods_priv_i); @@ -614,8 +623,13 @@ rb_class_public_instance_methods(argc, argv, mod) rb_scan_args(argc, argv, "01", &recur); if (argc == 0) { - rb_warn("public_instance_methods() default to true; specify false explicitly"); +#if RUBY_RELEASE_CODE < 20040101 + rb_warn("instance_methods parameter will default to 'true' in Jan 2004"); +#else recur = Qtrue; +#endif + rb_warn("public_instance_methods parameter will default to 'true' in Jan 2004"); + /* recur = Qtrue; */ } if (argc == 0) recur = Qtrue; return method_list(mod, RTEST(recur), ins_methods_pub_i); @@ -632,8 +646,11 @@ rb_obj_singleton_methods(argc, argv, obj) rb_scan_args(argc, argv, "01", &all); if (argc == 0) { - rb_warn("singleton_methods() default to true; specify false explicitly"); - all = Qtrue; +#if RUBY_RELEASE_CODE < 20040101 + rb_warn("singleton_methods parameter will default to 'true' in Jan 2004"); +#else + recur = Qtrue; +#endif } klass = CLASS_OF(obj); list = st_init_numtable(); diff --git a/ext/curses/curses.c b/ext/curses/curses.c index a666cce897..d2263ef007 100644 --- a/ext/curses/curses.c +++ b/ext/curses/curses.c @@ -13,6 +13,8 @@ * - Takaaki Tateishi (ttate@kt.jaist.ac.jp) */ +#include "ruby.h" + #if defined(HAVE_NCURSES_H) # include #elif defined(HAVE_NCURSES_CURSES_H) @@ -46,7 +48,6 @@ #endif #include -#include "ruby.h" #include "rubyio.h" static VALUE mCurses; diff --git a/ext/digest/sha2/sha2.c b/ext/digest/sha2/sha2.c index a3c3258082..31b5ff1690 100644 --- a/ext/digest/sha2/sha2.c +++ b/ext/digest/sha2/sha2.c @@ -36,10 +36,10 @@ /* $RoughId: sha2.c,v 1.3 2002/02/26 22:03:36 knu Exp $ */ /* $Id$ */ +#include "sha2.h" #include #include /* memcpy()/memset() or bcopy()/bzero() */ #include /* assert() */ -#include "sha2.h" /* * ASSERT NOTE: diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 098ffb0cfc..e9f2687858 100644 --- a/ext/iconv/iconv.c +++ b/ext/iconv/iconv.c @@ -32,10 +32,10 @@ Which coding systems are available, it depends on the platform. =end */ +#include "ruby.h" #include #include #include -#include "ruby.h" #include "intern.h" /* Invalid value for iconv_t is -1 but 0 for VALUE, I hope VALUE is diff --git a/ext/racc/cparse/cparse.c b/ext/racc/cparse/cparse.c index 6ed6293dee..3d75cc9ca7 100644 --- a/ext/racc/cparse/cparse.c +++ b/ext/racc/cparse/cparse.c @@ -11,8 +11,8 @@ */ -#include #include "ruby.h" +#include /* ----------------------------------------------------------------------- diff --git a/hash.c b/hash.c index d07530a834..e5aa6cf109 100644 --- a/hash.c +++ b/hash.c @@ -388,7 +388,7 @@ rb_hash_indexes(argc, argv, hash) VALUE indexes; int i; - rb_warn("Hash#%s is deprecated; use Hash#select", + rb_warn("Hash#%s is deprecated; use Hash#values_at", rb_id2name(rb_frame_last_func())); indexes = rb_ary_new2(argc); for (i=0; i 0) { - rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); - } - rb_hash_foreach(hash, select_i, result); + for (i=0; i 0) { + rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); + } + rb_hash_foreach(hash, select_i, result); return result; } @@ -1363,38 +1376,50 @@ env_delete_if() } static VALUE -env_select(argc, argv) +env_values_at(argc, argv) int argc; VALUE *argv; { VALUE result = rb_ary_new(); long i; - if (rb_block_given_p()) { - char **env; + for (i=0; i 0) { - rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); - } - env = GET_ENVIRON(environ); - while (*env) { - char *s = strchr(*env, '='); - if (s) { - VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env), - rb_tainted_str_new2(s+1)); - if (RTEST(rb_yield(assoc))) { - rb_ary_push(result, assoc); - } - } - env++; - } - FREE_ENVIRON(environ); +static VALUE +env_select(argc, argv) + int argc; + VALUE *argv; +{ + VALUE result; + long i; + char **env; + + if (!rb_block_given_p()) { + rb_warn("ENV.select(index..) is deprecated; use ENV.values_at"); + return env_values_at(argc, argv); } - else { - for (i=0; i 0) { + rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); + } + result = rb_ary_new(); + env = GET_ENVIRON(environ); + while (*env) { + char *s = strchr(*env, '='); + if (s) { + VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env), + rb_tainted_str_new2(s+1)); + if (RTEST(rb_yield(assoc))) { + rb_ary_push(result, assoc); + } } + env++; } + FREE_ENVIRON(environ); + return result; } @@ -1575,7 +1600,7 @@ env_indexes(argc, argv) int i; VALUE indexes = rb_ary_new2(argc); - rb_warn("ENV.%s is deprecated; use ENV.select", + rb_warn("ENV.%s is deprecated; use ENV.values_at", rb_id2name(rb_frame_last_func())); for (i=0;iregs; + VALUE target = RMATCH(match)->str; + VALUE result = rb_ary_new(); + int i; + int taint = OBJ_TAINTED(match); + + for (i=0; inum_regs; i++) { + VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]); + if (taint) OBJ_TAINT(str); + if (rb_yield(str)) { + rb_ary_push(result, str); + } + } + return result; + } +} + static VALUE match_to_s(match) VALUE match; @@ -1715,6 +1743,7 @@ Init_Regexp() rb_define_method(rb_cMatch, "to_a", match_to_a, 0); rb_define_method(rb_cMatch, "[]", match_aref, -1); rb_define_method(rb_cMatch, "select", match_select, -1); + rb_define_method(rb_cMatch, "values_at", match_values_at, -1); rb_define_method(rb_cMatch, "pre_match", rb_reg_match_pre, 0); rb_define_method(rb_cMatch, "post_match", rb_reg_match_post, 0); rb_define_method(rb_cMatch, "to_s", match_to_s, 0); diff --git a/struct.c b/struct.c index b1fa31fbd2..d3467bc67b 100644 --- a/struct.c +++ b/struct.c @@ -529,6 +529,19 @@ rb_struct_aset(s, idx, val) return RSTRUCT(s)->ptr[i] = val; } +static VALUE +rb_struct_values_at(argc, argv, s) + int argc; + VALUE *argv; + VALUE s; +{ + VALUE result = rb_ary_new(); + long i; + + for (i=0; i 0) { - rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); - } - for (i = 0; i < RSTRUCT(s)->len; i++) { - if (RTEST(rb_yield(RSTRUCT(s)->ptr[i]))) { - rb_ary_push(result, RSTRUCT(s)->ptr[i]); - } - } + if (!rb_block_given_p()) { + rb_warn("Struct#select(index..) is deprecated; use Struct#values_at"); + return rb_struct_values_at(argc, argv, s); } - else { - for (i=0; i 0) { + rb_raise(rb_eArgError, "wrong number arguments(%d for 0)", argc); + } + result = rb_ary_new(); + for (i = 0; i < RSTRUCT(s)->len; i++) { + if (RTEST(rb_yield(RSTRUCT(s)->ptr[i]))) { + rb_ary_push(result, RSTRUCT(s)->ptr[i]); } } + return result; } @@ -646,6 +658,7 @@ Init_Struct() rb_define_method(rb_cStruct, "[]", rb_struct_aref, 1); rb_define_method(rb_cStruct, "[]=", rb_struct_aset, 2); rb_define_method(rb_cStruct, "select", rb_struct_select, -1); + rb_define_method(rb_cStruct, "values_at", rb_struct_values_at, -1); rb_define_method(rb_cStruct, "members", rb_struct_members, 0); } -- cgit v1.2.3