diff --git a/vm_eval.c b/vm_eval.c index 0dcbafa..eb899c9 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -949,7 +949,7 @@ rb_each(VALUE obj) } static VALUE -eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *volatile file, volatile int line) +eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *volatile file, volatile int line, volatile int is_user_file) { int state; VALUE result = Qundef; @@ -977,7 +977,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char if (rb_obj_is_kind_of(scope, rb_cBinding)) { GetBindingPtr(scope, bind); envval = bind->env; - if (strcmp(file, "(eval)") == 0 && bind->filename != Qnil) { + if (!is_user_file && strcmp(file, "(eval)") == 0 && bind->filename != Qnil) { file = RSTRING_PTR(bind->filename); line = bind->line_no; } @@ -1035,7 +1035,7 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char if (state) { if (state == TAG_RAISE) { VALUE errinfo = th->errinfo; - if (strcmp(file, "(eval)") == 0) { + if (!is_user_file && strcmp(file, "(eval)") == 0) { VALUE mesg, errat, bt2; extern VALUE rb_get_backtrace(VALUE info); ID id_mesg; @@ -1066,9 +1066,9 @@ eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char } static VALUE -eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line) +eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line, int is_user_file) { - return eval_string_with_cref(self, src, scope, 0, file, line); + return eval_string_with_cref(self, src, scope, 0, file, line, is_user_file); } /* @@ -1095,6 +1095,7 @@ rb_f_eval(int argc, VALUE *argv, VALUE self) VALUE src, scope, vfile, vline; const char *file = "(eval)"; int line = 1; + int is_user_file = FALSE; rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline); if (rb_safe_level() >= 4) { @@ -1109,6 +1110,7 @@ rb_f_eval(int argc, VALUE *argv, VALUE self) } if (argc >= 3) { StringValue(vfile); + is_user_file = TRUE; } if (argc >= 4) { line = NUM2INT(vline); @@ -1116,13 +1118,13 @@ rb_f_eval(int argc, VALUE *argv, VALUE self) if (!NIL_P(vfile)) file = RSTRING_PTR(vfile); - return eval_string(self, src, scope, file, line); + return eval_string(self, src, scope, file, line, is_user_file); } VALUE rb_eval_string(const char *str) { - return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1); + return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1, FALSE); } VALUE @@ -1187,7 +1189,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { - val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0); + val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0, FALSE); } POP_TAG(); @@ -1223,7 +1225,7 @@ yield_under(VALUE under, VALUE self, VALUE values) /* string eval under the class/module context */ static VALUE -eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line) +eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line, int is_user_file) { NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL); @@ -1234,12 +1236,14 @@ eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line) SafeStringValue(src); } - return eval_string_with_cref(self, src, Qnil, cref, file, line); + return eval_string_with_cref(self, src, Qnil, cref, file, line, is_user_file); } static VALUE specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) { + int is_user_file = FALSE; + if (rb_block_given_p()) { if (argc > 0) { rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); @@ -1270,9 +1274,10 @@ specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self) line = NUM2INT(argv[2]); if (argc > 1) { file = StringValuePtr(argv[1]); + is_user_file = TRUE; } } - return eval_under(klass, self, argv[0], file, line); + return eval_under(klass, self, argv[0], file, line, is_user_file); } }