2007-06-24 20:45:48 -04:00
|
|
|
/* -*-c-*- */
|
2006-12-31 10:02:22 -05:00
|
|
|
/*
|
|
|
|
* included by eval.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
warn_printf(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
va_init_list(args, fmt);
|
|
|
|
vsnprintf(buf, BUFSIZ, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
rb_write_error(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define warn_print(x) rb_write_error(x)
|
2010-12-11 23:28:29 -05:00
|
|
|
#define warn_print2(x,l) rb_write_error2((x),(l))
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
static void
|
|
|
|
error_pos(void)
|
|
|
|
{
|
2007-06-24 16:33:04 -04:00
|
|
|
const char *sourcefile = rb_sourcefile();
|
|
|
|
int sourceline = rb_sourceline();
|
|
|
|
|
|
|
|
if (sourcefile) {
|
|
|
|
if (sourceline == 0) {
|
|
|
|
warn_printf("%s", sourcefile);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else if (rb_frame_callee()) {
|
2007-06-24 16:33:04 -04:00
|
|
|
warn_printf("%s:%d:in `%s'", sourcefile, sourceline,
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_id2name(rb_frame_callee()));
|
|
|
|
}
|
|
|
|
else {
|
2007-06-24 16:33:04 -04:00
|
|
|
warn_printf("%s:%d", sourcefile, sourceline);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VALUE
|
|
|
|
get_backtrace(VALUE info)
|
|
|
|
{
|
|
|
|
if (NIL_P(info))
|
|
|
|
return Qnil;
|
|
|
|
info = rb_funcall(info, rb_intern("backtrace"), 0);
|
|
|
|
if (NIL_P(info))
|
|
|
|
return Qnil;
|
2007-07-19 06:24:17 -04:00
|
|
|
return rb_check_backtrace(info);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
* eval_method.c: renamed from vm_method.c. "vm_method.c" is included
by "vm.c".
* vm_eval.c: added. Some codes are moved from "eval.c"
* common.mk: fix for above changes.
* compile.c: make a vm_eval(0)
* eval.c, eval_error.c, eval_intern.h, eval_jump.c, proc.c, vm.c,
id.c, id.h, vm_core.h, vm_dump.c, vm_evalbody.c, vm_insnhelper.c,
blockinlining.c: fix for above changes. and do some refactoring.
this changes improve rb_yield() performance.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@16576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2008-05-24 13:50:17 -04:00
|
|
|
VALUE
|
|
|
|
rb_get_backtrace(VALUE info)
|
|
|
|
{
|
|
|
|
return get_backtrace(info);
|
|
|
|
}
|
|
|
|
|
2012-05-24 02:36:44 -04:00
|
|
|
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt);
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static void
|
|
|
|
set_backtrace(VALUE info, VALUE bt)
|
|
|
|
{
|
2012-05-24 02:09:23 -04:00
|
|
|
ID set_backtrace = rb_intern("set_backtrace");
|
|
|
|
|
|
|
|
if (rb_backtrace_p(bt)) {
|
2012-05-24 02:36:44 -04:00
|
|
|
if (rb_method_basic_definition_p(CLASS_OF(info), set_backtrace)) {
|
2012-05-24 02:09:23 -04:00
|
|
|
rb_exc_set_backtrace(info, bt);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bt = rb_backtrace_to_str_ary(bt);
|
|
|
|
}
|
|
|
|
}
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_funcall(info, rb_intern("set_backtrace"), 1, bt);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
error_print(void)
|
|
|
|
{
|
2009-02-28 06:12:36 -05:00
|
|
|
volatile VALUE errat = Qnil; /* OK */
|
2010-06-21 10:43:58 -04:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
|
|
|
VALUE errinfo = th->errinfo;
|
|
|
|
int raised_flag = th->raised_flag;
|
2006-12-31 10:02:22 -05:00
|
|
|
volatile VALUE eclass, e;
|
2009-02-28 06:12:36 -05:00
|
|
|
const char *volatile einfo;
|
|
|
|
volatile long elen;
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2007-10-02 21:06:57 -04:00
|
|
|
if (NIL_P(errinfo))
|
2006-12-31 10:02:22 -05:00
|
|
|
return;
|
2010-06-21 10:43:58 -04:00
|
|
|
rb_thread_raised_clear(th);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2012-10-23 16:42:45 -04:00
|
|
|
TH_PUSH_TAG(th);
|
|
|
|
if (TH_EXEC_TAG() == 0) {
|
2007-10-02 21:06:57 -04:00
|
|
|
errat = get_backtrace(errinfo);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
errat = Qnil;
|
|
|
|
}
|
2012-10-23 16:42:45 -04:00
|
|
|
if (TH_EXEC_TAG())
|
2006-12-31 10:02:22 -05:00
|
|
|
goto error;
|
|
|
|
if (NIL_P(errat)) {
|
2007-08-18 03:44:51 -04:00
|
|
|
const char *file = rb_sourcefile();
|
|
|
|
int line = rb_sourceline();
|
2009-08-04 23:39:29 -04:00
|
|
|
if (!file)
|
2007-08-18 03:44:51 -04:00
|
|
|
warn_printf("%d", line);
|
2009-08-04 23:39:29 -04:00
|
|
|
else if (!line)
|
2009-08-06 14:25:11 -04:00
|
|
|
warn_printf("%s", file);
|
2009-08-04 23:39:29 -04:00
|
|
|
else
|
|
|
|
warn_printf("%s:%d", file, line);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else if (RARRAY_LEN(errat) == 0) {
|
|
|
|
error_pos();
|
|
|
|
}
|
|
|
|
else {
|
2013-05-13 05:56:22 -04:00
|
|
|
VALUE mesg = RARRAY_AREF(errat, 0);
|
2006-12-31 10:02:22 -05:00
|
|
|
|
|
|
|
if (NIL_P(mesg))
|
|
|
|
error_pos();
|
|
|
|
else {
|
|
|
|
warn_print2(RSTRING_PTR(mesg), RSTRING_LEN(mesg));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-02 21:06:57 -04:00
|
|
|
eclass = CLASS_OF(errinfo);
|
2012-10-23 16:42:45 -04:00
|
|
|
if (TH_EXEC_TAG() == 0) {
|
2007-10-02 21:06:57 -04:00
|
|
|
e = rb_funcall(errinfo, rb_intern("message"), 0, 0);
|
2006-12-31 10:02:22 -05:00
|
|
|
StringValue(e);
|
|
|
|
einfo = RSTRING_PTR(e);
|
|
|
|
elen = RSTRING_LEN(e);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
einfo = "";
|
|
|
|
elen = 0;
|
|
|
|
}
|
2012-10-23 16:42:45 -04:00
|
|
|
if (TH_EXEC_TAG())
|
2006-12-31 10:02:22 -05:00
|
|
|
goto error;
|
|
|
|
if (eclass == rb_eRuntimeError && elen == 0) {
|
|
|
|
warn_print(": unhandled exception\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
VALUE epath;
|
|
|
|
|
|
|
|
epath = rb_class_name(eclass);
|
|
|
|
if (elen == 0) {
|
|
|
|
warn_print(": ");
|
|
|
|
warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
|
|
|
|
warn_print("\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char *tail = 0;
|
|
|
|
long len = elen;
|
|
|
|
|
|
|
|
if (RSTRING_PTR(epath)[0] == '#')
|
|
|
|
epath = 0;
|
2007-08-18 03:44:51 -04:00
|
|
|
if ((tail = memchr(einfo, '\n', elen)) != 0) {
|
2006-12-31 10:02:22 -05:00
|
|
|
len = tail - einfo;
|
|
|
|
tail++; /* skip newline */
|
|
|
|
}
|
|
|
|
warn_print(": ");
|
|
|
|
warn_print2(einfo, len);
|
|
|
|
if (epath) {
|
|
|
|
warn_print(" (");
|
|
|
|
warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
|
|
|
|
warn_print(")\n");
|
|
|
|
}
|
|
|
|
if (tail) {
|
|
|
|
warn_print2(tail, elen - len - 1);
|
2008-02-14 09:51:08 -05:00
|
|
|
if (einfo[elen-1] != '\n') warn_print2("\n", 1);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NIL_P(errat)) {
|
|
|
|
long i;
|
|
|
|
long len = RARRAY_LEN(errat);
|
|
|
|
VALUE *ptr = RARRAY_PTR(errat);
|
2007-06-19 19:27:47 -04:00
|
|
|
int skip = eclass == rb_eSysStackError;
|
2009-02-22 09:23:33 -05:00
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
#define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
|
|
|
|
#define TRACE_HEAD 8
|
|
|
|
#define TRACE_TAIL 5
|
|
|
|
|
|
|
|
for (i = 1; i < len; i++) {
|
2012-04-13 11:34:34 -04:00
|
|
|
if (RB_TYPE_P(ptr[i], T_STRING)) {
|
2006-12-31 10:02:22 -05:00
|
|
|
warn_printf("\tfrom %s\n", RSTRING_PTR(ptr[i]));
|
|
|
|
}
|
2007-06-19 19:27:47 -04:00
|
|
|
if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
|
2006-12-31 10:02:22 -05:00
|
|
|
warn_printf("\t ... %ld levels...\n",
|
|
|
|
len - TRACE_HEAD - TRACE_TAIL);
|
|
|
|
i = len - TRACE_TAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
error:
|
2012-10-23 16:42:45 -04:00
|
|
|
TH_POP_TAG();
|
2010-06-21 10:43:58 -04:00
|
|
|
rb_thread_raised_set(th, raised_flag);
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2007-08-18 03:44:51 -04:00
|
|
|
void
|
|
|
|
ruby_error_print(void)
|
|
|
|
{
|
|
|
|
error_print();
|
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
void
|
2007-12-17 18:01:50 -05:00
|
|
|
rb_print_undef(VALUE klass, ID id, int scope)
|
2006-12-31 10:02:22 -05:00
|
|
|
{
|
2008-05-31 05:28:20 -04:00
|
|
|
const char *v;
|
2007-12-17 18:01:50 -05:00
|
|
|
|
|
|
|
switch (scope) {
|
|
|
|
default:
|
|
|
|
case NOEX_PUBLIC: v = ""; break;
|
|
|
|
case NOEX_PRIVATE: v = " private"; break;
|
|
|
|
case NOEX_PROTECTED: v = " protected"; break;
|
|
|
|
}
|
2012-12-22 10:04:57 -05:00
|
|
|
rb_name_error(id, "undefined%s method `%"PRIsVALUE"' for %s `%"PRIsVALUE"'", v,
|
|
|
|
QUOTE_ID(id),
|
2011-09-29 07:07:45 -04:00
|
|
|
(RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
|
2012-12-22 10:04:57 -05:00
|
|
|
rb_class_name(klass));
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
|
2011-07-26 12:05:35 -04:00
|
|
|
void
|
|
|
|
rb_print_undef_str(VALUE klass, VALUE name)
|
|
|
|
{
|
2012-12-22 10:04:57 -05:00
|
|
|
rb_name_error_str(name, "undefined method `%"PRIsVALUE"' for %s `%"PRIsVALUE"'",
|
|
|
|
QUOTE(name),
|
2011-09-29 07:07:45 -04:00
|
|
|
(RB_TYPE_P(klass, T_MODULE)) ? "module" : "class",
|
2012-12-22 10:04:57 -05:00
|
|
|
rb_class_name(klass));
|
2011-07-26 12:05:35 -04:00
|
|
|
}
|
|
|
|
|
2006-12-31 10:02:22 -05:00
|
|
|
static int
|
|
|
|
sysexit_status(VALUE err)
|
|
|
|
{
|
|
|
|
VALUE st = rb_iv_get(err, "status");
|
|
|
|
return NUM2INT(st);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
error_handle(int ex)
|
|
|
|
{
|
|
|
|
int status = EXIT_FAILURE;
|
* blockinlining.c, error.c, eval.c, eval_error.h, eval_intern.h,
eval_jump.h, eval_load.c, eval_safe.h, gc.c, proc.c, signal.c,
thread.c, thread_pthread.ci, thread_win32.ci, vm.c, vm.h,
vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fix typo (rb_thead_t -> rb_thread_t).
* eval_intern.h: remove unused definitions.
* common.mk: fix around vm_opts.h path
and remove harmful argument passed to insns2vm.rb.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11658 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-08 01:37:46 -05:00
|
|
|
rb_thread_t *th = GET_THREAD();
|
2006-12-31 10:02:22 -05:00
|
|
|
|
2009-06-08 12:14:06 -04:00
|
|
|
if (rb_threadptr_set_raised(th))
|
2006-12-31 10:02:22 -05:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
switch (ex & TAG_MASK) {
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case 0:
|
2006-12-31 10:02:22 -05:00
|
|
|
status = EXIT_SUCCESS;
|
|
|
|
break;
|
|
|
|
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_RETURN:
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_print(": unexpected return\n");
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_NEXT:
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_print(": unexpected next\n");
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_BREAK:
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_print(": unexpected break\n");
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_REDO:
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_print(": unexpected redo\n");
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_RETRY:
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_print(": retry outside of rescue clause\n");
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
case TAG_THROW:
|
|
|
|
/* TODO: fix me */
|
2006-12-31 10:02:22 -05:00
|
|
|
error_pos();
|
|
|
|
warn_printf(": unexpected throw\n");
|
|
|
|
break;
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_RAISE: {
|
2007-04-19 13:37:03 -04:00
|
|
|
VALUE errinfo = GET_THREAD()->errinfo;
|
|
|
|
if (rb_obj_is_kind_of(errinfo, rb_eSystemExit)) {
|
|
|
|
status = sysexit_status(errinfo);
|
|
|
|
}
|
|
|
|
else if (rb_obj_is_instance_of(errinfo, rb_eSignal)) {
|
|
|
|
/* no message when exiting by signal */
|
2006-12-31 10:02:22 -05:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
error_print();
|
|
|
|
}
|
|
|
|
break;
|
2007-04-19 13:37:03 -04:00
|
|
|
}
|
2008-05-27 09:10:46 -04:00
|
|
|
case TAG_FATAL:
|
|
|
|
error_print();
|
|
|
|
break;
|
* call_cfunc.ci, compile.c, compile.h, debug.h, eval.c,
eval_error.h, eval_jump.h, eval_load.c, eval_thread.c, gc.c,
insnhelper.h, insns.def, iseq.c, main.c, numeric.c, parse.y,
range.c, regenc.h, ruby.h, signal.c, thread.c, thread_win32.ci,
vm.c, vm.h, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h:
fixed indents and non-C90 comments.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2007-02-02 11:26:04 -05:00
|
|
|
default:
|
2006-12-31 10:02:22 -05:00
|
|
|
rb_bug("Unknown longjmp status %d", ex);
|
|
|
|
break;
|
|
|
|
}
|
2009-06-08 12:14:06 -04:00
|
|
|
rb_threadptr_reset_raised(th);
|
2006-12-31 10:02:22 -05:00
|
|
|
return status;
|
|
|
|
}
|