mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (rb_yield_0): give warning for multiple values for a
block parameter. * eval.c (rb_yield_values): a function to yield multiple values. * array.c (sort_1): use rb_yield_values. * enum.c (min_ii, max_ii): ditto. * hash.c (rb_hash_update_block_i, delete_if_i, select_i, each_pair_i, env_each, env_reject_bang, env_select, env_update_i): ditto. * struct.c (rb_struct_each_pair): ditto. * eval.c (top_include): should include module in the current self, not ruby_top_self. [ruby-dev:20198] * eval.c (top_include): stop inclusion to ruby_wrapper; give warning. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3833 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3b68b107e9
commit
82cf98939f
8 changed files with 83 additions and 28 deletions
23
ChangeLog
23
ChangeLog
|
@ -16,6 +16,29 @@ Tue May 20 10:51:26 2003 Nobuyoshi Nakada <nobu.nokada@softhome.net>
|
||||||
* error.c (name_err_initialize, nometh_err_initialize,
|
* error.c (name_err_initialize, nometh_err_initialize,
|
||||||
syserr_initialize): initialize attributes.
|
syserr_initialize): initialize attributes.
|
||||||
|
|
||||||
|
Tue May 20 10:26:56 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (rb_yield_0): give warning for multiple values for a
|
||||||
|
block parameter.
|
||||||
|
|
||||||
|
* eval.c (rb_yield_values): a function to yield multiple values.
|
||||||
|
|
||||||
|
* array.c (sort_1): use rb_yield_values.
|
||||||
|
|
||||||
|
* enum.c (min_ii, max_ii): ditto.
|
||||||
|
|
||||||
|
* hash.c (rb_hash_update_block_i, delete_if_i, select_i,
|
||||||
|
each_pair_i, env_each, env_reject_bang, env_select,
|
||||||
|
env_update_i): ditto.
|
||||||
|
|
||||||
|
* struct.c (rb_struct_each_pair): ditto.
|
||||||
|
|
||||||
|
* eval.c (top_include): should include module in the current self,
|
||||||
|
not ruby_top_self. [ruby-dev:20198]
|
||||||
|
|
||||||
|
* eval.c (top_include): stop inclusion to ruby_wrapper; give
|
||||||
|
warning.
|
||||||
|
|
||||||
Mon May 19 18:54:30 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
|
Mon May 19 18:54:30 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
|
||||||
|
|
||||||
* ext/syck/token.c, ext/syck/implicit.c: expanded character set to
|
* ext/syck/token.c, ext/syck/implicit.c: expanded character set to
|
||||||
|
|
2
array.c
2
array.c
|
@ -1085,7 +1085,7 @@ static int
|
||||||
sort_1(a, b)
|
sort_1(a, b)
|
||||||
VALUE *a, *b;
|
VALUE *a, *b;
|
||||||
{
|
{
|
||||||
VALUE retval = rb_yield(rb_assoc_new(*a, *b));
|
VALUE retval = rb_yield_values(2, *a, *b);
|
||||||
return rb_cmpint(retval, *a, *b);
|
return rb_cmpint(retval, *a, *b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
4
enum.c
4
enum.c
|
@ -397,7 +397,7 @@ min_ii(i, memo)
|
||||||
memo->u1.value = i;
|
memo->u1.value = i;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
|
cmp = rb_yield_values(2, i, memo->u1.value);
|
||||||
if (rb_cmpint(cmp, i, memo->u1.value) < 0) {
|
if (rb_cmpint(cmp, i, memo->u1.value) < 0) {
|
||||||
memo->u1.value = i;
|
memo->u1.value = i;
|
||||||
}
|
}
|
||||||
|
@ -448,7 +448,7 @@ max_ii(i, memo)
|
||||||
memo->u1.value = i;
|
memo->u1.value = i;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
cmp = rb_yield(rb_assoc_new(i, memo->u1.value));
|
cmp = rb_yield_values(2, i, memo->u1.value);
|
||||||
if (rb_cmpint(cmp, i, memo->u1.value) > 0) {
|
if (rb_cmpint(cmp, i, memo->u1.value) > 0) {
|
||||||
memo->u1.value = i;
|
memo->u1.value = i;
|
||||||
}
|
}
|
||||||
|
|
49
eval.c
49
eval.c
|
@ -4025,7 +4025,7 @@ rb_yield_0(val, self, klass, pcall, avalue)
|
||||||
if (block->var) {
|
if (block->var) {
|
||||||
PUSH_TAG(PROT_NONE);
|
PUSH_TAG(PROT_NONE);
|
||||||
if ((state = EXEC_TAG()) == 0) {
|
if ((state = EXEC_TAG()) == 0) {
|
||||||
if (block->var == (NODE*)1) {
|
if (block->var == (NODE*)1) { /* no parameter || */
|
||||||
if (pcall && RARRAY(val)->len != 0) {
|
if (pcall && RARRAY(val)->len != 0) {
|
||||||
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
|
rb_raise(rb_eArgError, "wrong number of arguments (%ld for 0)",
|
||||||
RARRAY(val)->len);
|
RARRAY(val)->len);
|
||||||
|
@ -4044,8 +4044,22 @@ rb_yield_0(val, self, klass, pcall, avalue)
|
||||||
massign(self, block->var, val, pcall);
|
massign(self, block->var, val, pcall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (avalue) val = avalue_splat(val);
|
if (avalue) {
|
||||||
if (val == Qundef) val = Qnil;
|
if (RARRAY(val)->len == 0) {
|
||||||
|
goto zero_arg;
|
||||||
|
}
|
||||||
|
if (RARRAY(val)->len == 1) {
|
||||||
|
val = RARRAY(val)->ptr[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rb_warn("multiple values for a block parameter (%d for 1)", RARRAY(val)->len);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (val == Qundef) {
|
||||||
|
zero_arg:
|
||||||
|
rb_warn("multiple values for a block parameter (0 for 1)");
|
||||||
|
val = Qnil;
|
||||||
|
}
|
||||||
assign(self, block->var, val, pcall);
|
assign(self, block->var, val, pcall);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4136,6 +4150,26 @@ rb_yield(val)
|
||||||
return rb_yield_0(val, 0, 0, 0, 0);
|
return rb_yield_0(val, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
#ifdef HAVE_STDARG_PROTOTYPES
|
||||||
|
rb_yield_values(int n, ...)
|
||||||
|
#else
|
||||||
|
rb_yield_values(int n, va_alist)
|
||||||
|
int n;
|
||||||
|
va_dcl
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
VALUE ary = rb_ary_new2(n);
|
||||||
|
|
||||||
|
va_init_list(args, n);
|
||||||
|
while (n--) {
|
||||||
|
rb_ary_push(ary, va_arg(args, VALUE));
|
||||||
|
}
|
||||||
|
va_end(args);
|
||||||
|
return rb_yield_0(ary, 0, 0, 0, Qtrue);
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
rb_f_loop()
|
rb_f_loop()
|
||||||
{
|
{
|
||||||
|
@ -5623,7 +5657,7 @@ rb_load(fname, wrap)
|
||||||
/* load in anonymous module as toplevel */
|
/* load in anonymous module as toplevel */
|
||||||
ruby_class = ruby_wrapper = rb_module_new();
|
ruby_class = ruby_wrapper = rb_module_new();
|
||||||
self = rb_obj_clone(ruby_top_self);
|
self = rb_obj_clone(ruby_top_self);
|
||||||
rb_extend_object(self, ruby_class);
|
rb_extend_object(self, ruby_wrapper);
|
||||||
PUSH_CREF(ruby_wrapper);
|
PUSH_CREF(ruby_wrapper);
|
||||||
}
|
}
|
||||||
PUSH_ITER(ITER_NOT);
|
PUSH_ITER(ITER_NOT);
|
||||||
|
@ -6167,14 +6201,15 @@ rb_obj_extend(argc, argv, obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
top_include(argc, argv)
|
top_include(argc, argv, self)
|
||||||
int argc;
|
int argc;
|
||||||
VALUE *argv;
|
VALUE *argv;
|
||||||
|
VALUE self;
|
||||||
{
|
{
|
||||||
rb_secure(4);
|
rb_secure(4);
|
||||||
if (ruby_wrapper) {
|
if (ruby_wrapper) {
|
||||||
rb_obj_extend(argc, argv, ruby_top_self);
|
rb_warn("main#include in the wrapped load is effective only for toplevel");
|
||||||
return rb_mod_include(argc, argv, ruby_wrapper);
|
return rb_obj_extend(argc, argv, self);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return rb_mod_include(argc, argv, rb_cObject);
|
return rb_mod_include(argc, argv, rb_cObject);
|
||||||
|
|
29
hash.c
29
hash.c
|
@ -465,7 +465,7 @@ delete_if_i(key, value)
|
||||||
VALUE key, value;
|
VALUE key, value;
|
||||||
{
|
{
|
||||||
if (key == Qundef) return ST_CONTINUE;
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
if (RTEST(rb_yield(rb_assoc_new(key, value))))
|
if (RTEST(rb_yield_values(2, key, value)))
|
||||||
return ST_DELETE;
|
return ST_DELETE;
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
@ -500,12 +500,9 @@ static enum st_retval
|
||||||
select_i(key, value, result)
|
select_i(key, value, result)
|
||||||
VALUE key, value, result;
|
VALUE key, value, result;
|
||||||
{
|
{
|
||||||
VALUE assoc;
|
|
||||||
|
|
||||||
if (key == Qundef) return ST_CONTINUE;
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
assoc = rb_assoc_new(key, value);
|
if (RTEST(rb_yield_values(2, key, value)))
|
||||||
if (RTEST(rb_yield(assoc)))
|
rb_ary_push(result, rb_assoc_new(key, value));
|
||||||
rb_ary_push(result, assoc);
|
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -663,7 +660,7 @@ each_pair_i(key, value)
|
||||||
VALUE key, value;
|
VALUE key, value;
|
||||||
{
|
{
|
||||||
if (key == Qundef) return ST_CONTINUE;
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
rb_yield(rb_assoc_new(key, value));
|
rb_yield_values(2, key, value);
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -938,7 +935,7 @@ rb_hash_update_block_i(key, value, hash)
|
||||||
{
|
{
|
||||||
if (key == Qundef) return ST_CONTINUE;
|
if (key == Qundef) return ST_CONTINUE;
|
||||||
if (rb_hash_has_key(hash, key)) {
|
if (rb_hash_has_key(hash, key)) {
|
||||||
value = rb_yield(rb_ary_new3(3, key, rb_hash_aref(hash, key), value));
|
value = rb_yield_values(3, key, rb_hash_aref(hash, key), value);
|
||||||
}
|
}
|
||||||
rb_hash_aset(hash, key, value);
|
rb_hash_aset(hash, key, value);
|
||||||
return ST_CONTINUE;
|
return ST_CONTINUE;
|
||||||
|
@ -1334,8 +1331,8 @@ env_each(hash)
|
||||||
while (*env) {
|
while (*env) {
|
||||||
char *s = strchr(*env, '=');
|
char *s = strchr(*env, '=');
|
||||||
if (s) {
|
if (s) {
|
||||||
rb_yield(rb_assoc_new(rb_tainted_str_new(*env, s-*env),
|
rb_yield_values(2, rb_tainted_str_new(*env, s-*env),
|
||||||
rb_tainted_str_new2(s+1)));
|
rb_tainted_str_new2(s+1));
|
||||||
}
|
}
|
||||||
env++;
|
env++;
|
||||||
}
|
}
|
||||||
|
@ -1359,7 +1356,7 @@ env_reject_bang()
|
||||||
while (len--) {
|
while (len--) {
|
||||||
VALUE val = rb_f_getenv(Qnil, *ptr);
|
VALUE val = rb_f_getenv(Qnil, *ptr);
|
||||||
if (!NIL_P(val)) {
|
if (!NIL_P(val)) {
|
||||||
if (RTEST(rb_yield(rb_assoc_new(*ptr, val)))) {
|
if (RTEST(rb_yield_values(2, *ptr, val))) {
|
||||||
FL_UNSET(*ptr, FL_TAINT);
|
FL_UNSET(*ptr, FL_TAINT);
|
||||||
env_delete(Qnil, *ptr);
|
env_delete(Qnil, *ptr);
|
||||||
del++;
|
del++;
|
||||||
|
@ -1413,10 +1410,10 @@ env_select(argc, argv)
|
||||||
while (*env) {
|
while (*env) {
|
||||||
char *s = strchr(*env, '=');
|
char *s = strchr(*env, '=');
|
||||||
if (s) {
|
if (s) {
|
||||||
VALUE assoc = rb_assoc_new(rb_tainted_str_new(*env, s-*env),
|
VALUE k = rb_tainted_str_new(*env, s-*env);
|
||||||
rb_tainted_str_new2(s+1));
|
VALUE v = rb_tainted_str_new2(s+1);
|
||||||
if (RTEST(rb_yield(assoc))) {
|
if (RTEST(rb_yield_values(2, k, v))) {
|
||||||
rb_ary_push(result, assoc);
|
rb_ary_push(result, rb_assoc_new(k, v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
env++;
|
env++;
|
||||||
|
@ -1712,7 +1709,7 @@ env_update_i(key, val)
|
||||||
{
|
{
|
||||||
if (key != Qundef) {
|
if (key != Qundef) {
|
||||||
if (rb_block_given_p()) {
|
if (rb_block_given_p()) {
|
||||||
val = rb_yield(rb_ary_new3(3, key, rb_f_getenv(Qnil, key), val));
|
val = rb_yield_values(3, key, rb_f_getenv(Qnil, key), val);
|
||||||
}
|
}
|
||||||
env_aset(Qnil, key, val);
|
env_aset(Qnil, key, val);
|
||||||
}
|
}
|
||||||
|
|
1
ruby.h
1
ruby.h
|
@ -532,6 +532,7 @@ void rb_warn __((const char*, ...)); /* reports always */
|
||||||
|
|
||||||
VALUE rb_each _((VALUE));
|
VALUE rb_each _((VALUE));
|
||||||
VALUE rb_yield _((VALUE));
|
VALUE rb_yield _((VALUE));
|
||||||
|
VALUE rb_yield_values __((int n, ...));
|
||||||
int rb_block_given_p _((void));
|
int rb_block_given_p _((void));
|
||||||
VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE));
|
VALUE rb_iterate _((VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE));
|
||||||
VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE));
|
VALUE rb_rescue _((VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE));
|
||||||
|
|
|
@ -254,7 +254,6 @@ test_ok(f.call(42) == 42)
|
||||||
test_ok(f.call([42]) == [42])
|
test_ok(f.call([42]) == [42])
|
||||||
test_ok(f.call([[42]]) == [[42]])
|
test_ok(f.call([[42]]) == [[42]])
|
||||||
test_ok(f.call([42,55]) == [42,55])
|
test_ok(f.call([42,55]) == [42,55])
|
||||||
test_ok(f.call(42,55) == [42,55])
|
|
||||||
|
|
||||||
f = lambda{|x,| x}
|
f = lambda{|x,| x}
|
||||||
test_ok(f.call(42) == 42)
|
test_ok(f.call(42) == 42)
|
||||||
|
|
2
struct.c
2
struct.c
|
@ -346,7 +346,7 @@ rb_struct_each_pair(s)
|
||||||
rb_bug("non-initialized struct");
|
rb_bug("non-initialized struct");
|
||||||
}
|
}
|
||||||
for (i=0; i<RSTRUCT(s)->len; i++) {
|
for (i=0; i<RSTRUCT(s)->len; i++) {
|
||||||
rb_yield(rb_assoc_new(RARRAY(member)->ptr[i], RSTRUCT(s)->ptr[i]));
|
rb_yield_values(2, RARRAY(member)->ptr[i], RSTRUCT(s)->ptr[i]);
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue