12 #include "ruby/internal/config.h"
26 #ifdef HAVE_SYS_WAIT_H
27 # include <sys/wait.h>
31 # include <AvailabilityMacros.h>
35 #include "internal/class.h"
36 #include "internal/error.h"
37 #include "internal/eval.h"
38 #include "internal/hash.h"
39 #include "internal/io.h"
40 #include "internal/load.h"
41 #include "internal/object.h"
42 #include "internal/process.h"
43 #include "internal/string.h"
44 #include "internal/symbol.h"
45 #include "internal/thread.h"
46 #include "internal/variable.h"
50 #include "ruby_assert.h"
62 #define EXIT_SUCCESS 0
66 #define WIFEXITED(status) 1
70 #define WEXITSTATUS(status) (status)
75 int rb_str_end_with_asciichar(
VALUE str,
int c);
77 long rb_backtrace_length_limit = -1;
79 VALUE rb_eEWOULDBLOCK;
80 VALUE rb_eEINPROGRESS;
81 static VALUE rb_mWarning;
82 static VALUE rb_cWarningBuffer;
85 static ID id_category;
86 static ID id_deprecated;
87 static ID id_experimental;
88 static ID id_performance;
89 static VALUE sym_category;
90 static VALUE sym_highlight;
95 extern const char *rb_dynamic_description;
100 #define defined_error(name, num) if (err == (num)) return (name);
101 #define undefined_error(name)
102 #include "known_errors.inc"
104 #undef undefined_error
109 err_position_0(
char *buf,
long len,
const char *file,
int line)
114 else if (line == 0) {
115 return snprintf(buf,
len,
"%s: ", file);
118 return snprintf(buf,
len,
"%s:%d: ", file, line);
124 err_vcatf(
VALUE str, const
char *pre, const
char *file,
int line,
125 const
char *fmt, va_list args)
140 rb_syntax_error_append(
VALUE exc,
VALUE file,
int line,
int column,
146 err_vcatf(mesg, NULL, fn, line, fmt, args);
148 rb_write_error_str(mesg);
152 exc = syntax_error_with_path(exc, file, &mesg, enc);
153 err_vcatf(mesg, NULL, fn, line, fmt, args);
159 static unsigned int warning_disabled_categories = (
161 ~RB_WARN_CATEGORY_DEFAULT_BITS);
164 rb_warning_category_mask(
VALUE category)
166 return 1U << rb_warning_category_from_name(category);
170 rb_warning_category_from_name(
VALUE category)
176 !st_lookup(warning_categories.id2enum, cat_id, &cat_value)) {
186 if (!st_lookup(warning_categories.enum2id, category, &
id)) {
193 rb_warning_category_update(
unsigned int mask,
unsigned int bits)
195 warning_disabled_categories &= ~mask;
196 warning_disabled_categories |= mask & ~bits;
202 return !(warning_disabled_categories & (1U << category));
230 return RBOOL(rb_warning_category_enabled_p(cat));
244 unsigned int mask = rb_warning_category_mask(category);
245 unsigned int disabled = warning_disabled_categories;
250 warning_disabled_categories = disabled;
262 rb_warning_s_categories(
VALUE mod)
264 st_index_t num = warning_categories.id2enum->num_entries;
266 num = st_keys(warning_categories.id2enum, ids, num);
268 for (st_index_t i = 0; i < num; ++i) {
286 rb_warning_s_warn(
int argc,
VALUE *argv,
VALUE mod)
297 if (!
NIL_P(category)) {
299 if (!rb_warning_category_enabled_p(cat))
return Qnil;
301 rb_write_error_str(str);
347 rb_warning_warn_arity(
void)
350 return me ? rb_method_entry_arity(me) : 1;
357 rb_warning_category_from_name(category);
360 if (rb_warning_warn_arity() == 1) {
361 return rb_warning_warn(rb_mWarning, str);
373 rb_write_warning_str(
VALUE str)
375 rb_warning_warn(rb_mWarning, str);
380 warn_vsprintf(
rb_encoding *enc, const
char *file,
int line, const
char *fmt, va_list args)
384 err_vcatf(str,
"warning: ", file, line, fmt, args);
388 #define with_warn_vsprintf(enc, file, line, fmt) \
391 va_start(args, fmt); \
392 str = warn_vsprintf(enc, file, line, fmt, args); \
399 with_warn_vsprintf(NULL, file, line, fmt) {
400 rb_write_warning_str(str);
406 rb_enc_compile_warn(
rb_encoding *enc,
const char *file,
int line,
const char *fmt, ...)
409 with_warn_vsprintf(enc, file, line, fmt) {
410 rb_write_warning_str(str);
420 with_warn_vsprintf(NULL, file, line, fmt) {
421 rb_write_warning_str(str);
428 rb_enc_compile_warning(
rb_encoding *enc,
const char *file,
int line,
const char *fmt, ...)
431 with_warn_vsprintf(enc, file, line, fmt) {
432 rb_write_warning_str(str);
441 with_warn_vsprintf(NULL, file, line, fmt) {
442 rb_warn_category(str, rb_warning_category_to_name(category));
449 warning_string(
rb_encoding *enc, const
char *fmt, va_list args)
452 const char *file = rb_source_location_cstr(&line);
453 return warn_vsprintf(enc, file, line, fmt, args);
456 #define with_warning_string(mesg, enc, fmt) \
457 with_warning_string_from(mesg, enc, fmt, fmt)
458 #define with_warning_string_from(mesg, enc, fmt, last_arg) \
460 va_list args; va_start(args, last_arg); \
461 mesg = warning_string(enc, fmt, args); \
468 with_warning_string(mesg, 0, fmt) {
469 rb_write_warning_str(mesg);
478 with_warning_string(mesg, 0, fmt) {
479 rb_warn_category(mesg, rb_warning_category_to_name(category));
485 rb_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
488 with_warning_string(mesg, enc, fmt) {
489 rb_write_warning_str(mesg);
499 with_warning_string(mesg, 0, fmt) {
500 rb_write_warning_str(mesg);
510 with_warning_string(mesg, 0, fmt) {
511 rb_warn_category(mesg, rb_warning_category_to_name(category));
517 rb_warning_string(
const char *fmt, ...)
519 with_warning_string(mesg, 0, fmt) {
526 rb_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
529 with_warning_string(mesg, enc, fmt) {
530 rb_write_warning_str(mesg);
537 deprecation_warning_enabled(
void)
545 warn_deprecated(
VALUE mesg,
const char *removal,
const char *suggest)
550 rb_str_catf(mesg,
" and will be removed in Ruby %s", removal);
552 if (suggest)
rb_str_catf(mesg,
"; use %s instead", suggest);
554 rb_warn_category(mesg,
ID2SYM(id_deprecated));
558 rb_warn_deprecated(
const char *fmt,
const char *suggest, ...)
560 if (!deprecation_warning_enabled())
return;
562 with_warning_string_from(mesg, 0, fmt, suggest) {
563 warn_deprecated(mesg, NULL, suggest);
568 rb_warn_deprecated_to_remove(
const char *removal,
const char *fmt,
const char *suggest, ...)
570 if (!deprecation_warning_enabled())
return;
572 with_warning_string_from(mesg, 0, fmt, suggest) {
573 warn_deprecated(mesg, removal, suggest);
578 end_with_asciichar(
VALUE str,
int c)
581 rb_str_end_with_asciichar(str, c);
586 warning_write(
int argc,
VALUE *argv,
VALUE buf)
605 if (!
NIL_P(uplevel)) {
610 location = rb_ec_backtrace_location_ary(ec, lev + 1, 1, TRUE);
611 if (!
NIL_P(location)) {
615 if (argc > 1 || !
NIL_P(uplevel) || !end_with_asciichar(str,
'\n')) {
617 if (
NIL_P(uplevel)) {
620 else if (
NIL_P(location) ||
629 RBASIC_SET_CLASS(str, rb_cWarningBuffer);
634 if (!
NIL_P(category)) {
635 category = rb_to_symbol_type(category);
636 rb_warning_category_from_name(category);
639 if (exc == rb_mWarning) {
641 rb_write_error_str(str);
644 rb_warn_category(str, category);
650 #define MAX_BUG_REPORTERS 0x100
653 void (*func)(
FILE *out,
void *data);
657 static int bug_reporters_size;
660 rb_bug_reporter_add(
void (*func)(
FILE *,
void *),
void *data)
663 if (bug_reporters_size >= MAX_BUG_REPORTERS) {
667 reporter->func = func;
668 reporter->data = data;
677 #if defined __CYGWIN__ || defined DOSISH
678 # define PATH_SEP_ENCODING 1
680 if (x ==
':')
return true;
681 if (x ==
'\\')
return true;
691 static const char PATHSEP_REPLACE =
'!';
694 append_pathname(
char *p,
const char *pe,
VALUE str)
696 #ifdef PATH_SEP_ENCODING
705 while (p < pe && s < se && (c = *s) !=
'\0') {
707 if (s == se || !*s)
break;
708 if (path_sep_p(s[1]))
goto skipsep;
710 else if (path_sep_p(c)) {
712 *p++ = PATHSEP_REPLACE;
714 while (++s < se && path_sep_p(*s));
717 const char *
const ss = s;
718 while (p < pe && s < se && *s && !path_sep_p(*s)) {
719 #ifdef PATH_SEP_ENCODING
727 if (s > ss) memcpy(p - (s - ss), ss, s - ss);
734 append_basename(
char *p,
const char *pe,
struct path_string *path,
VALUE str)
737 #ifdef PATH_SEP_ENCODING
743 if (path_sep_p(p[-1])) {
744 #ifdef PATH_SEP_ENCODING
760 size_t n = path->len;
761 if (p + n > pe) n = pe - p;
762 memcpy(p, path->ptr, n);
767 finish_report(
FILE *out, rb_pid_t pid)
769 if (out != stdout && out != stderr) fclose(out);
770 #ifdef HAVE_WORKING_FORK
771 if (pid > 0) waitpid(pid, NULL, 0);
800 expand_report_argument(
const char **input_template,
struct report_expansion *values,
801 char *buf,
size_t size,
bool word)
804 char *end = buf + size;
805 const char *
template = *input_template;
808 if (p >= end-1 || !*
template)
return NULL;
810 char c = *
template++;
812 if (!store)
continue;
815 switch (c = *
template++) {
817 p = append_basename(p, end, &values->exe,
rb_argv0);
820 p = append_pathname(p, end,
rb_argv0);
823 p = append_basename(p, end, &values->script, GET_VM()->orig_progname);
826 p = append_pathname(p, end, GET_VM()->orig_progname);
829 if (!values->pid) values->pid = getpid();
834 if (!values->time) values->time = time(NULL);
835 snprintf(p, end-p,
"%" PRI_TIMET_PREFIX
"d", values->time);
839 if (c >=
'0' && c <=
'7') {
842 if (!c) store =
false;
847 if (p < end-1) *p++ = c;
849 *input_template =
template;
854 FILE *ruby_popen_writer(
char *
const *argv, rb_pid_t *pid);
857 open_report_path(
const char *
template,
char *buf,
size_t size, rb_pid_t *pid)
861 if (!
template)
return NULL;
862 if (0) fprintf(stderr,
"RUBY_CRASH_REPORT=%s\n", buf);
863 if (*
template ==
'|') {
864 char *argv[16], *bufend = buf + size, *p;
867 for (argc = 0; argc < numberof(argv) - 1; ++argc) {
868 while (*
template &&
ISSPACE(*
template))
template++;
869 p = expand_report_argument(&
template, &values, buf, bufend-buf,
true);
875 if (!p)
return ruby_popen_writer(argv, pid);
877 else if (*
template) {
878 expand_report_argument(&
template, &values, buf, size,
false);
879 return fopen(buf,
"w");
884 static const char *crash_report;
887 #define REPORT_BUG_BUFSIZ 256
889 bug_report_file(
const char *file,
int line, rb_pid_t *pid)
891 char buf[REPORT_BUG_BUFSIZ];
892 const char *report = crash_report;
893 if (!report) report = getenv(
"RUBY_CRASH_REPORT");
894 FILE *out = open_report_path(report, buf,
sizeof(buf), pid);
895 int len = err_position_0(buf,
sizeof(buf), file, line);
898 if ((ssize_t)fwrite(buf, 1,
len, out) == (ssize_t)
len)
return out;
901 if ((ssize_t)fwrite(buf, 1,
len, stderr) == (ssize_t)
len) {
904 if ((ssize_t)fwrite(buf, 1,
len, stdout) == (ssize_t)
len) {
911 FUNC_MINIMIZED(
static void bug_important_message(
FILE *out,
const char *
const msg,
size_t len));
914 bug_important_message(
FILE *out,
const char *
const msg,
size_t len)
916 const char *
const endmsg = msg +
len;
920 if (isatty(fileno(out))) {
921 static const char red[] =
"\033[;31;1;7m";
922 static const char green[] =
"\033[;32;7m";
923 static const char reset[] =
"\033[m";
924 const char *e = strchr(p,
'\n');
925 const int w = (int)(e - p);
927 int i = (int)(e - p);
928 fputs(*p ==
' ' ? green : red, out);
929 fwrite(p, 1, e - p, out);
930 for (; i < w; ++i) fputc(
' ', out);
933 }
while ((p = e + 1) < endmsg && (e = strchr(p,
'\n')) != 0 && e > p + 1);
935 fwrite(p, 1, endmsg - p, out);
938 #undef CRASH_REPORTER_MAY_BE_CREATED
939 #if defined(__APPLE__) && \
940 (!defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 || defined(__POWERPC__))
941 # define CRASH_REPORTER_MAY_BE_CREATED
944 preface_dump(
FILE *out)
946 #if defined __APPLE__
947 static const char msg[] =
""
948 "-- Crash Report log information "
949 "--------------------------------------------\n"
950 " See Crash Report log file in one of the following locations:\n"
951 # ifdef CRASH_REPORTER_MAY_BE_CREATED
952 " * ~/Library/Logs/CrashReporter\n"
953 " * /Library/Logs/CrashReporter\n"
955 " * ~/Library/Logs/DiagnosticReports\n"
956 " * /Library/Logs/DiagnosticReports\n"
957 " for more details.\n"
958 "Don't forget to include the above Crash Report log file in bug reports.\n"
960 const size_t msglen =
sizeof(msg) - 1;
962 const char *msg = NULL;
963 const size_t msglen = 0;
965 bug_important_message(out, msg, msglen);
969 postscript_dump(
FILE *out)
971 #if defined __APPLE__
972 static const char msg[] =
""
975 "\n""Don't forget to include the Crash Report log file under\n"
976 # ifdef CRASH_REPORTER_MAY_BE_CREATED
979 "DiagnosticReports directory in bug reports.\n"
982 const size_t msglen =
sizeof(msg) - 1;
984 const char *msg = NULL;
985 const size_t msglen = 0;
987 bug_important_message(out, msg, msglen);
992 bug_report_begin_valist(
FILE *out, const
char *fmt, va_list args)
994 char buf[REPORT_BUG_BUFSIZ];
996 fputs(
"[BUG] ", out);
997 vsnprintf(buf,
sizeof(buf), fmt, args);
999 snprintf(buf,
sizeof(buf),
"\n%s\n\n", rb_dynamic_description);
1004 #define bug_report_begin(out, fmt) do { \
1006 va_start(args, fmt); \
1007 bug_report_begin_valist(out, fmt, args); \
1012 bug_report_end(
FILE *out, rb_pid_t pid)
1017 for (i=0; i<bug_reporters_size; i++) {
1019 (*reporter->func)(out, reporter->data);
1022 postscript_dump(out);
1023 finish_report(out, pid);
1026 #define report_bug(file, line, fmt, ctx) do { \
1027 rb_pid_t pid = -1; \
1028 FILE *out = bug_report_file(file, line, &pid); \
1030 bug_report_begin(out, fmt); \
1031 rb_vm_bugreport(ctx, out); \
1032 bug_report_end(out, pid); \
1036 #define report_bug_valist(file, line, fmt, ctx, args) do { \
1037 rb_pid_t pid = -1; \
1038 FILE *out = bug_report_file(file, line, &pid); \
1040 bug_report_begin_valist(out, fmt, args); \
1041 rb_vm_bugreport(ctx, out); \
1042 bug_report_end(out, pid); \
1047 ruby_set_crash_report(
const char *
template)
1049 crash_report =
template;
1052 char buf[REPORT_BUG_BUFSIZ];
1053 FILE *out = open_report_path(
template, buf,
sizeof(buf), &pid);
1055 time_t t = time(NULL);
1056 fprintf(out,
"ruby_test_bug_report: %s", ctime(&t));
1057 finish_report(out, pid);
1062 NORETURN(
static void die(
void));
1066 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
1067 _set_abort_behavior( 0, _CALL_REPORTFAULT);
1075 rb_bug_without_die(const
char *fmt, va_list args)
1077 const char *file = NULL;
1081 file = rb_source_location_cstr(&line);
1084 report_bug_valist(file, line, fmt, NULL, args);
1091 va_start(args, fmt);
1092 rb_bug_without_die(fmt, args);
1098 rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler,
int sig,
const void *ctx,
const char *fmt, ...)
1100 const char *file = NULL;
1104 file = rb_source_location_cstr(&line);
1107 report_bug(file, line, fmt, ctx);
1109 if (default_sighandler) default_sighandler(sig);
1120 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
1122 const char *errno_str = rb_strerrno(errno_arg);
1124 rb_bug(
"%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
1126 rb_bug(
"%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
1134 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
1135 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
1138 rb_async_bug_errno(
const char *mesg,
int errno_arg)
1140 WRITE_CONST(2,
"[ASYNC BUG] ");
1141 write_or_abort(2, mesg, strlen(mesg));
1142 WRITE_CONST(2,
"\n");
1144 if (errno_arg == 0) {
1145 WRITE_CONST(2,
"errno == 0 (NOERROR)\n");
1148 const char *errno_str = rb_strerrno(errno_arg);
1151 errno_str =
"undefined errno";
1152 write_or_abort(2, errno_str, strlen(errno_str));
1154 WRITE_CONST(2,
"\n\n");
1155 write_or_abort(2, rb_dynamic_description, strlen(rb_dynamic_description));
1160 rb_report_bug_valist(
VALUE file,
int line,
const char *fmt, va_list args)
1162 report_bug_valist(
RSTRING_PTR(file), line, fmt, NULL, args);
1166 rb_assert_failure(
const char *file,
int line,
const char *name,
const char *expr)
1168 rb_assert_failure_detail(file, line, name, expr, NULL);
1172 rb_assert_failure_detail(
const char *file,
int line,
const char *name,
const char *expr,
1173 const char *fmt, ...)
1176 fprintf(out,
"Assertion Failed: %s:%d:", file, line);
1177 if (name) fprintf(out,
"%s:", name);
1182 va_start(args, fmt);
1184 vfprintf(out, fmt, args);
1187 fprintf(out,
"\n%s\n\n", rb_dynamic_description);
1190 rb_vm_bugreport(NULL, out);
1191 bug_report_end(out, -1);
1195 static const char builtin_types[][10] = {
1228 rb_builtin_type_name(
int t)
1231 if ((
unsigned int)t >= numberof(builtin_types))
return 0;
1232 name = builtin_types[t];
1233 if (*name)
return name;
1238 displaying_class_of(
VALUE x)
1241 case Qfalse:
return rb_fstring_cstr(
"false");
1242 case Qnil:
return rb_fstring_cstr(
"nil");
1243 case Qtrue:
return rb_fstring_cstr(
"true");
1249 builtin_class_name(
VALUE x)
1275 rb_builtin_class_name(
VALUE x)
1277 const char *etype = builtin_class_name(x);
1285 COLDFUNC NORETURN(
static void unexpected_type(
VALUE,
int,
int));
1286 #define UNDEF_LEAKED "undef leaked to the Ruby space"
1289 unexpected_type(
VALUE x,
int xt,
int t)
1291 const char *tname = rb_builtin_type_name(t);
1295 mesg =
rb_sprintf(
"wrong argument type %"PRIsVALUE
" (expected %s)",
1296 displaying_class_of(x), tname);
1299 else if (xt >
T_MASK && xt <= 0x3f) {
1300 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given, probably comes"
1301 " from extension library for ruby 1.8)", t, xt);
1304 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given)", t, xt);
1319 if (xt != t || (xt ==
T_DATA && rbimpl_rtypeddata_p(x))) {
1328 unexpected_type(x, xt, t);
1339 unexpected_type(x,
TYPE(x), t);
1346 if (child == parent)
return 1;
1362 #undef rb_typeddata_is_instance_of
1366 return rb_typeddata_is_instance_of_inline(obj, data_type);
1375 actual = displaying_class_of(obj);
1378 actual = displaying_class_of(obj);
1385 return RTYPEDDATA_GET_DATA(obj);
1425 static VALUE rb_eNOERROR;
1427 ID ruby_static_id_cause;
1428 #define id_cause ruby_static_id_cause
1429 static ID id_message, id_detailed_message, id_backtrace;
1430 static ID id_key, id_matchee, id_args, id_Errno, id_errno, id_i_path;
1431 static ID id_receiver, id_recv, id_iseq, id_local_variables;
1432 static ID id_private_call_p, id_top, id_bottom;
1434 #define id_bt_locations idBt_locations
1435 #define id_mesg idMesg
1436 #define id_name idName
1438 #undef rb_exc_new_cstr
1456 rb_yjit_lazy_push_frame(GET_EC()->cfp->pc);
1491 exc_initialize(
int argc,
VALUE *argv,
VALUE exc)
1496 return exc_init(exc, arg);
1525 exc_exception(
int argc,
VALUE *argv,
VALUE self)
1530 if (argc == 0)
return self;
1531 if (argc == 1 &&
self == argv[0])
return self;
1563 rb_get_message(
VALUE exc)
1566 if (UNDEF_P(e))
return Qnil;
1572 rb_get_detailed_message(
VALUE exc,
VALUE opt)
1581 if (UNDEF_P(e))
return Qnil;
1593 exc_s_to_tty_p(
VALUE self)
1595 return RBOOL(rb_stderr_tty_p());
1599 check_highlight_keyword(
VALUE opt,
int auto_tty_detect)
1606 switch (highlight) {
1608 rb_bool_expected(highlight,
"highlight", TRUE);
1614 if (
NIL_P(highlight)) {
1615 highlight = RBOOL(auto_tty_detect && rb_stderr_tty_p());
1622 check_order_keyword(
VALUE opt)
1627 static VALUE kw_order;
1632 if (order !=
Qnil) {
1634 if (
id == id_bottom) order =
Qtrue;
1635 else if (
id == id_top) order =
Qfalse;
1638 "order: %+"PRIsVALUE, order);
1698 exc_full_message(
int argc,
VALUE *argv,
VALUE exc)
1700 VALUE opt, str, emesg, errat;
1701 VALUE highlight, order;
1705 highlight = check_highlight_keyword(opt, 1);
1706 order = check_order_keyword(opt);
1714 errat = rb_get_backtrace(exc);
1715 emesg = rb_get_detailed_message(exc, opt);
1717 rb_error_write(exc, emesg, errat, str, opt, highlight, order);
1731 exc_message(
VALUE exc)
1782 exc_detailed_message(
int argc,
VALUE *argv,
VALUE exc)
1788 VALUE highlight = check_highlight_keyword(opt, 0);
1790 extern VALUE rb_decorate_message(
const VALUE eclass,
VALUE emesg,
int highlight);
1792 return rb_decorate_message(
CLASS_OF(exc), rb_get_message(exc),
RTEST(highlight));
1809 exc_inspect(
VALUE exc)
1865 exc_backtrace(
VALUE exc)
1871 if (rb_backtrace_p(obj)) {
1872 obj = rb_backtrace_to_str_ary(obj);
1882 rb_get_backtrace(
VALUE exc)
1884 ID mid = id_backtrace;
1892 info = exc_backtrace(exc);
1899 return rb_check_backtrace(info);
1924 exc_backtrace_locations(
VALUE exc)
1930 obj = rb_backtrace_to_location_ary(obj);
1936 rb_check_backtrace(
VALUE bt)
1939 static const char err[] =
"backtrace must be an Array of String or an Array of Thread::Backtrace::Location";
1943 if (rb_backtrace_p(bt))
return bt;
1977 VALUE btobj = rb_location_ary_to_backtrace(bt);
1984 return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1991 return exc_set_backtrace(exc, bt);
2027 exc_cause(
VALUE exc)
2033 try_convert_to_exception(
VALUE obj)
2050 VALUE mesg, backtrace;
2052 if (exc == obj)
return Qtrue;
2057 obj =
rb_protect(try_convert_to_exception, obj, &state);
2058 if (state || UNDEF_P(obj)) {
2064 if (UNDEF_P(mesg))
return Qfalse;
2066 if (UNDEF_P(backtrace))
return Qfalse;
2070 backtrace = exc_backtrace(obj);
2075 return rb_equal(exc_backtrace(exc), backtrace);
2091 exit_initialize(
int argc,
VALUE *argv,
VALUE exc)
2099 status =
INT2FIX(EXIT_SUCCESS);
2104 status =
INT2FIX(EXIT_FAILURE);
2110 if (
NIL_P(status)) {
2111 status =
INT2FIX(EXIT_SUCCESS);
2114 #if EXIT_SUCCESS != 0
2116 status =
INT2FIX(EXIT_SUCCESS);
2125 status =
INT2FIX(EXIT_SUCCESS);
2141 exit_status(
VALUE exc)
2155 exit_success_p(
VALUE exc)
2160 if (
NIL_P(status_val))
2163 return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
2169 if (!UNDEF_P(recv))
rb_ivar_set(exc, id_recv, recv);
2186 frozen_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2189 VALUE values[numberof(keywords)], options;
2192 keywords[0] = id_receiver;
2193 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2195 err_init_recv(
self, values[0]);
2207 #define frozen_err_receiver name_err_receiver
2215 va_start(args, fmt);
2230 va_start(args, fmt);
2244 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
2246 err_init_recv(exc, recv);
2247 if (cfp && VM_FRAME_TYPE(cfp) != VM_FRAME_MAGIC_DUMMY) {
2248 rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
2267 name_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2270 VALUE values[numberof(keywords)], name, options;
2273 keywords[0] = id_receiver;
2274 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2275 name = (argc > 1) ? argv[--argc] :
Qnil;
2277 name_err_init_attr(
self, values[0], name);
2286 exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
2287 return name_err_init_attr(exc, recv, method);
2294 return name_err_init(exc, mesg, recv, method);
2305 name_err_name(
VALUE self)
2321 name_err_local_variables(
VALUE self)
2327 if (!
NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
2335 nometh_err_init_attr(
VALUE exc,
VALUE args,
int priv)
2359 nometh_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2362 VALUE args, options;
2364 priv = (argc > 3) && (--argc,
RTEST(argv[argc]));
2365 args = (argc > 2) ? argv[--argc] :
Qnil;
2366 if (!
NIL_P(options)) argv[argc++] = options;
2368 return nometh_err_init_attr(
self, args, priv);
2375 name_err_init(exc, mesg, recv, method);
2376 return nometh_err_init_attr(exc, args, priv);
2386 name_err_mesg_mark(
void *p)
2395 name_err_mesg_update(
void *p)
2409 name_err_mesg_update,
2411 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
2435 name_err_mesg_alloc(
VALUE klass)
2442 name_err_mesg_init_copy(
VALUE obj1,
VALUE obj2)
2444 if (obj1 == obj2)
return obj1;
2461 if (obj1 == obj2)
return Qtrue;
2478 name_err_mesg_receiver_name(
VALUE obj)
2489 name_err_mesg_to_str(
VALUE obj)
2497 struct RString s_str, c_str, d_str;
2498 VALUE c, s, d = 0, args[4], c2;
2502 #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
2503 c = s = FAKE_CSTR(&s_str,
"");
2507 c = d = FAKE_CSTR(&d_str,
"nil");
2510 c = d = FAKE_CSTR(&d_str,
"true");
2513 c = d = FAKE_CSTR(&d_str,
"false");
2517 d =
rb_protect(name_err_mesg_receiver_name, obj, &state);
2518 if (state || NIL_OR_UNDEF_P(d))
2532 s = FAKE_CSTR(&s_str,
"module ");
2536 s = FAKE_CSTR(&s_str,
"class ");
2548 s = FAKE_CSTR(&s_str,
"");
2549 if (obj == rb_vm_top_self()) {
2550 c = FAKE_CSTR(&c_str,
"main");
2558 s = FAKE_CSTR(&s_str,
"an instance of ");
2562 c2 =
rb_protect(name_err_mesg_receiver_name, c, &state);
2563 if (state || NIL_OR_UNDEF_P(c2))
2588 return name_err_mesg_to_str(obj);
2606 name_err_receiver(
VALUE self)
2608 VALUE recv = rb_ivar_lookup(
self, id_recv,
Qundef);
2609 if (!UNDEF_P(recv))
return recv;
2630 nometh_err_args(
VALUE self)
2643 nometh_err_private_call_p(
VALUE self)
2664 key_err_receiver(
VALUE self)
2668 recv = rb_ivar_lookup(
self, id_receiver,
Qundef);
2669 if (!UNDEF_P(recv))
return recv;
2681 key_err_key(
VALUE self)
2685 key = rb_ivar_lookup(
self, id_key,
Qundef);
2686 if (!UNDEF_P(key))
return key;
2710 key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2716 if (!
NIL_P(options)) {
2718 VALUE values[numberof(keywords)];
2720 keywords[0] = id_receiver;
2721 keywords[1] = id_key;
2722 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2723 for (i = 0; i < numberof(values); ++i) {
2724 if (!UNDEF_P(values[i])) {
2741 no_matching_pattern_key_err_matchee(
VALUE self)
2745 matchee = rb_ivar_lookup(
self, id_matchee,
Qundef);
2746 if (!UNDEF_P(matchee))
return matchee;
2758 no_matching_pattern_key_err_key(
VALUE self)
2762 key = rb_ivar_lookup(
self, id_key,
Qundef);
2763 if (!UNDEF_P(key))
return key;
2776 no_matching_pattern_key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2782 if (!
NIL_P(options)) {
2784 VALUE values[numberof(keywords)];
2786 keywords[0] = id_matchee;
2787 keywords[1] = id_key;
2788 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2789 for (i = 0; i < numberof(values); ++i) {
2790 if (!UNDEF_P(values[i])) {
2808 syntax_error_initialize(
int argc,
VALUE *argv,
VALUE self)
2812 mesg = rb_fstring_lit(
"compile error");
2829 if (old_path != path) {
2832 old_path, (
void *)old_path, (
void *)path);
2837 (
FL_TEST(old_path, RSTRING_FSTR) ?
":FSTR" :
""),
2896 rb_free_warning(
void)
2898 st_free_table(warning_categories.id2enum);
2899 st_free_table(warning_categories.enum2id);
2900 st_free_table(syserr_tbl);
2904 setup_syserr(
int n,
const char *name)
2913 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2918 rb_eEWOULDBLOCK = error;
2921 rb_eEINPROGRESS = error;
2926 st_add_direct(syserr_tbl, n, (st_data_t)error);
2931 set_syserr(
int n,
const char *name)
2935 if (!st_lookup(syserr_tbl, n, &error)) {
2936 return setup_syserr(n, name);
2950 if (!st_lookup(syserr_tbl, n, &error)) {
2953 snprintf(name,
sizeof(name),
"E%03d", n);
2954 return setup_syserr(n, name);
2956 return (
VALUE)error;
2970 syserr_initialize(
int argc,
VALUE *argv,
VALUE self)
2973 VALUE mesg, error, func, errmsg;
2977 st_data_t data = (st_data_t)klass;
2980 error = mesg; mesg =
Qnil;
2982 if (!
NIL_P(error) && st_lookup(syserr_tbl,
NUM2LONG(error), &data)) {
2983 klass = (
VALUE)data;
2988 RBASIC_SET_CLASS(
self, klass);
2996 else err =
"unknown error";
3020 syserr_errno(
VALUE self)
3415 exception_alloc(
VALUE klass)
3417 return rb_class_allocate_instance(klass);
3421 exception_dumper(
VALUE exc)
3431 ivar_copy_i(
ID key,
VALUE val, st_data_t exc)
3437 void rb_exc_check_circular_cause(
VALUE exc);
3453 rb_exc_check_circular_cause(exc);
3463 Init_Exception(
void)
3550 syserr_tbl = st_init_numtable();
3589 id_iseq = rb_make_internal_id();
3590 id_recv = rb_make_internal_id();
3592 sym_category =
ID2SYM(id_category);
3595 warning_categories.id2enum = rb_init_identtable();
3600 warning_categories.enum2id = rb_init_identtable();
3613 va_start(args, fmt);
3621 rb_vraise(
VALUE exc,
const char *fmt, va_list ap)
3630 va_start(args, fmt);
3631 rb_vraise(exc, fmt, args);
3635 NORETURN(
static void raise_loaderror(
VALUE path,
VALUE mesg));
3651 va_start(args, fmt);
3654 raise_loaderror(
Qnil, mesg);
3663 va_start(args, fmt);
3666 raise_loaderror(path, mesg);
3673 "%"PRIsVALUE
"() function is unimplemented on this machine",
3683 if (! ruby_thread_has_gvl_p()) {
3686 fprintf(stderr,
"[FATAL] rb_fatal() outside of GVL\n");
3687 rb_print_backtrace(stderr);
3691 va_start(args, fmt);
3699 make_errno_exc(
const char *mesg)
3705 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
3711 make_errno_exc_str(
VALUE mesg)
3716 if (!mesg) mesg =
Qnil;
3719 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
3757 #undef rb_sys_fail_str
3764 #ifdef RUBY_FUNCTION_NAME_STRING
3766 rb_sys_fail_path_in(
const char *func_name,
VALUE path)
3771 rb_syserr_fail_path_in(func_name, n, path);
3775 rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
3777 rb_exc_raise(rb_syserr_new_path_in(func_name, n, path));
3781 rb_syserr_new_path_in(
const char *func_name,
int n,
VALUE path)
3785 if (!path) path =
Qnil;
3788 if (!func_name) func_name =
"(null)";
3789 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
3798 NORETURN(
static void rb_mod_exc_raise(
VALUE exc,
VALUE mod));
3810 VALUE exc = make_errno_exc(mesg);
3811 rb_mod_exc_raise(exc, mod);
3817 VALUE exc = make_errno_exc_str(mesg);
3818 rb_mod_exc_raise(exc, mod);
3825 rb_mod_exc_raise(exc, mod);
3832 rb_mod_exc_raise(exc, mod);
3836 syserr_warning(
VALUE mesg,
int err)
3840 rb_write_warning_str(mesg);
3845 rb_sys_warn(
const char *fmt, ...)
3848 int errno_save =
errno;
3849 with_warning_string(mesg, 0, fmt) {
3850 syserr_warning(mesg, errno_save);
3857 rb_syserr_warn(
int err,
const char *fmt, ...)
3860 with_warning_string(mesg, 0, fmt) {
3861 syserr_warning(mesg, err);
3867 rb_sys_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
3870 int errno_save =
errno;
3871 with_warning_string(mesg, enc, fmt) {
3872 syserr_warning(mesg, errno_save);
3879 rb_syserr_enc_warn(
int err,
rb_encoding *enc,
const char *fmt, ...)
3882 with_warning_string(mesg, enc, fmt) {
3883 syserr_warning(mesg, err);
3893 int errno_save =
errno;
3894 with_warning_string(mesg, 0, fmt) {
3895 syserr_warning(mesg, errno_save);
3903 rb_syserr_warning(
int err,
const char *fmt, ...)
3906 with_warning_string(mesg, 0, fmt) {
3907 syserr_warning(mesg, err);
3914 rb_sys_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
3917 int errno_save =
errno;
3918 with_warning_string(mesg, enc, fmt) {
3919 syserr_warning(mesg, errno_save);
3926 rb_syserr_enc_warning(
int err,
rb_encoding *enc,
const char *fmt, ...)
3929 with_warning_string(mesg, enc, fmt) {
3930 syserr_warning(mesg, err);
3936 rb_load_fail(
VALUE path,
const char *err)
3941 raise_loaderror(path, mesg);
3956 va_start(args, fmt);
3965 inspect_frozen_obj(
VALUE obj,
VALUE mesg,
int recur)
3977 get_created_info(
VALUE obj,
int *pline)
3993 rb_yjit_lazy_push_frame(GET_EC()->cfp->pc);
4003 VALUE created_path = get_created_info(frozen_obj, &created_line);
4004 if (!
NIL_P(created_path)) {
4005 rb_str_catf(mesg,
", created at %"PRIsVALUE
":%d", created_path, created_line);
4011 rb_warn_unchilled(
VALUE obj)
4016 VALUE file = rb_source_location(&line);
4023 rb_str_cat2(mesg,
"warning: literal string will be frozen in the future");
4026 if (STR_SHARED_P(str)) {
4027 str =
RSTRING(obj)->as.heap.aux.shared;
4029 VALUE created = get_created_info(str, &line);
4030 if (
NIL_P(created)) {
4031 rb_str_cat2(mesg,
" (run with --debug-frozen-string-literal for more information)\n");
4036 rb_str_cat2(mesg,
": info: the string was created here\n");
4038 rb_warn_category(mesg, rb_warning_category_to_name(category));
4042 #undef rb_check_frozen
4060 rb_eNOERROR = setup_syserr(0,
"NOERROR");
4065 #define defined_error(name, num) set_syserr((num), (name));
4066 #define undefined_error(name) rb_define_const(rb_mErrno, (name), rb_eNOERROR);
4067 #include "known_errors.inc"
4068 #undef defined_error
4069 #undef undefined_error
4072 #include "warning.rbinc"
#define RUBY_DEBUG
Define this macro when you want assertions.
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
VALUE rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
Identical to rb_enc_sprintf(), except it takes a va_list instead of variadic arguments.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
Defines a top-level module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define TYPE(_)
Old name of rb_type.
#define ISSPACE
Old name of rb_isspace.
#define T_STRING
Old name of RUBY_T_STRING.
#define T_MASK
Old name of RUBY_T_MASK.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#define ID2SYM
Old name of RB_ID2SYM.
#define rb_str_buf_new2
Old name of rb_str_buf_new_cstr.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define T_DATA
Old name of RUBY_T_DATA.
#define CLASS_OF
Old name of rb_class_of.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_TRUE
Old name of RUBY_T_TRUE.
#define FL_ABLE
Old name of RB_FL_ABLE.
#define rb_ary_new3
Old name of rb_ary_new_from_args.
#define rb_exc_new3
Old name of rb_exc_new_str.
#define T_FALSE
Old name of RUBY_T_FALSE.
#define Qtrue
Old name of RUBY_Qtrue.
#define NUM2INT
Old name of RB_NUM2INT.
#define INT2NUM
Old name of RB_INT2NUM.
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define T_ARRAY
Old name of RUBY_T_ARRAY.
#define T_OBJECT
Old name of RUBY_T_OBJECT.
#define NIL_P
Old name of RB_NIL_P.
#define T_SYMBOL
Old name of RUBY_T_SYMBOL.
#define T_CLASS
Old name of RUBY_T_CLASS.
#define FL_TEST
Old name of RB_FL_TEST.
#define NUM2LONG
Old name of RB_NUM2LONG.
#define FIXNUM_P
Old name of RB_FIXNUM_P.
#define SYMBOL_P
Old name of RB_SYMBOL_P.
void rb_notimplement(void)
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Identical to rb_sys_fail(), except it takes additional module to extend the exception object before r...
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead of returning false.
rb_warning_category_t
Warning categories.
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports unless $VERBOSE is nil.
void rb_raise(VALUE exc, const char *fmt,...)
Exception entry point.
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Checks for the domestic relationship between the two.
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Identical to rb_compile_warning(), except it reports unless $VERBOSE is nil.
void rb_category_warning(rb_warning_category_t category, const char *fmt,...)
Identical to rb_warning(), except it takes additional "category" parameter.
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Identical to rb_mod_sys_fail(), except it does not depend on C global variable errno.
void rb_check_frozen(VALUE obj)
Queries if the passed object is frozen.
VALUE rb_eNotImpError
NotImplementedError exception.
VALUE rb_eScriptError
ScriptError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Checks if the given object is of given kind.
void rb_syserr_fail(int e, const char *mesg)
Raises appropriate exception that represents a C errno.
VALUE rb_eKeyError
KeyError exception.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_cNameErrorMesg
NameError::Message class.
VALUE rb_eSystemExit
SystemExit exception.
void rb_sys_fail(const char *mesg)
Converts a C errno into a Ruby exception, then raises it.
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
void rb_sys_warning(const char *fmt,...)
Identical to rb_sys_fail(), except it does not raise an exception to render a warning instead.
void rb_check_copyable(VALUE obj, VALUE orig)
Ensures that the passed object can be initialize_copy relationship.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_mErrno
Errno module.
VALUE rb_syserr_new_str(int n, VALUE arg)
Identical to rb_syserr_new(), except it takes the message in Ruby's String instead of C's.
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Identical to rb_mod_syserr_fail(), except it takes the message in Ruby's String instead of C's.
void rb_error_frozen(const char *what)
Identical to rb_frozen_error_raise(), except its raising exception has a message like "can't modify f...
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_eFrozenError
FrozenError exception.
VALUE rb_eNoMemError
NoMemoryError exception.
VALUE rb_eRangeError
RangeError exception.
VALUE rb_eLoadError
LoadError exception.
void rb_syserr_fail_str(int e, VALUE mesg)
Identical to rb_syserr_fail(), except it takes the message in Ruby's String instead of C's.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eNoMatchingPatternError
NoMatchingPatternError exception.
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
void rb_fatal(const char *fmt,...)
Raises the unsung "fatal" exception.
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Raises an instance of rb_eFrozenError.
VALUE rb_eEncCompatError
Encoding::CompatibilityError exception.
void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt,...)
Identical to rb_compile_warn(), except it also accepts category.
VALUE rb_eFatal
fatal exception.
void rb_invalid_str(const char *str, const char *type)
Honestly I don't understand the name, but it raises an instance of rb_eArgError.
VALUE rb_eInterrupt
Interrupt exception.
VALUE rb_eNameError
NameError exception.
VALUE rb_eNoMethodError
NoMethodError exception.
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports unless $VERBOSE is nil.
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Creates an instance of the passed exception class.
VALUE rb_eNoMatchingPatternKeyError
NoMatchingPatternKeyError exception.
void rb_error_frozen_object(VALUE frozen_obj)
Identical to rb_error_frozen(), except it takes arbitrary Ruby object instead of C's string.
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Identical to rb_exc_new_cstr(), except it takes a Ruby's string instead of C's.
VALUE rb_eArgError
ArgumentError exception.
void rb_bug_errno(const char *mesg, int errno_arg)
This is a wrapper of rb_bug() which automatically constructs appropriate message from the passed errn...
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Identical to rb_raise(), except it additionally takes an encoding.
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Issues a compile-time warning that happens at __file__:__line__.
void rb_loaderror(const char *fmt,...)
Raises an instance of rb_eLoadError.
VALUE rb_eException
Mother of all exceptions.
VALUE rb_eIndexError
IndexError exception.
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Identical to rb_loaderror(), except it additionally takes which file is unable to load.
VALUE rb_eSyntaxError
SyntaxError exception.
VALUE rb_eEncodingError
EncodingError exception.
VALUE rb_syserr_new(int n, const char *mesg)
Creates an exception object that represents the given C errno.
VALUE rb_eSecurityError
SecurityError exception.
void rb_sys_fail_str(VALUE mesg)
Identical to rb_sys_fail(), except it takes the message in Ruby's String instead of C's.
void rb_unexpected_type(VALUE x, int t)
Fails with the given object's type incompatibility to the type.
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Identical to rb_mod_sys_fail(), except it takes the message in Ruby's String instead of C's.
void rb_check_type(VALUE x, int t)
This was the old implementation of Check_Type(), but they diverged.
VALUE rb_eSystemCallError
SystemCallError exception.
void rb_warning(const char *fmt,...)
Issues a warning.
VALUE rb_eSignal
SignalException exception.
@ RB_WARN_CATEGORY_DEPRECATED
Warning is for deprecated features.
@ RB_WARN_CATEGORY_EXPERIMENTAL
Warning is for experimental features.
@ RB_WARN_CATEGORY_PERFORMANCE
Warning is for performance issues (not enabled by -w).
@ RB_WARN_CATEGORY_NONE
Category unspecified.
VALUE rb_check_to_int(VALUE val)
Identical to rb_check_to_integer(), except it uses #to_int for conversion.
VALUE rb_any_to_s(VALUE obj)
Generates a textual representation of the given object.
VALUE rb_obj_alloc(VALUE klass)
Allocates an instance of the given class.
VALUE rb_class_new_instance(int argc, const VALUE *argv, VALUE klass)
Allocates, then initialises an instance of the given class.
VALUE rb_obj_init_copy(VALUE src, VALUE dst)
Default implementation of #initialize_copy, #initialize_dup and #initialize_clone.
VALUE rb_obj_class(VALUE obj)
Queries the class of an object.
VALUE rb_cEncoding
Encoding class.
VALUE rb_inspect(VALUE obj)
Generates a human-readable textual representation of the given object.
VALUE rb_class_real(VALUE klass)
Finds a "real" class.
VALUE rb_equal(VALUE lhs, VALUE rhs)
This function is an optimised version of calling #==.
VALUE rb_obj_clone(VALUE obj)
Produces a shallow copy of the given object.
VALUE rb_obj_is_kind_of(VALUE obj, VALUE klass)
Queries if the given object is an instance (of possibly descendants) of the given class.
VALUE rb_String(VALUE val)
This is the logic behind Kernel#String.
VALUE rb_cString
String class.
#define RB_OBJ_WRITE(old, slot, young)
Declaration of a "back" pointer.
rb_encoding * rb_locale_encoding(void)
Queries the encoding that represents the current locale.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
static char * rb_enc_prev_char(const char *s, const char *p, const char *e, rb_encoding *enc)
Queries the previous (left) character.
int rb_enc_mbclen(const char *p, const char *e, rb_encoding *enc)
Queries the number of bytes of the character at the passed pointer.
rb_encoding * rb_enc_get(VALUE obj)
Identical to rb_enc_get_index(), except the return type.
static const char * rb_enc_name(rb_encoding *enc)
Queries the (canonical) name of the passed encoding.
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
Identical to rb_str_new(), except it additionally takes an encoding.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
Identical to rb_call_super(), except you can specify how to handle the last element of the given arra...
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
void rb_gc_mark_movable(VALUE obj)
Maybe this is the only function provided for C extensions to control the pinning of objects,...
VALUE rb_gc_location(VALUE obj)
Finds a new "location" of an object.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_new_capa(long capa)
Identical to rb_ary_new(), except it additionally specifies how many rooms of objects it should alloc...
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_freeze(VALUE obj)
Freeze an array, preventing further modifications.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
static void rb_check_frozen_inline(VALUE obj)
Just another name of rb_check_frozen.
static int rb_check_arity(int argc, int min, int max)
Ensures that the passed integer is in the passed range.
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_lookup(VALUE hash, VALUE key)
Identical to rb_hash_aref(), except it always returns RUBY_Qnil for misshits.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_io_puts(int argc, const VALUE *argv, VALUE io)
Iterates over the passed array to apply rb_io_write() individually.
VALUE rb_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
void ruby_default_signal(int sig)
Pretends as if there was no custom signal handler.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
VALUE rb_str_buf_cat(VALUE, const char *, long)
Just another name of rb_str_cat.
VALUE rb_str_cat2(VALUE, const char *)
Just another name of rb_str_cat_cstr.
VALUE rb_str_dup(VALUE str)
Duplicates a string.
VALUE rb_str_buf_append(VALUE dst, VALUE src)
Identical to rb_str_cat_cstr(), except it takes Ruby's string instead of C's.
VALUE rb_str_equal(VALUE str1, VALUE str2)
Equality of two strings.
void rb_str_set_len(VALUE str, long len)
Overwrites the length of the string.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_str_buf_new_cstr(const char *ptr)
This is a rb_str_buf_new() + rb_str_buf_cat() combo.
VALUE rb_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_new_cstr(const char *ptr)
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_cat_cstr(VALUE dst, const char *src)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
void rb_ivar_foreach(VALUE obj, int(*func)(ID name, VALUE val, st_data_t arg), st_data_t arg)
Iterates over an object's instance variables.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well...
void rb_attr(VALUE klass, ID name, int need_reader, int need_writer, int honour_visibility)
This function resembles now-deprecated Module#attr.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
VALUE rb_check_funcall_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_check_funcall(), except you can specify how to handle the last element of the given a...
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
char * ptr
Pointer to the underlying memory region, of at least capa bytes.
int len
Length of the buffer.
#define DECIMAL_SIZE_OF(expr)
An approximation of decimal representation size.
unsigned long ruby_scan_oct(const char *str, size_t len, size_t *consumed)
Interprets the passed string as an octal unsigned integer.
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt)
Formats a string.
VALUE rb_sprintf(const char *fmt,...)
Ruby's extended sprintf(3).
VALUE rb_str_vcatf(VALUE dst, const char *fmt, va_list ap)
Identical to rb_str_catf(), except it takes a va_list.
VALUE rb_vsprintf(const char *fmt, va_list ap)
Identical to rb_sprintf(), except it takes a va_list.
VALUE rb_str_catf(VALUE dst, const char *fmt,...)
Identical to rb_sprintf(), except it renders the output to the specified object rather than creating ...
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
#define ALLOCA_N(type, n)
VALUE type(ANYARGS)
ANYARGS-ed function type.
#define PRI_PIDT_PREFIX
A rb_sprintf() format prefix to be used for a pid_t parameter.
#define RARRAY_LEN
Just another name of rb_array_len.
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
char * rb_string_value_ptr(volatile VALUE *ptr)
Identical to rb_str_to_str(), except it returns the converted string's backend memory region.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
#define RSTRING(obj)
Convenient casting macro.
static bool RTYPEDDATA_P(VALUE obj)
Checks whether the passed object is RTypedData or RData.
#define RUBY_TYPED_DEFAULT_FREE
This is a value you can set to rb_data_type_struct::dfree.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given object.
#define TypedData_Make_Struct(klass, type, data_type, sval)
Identical to TypedData_Wrap_Struct, except it allocates a new data region internally instead of takin...
VALUE rb_argv0
The value of $0 at process bootup.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#define errno
Ractor-aware version of errno.
#define RB_PASS_KEYWORDS
Pass keywords, final argument should be a hash of keywords.
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
static bool RB_SPECIAL_CONST_P(VALUE obj)
Checks if the given object is of enum ruby_special_consts.
#define RTEST
This is an old name of RB_TEST.
This is the struct that holds necessary info for a struct.
const rb_data_type_t * parent
Parent of this class.
const char * wrap_struct_name
Name of structs of this kind.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
uintptr_t VALUE
Type that represents a Ruby object.
static enum ruby_value_type RB_BUILTIN_TYPE(VALUE obj)
Queries the type of the object.
static void Check_Type(VALUE v, enum ruby_value_type t)
Identical to RB_TYPE_P(), except it raises exceptions on predication failure.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.