28 # include <AvailabilityMacros.h> 32 #define EXIT_SUCCESS 0 36 #define WIFEXITED(status) 1 40 #define WEXITSTATUS(status) (status) 57 "You may have encountered a bug in the Ruby interpreter" \
58 " or extension libraries.\n" \
59 "Bug reports are welcome.\n" \
61 "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
67 #define defined_error(name, num) if (err == (num)) return (name); 68 #define undefined_error(name) 69 #include "known_errors.inc" 71 #undef undefined_error 82 return snprintf(buf, len,
"%s: ", file);
85 return snprintf(buf, len,
"%s:%d: ", file, line);
91 const char *fmt, va_list args)
153 rb_fatal(
"%s is only for internal use and deprecated; do not use", func);
176 err_vcatf(str,
"warning: ", file, line, fmt, args);
265 rb_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
304 #define MAX_BUG_REPORTERS 0x100 328 #define REPORT_BUG_BUFSIZ 256 336 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
337 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
348 const char *
const endmsg = msg +
len;
352 if (isatty(
fileno(out))) {
353 static const char red[] =
"\033[;31;1;7m";
354 static const char green[] =
"\033[;32;7m";
355 static const char reset[] =
"\033[m";
356 const char *e =
strchr(p,
'\n');
357 const int w = (int)(e - p);
359 int i = (int)(e - p);
360 fputs(*p ==
' ' ? green : red, out);
361 fwrite(p, 1, e - p, out);
362 for (; i < w; ++i) fputc(
' ', out);
365 }
while ((p = e + 1) < endmsg && (e =
strchr(p,
'\n')) != 0 && e > p + 1);
367 fwrite(p, 1, endmsg - p, out);
373 #if defined __APPLE__ 374 static const char msg[] =
"" 375 "-- Crash Report log information " 376 "--------------------------------------------\n" 377 " See Crash Report log file under the one of following:\n" 378 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 379 " * ~/Library/Logs/CrashReporter\n" 380 " * /Library/Logs/CrashReporter\n" 382 " * ~/Library/Logs/DiagnosticReports\n" 383 " * /Library/Logs/DiagnosticReports\n" 384 " for more details.\n" 385 "Don't forget to include the above Crash Report log file in bug reports.\n" 387 const size_t msglen =
sizeof(
msg) - 1;
389 const char *msg =
NULL;
390 const size_t msglen = 0;
398 #if defined __APPLE__ 399 static const char msg[] =
"" 402 "\n""Don't forget to include the Crash Report log file under\n" 403 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 406 "DiagnosticReports directory in bug reports.\n" 409 const size_t msglen =
sizeof(
msg) - 1;
411 const char *msg =
NULL;
412 const size_t msglen = 0;
422 fputs(
"[BUG] ", out);
430 #define bug_report_begin(out, fmt) do { \ 432 va_start(args, fmt); \ 433 bug_report_begin_valist(out, fmt, args); \ 445 (*reporter->
func)(out, reporter->
data);
452 #define report_bug(file, line, fmt, ctx) do { \ 453 FILE *out = bug_report_file(file, line); \ 455 bug_report_begin(out, fmt); \ 456 rb_vm_bugreport(ctx); \ 457 bug_report_end(out); \ 461 #define report_bug_valist(file, line, fmt, ctx, args) do { \ 462 FILE *out = bug_report_file(file, line); \ 464 bug_report_begin_valist(out, fmt, args); \ 465 rb_vm_bugreport(ctx); \ 466 bug_report_end(out); \ 474 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80 475 _set_abort_behavior( 0, _CALL_REPORTFAULT);
484 const char *file =
NULL;
499 const char *file =
NULL;
516 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
530 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0) 531 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1) 540 if (errno_arg == 0) {
547 errno_str =
"undefined errno";
567 fprintf(out,
"Assertion Failed: %s:%d:", file, line);
568 if (name) fprintf(out,
"%s:", name);
612 if ((
unsigned int)t >=
numberof(builtin_types))
return 0;
613 name = builtin_types[t];
614 if (*name)
return name;
656 #define UNDEF_LEAKED "undef leaked to the Ruby space" 667 mesg =
rb_sprintf(
"wrong argument type %s (expected %s)",
674 else if (xt >
T_MASK && xt <= 0x3f) {
675 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given, probably comes" 676 " from extension library for ruby 1.8)", t, xt);
679 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given)", t, xt);
713 if (child == parent)
return 1;
790 #define id_bt_locations idBt_locations 791 #define id_mesg idMesg 792 #define id_status ruby_static_id_status 794 #undef rb_exc_new_cstr 853 if (argc == 0)
return self;
854 if (argc == 1 &&
self == argv[0])
return self;
1009 static const char err[] =
"backtrace must be Array of String";
1082 VALUE mesg, backtrace;
1084 if (exc == obj)
return Qtrue;
1090 if (status || obj ==
Qundef) {
1144 if (
NIL_P(status)) {
1148 #if EXIT_SUCCESS != 0 1194 if (
NIL_P(status_val))
1209 va_start(args, fmt);
1224 va_start(args, fmt);
1248 name = (argc > 1) ? argv[--argc] :
Qnil;
1312 VALUE args = (argc > 2) ? argv[--argc] :
Qnil;
1334 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE 1384 if (obj1 == obj2)
return Qtrue;
1408 VALUE c, s, d = 0, args[4];
1409 int state = 0, singleton = 0;
1412 #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii) 1478 if (recv !=
Qundef)
return recv;
1482 rb_raise(rb_eArgError,
"no receiver is available");
1573 if (!
st_lookup(syserr_tbl, n, &error)) {
1581 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 1607 if (!
st_lookup(syserr_tbl, n, &error)) {
1610 snprintf(name,
sizeof(name),
"E%03d", n);
1630 #if !defined(_WIN32) 1637 if (klass == rb_eSystemCallError) {
1641 error = mesg; mesg =
Qnil;
1644 klass = (
VALUE)data;
1647 rb_raise(rb_eTypeError,
"invalid instance type");
1657 else err =
"unknown error";
1703 else if (
self == rb_eSystemCallError)
return Qtrue;
2140 rb_eNotImpError =
rb_define_class(
"NotImplementedError", rb_eScriptError);
2157 rb_eRuntimeError =
rb_define_class(
"RuntimeError", rb_eStandardError);
2160 rb_eEncodingError =
rb_define_class(
"EncodingError", rb_eStandardError);
2164 rb_eSystemCallError =
rb_define_class(
"SystemCallError", rb_eStandardError);
2199 va_start(args, fmt);
2212 va_start(args, fmt);
2234 va_start(args, fmt);
2246 va_start(args, fmt);
2256 "%"PRIsVALUE"() function is unimplemented on this machine",
2266 va_start(args, fmt);
2280 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
2291 if (!mesg) mesg =
Qnil;
2294 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
2337 #ifdef RUBY_FUNCTION_NAME_STRING 2339 rb_sys_fail_path_in(
const char *func_name,
VALUE path)
2344 rb_syserr_fail_path_in(func_name, n, path);
2348 rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
2352 if (!path) path =
Qnil;
2355 if (!func_name) func_name =
"(null)";
2356 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
2408 va_start(args, fmt);
2428 va_start(args, fmt);
2449 rb_raise(rb_eRuntimeError,
"can't modify frozen %s", what);
2471 #undef rb_check_frozen 2483 #undef rb_check_trusted 2507 #define defined_error(name, num) set_syserr((num), (name)); 2508 #define undefined_error(name) set_syserr(0, (name)); 2509 #include "known_errors.inc" 2510 #undef defined_error 2511 #undef undefined_error
const char * rb_builtin_class_name(VALUE x)
static VALUE syserr_errno(VALUE self)
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
static VALUE make_errno_exc_str(VALUE mesg)
static void preface_dump(FILE *out)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
static VALUE exc_backtrace(VALUE exc)
RUBY_EXTERN VALUE rb_cData
VALUE rb_ary_entry(VALUE ary, long offset)
#define RUBY_EVENT_C_RETURN
void rb_bug(const char *fmt,...)
static const rb_data_type_t name_err_mesg_data_type
static VALUE get_syserr(int n)
void rb_compile_error(const char *file, int line, const char *fmt,...)
#define RUBY_TYPED_FREE_IMMEDIATELY
size_t strlen(const char *)
void rb_syserr_fail(int e, const char *mesg)
static VALUE exc_message(VALUE exc)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
#define REPORT_BUG_BUFSIZ
void rb_error_frozen_object(VALUE frozen_obj)
VALUE rb_iseqw_new(const rb_iseq_t *)
VALUE rb_fstring_cstr(const char *str)
void rb_error_frozen(const char *what)
static size_t name_err_mesg_memsize(const void *p)
#define TypedData_Wrap_Struct(klass, data_type, sval)
VALUE rb_backtrace_to_location_ary(VALUE obj)
VALUE rb_syserr_new_str(int n, VALUE arg)
#define TypedData_Get_Struct(obj, type, data_type, sval)
const char * rb_builtin_type_name(int t)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
#define rb_check_frozen_internal(obj)
ID rb_frame_this_func(void)
static VALUE exc_to_s(VALUE exc)
static VALUE name_err_name(VALUE self)
void rb_must_asciicompat(VALUE)
#define FAKE_CSTR(v, str)
VALUE rb_str_buf_new2(const char *)
SSL_METHOD *(* func)(void)
static VALUE name_err_local_variables(VALUE self)
#define WIFEXITED(status)
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
void rb_async_bug_errno(const char *mesg, int errno_arg)
void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
void rb_str_set_len(VALUE, long)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
#define RBASIC_SET_CLASS(obj, cls)
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
void rb_raise(VALUE exc, const char *fmt,...)
const rb_data_type_t * parent
void rb_compile_warn(const char *file, int line, const char *fmt,...)
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
static VALUE warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
static VALUE exc_set_backtrace(VALUE exc, VALUE bt)
static VALUE name_err_initialize(int argc, VALUE *argv, VALUE self)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
static VALUE syserr_eqq(VALUE self, VALUE exc)
#define WEXITSTATUS(status)
static VALUE nometh_err_private_call_p(VALUE self)
void rb_load_fail(VALUE path, const char *err)
const char * rb_source_loc(int *pline)
void rb_loaderror(const char *fmt,...)
static st_table * syserr_tbl
VALUE rb_str_buf_append(VALUE, VALUE)
void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args)
NORETURN(static void die(void))
const char * rb_obj_classname(VALUE)
void rb_name_error_str(VALUE str, const char *fmt,...)
static VALUE exc_exception(int argc, VALUE *argv, VALUE self)
#define report_bug_valist(file, line, fmt, ctx, args)
VALUE rb_str_buf_cat(VALUE, const char *, long)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
void rb_name_error(ID id, const char *fmt,...)
static VALUE exc_backtrace_locations(VALUE exc)
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
void rb_exc_raise(VALUE mesg)
#define RB_TYPE_P(obj, type)
static ID id_local_variables
static VALUE exc_cause(VALUE exc)
VALUE rb_class_name(VALUE)
void rb_compile_error_append(const char *fmt,...)
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
RUBY_EXTERN VALUE rb_cObject
static const char * builtin_class_name(VALUE x)
void rb_attr(VALUE, ID, int, int, int)
static VALUE name_err_mesg_dump(VALUE obj, VALUE limit)
VALUE rb_syserr_new(int n, const char *mesg)
static VALUE exc_equal(VALUE exc, VALUE obj)
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_obj_as_string(VALUE)
void rb_check_trusted(VALUE obj)
VALUE rb_iseqw_local_variables(VALUE iseqval)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE name_err_receiver(VALUE self)
static VALUE try_convert_to_exception(VALUE obj)
static void rb_write_warning_str(VALUE str)
static VALUE exit_success_p(VALUE exc)
#define name_err_mesg_free
void rb_define_const(VALUE, const char *, VALUE)
void rb_unexpected_type(VALUE x, int t)
void rb_sys_fail_str(VALUE mesg)
static VALUE nometh_err_args(VALUE self)
static VALUE name_err_mesg_to_str(VALUE obj)
void rb_check_type(VALUE x, int t)
#define write_or_abort(fd, str, len)
static VALUE set_syserr(int n, const char *name)
static VALUE exit_status(VALUE exc)
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
VALUE rb_obj_alloc(VALUE)
#define RUBY_EVENT_C_CALL
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
#define MAX_BUG_REPORTERS
void Init_Exception(void)
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
int rb_backtrace_p(VALUE obj)
static VALUE name_err_mesg_equal(VALUE obj1, VALUE obj2)
VALUE rb_const_get(VALUE, ID)
VALUE rb_backtrace_to_str_ary(VALUE obj)
VALUE rb_sprintf(const char *format,...)
static const char builtin_types[][10]
VALUE rb_str_format(int, const VALUE *, VALUE)
void rb_print_backtrace(void)
static int bug_reporters_size
void rb_fatal(const char *fmt,...)
VALUE rb_eSystemCallError
static FILE * bug_report_file(const char *file, int line)
VALUE rb_str_vcatf(VALUE, const char *, va_list)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
VALUE rb_ivar_set(VALUE, ID, VALUE)
unsigned char buf[MIME_BUF_SIZE]
rb_encoding * rb_usascii_encoding(void)
void rb_vm_bugreport(const void *)
static VALUE exc_initialize(int argc, VALUE *argv, VALUE exc)
#define report_bug(file, line, fmt, ctx)
void rb_check_frozen(VALUE obj)
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
rb_encoding * rb_locale_encoding(void)
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, called_id_, klass_, data_)
static int err_position_0(char *buf, long len, const char *file, int line)
char * strchr(char *, char)
void rb_extend_object(VALUE obj, VALUE module)
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
static VALUE rb_warn_m(int argc, VALUE *argv, VALUE exc)
VALUE rb_io_puts(int, const VALUE *, VALUE)
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
void rb_bug_errno(const char *mesg, int errno_arg)
static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
VALUE rb_call_super(int, const VALUE *)
void rb_check_copyable(VALUE obj, VALUE orig)
VALUE rb_str_new_cstr(const char *)
void rb_sys_fail(const char *mesg)
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self)
void(* func)(FILE *out, void *data)
static void postscript_dump(FILE *out)
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
static const char * rb_strerrno(int err)
#define WRITE_CONST(fd, str)
int rb_respond_to(VALUE, ID)
register unsigned int len
VALUE rb_check_to_int(VALUE)
static ID id_private_call_p
VALUE rb_equal(VALUE, VALUE)
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
RUBY_EXTERN VALUE rb_stderr
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
#define RARRAY_AREF(a, i)
static VALUE nometh_err_initialize(int argc, VALUE *argv, VALUE self)
void rb_set_errinfo(VALUE err)
void rb_mod_sys_fail(VALUE mod, const char *mesg)
VALUE rb_str_buf_new_cstr(const char *)
static void bug_report_end(FILE *out)
static VALUE err_vcatf(VALUE str, const char *pre, const char *file, int line, const char *fmt, va_list args)
static VALUE exc_inspect(VALUE exc)
VALUE rb_str_catf(VALUE str, const char *format,...)
void rb_syserr_fail_str(int e, VALUE mesg)
void rb_compile_warning(const char *file, int line, const char *fmt,...)
static VALUE make_errno_exc(const char *mesg)
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
static VALUE rb_warning_s_warn(VALUE mod, VALUE str)
RUBY_EXTERN char * strerror(int)
static void bug_important_message(FILE *out, const char *const msg, size_t len)
static VALUE syntax_error_initialize(int argc, VALUE *argv, VALUE self)
int rb_method_basic_definition_p(VALUE, ID)
VALUE rb_str_cat_cstr(VALUE, const char *)
#define ONLY_FOR_INTERNAL_USE(func)
VALUE rb_check_backtrace(VALUE bt)
void rb_notimplement(void)
static void raise_loaderror(VALUE path, VALUE mesg)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
const char ruby_description[]
VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
static VALUE warning_string(rb_encoding *enc, const char *fmt, va_list args)
const lazyenum_funcs * fn
void rb_error_untrusted(VALUE obj)
VALUE rb_source_location(int *pline)
VALUE rb_get_backtrace(VALUE exc)
void ruby_only_for_internal_use(const char *func)
#define RTYPEDDATA_DATA(v)
void rb_warning(const char *fmt,...)
const char * wrap_struct_name
#define rb_intern_const(str)
static const char REPORTBUG_MSG[]
void rb_bug_context(const void *ctx, const char *fmt,...)
FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len))
VALUE rb_define_module(const char *name)
VALUE rb_vsprintf(const char *, va_list)
void rb_exc_fatal(VALUE mesg)
#define RTYPEDDATA_TYPE(v)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_str_append(VALUE, VALUE)
void rb_warn(const char *fmt,...)
void rb_invalid_str(const char *str, const char *type)
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
ID rb_make_internal_id(void)
VALUE rb_obj_clone(VALUE)
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
static void bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
static VALUE name_err_mesg_load(VALUE klass, VALUE str)
VALUE rb_attr_get(VALUE, ID)
void rb_sys_warning(const char *fmt,...)
static void name_err_mesg_mark(void *p)
RUBY_EXTERN void rb_write_error_str(VALUE mesg)
VALUE rb_str_new(const char *, long)
VALUE rb_obj_class(VALUE)
static void unexpected_type(VALUE x, int xt, int t)