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
296 report_bug(
const char *file,
int line,
const char *fmt, va_list args)
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;
1042 VALUE args = (argc > 2) ? 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;
1808 rb_eNotImpError =
rb_define_class(
"NotImplementedError", rb_eScriptError);
1823 rb_eRuntimeError =
rb_define_class(
"RuntimeError", rb_eStandardError);
1826 rb_eEncodingError =
rb_define_class(
"EncodingError", rb_eStandardError);
1830 rb_eSystemCallError =
rb_define_class(
"SystemCallError", rb_eStandardError);
1846 va_start(args, fmt);
1859 va_start(args, fmt);
1881 va_start(args, fmt);
1893 va_start(args, fmt);
1903 "%s() function is unimplemented on this machine",
1913 va_start(args, fmt);
1927 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
1938 if (!mesg) mesg =
Qnil;
1941 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
1984 #ifdef RUBY_FUNCTION_NAME_STRING
1986 rb_sys_fail_path_in(
const char *func_name,
VALUE path)
1991 rb_syserr_fail_path_in(func_name, n, path);
1995 rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
1999 if (!path) path =
Qnil;
2002 if (!func_name) func_name =
"(null)";
2003 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
2055 snprintf(buf, BUFSIZ,
"warning: %s", fmt);
2058 va_start(args, fmt);
2076 rb_raise(rb_eRuntimeError,
"can't modify frozen %s", what);
2079 #undef rb_check_frozen
2091 #undef rb_check_trusted
2115 #define defined_error(name, num) set_syserr((num), (name));
2116 #define undefined_error(name) set_syserr(0, (name));
2117 #include "known_errors.inc"
2118 #undef defined_error
2119 #undef undefined_error