summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c79
1 files changed, 51 insertions, 28 deletions
diff --git a/eval.c b/eval.c
index 74ef503..f8d1ea8 100644
--- a/eval.c
+++ b/eval.c
@@ -168,10 +168,10 @@ print_undef(klass, id)
VALUE klass;
ID id;
{
- rb_raise(rb_eNameError, "undefined method `%s' for %s `%s'",
- rb_id2name(id),
- (TYPE(klass) == T_MODULE)?"module":"class",
- rb_class2name(klass));
+ rb_name_error(id, "undefined method `%s' for %s `%s'",
+ rb_id2name(id),
+ (TYPE(klass) == T_MODULE)?"module":"class",
+ rb_class2name(klass));
}
static ID removed, singleton_removed, undefined, singleton_undefined;
@@ -315,8 +315,8 @@ remove_method(klass, mid)
}
if (OBJ_FROZEN(klass)) rb_error_frozen("class/module");
if (!st_delete(RCLASS(klass)->m_tbl, &mid, &body)) {
- rb_raise(rb_eNameError, "method `%s' not defined in %s",
- rb_id2name(mid), rb_class2name(klass));
+ rb_name_error(mid, "method `%s' not defined in %s",
+ rb_id2name(mid), rb_class2name(klass));
}
rb_clear_cache_by_id(mid);
if (FL_TEST(klass, FL_SINGLETON)) {
@@ -546,6 +546,7 @@ struct BLOCK {
int flags;
struct RVarmap *dyna_vars;
VALUE orig_thread;
+ VALUE wrapper;
struct BLOCK *prev;
};
@@ -1273,7 +1274,7 @@ rb_eval_string_wrap(str, state)
PUSH_CLASS();
ruby_class = ruby_wrapper = rb_module_new();
ruby_top_self = rb_obj_clone(ruby_top_self);
- rb_extend_object(self, ruby_class);
+ rb_extend_object(ruby_top_self, ruby_class);
val = rb_eval_string_protect(str, &status);
ruby_top_self = self;
@@ -1336,7 +1337,7 @@ rb_eval_cmd(cmd, arg)
saved_scope = ruby_scope;
ruby_scope = top_scope;
- ruby_class = rb_cObject;
+ ruby_class = ruby_wrapper ? ruby_wrapper : rb_cObject;
if (OBJ_TAINTED(cmd)) {
ruby_safe_level = 4;
}
@@ -1545,8 +1546,8 @@ rb_undef(klass, id)
else if (TYPE(c) == T_MODULE) {
s0 = " module";
}
- rb_raise(rb_eNameError, "undefined method `%s' for%s `%s'",
- rb_id2name(id),s0,rb_class2name(c));
+ rb_name_error(id, "undefined method `%s' for%s `%s'",
+ rb_id2name(id),s0,rb_class2name(c));
}
rb_add_method(klass, id, 0, NOEX_PUBLIC);
rb_clear_cache_by_id(id);
@@ -2378,7 +2379,7 @@ rb_eval(self, n)
case NODE_BREAK:
if (node->nd_stts) {
- return_value(rb_eval(self, node->nd_stts));
+ return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
}
else {
return_value(Qnil);
@@ -2388,7 +2389,7 @@ rb_eval(self, n)
case NODE_NEXT:
if (node->nd_stts) {
- return_value(rb_eval(self, node->nd_stts));
+ return_value(avalue_to_svalue(rb_eval(self, node->nd_stts)));
}
else {
return_value(Qnil);
@@ -2616,8 +2617,9 @@ rb_eval(self, n)
TMP_PROTECT;
if (ruby_frame->last_class == 0) {
- rb_raise(rb_eNameError, "superclass method `%s' disabled",
- rb_id2name(ruby_frame->last_func));
+ rb_name_error(ruby_frame->last_func,
+ "superclass method `%s' disabled",
+ rb_id2name(ruby_frame->last_func));
}
if (nd_type(node) == NODE_ZSUPER) {
argc = ruby_frame->argc;
@@ -4119,7 +4121,6 @@ rb_f_missing(argc, argv, obj)
}
id = SYM2ID(argv[0]);
- argc--; argv++;
switch (TYPE(obj)) {
case T_NIL:
@@ -4167,9 +4168,17 @@ rb_f_missing(argc, argv, obj)
PUSH_FRAME(); /* fake frame */
*ruby_frame = *_frame.prev->prev;
- rb_raise(exc, format, rb_id2name(id),
- desc, desc[0]=='#'?"":":",
- desc[0]=='#'?"":rb_class2name(CLASS_OF(obj)));
+ {
+ char buf[BUFSIZ];
+
+ snprintf(buf, BUFSIZ, format, rb_id2name(id),
+ desc, desc[0]=='#'?"":":",
+ desc[0]=='#'?"":rb_class2name(CLASS_OF(obj)));
+ exc = rb_exc_new2(exc, buf);
+ rb_iv_set(exc, "name", argv[0]);
+ rb_iv_set(exc, "args", rb_ary_new4(argc-1, argv+1));
+ rb_exc_raise(exc);
+ }
POP_FRAME();
return Qnil; /* not reached */
@@ -4195,15 +4204,15 @@ rb_undefined(obj, id, argc, argv, call_status)
}
#ifdef DJGPP
-static int STACK_LEVEL_MAX = 65535;
+static unsigned int STACK_LEVEL_MAX = 65535;
#else
#ifdef __human68k__
-extern int _stacksize;
+extern unsigned int _stacksize;
# define STACK_LEVEL_MAX (_stacksize - 4096)
#undef HAVE_GETRLIMIT
#else
#ifdef HAVE_GETRLIMIT
-static int STACK_LEVEL_MAX = 655300;
+static unsigned int STACK_LEVEL_MAX = 655300;
#else
# define STACK_LEVEL_MAX 655300
#endif
@@ -4586,8 +4595,8 @@ rb_call(klass, recv, mid, argc, argv, scope)
}
else if ((body = rb_get_method_body(&klass, &id, &noex)) == 0) {
if (scope == 3) {
- rb_raise(rb_eNameError, "super: no superclass method `%s'",
- rb_id2name(mid));
+ rb_name_error(mid, "super: no superclass method `%s'",
+ rb_id2name(mid));
}
return rb_undefined(recv, mid, argc, argv, scope==2?CSTAT_VCALL:0);
}
@@ -4712,8 +4721,8 @@ rb_call_super(argc, argv)
VALUE result;
if (ruby_frame->last_class == 0) {
- rb_raise(rb_eNameError, "superclass method `%s' must be enabled by rb_enable_super()",
- rb_id2name(ruby_frame->last_func));
+ rb_name_error(ruby_frame->last_func, "superclass method `%s' must be enabled by rb_enable_super()",
+ rb_id2name(ruby_frame->last_func));
}
PUSH_ITER(ruby_iter->iter?ITER_PRE:ITER_NOT);
@@ -4843,6 +4852,7 @@ eval(self, src, scope, file, line)
struct RVarmap * volatile old_dyna_vars;
VALUE volatile old_cref;
int volatile old_vmode;
+ volatile VALUE old_wrapper;
struct FRAME frame;
char *filesave = ruby_sourcefile;
int linesave = ruby_sourceline;
@@ -4853,6 +4863,7 @@ eval(self, src, scope, file, line)
file = ruby_sourcefile;
line = ruby_sourceline;
}
+ PUSH_CLASS();
if (!NIL_P(scope)) {
if (!rb_obj_is_block(scope)) {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Proc/Binding)",
@@ -4874,17 +4885,18 @@ eval(self, src, scope, file, line)
scope_vmode = data->vmode;
old_cref = (VALUE)ruby_cref;
ruby_cref = (NODE*)ruby_frame->cbase;
+ old_wrapper = ruby_wrapper;
+ ruby_wrapper = data->wrapper;
self = data->self;
ruby_frame->iter = data->iter;
+ ruby_class = ruby_cbase;
}
else {
if (ruby_frame->prev) {
ruby_frame->iter = ruby_frame->prev->iter;
}
}
- PUSH_CLASS();
- ruby_class = ruby_cbase;
ruby_in_eval++;
if (TYPE(ruby_class) == T_ICLASS) {
@@ -4909,6 +4921,7 @@ eval(self, src, scope, file, line)
if (!NIL_P(scope)) {
int dont_recycle = ruby_scope->flags & SCOPE_DONT_RECYCLE;
+ ruby_wrapper = old_wrapper;
ruby_cref = (NODE*)old_cref;
ruby_frame = frame.tmp;
ruby_scope = old_scope;
@@ -6079,6 +6092,7 @@ blk_mark(data)
rb_gc_mark((VALUE)data->dyna_vars);
rb_gc_mark((VALUE)data->klass);
rb_gc_mark((VALUE)data->tag);
+ rb_gc_mark(data->wrapper);
data = data->prev;
}
}
@@ -6194,6 +6208,7 @@ rb_f_binding(self)
*data = *ruby_block;
data->orig_thread = rb_thread_current();
+ data->wrapper = ruby_wrapper;
data->iter = rb_f_block_given_p();
frame_dup(&data->frame);
if (ruby_frame->prev) {
@@ -6283,6 +6298,7 @@ proc_new(klass)
*data = *ruby_block;
data->orig_thread = rb_thread_current();
+ data->wrapper = ruby_wrapper;
data->iter = data->prev?Qtrue:Qfalse;
frame_dup(&data->frame);
if (data->iter) {
@@ -6352,6 +6368,7 @@ proc_invoke(proc, args, pcall)
int state;
volatile int orphan;
volatile int safe = ruby_safe_level;
+ volatile VALUE old_wrapper = ruby_wrapper;
if (rb_block_given_p() && ruby_frame->last_func) {
rb_warning("block for %s#%s is useless",
@@ -6362,6 +6379,7 @@ proc_invoke(proc, args, pcall)
Data_Get_Struct(proc, struct BLOCK, data);
orphan = blk_orphan(data);
+ ruby_wrapper = data->wrapper;
/* PUSH BLOCK from data */
old_block = ruby_block;
_block = *data;
@@ -6387,6 +6405,7 @@ proc_invoke(proc, args, pcall)
state &= TAG_MASK;
}
ruby_block = old_block;
+ ruby_wrapper = old_wrapper;
ruby_safe_level = safe;
switch (state) {
@@ -6496,6 +6515,7 @@ block_pass(self, node)
int state;
volatile int orphan;
volatile int safe = ruby_safe_level;
+ volatile VALUE old_wrapper = ruby_wrapper;
if (NIL_P(block)) {
return rb_eval(self, node->nd_iter);
@@ -6511,6 +6531,8 @@ block_pass(self, node)
Data_Get_Struct(block, struct BLOCK, data);
orphan = blk_orphan(data);
+ ruby_wrapper = data->wrapper;
+
/* PUSH BLOCK from data */
old_block = ruby_block;
_block = *data;
@@ -6548,6 +6570,7 @@ block_pass(self, node)
}
}
ruby_block = old_block;
+ ruby_wrapper = old_wrapper;
ruby_safe_level = safe;
switch (state) {/* escape from orphan procedure */
@@ -8989,7 +9012,7 @@ rb_f_throw(argc, argv)
tt = tt->prev;
}
if (!tt) {
- rb_raise(rb_eNameError, "uncaught throw `%s'", rb_id2name(t));
+ rb_name_error(t, "uncaught throw `%s'", rb_id2name(t));
}
return_value(value);
rb_trap_restore_mask();