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

* eval.c: remove rb_cBlock.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3952 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-06-17 03:12:28 +00:00
parent ae6fd90c18
commit f7afa61a0a
3 changed files with 35 additions and 44 deletions

View file

@ -1,3 +1,7 @@
Mon Jun 16 19:01:25 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c: remove rb_cBlock.
Mon Jun 16 18:06:33 2003 WATANABE Hirofumi <eban@ruby-lang.org> Mon Jun 16 18:06:33 2003 WATANABE Hirofumi <eban@ruby-lang.org>
* numeric.c (rb_fix2uint): renamed from rb_fix2int on IA64. * numeric.c (rb_fix2uint): renamed from rb_fix2int on IA64.

74
eval.c
View file

@ -93,7 +93,7 @@ char *strrchr _((const char*,const char));
#include <sys/stat.h> #include <sys/stat.h>
VALUE rb_cBlock, rb_cProc; VALUE rb_cProc;
static VALUE rb_cBinding; static VALUE rb_cBinding;
static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE)); static VALUE proc_invoke _((VALUE,VALUE,VALUE,VALUE));
static VALUE rb_f_binding _((VALUE)); static VALUE rb_f_binding _((VALUE));
@ -2179,21 +2179,11 @@ static int handle_rescue _((VALUE,NODE*));
static void blk_free(); static void blk_free();
static VALUE
rb_obj_is_block(block)
VALUE block;
{
if (TYPE(block) == T_DATA && RDATA(block)->dfree == (RUBY_DATA_FUNC)blk_free) {
return Qtrue;
}
return Qfalse;
}
static VALUE static VALUE
rb_obj_is_proc(proc) rb_obj_is_proc(proc)
VALUE proc; VALUE proc;
{ {
if (rb_obj_is_block(proc) && rb_obj_is_kind_of(proc, rb_cProc)) { if (TYPE(proc) == T_DATA && RDATA(proc)->dfree == (RUBY_DATA_FUNC)blk_free) {
return Qtrue; return Qtrue;
} }
return Qfalse; return Qfalse;
@ -5341,7 +5331,7 @@ eval(self, src, scope, file, line)
int state; int state;
if (!NIL_P(scope)) { if (!NIL_P(scope)) {
if (!rb_obj_is_block(scope)) { if (!rb_obj_is_proc(scope)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)", rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
rb_obj_classname(scope)); rb_obj_classname(scope));
} }
@ -6837,8 +6827,7 @@ proc_alloc(klass, proc)
struct RVarmap *vars; struct RVarmap *vars;
if (!rb_block_given_p() && !rb_f_block_given_p()) { if (!rb_block_given_p() && !rb_f_block_given_p()) {
rb_raise(rb_eArgError, "tried to create %s object without a block", rb_raise(rb_eArgError, "tried to create Proc object without a block");
proc ? "Proc" : "Block");
} }
if (proc && !rb_block_given_p()) { if (proc && !rb_block_given_p()) {
rb_warn("tried to create Proc object without a block"); rb_warn("tried to create Proc object without a block");
@ -7132,7 +7121,7 @@ block_pass(self, node)
VALUE self; VALUE self;
NODE *node; NODE *node;
{ {
VALUE block = rb_eval(self, node->nd_body); /* OK */ VALUE proc = rb_eval(self, node->nd_body); /* OK */
VALUE b; VALUE b;
struct BLOCK * volatile old_block; struct BLOCK * volatile old_block;
struct BLOCK _block; struct BLOCK _block;
@ -7142,28 +7131,28 @@ block_pass(self, node)
volatile int orphan; volatile int orphan;
volatile int safe = ruby_safe_level; volatile int safe = ruby_safe_level;
if (NIL_P(block)) { if (NIL_P(proc)) {
PUSH_ITER(ITER_NOT); PUSH_ITER(ITER_NOT);
result = rb_eval(self, node->nd_iter); result = rb_eval(self, node->nd_iter);
POP_ITER(); POP_ITER();
return result; return result;
} }
if (!rb_obj_is_block(block)) { if (!rb_obj_is_proc(proc)) {
b = rb_check_convert_type(block, T_DATA, "Block", "to_proc"); b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc");
if (!rb_obj_is_block(b)) { if (!rb_obj_is_proc(b)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Block)", rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc)",
rb_obj_classname(block)); rb_obj_classname(proc));
} }
block = b; proc = b;
} }
if (ruby_safe_level >= 1 && OBJ_TAINTED(block)) { if (ruby_safe_level >= 1 && OBJ_TAINTED(proc)) {
if (ruby_safe_level > proc_get_safe_level(block)) { if (ruby_safe_level > proc_get_safe_level(proc)) {
rb_raise(rb_eSecurityError, "Insecure: tainted block value"); rb_raise(rb_eSecurityError, "Insecure: tainted block value");
} }
} }
Data_Get_Struct(block, struct BLOCK, data); Data_Get_Struct(proc, struct BLOCK, data);
orphan = block_orphan(data); orphan = block_orphan(data);
retry: retry:
@ -7178,7 +7167,7 @@ block_pass(self, node)
PUSH_TAG(PROT_NONE); PUSH_TAG(PROT_NONE);
state = EXEC_TAG(); state = EXEC_TAG();
if (state == 0) { if (state == 0) {
proc_set_safe_level(block); proc_set_safe_level(proc);
if (safe > ruby_safe_level) if (safe > ruby_safe_level)
ruby_safe_level = safe; ruby_safe_level = safe;
result = rb_eval(self, node->nd_iter); result = rb_eval(self, node->nd_iter);
@ -7217,7 +7206,7 @@ block_pass(self, node)
goto retry; goto retry;
case TAG_RETURN: case TAG_RETURN:
if (orphan) { if (orphan) {
localjump_error("return from block-closure", prot_tag->retval, state); localjump_error("return from proc-closure", prot_tag->retval, state);
} }
default: default:
JUMP_TAG(state); JUMP_TAG(state);
@ -7513,16 +7502,6 @@ mproc(method)
POP_FRAME(); POP_FRAME();
POP_ITER(); POP_ITER();
if (method) {
struct METHOD *mdata;
struct BLOCK *bdata;
Data_Get_Struct(method, struct METHOD, mdata);
Data_Get_Struct(proc, struct BLOCK, bdata);
bdata->body->nd_file = mdata->body->nd_file;
nd_set_line(bdata->body, nd_line(mdata->body));
}
return proc; return proc;
} }
@ -7548,7 +7527,17 @@ static VALUE
method_proc(method) method_proc(method)
VALUE method; VALUE method;
{ {
return rb_iterate((VALUE(*)_((VALUE)))mproc, method, bmcall, method); VALUE proc;
struct METHOD *mdata;
struct BLOCK *bdata;
proc = rb_iterate((VALUE(*)_((VALUE)))mproc, 0, bmcall, method);
Data_Get_Struct(method, struct METHOD, mdata);
Data_Get_Struct(proc, struct BLOCK, bdata);
bdata->body->nd_file = mdata->body->nd_file;
nd_set_line(bdata->body, nd_line(mdata->body));
return proc;
} }
static VALUE static VALUE
@ -7579,8 +7568,8 @@ rb_mod_define_method(argc, argv, mod)
else if (argc == 2) { else if (argc == 2) {
id = rb_to_id(argv[0]); id = rb_to_id(argv[0]);
body = argv[1]; body = argv[1];
if (!rb_obj_is_method(body) && !rb_obj_is_block(body)) { if (!rb_obj_is_method(body) && !rb_obj_is_proc(body)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Block/Method)", rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Method)",
rb_obj_classname(body)); rb_obj_classname(body));
} }
} }
@ -7602,7 +7591,7 @@ rb_mod_define_method(argc, argv, mod)
} }
else { else {
/* type error */ /* type error */
rb_raise(rb_eTypeError, "wrong argument type (expected Block/Method)"); rb_raise(rb_eTypeError, "wrong argument type (expected Proc/Method)");
} }
if (SCOPE_TEST(SCOPE_PRIVATE)) { if (SCOPE_TEST(SCOPE_PRIVATE)) {
@ -7633,7 +7622,6 @@ Init_Proc()
rb_global_variable(&sysstack_error); rb_global_variable(&sysstack_error);
rb_cProc = rb_define_class("Proc", rb_cObject); rb_cProc = rb_define_class("Proc", rb_cObject);
rb_cBlock = rb_cProc;
rb_undef_alloc_func(rb_cProc); rb_undef_alloc_func(rb_cProc);
rb_define_singleton_method(rb_cProc, "new", proc_s_new, -1); rb_define_singleton_method(rb_cProc, "new", proc_s_new, -1);

1
ruby.h
View file

@ -575,7 +575,6 @@ RUBY_EXTERN VALUE rb_cIO;
RUBY_EXTERN VALUE rb_cModule; RUBY_EXTERN VALUE rb_cModule;
RUBY_EXTERN VALUE rb_cNilClass; RUBY_EXTERN VALUE rb_cNilClass;
RUBY_EXTERN VALUE rb_cNumeric; RUBY_EXTERN VALUE rb_cNumeric;
RUBY_EXTERN VALUE rb_cBlock;
RUBY_EXTERN VALUE rb_cProc; RUBY_EXTERN VALUE rb_cProc;
RUBY_EXTERN VALUE rb_cRange; RUBY_EXTERN VALUE rb_cRange;
RUBY_EXTERN VALUE rb_cRegexp; RUBY_EXTERN VALUE rb_cRegexp;