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

* array.c: protoize.

* eval.c (splat_value): simpler and consistent array conversion
  for argument splat.  [yarv-dev:599]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9119 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2005-09-10 13:34:53 +00:00
parent 9207bf1041
commit ef05021686
3 changed files with 149 additions and 321 deletions

View file

@ -1,3 +1,12 @@
Sat Sep 10 22:34:19 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* array.c: protoize.
Sat Sep 10 00:23:01 2005 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (splat_value): simpler and consistent array conversion
for argument splat. [yarv-dev:599]
Fri Sep 9 16:45:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Sep 9 16:45:25 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_times): make empty strings to keep taintness, * string.c (rb_str_times): make empty strings to keep taintness,

421
array.c

File diff suppressed because it is too large Load diff

34
eval.c
View file

@ -377,8 +377,10 @@ static ID init, eqq, each, aref, aset, match, missing;
static ID added, singleton_added; static ID added, singleton_added;
static ID __id__, __send__, respond_to; static ID __id__, __send__, respond_to;
#define NOEX_WITH_SAFE(n) ((n) | ruby_safe_level << 4) #define NOEX_TAINTED 8
#define NOEX_SAFE(n) ((n) >> 4) #define NOEX_SAFE(n) ((n) >> 4)
#define NOEX_WITH(n, v) ((n) | (v) << 4)
#define NOEX_WITH_SAFE(n) NOEX_WITH(n, ruby_safe_level)
void void
rb_add_method(klass, mid, node, noex) rb_add_method(klass, mid, node, noex)
@ -2778,11 +2780,11 @@ static VALUE
splat_value(v) splat_value(v)
VALUE v; VALUE v;
{ {
VALUE val; VALUE tmp = rb_check_array_type(v);
if (NIL_P(v)) val = rb_ary_new3(1, Qnil); if (NIL_P(tmp)) v = rb_ary_new3(1, v);
else val = rb_Array(v); else v = tmp;
return rb_values_from_ary(val); return rb_values_from_ary(v);
} }
static VALUE static VALUE
@ -5924,12 +5926,16 @@ rb_call0(klass, recv, id, oid, argc, argv, body, flags)
} }
b2 = body = body->nd_next; b2 = body = body->nd_next;
PUSH_VARS();
PUSH_TAG(PROT_FUNC);
if (NOEX_SAFE(flags) > ruby_safe_level) { if (NOEX_SAFE(flags) > ruby_safe_level) {
if (ruby_safe_level == 0 && NOEX_SAFE(flags) > 2) {
rb_raise(rb_eSecurityError, "calling insecure method: %s",
rb_id2name(id));
}
safe = ruby_safe_level; safe = ruby_safe_level;
ruby_safe_level = NOEX_SAFE(flags); ruby_safe_level = NOEX_SAFE(flags);
} }
PUSH_VARS();
PUSH_TAG(PROT_FUNC);
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
NODE *node = 0; NODE *node = 0;
@ -8359,9 +8365,11 @@ static void
proc_save_safe_level(data) proc_save_safe_level(data)
VALUE data; VALUE data;
{ {
if (ruby_safe_level >= 3) {
int safe = ruby_safe_level; int safe = ruby_safe_level;
if (safe > PROC_TMAX) safe = PROC_TMAX; if (safe > PROC_TMAX) safe = PROC_TMAX;
FL_SET(data, (safe << PROC_TSHIFT) & PROC_TMASK); FL_SET(data, (safe << PROC_TSHIFT) & PROC_TMASK);
}
} }
static int static int
@ -8575,7 +8583,7 @@ proc_invoke(proc, args, self, klass)
ruby_block = old_block; ruby_block = old_block;
ruby_wrapper = old_wrapper; ruby_wrapper = old_wrapper;
POP_VARS(); POP_VARS();
if (proc_safe_level_p(proc)) ruby_safe_level = safe; ruby_safe_level = safe;
switch (state) { switch (state) {
case 0: case 0:
@ -9238,14 +9246,20 @@ rb_method_call(argc, argv, method)
{ {
VALUE result = Qnil; /* OK */ VALUE result = Qnil; /* OK */
struct METHOD *data; struct METHOD *data;
int safe;
Data_Get_Struct(method, struct METHOD, data); Data_Get_Struct(method, struct METHOD, data);
if (data->recv == Qundef) { if (data->recv == Qundef) {
rb_raise(rb_eTypeError, "can't call unbound method; bind first"); rb_raise(rb_eTypeError, "can't call unbound method; bind first");
} }
if (OBJ_TAINTED(method)) {
safe = NOEX_WITH(data->safe_level, 4)|NOEX_TAINTED;
}
else {
safe = data->safe_level;
}
PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT); PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
result = rb_call0(data->klass,data->recv,data->id,data->oid,argc,argv,data->body, result = rb_call0(data->klass,data->recv,data->id,data->oid,argc,argv,data->body,safe);
data->safe_level);
POP_ITER(); POP_ITER();
return result; return result;
} }