1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* eval.c: unify ruby_class (for method definition) and ruby_cbase

(for constant reference).

* eval.c (rb_call0): use TMP_ALLOC() instead of allocating
  a temporary array object.

* eval.c (eval): need not to protect $SAFE value.
  [ruby-core:07177]

* error.c (Init_Exception): change NameError to direct subclass of
  Exception so that default rescue do not handle it silently.

* struct.c (rb_struct_select): update RDoc description.
  [ruby-core:7254]

* numeric.c (int_upto): return an enumerator if no block is
  attached to the method.

* numeric.c (int_downto): ditto.

* numeric.c (int_dotimes): ditto.

* enum.c (enum_first): new method Enumerable#first to take first n
  element from an enumerable.

* enum.c (enum_group_by): new method Enumerable#group_by that
  groups enumerable values according to their block values.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9880 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-02-03 09:15:42 +00:00
parent e4f1feac3e
commit 5675cdbd41
27 changed files with 657 additions and 591 deletions

View file

@ -1,3 +1,8 @@
Fri Feb 3 17:57:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c: unify ruby_class (for method definition) and ruby_cbase
(for constant reference).
Fri Feb 3 15:02:10 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/syck.c (syck_move_tokens): should reset p->cursor or etc
@ -15,6 +20,17 @@ Thu Feb 2 17:13:01 2006 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/rdoc/parsers/parse_rb.rb (RDoc::RubyParser#get_tk): added
support of :'string' style Symbol.
Thu Feb 2 16:01:24 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (rb_call0): use TMP_ALLOC() instead of allocating
a temporary array object.
* eval.c (eval): need not to protect $SAFE value.
[ruby-core:07177]
* error.c (Init_Exception): change NameError to direct subclass of
Exception so that default rescue do not handle it silently.
Thu Feb 2 14:45:53 2006 Ville Mattila <ville.mattila@stonesoft.com>
* configure.in: The isinf is not regognized by autoconf
@ -29,6 +45,11 @@ Wed Feb 1 22:01:47 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ruby.c (set_arg0): if use setenv(3), environ space cannot be used
for altering argv[0].
Tue Jan 31 14:46:28 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* struct.c (rb_struct_select): update RDoc description.
[ruby-core:7254]
Tue Jan 31 11:58:51 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/multi-tk.rb: add MultiTkIp#eval and bg_eval.
@ -36,6 +57,21 @@ Tue Jan 31 11:58:51 2006 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk/namespace.rb: TkNamespace#eval was enbugged at the
last commit. Now it will return a proper object.
Tue Jan 31 08:07:02 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* numeric.c (int_upto): return an enumerator if no block is
attached to the method.
* numeric.c (int_downto): ditto.
* numeric.c (int_dotimes): ditto.
* enum.c (enum_first): new method Enumerable#first to take first n
element from an enumerable.
* enum.c (enum_group_by): new method Enumerable#group_by that
groups enumerable values according to their block values.
Tue Jan 31 00:08:22 2006 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
* ext/syck/rubyext.c (syck_resolver_transfer): workaround for SEGV.

144
enum.c
View file

@ -17,12 +17,6 @@
VALUE rb_mEnumerable;
static ID id_each, id_eqq, id_cmp;
VALUE
rb_each(VALUE obj)
{
return rb_funcall(obj, id_each, 0, 0);
}
static VALUE
grep_i(VALUE i, VALUE *arg)
{
@ -68,7 +62,7 @@ enum_grep(VALUE obj, VALUE pat)
arg[0] = pat;
arg[1] = ary;
rb_iterate(rb_each, obj, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)arg);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? grep_iter_i : grep_i, (VALUE)arg);
return ary;
}
@ -117,13 +111,13 @@ enum_count(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "1", &item);
args[0] = item;
args[1] = 0;
rb_iterate(rb_each, obj, count_i, (VALUE)&args);
rb_block_call(obj, id_each, 0, 0, count_i, (VALUE)&args);
return INT2NUM(args[1]);
}
else {
long n = 0;
rb_iterate(rb_each, obj, count_iter_i, (VALUE)&n);
rb_block_call(obj, id_each, 0, 0, count_iter_i, (VALUE)&n);
return INT2NUM(n);
}
}
@ -161,7 +155,7 @@ enum_find(int argc, VALUE *argv, VALUE obj)
rb_scan_args(argc, argv, "01", &if_none);
RETURN_ENUMERATOR(obj, argc, argv);
rb_iterate(rb_each, obj, find_i, (VALUE)&memo);
rb_block_call(obj, id_each, 0, 0, find_i, (VALUE)&memo);
if (memo != Qundef) {
return memo;
}
@ -201,7 +195,7 @@ enum_find_all(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, find_all_i, ary);
rb_block_call(obj, id_each, 0, 0, find_all_i, ary);
return ary;
}
@ -234,7 +228,7 @@ enum_reject(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, reject_i, ary);
rb_block_call(obj, id_each, 0, 0, reject_i, ary);
return ary;
}
@ -276,7 +270,7 @@ enum_collect(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
ary = rb_ary_new();
rb_iterate(rb_each, obj, collect_i, ary);
rb_block_call(obj, id_each, 0, 0, collect_i, ary);
return ary;
}
@ -296,7 +290,7 @@ enum_to_a(VALUE obj)
{
VALUE ary = rb_ary_new();
rb_iterate(rb_each, obj, collect_all, ary);
rb_block_call(obj, id_each, 0, 0, collect_all, ary);
return ary;
}
@ -351,7 +345,7 @@ enum_inject(int argc, VALUE *argv, VALUE obj)
if (rb_scan_args(argc, argv, "01", &memo) == 0)
memo = Qundef;
rb_iterate(rb_each, obj, inject_i, (VALUE)&memo);
rb_block_call(obj, id_each, 0, 0, inject_i, (VALUE)&memo);
if (memo == Qundef) return Qnil;
return memo;
}
@ -389,11 +383,103 @@ enum_partition(VALUE obj)
ary[0] = rb_ary_new();
ary[1] = rb_ary_new();
rb_iterate(rb_each, obj, partition_i, (VALUE)ary);
rb_block_call(obj, id_each, 0, 0, partition_i, (VALUE)ary);
return rb_assoc_new(ary[0], ary[1]);
}
static VALUE
group_by_i(VALUE i, VALUE hash)
{
VALUE group = rb_yield(i);
VALUE values;
values = rb_hash_aref(hash, group);
if (NIL_P(values)) {
values = rb_ary_new3(1, i);
rb_hash_aset(hash, group, values);
}
else {
rb_ary_push(values, i);
}
return Qnil;
}
/*
* call-seq:
* enum.group_by {| obj | block } => a_hash
*
* Returns a hash, which keys are evaluated result from the
* block, and values are arrays of elements in <i>enum</i>
* corresponding to the key.
*
* (1..6).group_by {|i| i%3} #=> {0=>[3, 6], 1=>[1, 4], 2=>[2, 5]}
*
*/
static VALUE
enum_group_by(VALUE obj)
{
VALUE hash;
RETURN_ENUMERATOR(obj, 0, 0);
hash = rb_hash_new();
rb_block_call(obj, id_each, 0, 0, group_by_i, hash);
return hash;
}
static VALUE
first_i(VALUE i, VALUE *ary)
{
if (NIL_P(ary[0])) {
ary[1] = i;
rb_iter_break();
}
else {
long n = NUM2LONG(ary[0]);
if (n <= 0) {
rb_iter_break();
}
rb_ary_push(ary[1], i);
n--;
ary[0] = INT2NUM(n);
}
return Qnil;
}
/*
* call-seq:
* enum.first -> obj or nil
* enum.first(n) -> an_array
*
* Returns the first element, or the first +n+ elements, of the enumerable.
* If the enumerable is empty, the first form returns <code>nil</code>, and the
* second form returns an empty array.
*
*/
static VALUE
enum_first(int argc, VALUE *argv, VALUE obj)
{
VALUE n, ary[2];
rb_scan_args(argc, argv, "01", &n);
if (NIL_P(n)) {
ary[0] = ary[1] = Qnil;
}
else {
ary[0] = n;
ary[1] = rb_ary_new2(NUM2LONG(n));
}
rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
return ary[1];
}
/*
* call-seq:
* enum.sort => array
@ -525,7 +611,7 @@ enum_sort_by(VALUE obj)
ary = rb_ary_new();
}
RBASIC(ary)->klass = 0;
rb_iterate(rb_each, obj, sort_by_i, ary);
rb_block_call(obj, id_each, 0, 0, sort_by_i, ary);
if (RARRAY(ary)->len > 1) {
ruby_qsort(RARRAY(ary)->ptr, RARRAY(ary)->len, sizeof(VALUE), sort_by_cmp, 0);
}
@ -581,7 +667,7 @@ enum_all(VALUE obj)
{
VALUE result = Qtrue;
rb_iterate(rb_each, obj, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? all_iter_i : all_i, (VALUE)&result);
return result;
}
@ -628,7 +714,7 @@ enum_any(VALUE obj)
{
VALUE result = Qfalse;
rb_iterate(rb_each, obj, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? any_iter_i : any_i, (VALUE)&result);
return result;
}
@ -681,7 +767,7 @@ enum_one(VALUE obj)
{
VALUE result = Qundef;
rb_iterate(rb_each, obj, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? one_iter_i : one_i, (VALUE)&result);
if (result == Qundef) return Qfalse;
return result;
}
@ -726,7 +812,7 @@ enum_none(VALUE obj)
{
VALUE result = Qtrue;
rb_iterate(rb_each, obj, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? none_iter_i : none_i, (VALUE)&result);
return result;
}
@ -784,7 +870,7 @@ enum_min(VALUE obj)
{
VALUE result = Qundef;
rb_iterate(rb_each, obj, rb_block_given_p() ? min_ii : min_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? min_ii : min_i, (VALUE)&result);
if (result == Qundef) return Qnil;
return result;
}
@ -842,7 +928,7 @@ enum_max(VALUE obj)
{
VALUE result = Qundef;
rb_iterate(rb_each, obj, rb_block_given_p() ? max_ii : max_i, (VALUE)&result);
rb_block_call(obj, id_each, 0, 0, rb_block_given_p() ? max_ii : max_i, (VALUE)&result);
if (result == Qundef) return Qnil;
return result;
}
@ -884,7 +970,7 @@ enum_min_by(VALUE obj)
memo[0] = Qundef;
memo[1] = Qnil;
rb_iterate(rb_each, obj, min_by_i, (VALUE)memo);
rb_block_call(obj, id_each, 0, 0, min_by_i, (VALUE)memo);
return memo[1];
}
@ -925,7 +1011,7 @@ enum_max_by(VALUE obj)
memo[0] = Qundef;
memo[1] = Qnil;
rb_iterate(rb_each, obj, max_by_i, (VALUE)memo);
rb_block_call(obj, id_each, 0, 0, max_by_i, (VALUE)memo);
return memo[1];
}
@ -959,7 +1045,7 @@ enum_member(VALUE obj, VALUE val)
memo[0] = val;
memo[1] = Qfalse;
rb_iterate(rb_each, obj, member_i, (VALUE)memo);
rb_block_call(obj, id_each, 0, 0, member_i, (VALUE)memo);
return memo[1];
}
@ -993,7 +1079,7 @@ enum_each_with_index(VALUE obj)
RETURN_ENUMERATOR(obj, 0, 0);
rb_iterate(rb_each, obj, each_with_index_i, (VALUE)&memo);
rb_block_call(obj, id_each, 0, 0, each_with_index_i, (VALUE)&memo);
return obj;
}
@ -1057,7 +1143,7 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
memo[0] = result;
memo[1] = rb_ary_new4(argc, argv);
memo[2] = 0;
rb_iterate(rb_each, obj, zip_i, (VALUE)memo);
rb_block_call(obj, id_each, 0, 0, zip_i, (VALUE)memo);
return result;
}
@ -1094,6 +1180,8 @@ Init_Enumerable(void)
rb_define_method(rb_mEnumerable,"map", enum_collect, 0);
rb_define_method(rb_mEnumerable,"inject", enum_inject, -1);
rb_define_method(rb_mEnumerable,"partition", enum_partition, 0);
rb_define_method(rb_mEnumerable,"group_by", enum_group_by, 0);
rb_define_method(rb_mEnumerable,"first", enum_first, -1);
rb_define_method(rb_mEnumerable,"all?", enum_all, 0);
rb_define_method(rb_mEnumerable,"any?", enum_any, 0);
rb_define_method(rb_mEnumerable,"one?", enum_one, 0);

View file

@ -32,18 +32,6 @@ proc_call(VALUE proc, VALUE args)
return rb_proc_call(proc, args);
}
static VALUE
method_call(VALUE method, VALUE args)
{
int argc = 0;
VALUE *argv = 0;
if (args) {
argc = RARRAY(args)->len;
argv = RARRAY(args)->ptr;
}
return rb_method_call(argc, argv, method);
}
struct enumerator {
VALUE method;
VALUE proc;
@ -168,7 +156,7 @@ enum_each_slice(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
rb_iterate(rb_each, obj, each_slice_i, (VALUE)args);
rb_block_call(obj, rb_intern("each"), 0, 0, each_slice_i, (VALUE)args);
ary = args[0];
if (RARRAY(ary)->len > 0) rb_yield(ary);
@ -235,7 +223,7 @@ enum_each_cons(VALUE obj, VALUE n)
args[0] = rb_ary_new2(size);
args[1] = (VALUE)size;
rb_iterate(rb_each, obj, each_cons_i, (VALUE)args);
rb_block_call(obj, rb_intern("each"), 0, 0, each_cons_i, (VALUE)args);
return Qnil;
}
@ -315,14 +303,6 @@ rb_enumeratorize(VALUE obj, VALUE meth, int argc, VALUE *argv)
return enumerator_init(enumerator_allocate(rb_cEnumerator), obj, meth, argc, argv);
}
static VALUE
enumerator_iter(VALUE memo)
{
struct enumerator *e = (struct enumerator *)memo;
return method_call(e->method, e->args);
}
/*
* call-seq:
* enum.each {...}
@ -335,8 +315,14 @@ static VALUE
enumerator_each(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
int argc = 0;
VALUE *argv = 0;
return rb_iterate(enumerator_iter, (VALUE)e, e->iter, (VALUE)e);
if (e->args) {
argc = RARRAY(e->args)->len;
argv = RARRAY(e->args)->ptr;
}
return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
}
static VALUE
@ -360,9 +346,17 @@ enumerator_with_index(VALUE obj)
{
struct enumerator *e = enumerator_ptr(obj);
VALUE memo = 0;
int argc = 0;
VALUE *argv = 0;
return rb_iterate(enumerator_iter, (VALUE)e,
enumerator_with_index_i, (VALUE)&memo);
if (e->args) {
argc = RARRAY(e->args)->len;
argv = RARRAY(e->args)->ptr;
}
return rb_block_call(e->method, rb_intern("call"), argc, argv, e->iter, (VALUE)e);
return rb_block_call(e->method, rb_intern("call"), argc, argv,
enumerator_with_index_i, (VALUE)&memo);
}
void

9
env.h
View file

@ -22,7 +22,7 @@ RUBY_EXTERN struct FRAME {
struct FRAME *prev;
struct FRAME *tmp;
struct RNode *node;
int iter;
struct BLOCK *block;
int flags;
unsigned long uniq;
} *ruby_frame;
@ -45,8 +45,8 @@ RUBY_EXTERN struct SCOPE {
#define SCOPE_DONT_RECYCLE 4
RUBY_EXTERN int ruby_in_eval;
RUBY_EXTERN VALUE ruby_class;
VALUE ruby_current_class_object(void);
#define ruby_class ruby_current_class_object()
struct RVarmap {
struct RBasic super;
@ -72,7 +72,6 @@ struct BLOCK {
struct SCOPE *scope;
VALUE klass;
struct RNode *cref;
int iter;
int vmode;
int flags;
int uniq;
@ -80,8 +79,6 @@ struct BLOCK {
VALUE orig_thread;
VALUE wrapper;
VALUE block_obj;
struct BLOCK *outer;
struct BLOCK *prev;
};
#define BLOCK_D_SCOPE 1

View file

@ -961,7 +961,7 @@ Init_Exception(void)
rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
rb_eNameError = rb_define_class("NameError", rb_eStandardError);
rb_eNameError = rb_define_class("NameError", rb_eException);
rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
rb_define_method(rb_eNameError, "name", name_err_name, 0);
rb_define_method(rb_eNameError, "to_s", name_err_to_s, 0);

906
eval.c

File diff suppressed because it is too large Load diff

View file

@ -426,20 +426,10 @@ fdbm_invert(obj)
return hash;
}
static VALUE each_pair _((VALUE));
static VALUE fdbm_store(VALUE,VALUE,VALUE);
static VALUE
each_pair(obj)
VALUE obj;
{
return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
}
static VALUE fdbm_store _((VALUE,VALUE,VALUE));
static VALUE
update_i(pair, dbm)
VALUE pair, dbm;
update_i(VALUE pair, VALUE dbm)
{
Check_Type(pair, T_ARRAY);
if (RARRAY(pair)->len < 2) {
@ -450,19 +440,17 @@ update_i(pair, dbm)
}
static VALUE
fdbm_update(obj, other)
VALUE obj, other;
fdbm_update(VALUE obj, VALUE other)
{
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}
static VALUE
fdbm_replace(obj, other)
VALUE obj, other;
fdbm_replace(VALUE obj, VALUE other)
{
fdbm_clear(obj);
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}

View file

@ -530,13 +530,6 @@ fgdbm_invert(obj)
static VALUE each_pair _((VALUE));
static VALUE
each_pair(obj)
VALUE obj;
{
return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
}
static VALUE fgdbm_store _((VALUE,VALUE,VALUE));
static VALUE
@ -555,7 +548,7 @@ static VALUE
fgdbm_update(obj, other)
VALUE obj, other;
{
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}
@ -564,7 +557,7 @@ fgdbm_replace(obj, other)
VALUE obj, other;
{
fgdbm_clear(obj);
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}

View file

@ -522,7 +522,7 @@ get_iconv_opt(struct rb_iconv_opt_t *opt, VALUE options)
opt->transliterate = Qundef;
opt->discard_ilseq = Qundef;
if (!NIL_P(options)) {
rb_iterate(rb_each, options, get_iconv_opt_i, (VALUE)opt);
rb_block_call(options, rb_intern("each"), 0, 0, get_iconv_opt_i, (VALUE)opt);
}
}

View file

@ -678,7 +678,7 @@ static VALUE
join_der(VALUE enumerable)
{
VALUE str = rb_str_new(0, 0);
rb_iterate(rb_each, enumerable, join_der_i, str);
rb_block_call(enumerable, rb_intern("each"), 0, 0, join_der_i, str);
return str;
}

View file

@ -246,7 +246,7 @@ static VALUE
ossl_config_set_section(VALUE self, VALUE section, VALUE hash)
{
VALUE arg[2] = { self, section };
rb_iterate(rb_each, hash, set_conf_section_i, (VALUE)arg);
rb_block_call(hash, rb_intern("each"), 0, 0, set_conf_section_i, (VALUE)arg);
return hash;
}

View file

@ -583,7 +583,7 @@ ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
certs = pkcs7_get_certs_or_crls(self, 1);
while((cert = sk_X509_pop(certs))) X509_free(cert);
rb_iterate(rb_each, ary, ossl_pkcs7_set_certs_i, self);
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
return ary;
}
@ -623,7 +623,7 @@ ossl_pkcs7_set_crls(VALUE self, VALUE ary)
crls = pkcs7_get_certs_or_crls(self, 0);
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
rb_iterate(rb_each, ary, ossl_pkcs7_set_crls_i, self);
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
return ary;
}

View file

@ -324,7 +324,7 @@ ossl_sslctx_setup(VALUE self)
val = ossl_sslctx_get_extra_cert(self);
if(!NIL_P(val)){
rb_iterate(rb_each, val, ossl_sslctx_add_extra_chain_cert_i, self);
rb_block_call(val, rb_intern("each"), 0, 0, ossl_sslctx_add_extra_chain_cert_i, self);
}
/* private key may be bundled in certificate file. */

View file

@ -125,7 +125,7 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
VALUE args;
if(NIL_P(template)) template = OBJECT_TYPE_TEMPLATE;
args = rb_ary_new3(2, self, template);
rb_iterate(rb_each, tmp, ossl_x509name_init_i, args);
rb_block_call(tmp, rb_intern("each"), 0, 0, ossl_x509name_init_i, args);
}
else{
unsigned char *p;

View file

@ -406,13 +406,6 @@ fsdbm_invert(obj)
static VALUE each_pair _((VALUE));
static VALUE
each_pair(obj)
VALUE obj;
{
return rb_funcall(obj, rb_intern("each_pair"), 0, 0);
}
static VALUE fsdbm_store _((VALUE,VALUE,VALUE));
static VALUE
@ -431,7 +424,7 @@ static VALUE
fsdbm_update(obj, other)
VALUE obj, other;
{
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}
@ -440,7 +433,7 @@ fsdbm_replace(obj, other)
VALUE obj, other;
{
fsdbm_clear(obj);
rb_iterate(each_pair, other, update_i, obj);
rb_block_call(other, rb_intern("each_pair"), 0, 0, update_i, obj);
return obj;
}

View file

@ -70,7 +70,7 @@
#endif
#include "sockport.h"
static int do_not_reverse_lookup = 1;
static int do_not_reverse_lookup = 0;
#define FMODE_NOREVLOOKUP 0x100
VALUE rb_cBasicSocket;

View file

@ -571,7 +571,7 @@ yaml_org_handler( n, ref )
VALUE dup = rb_funcall( tmph, s_dup, 0 );
tmp = rb_ary_reverse( tmp );
rb_ary_push( tmp, obj );
rb_iterate( rb_each, tmp, syck_merge_i, dup );
rb_block_call(tmp, rb_intern("each"), 0, 0, syck_merge_i, dup);
obj = dup;
skip_aset = 1;
}
@ -1006,7 +1006,7 @@ syck_resolver_node_import( self, node )
VALUE dup = rb_funcall( end, s_dup, 0 );
v = rb_ary_reverse( v );
rb_ary_push( v, obj );
rb_iterate( rb_each, v, syck_merge_i, dup );
rb_block_call(v, rb_intern("each"), 0, 0, syck_merge_i, dup);
obj = dup;
skip_aset = 1;
}
@ -1175,7 +1175,7 @@ syck_resolver_transfer( self, type, val )
}
else if ( !NIL_P( obj ) && rb_obj_is_instance_of( val, rb_cHash ) )
{
rb_iterate( rb_each, val, syck_set_ivars, obj );
rb_block_call(val, rb_intern("each"), 0, 0, syck_set_ivars, obj);
}
}
else

