28 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0]))
31 #define EXIT_SUCCESS 0
35 #define WIFEXITED(status) 1
39 #define WEXITSTATUS(status) (status)
44 #define REPORTBUG_MSG \
46 "You may have encountered a bug in the Ruby interpreter" \
47 " or extension libraries.\n" \
48 "Bug reports are welcome.\n" \
49 "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
54 #define defined_error(name, num) if (err == (num)) return (name);
55 #define undefined_error(name)
56 #include "known_errors.inc"
58 #undef undefined_error
69 return snprintf(buf, len,
"%s: ", file);
72 return snprintf(buf, len,
"%s:%d: ", file, line);
273 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
274 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
276 fputs(
"[BUG] ", out);
293 const char *file =
NULL;
305 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
306 _set_abort_behavior( 0, _CALL_REPORTFAULT);
316 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
330 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
331 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
340 if (errno_arg == 0) {
347 errno_str =
"undefined errno";
408 if (*name)
return name;
412 #define builtin_class_name rb_builtin_class_name
445 rb_bug(
"undef leaked to the Ruby space");
455 if (xt >
T_MASK && xt <= 0x3f) {
456 rb_fatal(
"unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
458 rb_bug(
"unknown type 0x%x (0x%x given)", t, xt);
466 if (child == parent)
return 1;
486 static const char mesg[] =
"wrong argument type %s (expected %s)";
592 if (argc == 0)
return self;
593 if (argc == 1 &&
self == argv[0])
return self;
713 static const char err[] =
"backtrace must be Array of String";
756 CONST_ID(id_exception,
"exception");
772 VALUE mesg, backtrace;
775 if (exc == obj)
return Qtrue;
780 ID id_message, id_backtrace;
782 CONST_ID(id_backtrace,
"backtrace");
785 if (status || obj ==
Qundef) {
843 #if EXIT_SUCCESS != 0
889 if (
NIL_P(status_val))
942 name = (argc > 1) ? argv[--argc] :
Qnil;
999 #define NAME_ERR_MESG_COUNT 3
1008 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1049 if (obj1 == obj2)
return Qtrue;
1072 const char *desc = 0;
1097 if (desc && desc[0] !=
'#') {
1184 if (!
st_lookup(syserr_tbl, n, &error)) {
1200 if (!
st_lookup(syserr_tbl, n, &error)) {
1203 snprintf(name,
sizeof(name),
"E%03d", n);
1223 #if !defined(_WIN32)
1234 error = mesg; mesg =
Qnil;
1237 klass = (
VALUE)data;
1250 else err =
"unknown error";
1772 va_start(args, fmt);
1785 va_start(args, fmt);
1807 va_start(args, fmt);
1819 va_start(args, fmt);
1829 "%s() function is unimplemented on this machine",
1839 va_start(args, fmt);
1853 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
1864 if (!mesg) mesg =
Qnil;
1867 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
1953 snprintf(buf, BUFSIZ,
"warning: %s", fmt);
1956 va_start(args, fmt);
1977 #undef rb_check_frozen
1993 #undef rb_check_trusted
2019 #define defined_error(name, num) set_syserr((num), (name));
2020 #define undefined_error(name) set_syserr(0, (name));
2021 #include "known_errors.inc"
2022 #undef defined_error
2023 #undef undefined_error
#define RB_TYPE_P(obj, type)
#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)
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)
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)
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_funcall(VALUE, ID, int,...)
Calls a method.
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)
#define rb_check_trusted_internal(obj)
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)
VALUE rb_ary_new3(long n,...)
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_str_append(VALUE, VALUE)
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,...)
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
vsnprintf(buf, BUFSIZ, fmt, args)
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)
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 *)
void Init_Exception(void)
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
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]
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)
VALUE rb_exc_new2(VALUE etype, const char *s)
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
static VALUE name_err_to_s(VALUE exc)
VALUE rb_ivar_set(VALUE, ID, VALUE)
RUBY_EXTERN VALUE rb_stderr
rb_encoding * rb_enc_get(VALUE obj)
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
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)
VALUE rb_exc_new3(VALUE etype, VALUE str)
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 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
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)
void rb_notimplement(void)
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)
void rb_warning(const char *fmt,...)
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)
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)