git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@835 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2000-07-15 00:33:12 +00:00
parent cc2c313903
commit 3f3bcc697e
5 changed files with 107 additions and 22 deletions

View File

@ -1,3 +1,9 @@
Sat Jul 15 01:32:34 2000 Yukihiro Matsumoto <matz@netlab.co.jp>
* eval.c (Init_eval): should prohibit `include' and
`module_function' for class Class. The latter was very
dangerous.
Fri Jul 14 17:19:59 2000 WATANABE Hirofumi <eban@os.rim.or.jp> Fri Jul 14 17:19:59 2000 WATANABE Hirofumi <eban@os.rim.or.jp>
* cygwin/GNUmakefile.in: use miniruby instead of sed. * cygwin/GNUmakefile.in: use miniruby instead of sed.

4
README
View File

@ -74,7 +74,7 @@ the error log and machine/OS type, to help others.
* Copying * Copying
Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.co.jp>. Ruby is copyrighted free software by Yukihiro Matsumoto <matz@zetabits.com>.
You can redistribute it and/or modify it under either the terms of the GPL You can redistribute it and/or modify it under either the terms of the GPL
(see COPYING file), or the conditions below: (see COPYING file), or the conditions below:
@ -143,7 +143,7 @@ The URL of the Ruby home-page is:
Feel free to send comments and bug reports to the author. Here is the Feel free to send comments and bug reports to the author. Here is the
author's latest mail address: author's latest mail address:
matz@netlab.co.jp matz@zetabits.com
------------------------------------------------------- -------------------------------------------------------
created at: Thu Aug 3 11:57:36 JST 1995 created at: Thu Aug 3 11:57:36 JST 1995

View File

@ -191,7 +191,7 @@ Public License)
* Ãø¼Ô * Ãø¼Ô
コメント,バグレポートその他は matz@netlab.co.jp まで. コメント,バグレポートその他は matz@zetabis.com まで.
------------------------------------------------------- -------------------------------------------------------
created at: Thu Aug 3 11:57:36 JST 1995 created at: Thu Aug 3 11:57:36 JST 1995
Local variables: Local variables:

115
eval.c
View File

