mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (BEGIN_CALLARGS): should not always reset ruby_iter,
need to restore previous value. [ruby-talk:77577] * array.c (rb_ary_fill): array length may be changed during the block execution. [ruby-talk:77579] * array.c (rb_ary_zip): ditto. * array.c (rb_ary_fill): ditto. * hash.c (env_reject_bang): length may be changed during the block execution. * hash.c (env_clear): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4254 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81f52e532b
commit
601354bd6b
6 changed files with 61 additions and 34 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
Fri Aug 1 09:54:38 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* eval.c (BEGIN_CALLARGS): should not always reset ruby_iter,
|
||||
need to restore previous value. [ruby-talk:77577]
|
||||
|
||||
* array.c (rb_ary_fill): array length may be changed during the
|
||||
block execution. [ruby-talk:77579]
|
||||
|
||||
* array.c (rb_ary_zip): ditto.
|
||||
|
||||
* array.c (rb_ary_fill): ditto.
|
||||
|
||||
* hash.c (env_reject_bang): length may be changed during the block
|
||||
execution.
|
||||
|
||||
* hash.c (env_clear): ditto.
|
||||
|
||||
Fri Aug 1 00:52:58 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* gc.c (Init_stack): IA64 requires STACK_LEVEL_MAX to be less than
|
||||
|
|
23
array.c
23
array.c
|
@ -50,7 +50,7 @@ rb_ary_modify_check(ary)
|
|||
{
|
||||
if (OBJ_FROZEN(ary)) rb_error_frozen("array");
|
||||
if (FL_TEST(ary, ARY_TMPLOCK))
|
||||
rb_raise(rb_eTypeError, "can't modify array during sort");
|
||||
rb_raise(rb_eTypeError, "can't modify array during iteration");
|
||||
if (!OBJ_TAINTED(ary) && rb_safe_level() >= 4)
|
||||
rb_raise(rb_eSecurityError, "Insecure: can't modify array");
|
||||
}
|
||||
|
@ -839,6 +839,9 @@ rb_ary_reverse_each(ary)
|
|||
|
||||
while (len--) {
|
||||
rb_yield(RARRAY(ary)->ptr[len]);
|
||||
if (RARRAY(ary)->len < len) {
|
||||
len = RARRAY(ary)->len;
|
||||
}
|
||||
}
|
||||
return ary;
|
||||
}
|
||||
|
@ -1423,12 +1426,11 @@ rb_ary_zip(argc, argv, ary)
|
|||
long len;
|
||||
VALUE result;
|
||||
|
||||
len = RARRAY(ary)->len;
|
||||
for (i=0; i<argc; i++) {
|
||||
argv[i] = to_ary(argv[i]);
|
||||
}
|
||||
if (rb_block_given_p()) {
|
||||
for (i=0; i<len; i++) {
|
||||
for (i=0; i<RARRAY(ary)->len; i++) {
|
||||
VALUE tmp = rb_ary_new2(argc+1);
|
||||
|
||||
rb_ary_push(tmp, rb_ary_entry(ary, i));
|
||||
|
@ -1439,6 +1441,7 @@ rb_ary_zip(argc, argv, ary)
|
|||
}
|
||||
return Qnil;
|
||||
}
|
||||
len = RARRAY(ary)->len;
|
||||
result = rb_ary_new2(len);
|
||||
for (i=0; i<len; i++) {
|
||||
VALUE tmp = rb_ary_new2(argc+1);
|
||||
|
@ -1562,15 +1565,21 @@ rb_ary_fill(argc, argv, ary)
|
|||
}
|
||||
RARRAY(ary)->len = end;
|
||||
}
|
||||
p = RARRAY(ary)->ptr + beg;
|
||||
pend = p + len;
|
||||
|
||||
if (block_p) {
|
||||
while (p < pend) {
|
||||
*p++ = rb_yield(LONG2NUM(beg++));
|
||||
VALUE v;
|
||||
long i;
|
||||
|
||||
for (i=0; i<RARRAY(ary)->len; i++) {
|
||||
beg++;
|
||||
v = rb_yield(LONG2NUM(beg++));
|
||||
if (i>=RARRAY(ary)->len) break;
|
||||
RARRAY(ary)->ptr[i] = v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
p = RARRAY(ary)->ptr + beg;
|
||||
pend = p + len;
|
||||
while (p < pend) {
|
||||
*p++ = item;
|
||||
}
|
||||
|
|
2
eval.c
2
eval.c
|
@ -1964,7 +1964,7 @@ copy_node_scope(node, rval)
|
|||
if (ruby_iter->iter == ITER_PRE) {\
|
||||
ruby_block = ruby_block->outer;\
|
||||
}\
|
||||
PUSH_ITER(ITER_NOT)
|
||||
PUSH_ITER((ruby_iter->prev ? ruby_iter->prev->iter : ITER_NOT))
|
||||
|
||||
#define END_CALLARGS \
|
||||
ruby_block = tmp_block;\
|
||||
|
|
38
hash.c
38
hash.c
|
@ -1372,25 +1372,21 @@ static VALUE
|
|||
env_reject_bang()
|
||||
{
|
||||
volatile VALUE keys;
|
||||
VALUE *ptr;
|
||||
long len;
|
||||
long i;
|
||||
int del = 0;
|
||||
|
||||
rb_secure(4);
|
||||
keys = env_keys();
|
||||
ptr = RARRAY(keys)->ptr;
|
||||
len = RARRAY(keys)->len;
|
||||
|
||||
while (len--) {
|
||||
VALUE val = rb_f_getenv(Qnil, *ptr);
|
||||
for (i=0; i<RARRAY(keys)->len; i++) {
|
||||
VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
|
||||
if (!NIL_P(val)) {
|
||||
if (RTEST(rb_yield_values(2, *ptr, val))) {
|
||||
FL_UNSET(*ptr, FL_TAINT);
|
||||
env_delete(Qnil, *ptr);
|
||||
if (RTEST(rb_yield_values(2, RARRAY(keys)->ptr[i], val))) {
|
||||
FL_UNSET(RARRAY(keys)->ptr[i], FL_TAINT);
|
||||
env_delete(Qnil, RARRAY(keys)->ptr[i]);
|
||||
del++;
|
||||
}
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
if (del == 0) return Qnil;
|
||||
return envtbl;
|
||||
|
@ -1454,20 +1450,16 @@ static VALUE
|
|||
env_clear()
|
||||
{
|
||||
volatile VALUE keys;
|
||||
VALUE *ptr;
|
||||
long len;
|
||||
long i;
|
||||
|
||||
rb_secure(4);
|
||||
keys = env_keys();
|
||||
ptr = RARRAY(keys)->ptr;
|
||||
len = RARRAY(keys)->len;
|
||||
|
||||
while (len--) {
|
||||
VALUE val = rb_f_getenv(Qnil, *ptr);
|
||||
for (i=0; i<RARRAY(keys)->len; i++) {
|
||||
VALUE val = rb_f_getenv(Qnil, RARRAY(keys)->ptr[i]);
|
||||
if (!NIL_P(val)) {
|
||||
env_delete(Qnil, *ptr);
|
||||
env_delete(Qnil, RARRAY(keys)->ptr[i]);
|
||||
}
|
||||
ptr++;
|
||||
}
|
||||
return envtbl;
|
||||
}
|
||||
|
@ -1719,18 +1711,14 @@ env_replace(env, hash)
|
|||
VALUE env, hash;
|
||||
{
|
||||
volatile VALUE keys = env_keys();
|
||||
VALUE *ptr;
|
||||
long len;
|
||||
long i;
|
||||
|
||||
if (env == hash) return env;
|
||||
hash = to_hash(hash);
|
||||
st_foreach(RHASH(hash)->tbl, env_replace_i, keys);
|
||||
|
||||
ptr = RARRAY(keys)->ptr;
|
||||
len = RARRAY(keys)->len;
|
||||
|
||||
while (len--) {
|
||||
env_delete(env, *ptr++);
|
||||
for (i=0; i<RARRAY(keys)->len; i++) {
|
||||
env_delete(env, RARRAY(keys)->ptr[i]);
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
|
|
@ -267,4 +267,3 @@ class Shell
|
|||
CommandProcessor.initialize
|
||||
CommandProcessor.run_config
|
||||
end
|
||||
|
||||
|
|
|
@ -1064,6 +1064,20 @@ marity_test(:p)
|
|||
lambda(&method(:test_ok)).call(true)
|
||||
lambda(&get_block{|a,n| test_ok(a,n)}).call(true, 2)
|
||||
|
||||
class ITER_TEST1
|
||||
def a
|
||||
block_given?
|
||||
end
|
||||
end
|
||||
|
||||
class ITER_TEST2 < ITER_TEST1
|
||||
def a
|
||||
test_ok(super)
|
||||
super
|
||||
end
|
||||
end
|
||||
test_ok(ITER_TEST2.new.a {})
|
||||
|
||||
test_check "float"
|
||||
test_ok(2.6.floor == 2)
|
||||
test_ok((-2.6).floor == -3)
|
||||
|
|
Loading…
Reference in a new issue