View file

@ -2218,7 +2218,7 @@ ole_invoke(argc, argv, self, wFlags)
op.dp.cArgs = cNamedArgs + argc - 2;
op.pNamedArgs = ALLOCA_N(OLECHAR*, cNamedArgs + 1);
op.dp.rgvarg = ALLOCA_N(VARIANTARG, op.dp.cArgs);
rb_iterate(rb_each, param, hash2named_arg, (VALUE)&op);
rb_block_call(param, rb_intern("each"), 0, 0, hash2named_arg, (VALUE)&op);
pDispID = ALLOCA_N(DISPID, cNamedArgs + 1);
op.pNamedArgs[0] = ole_mb2wc(StringValuePtr(cmd), -1);

2
io.c
View file

@ -5241,7 +5241,7 @@ argf_each_line(int argc, VALUE *argv, VALUE self)
if (TYPE(current_file) != T_FILE) {
for (;;) {
if (!next_argv()) return argf;
rb_iterate(rb_each, current_file, rb_yield, 0);
rb_block_call(current_file, rb_intern("each"), 0, 0, rb_yield, 0);
next_p = 1;
}
}

View file

@ -1457,8 +1457,8 @@ class OptionParser
: (({block}))
yielded with the found value when succeeded.
=end #'#"#`#
def search(id, k)
visit(:search, id, k) do |k|
def search(id, key)
visit(:search, id, key) do |k|
return k unless block_given?
return yield(k)
end

2
node.h
View file

@ -336,7 +336,7 @@ typedef struct RNode {
#define NEW_ERRINFO() NEW_NODE(NODE_ERRINFO,0,0,0)
#define NEW_DEFINED(e) NEW_NODE(NODE_DEFINED,e,0,0)
#define NEW_PREEXE(b) NEW_SCOPE(b)
#define NEW_POSTEXE() NEW_NODE(NODE_POSTEXE,0,0,0)
#define NEW_POSTEXE(b) NEW_NODE(NODE_POSTEXE,0,b,0)
#define NEW_BMETHOD(b) NEW_NODE(NODE_BMETHOD,0,0,b)
#define NEW_ATTRASGN(r,m,a) NEW_NODE(NODE_ATTRASGN,r,m,a)
#define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)

View file

@ -2672,6 +2672,7 @@ fix_size(VALUE fix)
static VALUE
int_upto(VALUE from, VALUE to)
{
RETURN_ENUMERATOR(from, 1, &to);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@ -2710,6 +2711,7 @@ int_upto(VALUE from, VALUE to)
static VALUE
int_downto(VALUE from, VALUE to)
{
RETURN_ENUMERATOR(from, 1, &to);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
@ -2749,6 +2751,7 @@ int_downto(VALUE from, VALUE to)
static VALUE
int_dotimes(VALUE num)
{
RETURN_ENUMERATOR(num, 0, 0);
if (FIXNUM_P(num)) {
long i, end;

View file

@ -867,7 +867,7 @@ stmt : kALIAS fitem {lex_state = EXPR_FNAME;} fitem
rb_warn("END in method; use at_exit");
}
$$ = NEW_ITER(0, NEW_POSTEXE(), $3);
$$ = NEW_POSTEXE($3);
/*%
if (in_def || in_single) {
rb_warn0("END in method; use at_exit");

1
ruby.h
View file

@ -575,6 +575,7 @@ VALUE rb_yield_splat(VALUE);
int rb_block_given_p(void);
void rb_need_block(void);
VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE);
VALUE rb_iterate_method(VALUE,ID,VALUE,VALUE(*)(ANYARGS),VALUE);
VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);
VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...);
VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE);

View file

@ -667,21 +667,15 @@ rb_struct_values_at(int argc, VALUE *argv, VALUE s)
/*
* call-seq:
* struct.select(fixnum, ... ) => array
* struct.select {|i| block } => array
*
* The first form returns an array containing the elements in
* <i>struct</i> corresponding to the given indices. The second
* form invokes the block passing in successive elements from
* Invokes the block passing in successive elements from
* <i>struct</i>, returning an array containing those elements
* for which the block returns a true value (equivalent to
* <code>Enumerable#select</code>).
*
* Lots = Struct.new(:a, :b, :c, :d, :e, :f)
* l = Lots.new(11, 22, 33, 44, 55, 66)
* l.select(1, 3, 5) #=> [22, 44, 66]
* l.select(0, 2, 4) #=> [11, 33, 55]
* l.select(-1, -3, -5) #=> [66, 44, 22]
* l.select {|v| (v % 2).zero? } #=> [22, 44, 66]
*/

View file

@ -1,11 +1,18 @@
module EnvUtil
def rubybin
unless ENV["RUBYOPT"]
end
if ruby = ENV["RUBY"]
return ruby
end
ruby = "ruby"
rubyexe = ruby+".exe"
3.times do
if File.exist? ruby or File.exist? ruby+".exe"
if File.exist? ruby and File.executable? ruby and !File.directory? ruby
return File.expand_path(ruby)
end
if File.exist? rubyexe and File.executable? rubyexe
return File.expand_path(ruby)
end
ruby = File.join("..", ruby)

View file

@ -9,7 +9,11 @@ class WEBrick::TestFileHandler < Test::Unit::TestCase
end
def get_res_body(res)
return res.body.read rescue res.body
if defined? res.body.read
res.body.read
else
res.body
end
end
def make_range_request(range_spec)