@ -78,6 +78,7 @@ static VALUE rb_f_block_given_p _((void));
static VALUE block_pass _((VALUE,NODE*)); static VALUE block_pass _((VALUE,NODE*));
static VALUE rb_cMethod; static VALUE rb_cMethod;
static VALUE method_proc _((VALUE)); static VALUE method_proc _((VALUE));
static VALUE rb_cUnboundMethod;
static int scope_vmode; static int scope_vmode;
#define SCOPE_PUBLIC 0 #define SCOPE_PUBLIC 0
@ -5557,6 +5558,9 @@ Init_eval()
rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1); rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1); rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
rb_undef_method(rb_cClass, "include");
rb_undef_method(rb_cClass, "module_function");
rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1); rb_define_private_method(rb_cModule, "remove_method", rb_mod_remove_method, 1);
rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1); rb_define_private_method(rb_cModule, "undef_method", rb_mod_undef_method, 1);
rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2); rb_define_private_method(rb_cModule, "alias_method", rb_mod_alias_method, 2);
@ -6094,22 +6098,20 @@ bm_mark(data)
} }
static VALUE static VALUE
rb_obj_method(obj, vid) mnew(klass, obj, id, mklass)
VALUE obj; VALUE klass, obj, mklass;
VALUE vid; ID id;
{ {
VALUE method; VALUE method;
VALUE klass = CLASS_OF(obj);
ID id;
NODE *body; NODE *body;
int noex; int noex;
struct METHOD *data; struct METHOD *data;
VALUE oklass = klass;
id = rb_to_id(vid); ID oid = id;
again: again:
if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) { if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
return rb_undefined(obj, rb_to_id(vid), 0, 0, 0); print_undef(oklass, oid);
} }
if (nd_type(body) == NODE_ZSUPER) { if (nd_type(body) == NODE_ZSUPER) {
@ -6117,20 +6119,36 @@ rb_obj_method(obj, vid)
goto again; goto again;
} }
method = Data_Make_Struct(rb_cMethod, struct METHOD, bm_mark, free, data); method = Data_Make_Struct(mklass, struct METHOD, bm_mark, free, data);
data->klass = klass; data->klass = klass;
data->recv = obj; data->recv = obj;
data->id = id; data->id = id;
data->body = body; data->body = body;
data->oklass = CLASS_OF(obj); data->oklass = oklass;
data->oid = rb_to_id(vid); data->oid = oid;
if (OBJ_TAINTED(obj)) { if (OBJ_TAINTED(obj) || OBJ_TAINTED(klass)) {
OBJ_TAINT(method); OBJ_TAINT(method);
} }
return method; return method;
} }
static VALUE
rb_obj_method(obj, vid)
VALUE obj;
VALUE vid;
{
return mnew(CLASS_OF(obj), obj, rb_to_id(vid), rb_cMethod);
}
static VALUE
rb_mod_method(mod, vid)
VALUE mod;
VALUE vid;
{
return mnew(mod, 0, rb_to_id(vid), rb_cUnboundMethod);
}
static VALUE static VALUE
method_clone(self) method_clone(self)
VALUE self; VALUE self;
@ -6139,7 +6157,7 @@ method_clone(self)
struct METHOD *orig, *data; struct METHOD *orig, *data;
Data_Get_Struct(self, struct METHOD, orig); Data_Get_Struct(self, struct METHOD, orig);
clone = Data_Make_Struct(rb_cMethod,struct METHOD,bm_mark,free,data); clone = Data_Make_Struct(CLASS_OF(self),struct METHOD,bm_mark,free,data);
CLONESETUP(clone, self); CLONESETUP(clone, self);
*data = *orig; *data = *orig;
@ -6147,10 +6165,10 @@ method_clone(self)
} }
static VALUE static VALUE
method_call(argc, argv, method) mcall(argc, argv, method, recv)
int argc; int argc;
VALUE *argv; VALUE *argv;
VALUE method; VALUE method, recv;
{ {
VALUE result; VALUE result;
struct METHOD *data; struct METHOD *data;
@ -6160,12 +6178,12 @@ method_call(argc, argv, method)
Data_Get_Struct(method, struct METHOD, data); Data_Get_Struct(method, struct METHOD, data);
PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT); PUSH_ITER(rb_block_given_p()?ITER_PRE:ITER_NOT);
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
if (OBJ_TAINTED(data->recv) || OBJ_TAINTED(method)) { if (OBJ_TAINTED(recv) || OBJ_TAINTED(method)) {
OBJ_TAINT(method); OBJ_TAINT(method);
if (ruby_safe_level < 4) ruby_safe_level = 4; if (ruby_safe_level < 4) ruby_safe_level = 4;
} }
if ((state = EXEC_TAG()) == 0) { if ((state = EXEC_TAG()) == 0) {
result = rb_call0(data->klass, data->recv, data->id, result = rb_call0(data->klass, recv, data->id,
argc, argv, data->body, 0); argc, argv, data->body, 0);
} }
POP_TAG(); POP_TAG();
@ -6175,6 +6193,42 @@ method_call(argc, argv, method)
return result; return result;
} }
static VALUE
method_call(argc, argv, method)
int argc;
VALUE *argv;
VALUE method;
{
struct METHOD *data;
Data_Get_Struct(method, struct METHOD, data);
return mcall(argc, argv, method, data->recv);
}
static VALUE
umethod_call(argc, argv, method)
int argc;
VALUE *argv;
VALUE method;
{
struct METHOD *data;
if (argc < 1) {
rb_raise(rb_eArgError, "wrong # of arguments");
}
Data_Get_Struct(method, struct METHOD, data);
if (FL_TEST(CLASS_OF(argv[0]), FL_SINGLETON) &&
st_lookup(RCLASS(CLASS_OF(argv[0]))->m_tbl, data->oid, 0)) {
rb_raise(rb_eTypeError, "method `%s' overridden", rb_id2name(data->oid));
}
if (!rb_obj_is_instance_of(argv[0], data->oklass)) {
rb_raise(rb_eTypeError, "first argument must be instance of %s",
rb_class2name(data->oklass));
}
return mcall(argc-1, argv+1, method, argv[0]);
}
static VALUE static VALUE
method_arity(method) method_arity(method)
VALUE method; VALUE method;
@ -6247,7 +6301,7 @@ mproc()
} }
static VALUE static VALUE
mcall(args, method) bmcall(args, method)
VALUE args, method; VALUE args, method;
{ {
if (TYPE(args) == T_ARRAY) { if (TYPE(args) == T_ARRAY) {
@ -6256,11 +6310,28 @@ mcall(args, method)
return method_call(1, &args, method); return method_call(1, &args, method);
} }
static VALUE
umcall(args, method)
VALUE args, method;
{
if (TYPE(args) == T_ARRAY) {
return umethod_call(RARRAY(args)->len, RARRAY(args)->ptr, method);
}
return umethod_call(1, &args, method);
}
static VALUE static VALUE
method_proc(method) method_proc(method)
VALUE method; VALUE method;
{ {
return rb_iterate(mproc, 0, mcall, method); return rb_iterate(mproc, 0, bmcall, method);
}
static VALUE
umethod_proc(method)
VALUE method;
{
return rb_iterate(mproc, 0, umcall, method);
} }
void void
@ -6292,6 +6363,12 @@ Init_Proc()
rb_define_method(rb_cMethod, "to_s", method_inspect, 0); rb_define_method(rb_cMethod, "to_s", method_inspect, 0);
rb_define_method(rb_cMethod, "to_proc", method_proc, 0); rb_define_method(rb_cMethod, "to_proc", method_proc, 0);
rb_define_method(rb_mKernel, "method", rb_obj_method, 1); rb_define_method(rb_mKernel, "method", rb_obj_method, 1);
rb_cUnboundMethod = rb_define_class("UnboundMethod", rb_cMethod);
rb_define_method(rb_cUnboundMethod, "call", umethod_call, -1);
rb_define_method(rb_cUnboundMethod, "[]", umethod_call, -1);
rb_define_method(rb_cUnboundMethod, "to_proc", umethod_proc, 0);
rb_define_method(rb_cModule, "instance_method", rb_mod_method, 1);
} }
static VALUE rb_eThreadError; static VALUE rb_eThreadError;

View File

@ -231,6 +231,7 @@ rb_obj_is_instance_of(obj, c)
switch (TYPE(c)) { switch (TYPE(c)) {
case T_MODULE: case T_MODULE:
case T_CLASS: case T_CLASS:
case T_ICLASS:
break; break;
case T_NIL: case T_NIL:
@ -266,6 +267,7 @@ rb_obj_is_kind_of(obj, c)
switch (TYPE(c)) { switch (TYPE(c)) {
case T_MODULE: case T_MODULE:
case T_CLASS: case T_CLASS:
case T_ICLASS:
break; break;
default: default: