summaryrefslogtreecommitdiff
path: root/eval.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-01 07:34:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1999-02-01 07:34:58 +0000
commit9b0dd20cbb3d0077c374509eb230adba84ed5488 (patch)
tree2a7936d597eff812a4e3fa896de7439b884a75f8 /eval.c
parent2344efc3835c3226fa06a85e6f3b1871415b8ad1 (diff)
990201
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_3@384 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c133
1 files changed, 68 insertions, 65 deletions
diff --git a/eval.c b/eval.c
index ef69ed2644..a7f42c6d81 100644
--- a/eval.c
+++ b/eval.c
@@ -371,7 +371,7 @@ rb_attr(klass, id, read, write, ex)
}
static ID init, eqq, each, aref, aset, match;
-VALUE rb_errinfo = Qnil;
+VALUE ruby_errinfo = Qnil;
extern NODE *ruby_eval_tree_begin;
extern NODE *ruby_eval_tree;
extern int ruby_nerrs;
@@ -789,9 +789,9 @@ error_print()
VALUE einfo;
volatile int safe = safe_level;
- if (NIL_P(rb_errinfo)) return;
+ if (NIL_P(ruby_errinfo)) return;
- errat = get_backtrace(rb_errinfo);
+ errat = get_backtrace(ruby_errinfo);
if (!NIL_P(errat)) {
VALUE mesg = RARRAY(errat)->ptr[0];
@@ -801,8 +801,8 @@ error_print()
}
}
- eclass = CLASS_OF(rb_errinfo);
- einfo = rb_obj_as_string(rb_errinfo);
+ eclass = CLASS_OF(ruby_errinfo);
+ einfo = rb_obj_as_string(ruby_errinfo);
if (eclass == rb_eRuntimeError && RSTRING(einfo)->len == 0) {
fprintf(stderr, ": unhandled exception\n");
}
@@ -962,7 +962,7 @@ eval_node(self)
return result;
}
-int rb_in_eval;
+int ruby_in_eval;
#ifdef USE_THREAD
static void rb_thread_cleanup _((void));
@@ -1040,7 +1040,7 @@ ruby_run()
break;
case TAG_RAISE:
case TAG_FATAL:
- if (rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
+ if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
exit(exit_status);
}
error_print();
@@ -1063,7 +1063,7 @@ compile_error(at)
char *mesg;
int len;
- mesg = str2cstr(rb_errinfo, &len);
+ mesg = str2cstr(ruby_errinfo, &len);
ruby_nerrs = 0;
str = rb_str_new2("compile error");
if (at) {
@@ -1982,7 +1982,7 @@ rb_eval(self, node)
case NODE_RESCUE:
retry_entry:
{
- volatile VALUE e_info = rb_errinfo;
+ volatile VALUE e_info = ruby_errinfo;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
@@ -2001,7 +2001,7 @@ rb_eval(self, node)
}
POP_TAG();
if (state == 0) {
- rb_errinfo = e_info;
+ ruby_errinfo = e_info;
}
else if (state == TAG_RETRY) {
state = 0;
@@ -2320,9 +2320,9 @@ rb_eval(self, node)
}
result = rb_eval(self, node->nd_value);
/* check for static scope constants */
- if (RTEST(rb_verbose) &&
+ if (RTEST(ruby_verbose) &&
ev_const_defined((NODE*)ruby_frame->cbase, node->nd_vid)) {
- if (RTEST(rb_verbose)) {
+ if (RTEST(ruby_verbose)) {
rb_warning("already initialized constant %s",
rb_id2name(node->nd_vid));
}
@@ -2468,10 +2468,10 @@ rb_eval(self, node)
str2 = list->nd_head->nd_lit;
break;
case NODE_EVSTR:
- rb_in_eval++;
+ ruby_in_eval++;
list->nd_head = compile(list->nd_head->nd_lit,0);
ruby_eval_tree = 0;
- rb_in_eval--;
+ ruby_in_eval--;
if (ruby_nerrs > 0) {
compile_error("string expansion");
}
@@ -2540,7 +2540,7 @@ rb_eval(self, node)
if (safe_level >= 3) {
rb_raise(rb_eSecurityError, "re-defining method prohibited");
}
- if (RTEST(rb_verbose)) {
+ if (RTEST(ruby_verbose)) {
rb_warning("discarding old %s", rb_id2name(node->nd_mid));
}
}
@@ -2607,7 +2607,7 @@ rb_eval(self, node)
if (safe_level >= 3) {
rb_raise(rb_eSecurityError, "re-defining method prohibited");
}
- if (RTEST(rb_verbose)) {
+ if (RTEST(ruby_verbose)) {
rb_warning("redefine %s", rb_id2name(node->nd_mid));
}
}
@@ -2962,7 +2962,7 @@ rb_f_exit(argc, argv, obj)
static void
rb_abort()
{
- if (rb_errinfo) {
+ if (ruby_errinfo) {
error_print();
}
rb_exit(1);
@@ -2992,7 +2992,7 @@ rb_longjmp(tag, mesg)
{
VALUE at;
- if (NIL_P(mesg)) mesg = rb_errinfo;
+ if (NIL_P(mesg)) mesg = ruby_errinfo;
if (NIL_P(mesg)) {
mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
}
@@ -3005,13 +3005,13 @@ rb_longjmp(tag, mesg)
}
}
if (!NIL_P(mesg)) {
- rb_errinfo = mesg;
+ ruby_errinfo = mesg;
}
- if (RTEST(rb_debug) && !NIL_P(rb_errinfo)
- && !rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
+ if (RTEST(ruby_debug) && !NIL_P(ruby_errinfo)
+ && !rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
fprintf(stderr, "Exception `%s' at %s:%d\n",
- rb_class2name(CLASS_OF(rb_errinfo)),
+ rb_class2name(CLASS_OF(ruby_errinfo)),
ruby_sourcefile, ruby_sourceline);
}
@@ -3366,7 +3366,7 @@ handle_rescue(self, node)
TMP_PROTECT;
if (!node->nd_args) {
- return rb_obj_is_kind_of(rb_errinfo, rb_eStandardError);
+ return rb_obj_is_kind_of(ruby_errinfo, rb_eStandardError);
}
BEGIN_CALLARGS;
@@ -3377,7 +3377,7 @@ handle_rescue(self, node)
if (!rb_obj_is_kind_of(argv[0], rb_cModule)) {
rb_raise(rb_eTypeError, "class or module required for rescue clause");
}
- if (rb_obj_is_kind_of(rb_errinfo, argv[0])) return 1;
+ if (rb_obj_is_kind_of(ruby_errinfo, argv[0])) return 1;
argv++;
}
return 0;
@@ -3390,18 +3390,18 @@ rb_rescue(b_proc, data1, r_proc, data2)
{
int state;
volatile VALUE result;
- volatile VALUE e_info = rb_errinfo;
+ volatile VALUE e_info = ruby_errinfo;
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
retry_entry:
result = (*b_proc)(data1);
}
- else if (state == TAG_RAISE && rb_obj_is_kind_of(rb_errinfo, rb_eStandardError)) {
+ else if (state == TAG_RAISE && rb_obj_is_kind_of(ruby_errinfo, rb_eStandardError)) {
if (r_proc) {
PUSH_TAG(PROT_NONE);
if ((state = EXEC_TAG()) == 0) {
- result = (*r_proc)(data2, rb_errinfo);
+ result = (*r_proc)(data2, ruby_errinfo);
}
POP_TAG();
if (state == TAG_RETRY) {
@@ -3414,7 +3414,7 @@ rb_rescue(b_proc, data1, r_proc, data2)
state = 0;
}
if (state == 0) {
- rb_errinfo = e_info;
+ ruby_errinfo = e_info;
}
}
POP_TAG();
@@ -4024,9 +4024,7 @@ backtrace(lev)
struct FRAME *frame = ruby_frame;
char buf[BUFSIZ];
VALUE ary;
- int slev = safe_level;
- safe_level = 0;
ary = rb_ary_new();
if (lev < 0) {
if (frame->last_func) {
@@ -4042,7 +4040,10 @@ backtrace(lev)
else {
while (lev-- > 0) {
frame = frame->prev;
- if (!frame) return Qnil;
+ if (!frame) {
+ ary = Qnil;
+ break;
+ }
}
}
while (frame && frame->file) {
@@ -4057,7 +4058,7 @@ backtrace(lev)
rb_ary_push(ary, rb_str_new2(buf));
frame = frame->prev;
}
- safe_level = slev;
+
return ary;
}
@@ -4178,7 +4179,7 @@ eval(self, src, scope, file, line)
PUSH_CLASS();
ruby_class = ((NODE*)ruby_frame->cbase)->nd_clss;
- rb_in_eval++;
+ ruby_in_eval++;
if (TYPE(ruby_class) == T_ICLASS) {
ruby_class = RBASIC(ruby_class)->klass;
}
@@ -4194,7 +4195,7 @@ eval(self, src, scope, file, line)
}
POP_TAG();
POP_CLASS();
- rb_in_eval--;
+ ruby_in_eval--;
if (!NIL_P(scope)) {
ruby_frame = ruby_frame->prev;
#ifdef USE_THREAD
@@ -4219,20 +4220,20 @@ eval(self, src, scope, file, line)
VALUE err;
VALUE errat;
- errat = get_backtrace(rb_errinfo);
+ errat = get_backtrace(ruby_errinfo);
if (strcmp(file, "(eval)") == 0) {
if (ruby_sourceline > 1) {
err = RARRAY(errat)->ptr[0];
rb_str_cat(err, ": ", 2);
- rb_str_concat(err, rb_errinfo);
+ rb_str_concat(err, ruby_errinfo);
}
else {
- err = rb_str_dup(rb_errinfo);
+ err = rb_str_dup(ruby_errinfo);
}
errat = Qnil;
- rb_exc_raise(rb_exc_new3(CLASS_OF(rb_errinfo), err));
+ rb_exc_raise(rb_exc_new3(CLASS_OF(ruby_errinfo), err));
}
- rb_exc_raise(rb_errinfo);
+ rb_exc_raise(ruby_errinfo);
}
JUMP_TAG(state);
}
@@ -4538,9 +4539,9 @@ rb_load(fname, wrap)
state = EXEC_TAG();
last_func = ruby_frame->last_func;
if (state == 0) {
- rb_in_eval++;
+ ruby_in_eval++;
rb_load_file(file);
- rb_in_eval--;
+ ruby_in_eval--;
if (ruby_nerrs == 0) {
eval_node(self);
}
@@ -4557,7 +4558,7 @@ rb_load(fname, wrap)
POP_VARS();
ruby_wrapper = 0;
if (ruby_nerrs > 0) {
- rb_exc_raise(rb_errinfo);
+ rb_exc_raise(ruby_errinfo);
}
if (state) JUMP_TAG(state);
}
@@ -4976,7 +4977,7 @@ static VALUE
errat_getter(id)
ID id;
{
- return get_backtrace(rb_errinfo);
+ return get_backtrace(ruby_errinfo);
}
static void
@@ -4985,10 +4986,10 @@ errat_setter(val, id, var)
ID id;
VALUE *var;
{
- if (NIL_P(rb_errinfo)) {
+ if (NIL_P(ruby_errinfo)) {
rb_raise(rb_eArgError, "$! not set");
}
- set_backtrace(rb_errinfo, val);
+ set_backtrace(ruby_errinfo, val);
}
VALUE rb_f_global_variables();
@@ -5102,7 +5103,7 @@ Init_eval()
rb_global_variable((VALUE*)&ruby_dyna_vars);
rb_define_virtual_variable("$@", errat_getter, errat_setter);
- rb_define_hooked_variable("$!", &rb_errinfo, 0, errinfo_setter);
+ rb_define_hooked_variable("$!", &ruby_errinfo, 0, errinfo_setter);
rb_define_global_function("eval", rb_f_eval, -1);
rb_define_global_function("iterator?", rb_f_iterator_p, 0);
@@ -5787,7 +5788,7 @@ struct thread {
char *file;
int line;
- VALUE rb_errinfo;
+ VALUE errinfo;
VALUE last_status;
VALUE last_line;
VALUE last_match;
@@ -5848,7 +5849,7 @@ thread_mark(th)
rb_gc_mark(th->scope);
rb_gc_mark(th->dyna_vars);
- rb_gc_mark(th->rb_errinfo);
+ rb_gc_mark(th->errinfo);
rb_gc_mark(th->last_line);
rb_gc_mark(th->last_match);
@@ -5940,7 +5941,7 @@ rb_thread_save_context(th)
th->misc = scope_vmode | (rb_trap_immediate<<8);
th->iter = ruby_iter;
th->tag = prot_tag;
- th->rb_errinfo = rb_errinfo;
+ th->errinfo = ruby_errinfo;
th->last_status = rb_last_status;
th->last_line = rb_lastline_get();
th->last_match = rb_backref_get();
@@ -6004,7 +6005,7 @@ rb_thread_restore_context(th, exit)
rb_trap_immediate = th->misc>>8;
ruby_iter = th->iter;
prot_tag = th->tag;
- rb_errinfo = th->rb_errinfo;
+ ruby_errinfo = th->errinfo;
rb_last_status = th->last_status;
safe_level = th->safe;
@@ -6592,12 +6593,12 @@ rb_thread_abort_exc_set(thread, val)
return val;
}
-#define THREAD_ALLOC(th) {\
+#define THREAD_ALLOC(th) do {\
th = ALLOC(struct thread);\
\
th->status = 0;\
th->result = 0;\
- th->rb_errinfo = Qnil;\
+ th->errinfo = Qnil;\
\
th->stk_ptr = 0;\
th->stk_len = 0;\
@@ -6610,16 +6611,18 @@ rb_thread_abort_exc_set(thread, val)
th->frame = 0;\
th->scope = 0;\
th->klass = 0;\
+ th->wrapper = 0;\
th->dyna_vars = 0;\
th->block = 0;\
th->iter = 0;\
th->tag = 0;\
- th->rb_errinfo = 0;\
+ th->errinfo = 0;\
th->last_status = 0;\
th->last_line = 0;\
th->last_match = 0;\
th->abort = 0;\
-}
+ th->locals = 0;\
+} while(0)
static thread_t
rb_thread_alloc(klass)
@@ -6735,24 +6738,24 @@ rb_thread_create_0(fn, arg, klass)
POP_TAG();
status = th->status;
rb_thread_remove();
- if (state && status != THREAD_TO_KILL && !NIL_P(rb_errinfo)) {
+ if (state && status != THREAD_TO_KILL && !NIL_P(ruby_errinfo)) {
if (state == TAG_FATAL) {
/* fatal error within this thread, need to stop whole script */
- main_thread->rb_errinfo = rb_errinfo;
+ main_thread->errinfo = ruby_errinfo;
rb_thread_cleanup();
}
- else if (rb_obj_is_kind_of(rb_errinfo, rb_eSystemExit)) {
+ else if (rb_obj_is_kind_of(ruby_errinfo, rb_eSystemExit)) {
/* delegate exception to main_thread */
- rb_thread_raise(1, &rb_errinfo, main_thread->thread);
+ rb_thread_raise(1, &ruby_errinfo, main_thread->thread);
}
- else if (rb_thread_abort || curr_thread->abort || RTEST(rb_debug)) {
+ else if (rb_thread_abort || curr_thread->abort || RTEST(ruby_debug)) {
VALUE err = rb_exc_new(rb_eSystemExit, 0, 0);
error_print();
/* exit on main_thread */
rb_thread_raise(1, &err, main_thread->thread);
}
else {
- curr_thread->rb_errinfo = rb_errinfo;
+ curr_thread->errinfo = ruby_errinfo;
}
}
rb_thread_schedule();
@@ -6799,13 +6802,13 @@ rb_thread_value(thread)
thread_t th = rb_thread_check(thread);
rb_thread_join(thread);
- if (!NIL_P(th->rb_errinfo)) {
- VALUE oldbt = get_backtrace(th->rb_errinfo);
+ if (!NIL_P(th->errinfo)) {
+ VALUE oldbt = get_backtrace(th->errinfo);
VALUE errat = make_backtrace();
rb_ary_unshift(errat, rb_ary_entry(oldbt, 0));
- set_backtrace(th->rb_errinfo, errat);
- rb_exc_raise(th->rb_errinfo);
+ set_backtrace(th->errinfo, errat);
+ rb_exc_raise(th->errinfo);
}
return th->result;
@@ -6818,7 +6821,7 @@ rb_thread_status(thread)
thread_t th = rb_thread_check(thread);
if (rb_thread_dead(th)) {
- if (NIL_P(th->rb_errinfo)) return Qfalse;
+ if (NIL_P(th->errinfo)) return Qfalse;
return Qnil;
}