29 #define EXIT_SUCCESS 0
33 #define WIFEXITED(status) 1
37 #define WEXITSTATUS(status) (status)
48 "You may have encountered a bug in the Ruby interpreter" \
49 " or extension libraries.\n" \
50 "Bug reports are welcome.\n" \
53 "Don't forget to include the above Crash Report log file.\n"
55 "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
61 #define defined_error(name, num) if (err == (num)) return (name);
62 #define undefined_error(name)
63 #include "known_errors.inc"
65 #undef undefined_error
76 return snprintf(buf, len,
"%s: ", file);
79 return snprintf(buf, len,
"%s:%d: ", file, line);
272 #define MAX_BUG_REPORTERS 0x100
303 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
304 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
306 fputs(
"[BUG] ", out);
319 (*reporter->
func)(out, reporter->
data);
330 const char *file =
NULL;
342 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
343 _set_abort_behavior( 0, _CALL_REPORTFAULT);
353 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
367 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
368 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
377 if (errno_arg == 0) {
384 errno_str =
"undefined errno";
443 if ((
unsigned int)t >=
numberof(builtin_types))
return 0;
444 name = builtin_types[
t];
445 if (*name)
return name;
449 #define builtin_class_name rb_builtin_class_name
482 rb_bug(
"undef leaked to the Ruby space");
492 if (xt >
T_MASK && xt <= 0x3f) {
493 rb_fatal(
"unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
495 rb_bug(
"unknown type 0x%x (0x%x given)", t, xt);
503 if (child == parent)
return 1;
523 static const char mesg[] =
"wrong argument type %s (expected %s)";
570 #undef rb_exc_new_cstr
629 if (argc == 0)
return self;
630 if (argc == 1 &&
self == argv[0])
return self;
760 CONST_ID(bt_locations,
"bt_locations");
772 static const char err[] =
"backtrace must be Array of String";
824 CONST_ID(id_exception,
"exception");
840 VALUE mesg, backtrace;
843 if (exc == obj)
return Qtrue;
848 ID id_message, id_backtrace;
850 CONST_ID(id_backtrace,
"backtrace");
853 if (status || obj ==
Qundef) {
911 #if EXIT_SUCCESS != 0
957 if (
NIL_P(status_val))
1010 name = (argc > 1) ? argv[--argc] :
Qnil;
1049 #define NAME_ERR_MESG_COUNT 3
1058 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1100 if (obj1 == obj2)
return Qtrue;
1123 const char *desc = 0;
1148 if (desc && desc[0] !=
'#') {
1235 if (!
st_lookup(syserr_tbl, n, &error)) {
1243 #if EAGAIN != EWOULDBLOCK
1269 if (!
st_lookup(syserr_tbl, n, &error)) {
1272 snprintf(name,
sizeof(name),
"E%03d", n);
1292 #if !defined(_WIN32)
1299 if (klass == rb_eSystemCallError) {
1303 error = mesg; mesg =
Qnil;
1306 klass = (
VALUE)data;
1309 rb_raise(rb_eTypeError,
"invalid instance type");
1319 else err =
"unknown error";
1376 else if (
self == rb_eSystemCallError)
return Qtrue;
1811 rb_eNotImpError =
rb_define_class(
"NotImplementedError", rb_eScriptError);
1826 rb_eRuntimeError =
rb_define_class(
"RuntimeError", rb_eStandardError);
1829 rb_eEncodingError =
rb_define_class(
"EncodingError", rb_eStandardError);
1833 rb_eSystemCallError =
rb_define_class(
"SystemCallError", rb_eStandardError);
1849 va_start(args, fmt);
1862 va_start(args, fmt);
1884 va_start(args, fmt);
1896 va_start(args, fmt);
1906 "%s() function is unimplemented on this machine",
1916 va_start(args, fmt);
1930 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
1941 if (!mesg) mesg =
Qnil;
1944 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
1987 #ifdef RUBY_FUNCTION_NAME_STRING
1989 rb_sys_fail_path_in(
const char *func_name,
VALUE path)
1994 rb_syserr_fail_path_in(func_name, n, path);
1998 rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
2002 if (!path) path =
Qnil;
2005 if (!func_name) func_name =
"(null)";
2006 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
2058 snprintf(buf, BUFSIZ,
"warning: %s", fmt);
2061 va_start(args, fmt);
2079 rb_raise(rb_eRuntimeError,
"can't modify frozen %s", what);
2082 #undef rb_check_frozen
2094 #undef rb_check_trusted
2118 #define defined_error(name, num) set_syserr((num), (name));
2119 #define undefined_error(name) set_syserr(0, (name));
2120 #include "known_errors.inc"
2121 #undef defined_error
2122 #undef undefined_error
#define RB_TYPE_P(obj, type)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
#define rb_check_frozen_internal(obj)
const char * rb_builtin_class_name(VALUE x)
static VALUE syserr_errno(VALUE self)
static void compile_err_append(VALUE mesg)
static VALUE make_errno_exc_str(VALUE mesg)
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
static VALUE exc_backtrace(VALUE exc)
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 rb_gc_mark_locations(start, end)
size_t strlen(const char *)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
const char * rb_obj_classname(VALUE)
VALUE rb_iv_set(VALUE, const char *, VALUE)
void rb_syserr_fail(int e, const char *mesg)
static VALUE exc_message(VALUE exc)
void(* func)(FILE *out, void *data)
int st_lookup(st_table *, st_data_t, st_data_t *)
void st_add_direct(st_table *, st_data_t, st_data_t)
#define rb_check_trusted(obj)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
VALUE rb_str_buf_append(VALUE, VALUE)
VALUE rb_io_puts(int, VALUE *, VALUE)
st_table * st_init_numtable(void)
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
SSL_METHOD *(* func)(void)
VALUE rb_const_get(VALUE, ID)
void rb_error_frozen(const char *what)
static size_t name_err_mesg_memsize(const void *p)
VALUE rb_syserr_new_str(int n, VALUE arg)
#define rb_check_frozen(obj)
const char * rb_builtin_type_name(int t)
VALUE rb_exc_new_str(VALUE etype, VALUE str)
VALUE rb_str_new_cstr(const char *)
ID rb_frame_this_func(void)
static VALUE exc_to_s(VALUE exc)
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
static VALUE name_err_name(VALUE self)
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
#define WIFEXITED(status)
void rb_async_bug_errno(const char *mesg, int errno_arg)
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
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,...)
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
VALUE rb_obj_class(VALUE)
void rb_compile_warn(const char *file, int line, const char *fmt,...)
VALUE rb_class_name(VALUE)
VALUE rb_backtrace_to_str_ary(VALUE obj)
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.
static VALUE syserr_eqq(VALUE self, VALUE exc)
#define WEXITSTATUS(status)
void rb_load_fail(VALUE path, const char *err)
void rb_loaderror(const char *fmt,...)
static st_table * syserr_tbl
VALUE rb_f_sprintf(int, const VALUE *)
VALUE rb_equal(VALUE, VALUE)
void rb_name_error_str(VALUE str, const char *fmt,...)
static VALUE exc_exception(int argc, VALUE *argv, VALUE self)
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)
void rb_compile_bug(const char *file, int line, const char *fmt,...)
#define TypedData_Get_Struct(obj, type, data_type, sval)
void rb_compile_error_append(const char *fmt,...)
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
const rb_data_type_t * parent
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)
#define RARRAY_AREF(a, i)
void rb_define_const(VALUE, const char *, VALUE)
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
static VALUE try_convert_to_exception(VALUE obj)
static VALUE exit_success_p(VALUE exc)
#define name_err_mesg_free
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)
void rb_vm_bugreport(void)
VALUE rb_call_super(int, const VALUE *)
#define write_or_abort(fd, str, len)
static VALUE set_syserr(int n, const char *name)
#define TypedData_Wrap_Struct(klass, data_type, sval)
static VALUE exit_status(VALUE exc)
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
unsigned char buf[MIME_BUF_SIZE]
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
VALUE rb_str_buf_new_cstr(const char *)
#define MAX_BUG_REPORTERS
void Init_Exception(void)
VALUE rb_str_buf_cat(VALUE, const char *, long)
static VALUE name_err_mesg_equal(VALUE obj1, VALUE obj2)
static VALUE compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
VALUE rb_obj_as_string(VALUE)
VALUE rb_obj_clone(VALUE)
VALUE rb_sprintf(const char *format,...)
static const char builtin_types[][10]
static int bug_reporters_size
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_fatal(const char *fmt,...)
VALUE rb_eSystemCallError
#define CONST_ID(var, str)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
void rb_attr(VALUE, ID, int, int, int)
static VALUE exc_initialize(int argc, VALUE *argv, VALUE exc)
rb_encoding * rb_locale_encoding(void)
static int err_position_0(char *buf, long len, const char *file, int line)
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)
void rb_bug_errno(const char *mesg, int errno_arg)
static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc)
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
VALUE rb_attr_get(VALUE, ID)
void rb_check_copyable(VALUE obj, VALUE orig)
void rb_sys_fail(const char *mesg)
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self)
static const char * rb_strerrno(int err)
VALUE rb_vsprintf(const char *, va_list)
#define WRITE_CONST(fd, str)
RUBY_EXTERN char * strerror(int)
#define NAME_ERR_MESG_COUNT
RUBY_EXTERN VALUE rb_stderr
rb_encoding * rb_enc_get(VALUE obj)
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
VALUE rb_check_to_int(VALUE)
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
int mild_compile_error
Thread-local state of compiling context.
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)
static VALUE exc_inspect(VALUE exc)
VALUE exc_cause(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)
RUBY_EXTERN VALUE rb_cObject
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
const char * wrap_struct_name
VALUE rb_str_vcatf(VALUE, const char *, va_list)
int rb_respond_to(VALUE, ID)
VALUE rb_check_backtrace(VALUE bt)
#define RBASIC_SET_CLASS(obj, cls)
void rb_notimplement(void)
rb_ivar_set(yielder, id_memo, LONG2NUM(++count))
static void raise_loaderror(VALUE path, VALUE mesg)
VALUE rb_str_new(const char *, long)
#define builtin_class_name
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
static void compile_warn_print(const char *file, int line, const char *fmt, va_list args)
int rb_backtrace_p(VALUE obj)
const char ruby_description[]
static void report_bug(const char *file, int line, const char *fmt, va_list args)
#define rb_enc_asciicompat(enc)
const char * rb_id2name(ID id)
void rb_error_untrusted(VALUE obj)
static void warn_print(const char *fmt, va_list args)
VALUE rb_backtrace_to_location_ary(VALUE obj)
void rb_warning(const char *fmt,...)
static const char REPORTBUG_MSG[]
VALUE rb_define_module(const char *name)
RUBY_EXTERN VALUE rb_cData
void rb_exc_fatal(VALUE mesg)
void rb_write_error_str(VALUE mesg)
static rb_thread_t * GET_THREAD(void)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
void rb_warn(const char *fmt,...)
void rb_invalid_str(const char *str, const char *type)
#define RTYPEDDATA_TYPE(v)
static VALUE name_err_mesg_load(VALUE klass, VALUE str)
void rb_sys_warning(const char *fmt,...)
static void name_err_mesg_mark(void *p)
VALUE rb_sourcefilename(void)