12#include "ruby/internal/config.h"
31# include <AvailabilityMacros.h>
35#include "internal/error.h"
36#include "internal/eval.h"
37#include "internal/hash.h"
38#include "internal/io.h"
39#include "internal/load.h"
40#include "internal/object.h"
41#include "internal/process.h"
42#include "internal/string.h"
43#include "internal/symbol.h"
44#include "internal/thread.h"
45#include "internal/variable.h"
49#include "ruby_assert.h"
64#define WIFEXITED(status) 1
68#define WEXITSTATUS(status) (status)
73int rb_str_end_with_asciichar(
VALUE str,
int c);
75long rb_backtrace_length_limit = -1;
79static VALUE rb_mWarning;
80static VALUE rb_cWarningBuffer;
84static ID id_deprecated;
85static ID id_experimental;
86static ID id_performance;
87static VALUE sym_category;
88static VALUE sym_highlight;
93extern const char *rb_dynamic_description;
98#define defined_error(name, num) if (err == (num)) return (name);
99#define undefined_error(name)
100#include "known_errors.inc"
102#undef undefined_error
107err_position_0(
char *buf,
long len,
const char *file,
int line)
112 else if (line == 0) {
113 return snprintf(buf,
len,
"%s: ", file);
116 return snprintf(buf,
len,
"%s:%d: ", file, line);
122err_vcatf(
VALUE str, const
char *pre, const
char *file,
int line,
123 const
char *fmt, va_list args)
127 if (line) rb_str_catf(str,
":%d", line);
131 rb_str_vcatf(str, fmt, args);
138rb_syntax_error_append(
VALUE exc,
VALUE file,
int line,
int column,
141 const char *fn =
NIL_P(file) ? NULL : RSTRING_PTR(file);
143 VALUE mesg = rb_enc_str_new(0, 0, enc);
144 err_vcatf(mesg, NULL, fn, line, fmt, args);
146 rb_write_error_str(mesg);
150 exc = syntax_error_with_path(exc, file, &mesg, enc);
151 err_vcatf(mesg, NULL, fn, line, fmt, args);
157static unsigned int warning_disabled_categories = (
159 ~RB_WARN_CATEGORY_DEFAULT_BITS);
162rb_warning_category_mask(
VALUE category)
164 return 1U << rb_warning_category_from_name(category);
168rb_warning_category_from_name(
VALUE category)
174 !st_lookup(warning_categories.id2enum, cat_id, &cat_value)) {
175 rb_raise(
rb_eArgError,
"unknown category: %"PRIsVALUE, category);
184 if (!st_lookup(warning_categories.enum2id, category, &
id)) {
185 rb_raise(
rb_eArgError,
"invalid category: %d", (
int)category);
191rb_warning_category_update(
unsigned int mask,
unsigned int bits)
193 warning_disabled_categories &= ~mask;
194 warning_disabled_categories |= mask & ~bits;
200 return !(warning_disabled_categories & (1U << category));
229 return RBOOL(rb_warning_category_enabled_p(cat));
243 unsigned int mask = rb_warning_category_mask(category);
244 unsigned int disabled = warning_disabled_categories;
249 warning_disabled_categories = disabled;
265rb_warning_s_warn(
int argc,
VALUE *argv,
VALUE mod)
276 if (!
NIL_P(category)) {
278 if (!rb_warning_category_enabled_p(cat))
return Qnil;
280 rb_write_error_str(str);
321 return rb_funcallv(mod, id_warn, 1, &str);
326rb_warning_warn_arity(
void)
329 return me ? rb_method_entry_arity(me) : 1;
336 rb_warning_category_from_name(category);
339 if (rb_warning_warn_arity() == 1) {
340 return rb_warning_warn(rb_mWarning, str);
345 args[1] = rb_hash_new();
346 rb_hash_aset(args[1], sym_category, category);
352rb_write_warning_str(
VALUE str)
354 rb_warning_warn(rb_mWarning, str);
359warn_vsprintf(
rb_encoding *enc, const
char *file,
int line, const
char *fmt, va_list args)
361 VALUE str = rb_enc_str_new(0, 0, enc);
363 err_vcatf(str,
"warning: ", file, line, fmt, args);
367#define with_warn_vsprintf(file, line, fmt) \
370 va_start(args, fmt); \
371 str = warn_vsprintf(NULL, file, line, fmt, args); \
375rb_compile_warn(
const char *file,
int line,
const char *fmt, ...)
378 with_warn_vsprintf(file, line, fmt) {
379 rb_write_warning_str(str);
386rb_compile_warning(
const char *file,
int line,
const char *fmt, ...)
389 with_warn_vsprintf(file, line, fmt) {
390 rb_write_warning_str(str);
399 with_warn_vsprintf(file, line, fmt) {
400 rb_warn_category(str, rb_warning_category_to_name(category));
407warning_string(
rb_encoding *enc, const
char *fmt, va_list args)
410 const char *file = rb_source_location_cstr(&line);
411 return warn_vsprintf(enc, file, line, fmt, args);
414#define with_warning_string(mesg, enc, fmt) \
415 with_warning_string_from(mesg, enc, fmt, fmt)
416#define with_warning_string_from(mesg, enc, fmt, last_arg) \
418 va_list args; va_start(args, last_arg); \
419 mesg = warning_string(enc, fmt, args); \
426 with_warning_string(mesg, 0, fmt) {
427 rb_write_warning_str(mesg);
436 with_warning_string(mesg, 0, fmt) {
437 rb_warn_category(mesg, rb_warning_category_to_name(category));
446 with_warning_string(mesg, enc, fmt) {
447 rb_write_warning_str(mesg);
457 with_warning_string(mesg, 0, fmt) {
458 rb_write_warning_str(mesg);
468 with_warning_string(mesg, 0, fmt) {
469 rb_warn_category(mesg, rb_warning_category_to_name(category));
475rb_warning_string(
const char *fmt, ...)
477 with_warning_string(mesg, 0, fmt) {
484rb_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
487 with_warning_string(mesg, enc, fmt) {
488 rb_write_warning_str(mesg);
495deprecation_warning_enabled(
void)
503warn_deprecated(
VALUE mesg,
const char *removal,
const char *suggest)
505 rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1);
508 rb_str_catf(mesg,
" and will be removed in Ruby %s", removal);
510 if (suggest) rb_str_catf(mesg,
"; use %s instead", suggest);
512 rb_warn_category(mesg,
ID2SYM(id_deprecated));
516rb_warn_deprecated(
const char *fmt,
const char *suggest, ...)
518 if (!deprecation_warning_enabled())
return;
520 with_warning_string_from(mesg, 0, fmt, suggest) {
521 warn_deprecated(mesg, NULL, suggest);
526rb_warn_deprecated_to_remove(
const char *removal,
const char *fmt,
const char *suggest, ...)
528 if (!deprecation_warning_enabled())
return;
530 with_warning_string_from(mesg, 0, fmt, suggest) {
531 warn_deprecated(mesg, removal, suggest);
536end_with_asciichar(
VALUE str,
int c)
539 rb_str_end_with_asciichar(str, c);
544warning_write(
int argc,
VALUE *argv,
VALUE buf)
563 if (!
NIL_P(uplevel)) {
568 location = rb_ec_backtrace_location_ary(ec, lev + 1, 1, TRUE);
569 if (!
NIL_P(location)) {
570 location = rb_ary_entry(location, 0);
573 if (argc > 1 || !
NIL_P(uplevel) || !end_with_asciichar(str,
'\n')) {
575 if (
NIL_P(uplevel)) {
578 else if (
NIL_P(location) ||
583 str = rb_sprintf(
"%s:%ld: warning: ",
587 RBASIC_SET_CLASS(str, rb_cWarningBuffer);
588 rb_io_puts(argc, argv, str);
592 if (!
NIL_P(category)) {
593 category = rb_to_symbol_type(category);
594 rb_warning_category_from_name(category);
597 if (exc == rb_mWarning) {
599 rb_write_error_str(str);
602 rb_warn_category(str, category);
608#define MAX_BUG_REPORTERS 0x100
611 void (*func)(
FILE *out,
void *data);
615static int bug_reporters_size;
618rb_bug_reporter_add(
void (*func)(
FILE *,
void *),
void *data)
621 if (bug_reporters_size >= MAX_BUG_REPORTERS) {
625 reporter->func = func;
626 reporter->data = data;
635#if defined __CYGWIN__ || defined DOSISH
636# define PATH_SEP_ENCODING 1
638 if (x ==
':')
return true;
639 if (x ==
'\\')
return true;
649static const char PATHSEP_REPLACE =
'!';
652append_pathname(
char *p,
const char *pe,
VALUE str)
654#ifdef PATH_SEP_ENCODING
657 const char *s = RSTRING_PTR(str);
658 const char *
const se = s + RSTRING_LEN(str);
663 while (p < pe && s < se && (c = *s) !=
'\0') {
665 if (s == se || !*s)
break;
666 if (path_sep_p(s[1]))
goto skipsep;
668 else if (path_sep_p(c)) {
670 *p++ = PATHSEP_REPLACE;
672 while (++s < se && path_sep_p(*s));
675 const char *
const ss = s;
676 while (p < pe && s < se && *s && !path_sep_p(*s)) {
677#ifdef PATH_SEP_ENCODING
678 int n = rb_enc_mbclen(s, se, enc);
685 if (s > ss) memcpy(p - (s - ss), ss, s - ss);
692append_basename(
char *p,
const char *pe,
struct path_string *path,
VALUE str)
695#ifdef PATH_SEP_ENCODING
698 const char *
const b = RSTRING_PTR(str), *
const e = RSTRING_END(str), *p = e;
701 if (path_sep_p(p[-1])) {
702#ifdef PATH_SEP_ENCODING
703 const char *t = rb_enc_prev_char(b, p, e, enc);
718 size_t n = path->len;
719 if (p + n > pe) n = pe - p;
720 memcpy(p, path->ptr, n);
725finish_report(
FILE *out, rb_pid_t pid)
727 if (out != stdout && out != stderr) fclose(out);
728#ifdef HAVE_WORKING_FORK
729 if (pid > 0) waitpid(pid, NULL, 0);
758expand_report_argument(
const char **input_template,
struct report_expansion *values,
759 char *buf,
size_t size,
bool word)
762 char *end = buf + size;
763 const char *
template = *input_template;
766 if (p >= end-1 || !*
template)
return NULL;
768 char c = *
template++;
770 if (!store)
continue;
773 switch (c = *
template++) {
775 p = append_basename(p, end, &values->exe,
rb_argv0);
778 p = append_pathname(p, end,
rb_argv0);
781 p = append_basename(p, end, &values->script, GET_VM()->orig_progname);
784 p = append_pathname(p, end, GET_VM()->orig_progname);
787 if (!values->pid) values->pid = getpid();
792 if (!values->time) values->time = time(NULL);
793 snprintf(p, end-p,
"%" PRI_TIMET_PREFIX
"d", values->time);
797 if (c >=
'0' && c <=
'7') {
798 c = (
unsigned char)ruby_scan_oct(
template-1, 3, &n);
800 if (!c) store =
false;
805 if (p < end-1) *p++ = c;
807 *input_template =
template;
812FILE *ruby_popen_writer(
char *
const *argv, rb_pid_t *pid);
815open_report_path(
const char *
template,
char *buf,
size_t size, rb_pid_t *pid)
819 if (!
template)
return NULL;
820 if (0) fprintf(stderr,
"RUBY_CRASH_REPORT=%s\n", buf);
821 if (*
template ==
'|') {
822 char *argv[16], *bufend = buf + size, *p;
825 for (argc = 0; argc < numberof(argv) - 1; ++argc) {
826 while (*
template &&
ISSPACE(*
template))
template++;
827 p = expand_report_argument(&
template, &values, buf, bufend-buf,
true);
833 if (!p)
return ruby_popen_writer(argv, pid);
835 else if (*
template) {
836 expand_report_argument(&
template, &values, buf, size,
false);
837 return fopen(buf,
"w");
842static const char *crash_report;
845#define REPORT_BUG_BUFSIZ 256
847bug_report_file(
const char *file,
int line, rb_pid_t *pid)
849 char buf[REPORT_BUG_BUFSIZ];
850 const char *report = crash_report;
851 if (!report) report = getenv(
"RUBY_CRASH_REPORT");
852 FILE *out = open_report_path(report, buf,
sizeof(buf), pid);
853 int len = err_position_0(buf,
sizeof(buf), file, line);
856 if ((ssize_t)fwrite(buf, 1,
len, out) == (ssize_t)
len)
return out;
859 if ((ssize_t)fwrite(buf, 1,
len, stderr) == (ssize_t)
len) {
862 if ((ssize_t)fwrite(buf, 1,
len, stdout) == (ssize_t)
len) {
869FUNC_MINIMIZED(
static void bug_important_message(
FILE *out,
const char *
const msg,
size_t len));
872bug_important_message(
FILE *out,
const char *
const msg,
size_t len)
874 const char *
const endmsg = msg +
len;
878 if (isatty(fileno(out))) {
879 static const char red[] =
"\033[;31;1;7m";
880 static const char green[] =
"\033[;32;7m";
881 static const char reset[] =
"\033[m";
882 const char *e = strchr(p,
'\n');
883 const int w = (int)(e - p);
885 int i = (int)(e - p);
886 fputs(*p ==
' ' ? green : red, out);
887 fwrite(p, 1, e - p, out);
888 for (; i < w; ++i) fputc(
' ', out);
891 }
while ((p = e + 1) < endmsg && (e = strchr(p,
'\n')) != 0 && e > p + 1);
893 fwrite(p, 1, endmsg - p, out);
896#undef CRASH_REPORTER_MAY_BE_CREATED
897#if defined(__APPLE__) && \
898 (!defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 || defined(__POWERPC__))
899# define CRASH_REPORTER_MAY_BE_CREATED
902preface_dump(
FILE *out)
905 static const char msg[] =
""
906 "-- Crash Report log information "
907 "--------------------------------------------\n"
908 " See Crash Report log file in one of the following locations:\n"
909# ifdef CRASH_REPORTER_MAY_BE_CREATED
910 " * ~/Library/Logs/CrashReporter\n"
911 " * /Library/Logs/CrashReporter\n"
913 " * ~/Library/Logs/DiagnosticReports\n"
914 " * /Library/Logs/DiagnosticReports\n"
915 " for more details.\n"
916 "Don't forget to include the above Crash Report log file in bug reports.\n"
918 const size_t msglen =
sizeof(msg) - 1;
920 const char *msg = NULL;
921 const size_t msglen = 0;
923 bug_important_message(out, msg, msglen);
927postscript_dump(
FILE *out)
930 static const char msg[] =
""
933 "\n""Don't forget to include the Crash Report log file under\n"
934# ifdef CRASH_REPORTER_MAY_BE_CREATED
937 "DiagnosticReports directory in bug reports.\n"
940 const size_t msglen =
sizeof(msg) - 1;
942 const char *msg = NULL;
943 const size_t msglen = 0;
945 bug_important_message(out, msg, msglen);
950bug_report_begin_valist(
FILE *out, const
char *fmt, va_list args)
952 char buf[REPORT_BUG_BUFSIZ];
954 fputs(
"[BUG] ", out);
955 vsnprintf(buf,
sizeof(buf), fmt, args);
957 snprintf(buf,
sizeof(buf),
"\n%s\n\n", rb_dynamic_description);
962#define bug_report_begin(out, fmt) do { \
964 va_start(args, fmt); \
965 bug_report_begin_valist(out, fmt, args); \
970bug_report_end(
FILE *out, rb_pid_t pid)
975 for (i=0; i<bug_reporters_size; i++) {
977 (*reporter->func)(out, reporter->data);
980 postscript_dump(out);
981 finish_report(out, pid);
984#define report_bug(file, line, fmt, ctx) do { \
986 FILE *out = bug_report_file(file, line, &pid); \
988 bug_report_begin(out, fmt); \
989 rb_vm_bugreport(ctx, out); \
990 bug_report_end(out, pid); \
994#define report_bug_valist(file, line, fmt, ctx, args) do { \
996 FILE *out = bug_report_file(file, line, &pid); \
998 bug_report_begin_valist(out, fmt, args); \
999 rb_vm_bugreport(ctx, out); \
1000 bug_report_end(out, pid); \
1005ruby_set_crash_report(
const char *
template)
1007 crash_report =
template;
1010 char buf[REPORT_BUG_BUFSIZ];
1011 FILE *out = open_report_path(
template, buf,
sizeof(buf), &pid);
1013 time_t t = time(NULL);
1014 fprintf(out,
"ruby_test_bug_report: %s", ctime(&t));
1015 finish_report(out, pid);
1020NORETURN(
static void die(
void));
1024#if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
1025 _set_abort_behavior( 0, _CALL_REPORTFAULT);
1033rb_bug_without_die(const
char *fmt, va_list args)
1035 const char *file = NULL;
1039 file = rb_source_location_cstr(&line);
1042 report_bug_valist(file, line, fmt, NULL, args);
1046rb_bug(
const char *fmt, ...)
1049 va_start(args, fmt);
1050 rb_bug_without_die(fmt, args);
1056rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler,
int sig,
const void *ctx,
const char *fmt, ...)
1058 const char *file = NULL;
1062 file = rb_source_location_cstr(&line);
1065 report_bug(file, line, fmt, ctx);
1067 if (default_sighandler) default_sighandler(sig);
1078 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
1080 const char *errno_str = rb_strerrno(errno_arg);
1082 rb_bug(
"%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
1084 rb_bug(
"%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
1092#define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
1093#define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
1096rb_async_bug_errno(
const char *mesg,
int errno_arg)
1098 WRITE_CONST(2,
"[ASYNC BUG] ");
1099 write_or_abort(2, mesg, strlen(mesg));
1100 WRITE_CONST(2,
"\n");
1102 if (errno_arg == 0) {
1103 WRITE_CONST(2,
"errno == 0 (NOERROR)\n");
1106 const char *errno_str = rb_strerrno(errno_arg);
1109 errno_str =
"undefined errno";
1110 write_or_abort(2, errno_str, strlen(errno_str));
1112 WRITE_CONST(2,
"\n\n");
1113 write_or_abort(2, rb_dynamic_description, strlen(rb_dynamic_description));
1118rb_report_bug_valist(
VALUE file,
int line,
const char *fmt, va_list args)
1120 report_bug_valist(RSTRING_PTR(file), line, fmt, NULL, args);
1124rb_assert_failure(
const char *file,
int line,
const char *name,
const char *expr)
1127 fprintf(out,
"Assertion Failed: %s:%d:", file, line);
1128 if (name) fprintf(out,
"%s:", name);
1129 fprintf(out,
"%s\n%s\n\n", expr, rb_dynamic_description);
1131 rb_vm_bugreport(NULL, out);
1132 bug_report_end(out, -1);
1136static const char builtin_types[][10] = {
1169rb_builtin_type_name(
int t)
1172 if ((
unsigned int)t >= numberof(builtin_types))
return 0;
1173 name = builtin_types[t];
1174 if (*name)
return name;
1179displaying_class_of(
VALUE x)
1182 case Qfalse:
return rb_fstring_cstr(
"false");
1183 case Qnil:
return rb_fstring_cstr(
"nil");
1184 case Qtrue:
return rb_fstring_cstr(
"true");
1190builtin_class_name(
VALUE x)
1203 else if (RB_TYPE_P(x,
T_TRUE)) {
1206 else if (RB_TYPE_P(x,
T_FALSE)) {
1216rb_builtin_class_name(
VALUE x)
1218 const char *etype = builtin_class_name(x);
1226COLDFUNC NORETURN(
static void unexpected_type(
VALUE,
int,
int));
1227#define UNDEF_LEAKED "undef leaked to the Ruby space"
1230unexpected_type(
VALUE x,
int xt,
int t)
1232 const char *tname = rb_builtin_type_name(t);
1236 mesg = rb_sprintf(
"wrong argument type %"PRIsVALUE
" (expected %s)",
1237 displaying_class_of(x), tname);
1240 else if (xt >
T_MASK && xt <= 0x3f) {
1241 mesg = rb_sprintf(
"unknown type 0x%x (0x%x given, probably comes"
1242 " from extension library for ruby 1.8)", t, xt);
1245 mesg = rb_sprintf(
"unknown type 0x%x (0x%x given)", t, xt);
1255 if (RB_UNLIKELY(UNDEF_P(x))) {
1256 rb_bug(UNDEF_LEAKED);
1260 if (xt != t || (xt ==
T_DATA && rbimpl_rtypeddata_p(x))) {
1269 unexpected_type(x, xt, t);
1276 if (RB_UNLIKELY(UNDEF_P(x))) {
1277 rb_bug(UNDEF_LEAKED);
1280 unexpected_type(x,
TYPE(x), t);
1287 if (child == parent)
return 1;
1296 if (!RB_TYPE_P(obj,
T_DATA) ||
1303#undef rb_typeddata_is_instance_of
1307 return rb_typeddata_is_instance_of_inline(obj, data_type);
1315 if (!RB_TYPE_P(obj,
T_DATA)) {
1316 actual = displaying_class_of(obj);
1319 actual = displaying_class_of(obj);
1326 return RTYPEDDATA_GET_DATA(obj);
1330 rb_raise(
rb_eTypeError,
"wrong argument type %"PRIsVALUE
" (expected %s)",
1366static VALUE rb_eNOERROR;
1368ID ruby_static_id_cause;
1369#define id_cause ruby_static_id_cause
1370static ID id_message, id_detailed_message, id_backtrace;
1371static ID id_key, id_matchee, id_args, id_Errno, id_errno, id_i_path;
1372static ID id_receiver, id_recv, id_iseq, id_local_variables;
1373static ID id_private_call_p, id_top, id_bottom;
1375#define id_bt_locations idBt_locations
1376#define id_mesg idMesg
1377#define id_name idName
1379#undef rb_exc_new_cstr
1420exc_initialize(
int argc,
VALUE *argv,
VALUE exc)
1425 return exc_init(exc, arg);
1442exc_exception(
int argc,
VALUE *argv,
VALUE self)
1447 if (argc == 0)
return self;
1448 if (argc == 1 && self == argv[0])
return self;
1465 VALUE mesg = rb_attr_get(exc, idMesg);
1475rb_get_message(
VALUE exc)
1478 if (UNDEF_P(e))
return Qnil;
1493 if (UNDEF_P(e))
return Qnil;
1505exc_s_to_tty_p(
VALUE self)
1507 return RBOOL(rb_stderr_tty_p());
1511check_highlight_keyword(
VALUE opt,
int auto_tty_detect)
1516 highlight = rb_hash_lookup(opt, sym_highlight);
1518 switch (highlight) {
1520 rb_bool_expected(highlight,
"highlight", TRUE);
1526 if (
NIL_P(highlight)) {
1527 highlight = RBOOL(auto_tty_detect && rb_stderr_tty_p());
1534check_order_keyword(
VALUE opt)
1539 static VALUE kw_order;
1542 order = rb_hash_lookup(opt, kw_order);
1544 if (order !=
Qnil) {
1546 if (
id == id_bottom) order =
Qtrue;
1547 else if (
id == id_top) order =
Qfalse;
1550 "order: %+"PRIsVALUE, order);
1579exc_full_message(
int argc,
VALUE *argv,
VALUE exc)
1581 VALUE opt, str, emesg, errat;
1582 VALUE highlight, order;
1586 highlight = check_highlight_keyword(opt, 1);
1587 order = check_order_keyword(opt);
1590 if (
NIL_P(opt)) opt = rb_hash_new();
1591 rb_hash_aset(opt, sym_highlight, highlight);
1595 errat = rb_get_backtrace(exc);
1596 emesg = rb_get_detailed_message(exc, opt);
1598 rb_error_write(exc, emesg, errat, str, opt, highlight, order);
1611exc_message(
VALUE exc)
1613 return rb_funcallv(exc, idTo_s, 0, 0);
1657exc_detailed_message(
int argc,
VALUE *argv,
VALUE exc)
1663 VALUE highlight = check_highlight_keyword(opt, 0);
1665 extern VALUE rb_decorate_message(
const VALUE eclass,
const VALUE emesg,
int highlight);
1667 return rb_decorate_message(
CLASS_OF(exc), rb_get_message(exc),
RTEST(highlight));
1678exc_inspect(
VALUE exc)
1683 exc = rb_obj_as_string(exc);
1684 if (RSTRING_LEN(exc) == 0) {
1690 rb_str_buf_append(str, klass);
1693 rb_str_catf(str,
":%+"PRIsVALUE, exc);
1697 rb_str_buf_append(str, exc);
1741exc_backtrace(
VALUE exc)
1745 obj = rb_attr_get(exc, id_bt);
1747 if (rb_backtrace_p(obj)) {
1748 obj = rb_backtrace_to_str_ary(obj);
1758rb_get_backtrace(
VALUE exc)
1760 ID mid = id_backtrace;
1762 if (rb_method_basic_definition_p(
CLASS_OF(exc), id_backtrace)) {
1768 info = exc_backtrace(exc);
1772 info = rb_funcallv(exc, mid, 0, 0);
1775 return rb_check_backtrace(info);
1789exc_backtrace_locations(
VALUE exc)
1793 obj = rb_attr_get(exc, id_bt_locations);
1795 obj = rb_backtrace_to_location_ary(obj);
1801rb_check_backtrace(
VALUE bt)
1804 static const char err[] =
"backtrace must be Array of String";
1808 if (rb_backtrace_p(bt))
return bt;
1809 if (!RB_TYPE_P(bt,
T_ARRAY)) {
1835 return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1841 return exc_set_backtrace(exc, bt);
1856 return rb_attr_get(exc, id_cause);
1860try_convert_to_exception(
VALUE obj)
1877 VALUE mesg, backtrace;
1879 if (exc == obj)
return Qtrue;
1884 obj = rb_protect(try_convert_to_exception, obj, &state);
1885 if (state || UNDEF_P(obj)) {
1886 rb_set_errinfo(
Qnil);
1891 if (UNDEF_P(mesg))
return Qfalse;
1893 if (UNDEF_P(backtrace))
return Qfalse;
1896 mesg = rb_attr_get(obj, id_mesg);
1897 backtrace = exc_backtrace(obj);
1900 if (!
rb_equal(rb_attr_get(exc, id_mesg), mesg))
1902 return rb_equal(exc_backtrace(exc), backtrace);
1918exit_initialize(
int argc,
VALUE *argv,
VALUE exc)
1926 status =
INT2FIX(EXIT_SUCCESS);
1931 status =
INT2FIX(EXIT_FAILURE);
1937 if (
NIL_P(status)) {
1938 status =
INT2FIX(EXIT_SUCCESS);
1941#if EXIT_SUCCESS != 0
1943 status =
INT2FIX(EXIT_SUCCESS);
1952 status =
INT2FIX(EXIT_SUCCESS);
1968exit_status(
VALUE exc)
1970 return rb_attr_get(exc, id_status);
1982exit_success_p(
VALUE exc)
1984 VALUE status_val = rb_attr_get(exc, id_status);
1987 if (
NIL_P(status_val))
1990 return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
1996 if (!UNDEF_P(recv))
rb_ivar_set(exc, id_recv, recv);
2013frozen_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2016 VALUE values[numberof(keywords)], options;
2019 keywords[0] = id_receiver;
2020 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2022 err_init_recv(self, values[0]);
2034#define frozen_err_receiver name_err_receiver
2042 va_start(args, fmt);
2057 va_start(args, fmt);
2071 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
2073 err_init_recv(exc, recv);
2074 if (cfp && VM_FRAME_TYPE(cfp) != VM_FRAME_MAGIC_DUMMY) {
2075 rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
2094name_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2097 VALUE values[numberof(keywords)], name, options;
2100 keywords[0] = id_receiver;
2101 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2102 name = (argc > 1) ? argv[--argc] :
Qnil;
2104 name_err_init_attr(self, values[0], name);
2113 exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
2114 return name_err_init_attr(exc, recv, method);
2121 return name_err_init(exc, mesg, recv, method);
2132name_err_name(
VALUE self)
2134 return rb_attr_get(self, id_name);
2148name_err_local_variables(
VALUE self)
2150 VALUE vars = rb_attr_get(self, id_local_variables);
2153 VALUE iseqw = rb_attr_get(self, id_iseq);
2154 if (!
NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
2155 if (
NIL_P(vars)) vars = rb_ary_new();
2162nometh_err_init_attr(
VALUE exc,
VALUE args,
int priv)
2186nometh_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2189 VALUE args, options;
2191 priv = (argc > 3) && (--argc,
RTEST(argv[argc]));
2192 args = (argc > 2) ? argv[--argc] :
Qnil;
2193 if (!
NIL_P(options)) argv[argc++] = options;
2195 return nometh_err_init_attr(self, args, priv);
2202 name_err_init(exc, mesg, recv, method);
2203 return nometh_err_init_attr(exc, args, priv);
2213name_err_mesg_mark(
void *p)
2216 rb_gc_mark_movable(ptr->mesg);
2217 rb_gc_mark_movable(ptr->recv);
2218 rb_gc_mark_movable(ptr->name);
2222name_err_mesg_update(
void *p)
2225 ptr->mesg = rb_gc_location(ptr->mesg);
2226 ptr->recv = rb_gc_location(ptr->recv);
2227 ptr->name = rb_gc_location(ptr->name);
2236 name_err_mesg_update,
2238 0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_EMBEDDABLE
2262name_err_mesg_alloc(
VALUE klass)
2269name_err_mesg_init_copy(
VALUE obj1,
VALUE obj2)
2271 if (obj1 == obj2)
return obj1;
2288 if (obj1 == obj2)
return Qtrue;
2305name_err_mesg_receiver_name(
VALUE obj)
2316name_err_mesg_to_str(
VALUE obj)
2321 VALUE mesg = ptr->mesg;
2324 struct RString s_str, c_str, d_str;
2325 VALUE c, s, d = 0, args[4], c2;
2329#define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
2330 c = s = FAKE_CSTR(&s_str,
"");
2334 c = d = FAKE_CSTR(&d_str,
"nil");
2337 c = d = FAKE_CSTR(&d_str,
"true");
2340 c = d = FAKE_CSTR(&d_str,
"false");
2343 if (strstr(RSTRING_PTR(mesg),
"%2$s")) {
2344 d = rb_protect(name_err_mesg_receiver_name, obj, &state);
2345 if (state || NIL_OR_UNDEF_P(d))
2348 rb_set_errinfo(
Qnil);
2359 s = FAKE_CSTR(&s_str,
"module ");
2363 s = FAKE_CSTR(&s_str,
"class ");
2375 s = FAKE_CSTR(&s_str,
"");
2376 if (obj == rb_vm_top_self()) {
2377 c = FAKE_CSTR(&c_str,
"main");
2385 s = FAKE_CSTR(&s_str,
"an instance of ");
2389 c2 = rb_protect(name_err_mesg_receiver_name, c, &state);
2390 if (state || NIL_OR_UNDEF_P(c2))
2393 rb_set_errinfo(
Qnil);
2402 args[0] = rb_obj_as_string(
ptr->name);
2415 return name_err_mesg_to_str(obj);
2433name_err_receiver(
VALUE self)
2435 VALUE recv = rb_ivar_lookup(self, id_recv,
Qundef);
2436 if (!UNDEF_P(recv))
return recv;
2438 VALUE mesg = rb_attr_get(self, id_mesg);
2457nometh_err_args(
VALUE self)
2459 return rb_attr_get(self, id_args);
2470nometh_err_private_call_p(
VALUE self)
2472 return rb_attr_get(self, id_private_call_p);
2491key_err_receiver(
VALUE self)
2495 recv = rb_ivar_lookup(self, id_receiver,
Qundef);
2496 if (!UNDEF_P(recv))
return recv;
2508key_err_key(
VALUE self)
2512 key = rb_ivar_lookup(self, id_key,
Qundef);
2513 if (!UNDEF_P(key))
return key;
2537key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2543 if (!
NIL_P(options)) {
2545 VALUE values[numberof(keywords)];
2547 keywords[0] = id_receiver;
2548 keywords[1] = id_key;
2549 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2550 for (i = 0; i < numberof(values); ++i) {
2551 if (!UNDEF_P(values[i])) {
2568no_matching_pattern_key_err_matchee(
VALUE self)
2572 matchee = rb_ivar_lookup(self, id_matchee,
Qundef);
2573 if (!UNDEF_P(matchee))
return matchee;
2585no_matching_pattern_key_err_key(
VALUE self)
2589 key = rb_ivar_lookup(self, id_key,
Qundef);
2590 if (!UNDEF_P(key))
return key;
2603no_matching_pattern_key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2609 if (!
NIL_P(options)) {
2611 VALUE values[numberof(keywords)];
2613 keywords[0] = id_matchee;
2614 keywords[1] = id_key;
2615 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2616 for (i = 0; i < numberof(values); ++i) {
2617 if (!UNDEF_P(values[i])) {
2635syntax_error_initialize(
int argc,
VALUE *argv,
VALUE self)
2639 mesg = rb_fstring_lit(
"compile error");
2650 *mesg = rb_enc_str_new(0, 0, enc);
2655 if (rb_attr_get(exc, id_i_path) != path) {
2658 VALUE s = *mesg = rb_attr_get(exc, idMesg);
2659 if (RSTRING_LEN(s) > 0 && *(RSTRING_END(s)-1) !=
'\n')
2698rb_free_warning(
void)
2700 st_free_table(warning_categories.id2enum);
2701 st_free_table(warning_categories.enum2id);
2702 st_free_table(syserr_tbl);
2706set_syserr(
int n,
const char *name)
2710 if (!st_lookup(syserr_tbl, n, &error)) {
2718#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2723 rb_eEWOULDBLOCK = error;
2726 rb_eEINPROGRESS = error;
2731 st_add_direct(syserr_tbl, n, error);
2744 if (!st_lookup(syserr_tbl, n, &error)) {
2747 snprintf(name,
sizeof(name),
"E%03d", n);
2748 error = set_syserr(n, name);
2764syserr_initialize(
int argc,
VALUE *argv,
VALUE self)
2767 VALUE mesg, error, func, errmsg;
2771 st_data_t data = (st_data_t)klass;
2774 error = mesg; mesg =
Qnil;
2776 if (!
NIL_P(error) && st_lookup(syserr_tbl,
NUM2LONG(error), &data)) {
2777 klass = (
VALUE)data;
2782 RBASIC_SET_CLASS(self, klass);
2790 else err =
"unknown error";
2796 if (!
NIL_P(func)) rb_str_catf(errmsg,
" @ %"PRIsVALUE, func);
2797 rb_str_catf(errmsg,
" - %"PRIsVALUE, str);
2814syserr_errno(
VALUE self)
2816 return rb_attr_get(self, id_errno);
2837 num = rb_attr_get(exc, id_errno);
2839 num = rb_funcallv(exc, id_errno, 0, 0);
3244exception_alloc(
VALUE klass)
3246 return rb_class_allocate_instance(klass);
3250exception_dumper(
VALUE exc)
3260ivar_copy_i(
ID key,
VALUE val, st_data_t exc)
3266void rb_exc_check_circular_cause(
VALUE exc);
3278 if (RB_TYPE_P(exc,
T_CLASS))
return obj;
3282 rb_exc_check_circular_cause(exc);
3284 if (rb_attr_get(exc, id_bt) == rb_attr_get(exc, id_bt_locations)) {
3379 syserr_tbl = st_init_numtable();
3417 id_iseq = rb_make_internal_id();
3418 id_recv = rb_make_internal_id();
3420 sym_category =
ID2SYM(id_category);
3423 warning_categories.id2enum = rb_init_identtable();
3428 warning_categories.enum2id = rb_init_identtable();
3441 va_start(args, fmt);
3449rb_vraise(
VALUE exc,
const char *fmt, va_list ap)
3455rb_raise(
VALUE exc,
const char *fmt, ...)
3458 va_start(args, fmt);
3459 rb_vraise(exc, fmt, args);
3463NORETURN(
static void raise_loaderror(
VALUE path,
VALUE mesg));
3479 va_start(args, fmt);
3482 raise_loaderror(
Qnil, mesg);
3491 va_start(args, fmt);
3494 raise_loaderror(path, mesg);
3501 "%"PRIsVALUE
"() function is unimplemented on this machine",
3502 rb_id2str(rb_frame_this_func()));
3506rb_fatal(
const char *fmt, ...)
3511 if (! ruby_thread_has_gvl_p()) {
3514 fprintf(stderr,
"[FATAL] rb_fatal() outside of GVL\n");
3515 rb_print_backtrace(stderr);
3519 va_start(args, fmt);
3527make_errno_exc(
const char *mesg)
3533 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
3539make_errno_exc_str(
VALUE mesg)
3544 if (!mesg) mesg =
Qnil;
3546 const char *s = !
NIL_P(mesg) ? RSTRING_PTR(mesg) :
"";
3547 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
3580rb_sys_fail(
const char *mesg)
3582 rb_exc_raise(make_errno_exc(mesg));
3585#undef rb_sys_fail_str
3589 rb_exc_raise(make_errno_exc_str(mesg));
3592#ifdef RUBY_FUNCTION_NAME_STRING
3594rb_sys_fail_path_in(
const char *func_name,
VALUE path)
3599 rb_syserr_fail_path_in(func_name, n, path);
3603rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
3605 rb_exc_raise(rb_syserr_new_path_in(func_name, n, path));
3609rb_syserr_new_path_in(
const char *func_name,
int n,
VALUE path)
3613 if (!path) path =
Qnil;
3615 const char *s = !
NIL_P(path) ? RSTRING_PTR(path) :
"";
3616 if (!func_name) func_name =
"(null)";
3617 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
3626NORETURN(
static void rb_mod_exc_raise(
VALUE exc,
VALUE mod));
3638 VALUE exc = make_errno_exc(mesg);
3639 rb_mod_exc_raise(exc, mod);
3645 VALUE exc = make_errno_exc_str(mesg);
3646 rb_mod_exc_raise(exc, mod);
3653 rb_mod_exc_raise(exc, mod);
3660 rb_mod_exc_raise(exc, mod);
3664syserr_warning(
VALUE mesg,
int err)
3666 rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
3667 rb_str_catf(mesg,
": %s\n", strerror(err));
3668 rb_write_warning_str(mesg);
3673rb_sys_warn(
const char *fmt, ...)
3676 int errno_save =
errno;
3677 with_warning_string(mesg, 0, fmt) {
3678 syserr_warning(mesg, errno_save);
3685rb_syserr_warn(
int err,
const char *fmt, ...)
3688 with_warning_string(mesg, 0, fmt) {
3689 syserr_warning(mesg, err);
3695rb_sys_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
3698 int errno_save =
errno;
3699 with_warning_string(mesg, enc, fmt) {
3700 syserr_warning(mesg, errno_save);
3707rb_syserr_enc_warn(
int err,
rb_encoding *enc,
const char *fmt, ...)
3710 with_warning_string(mesg, enc, fmt) {
3711 syserr_warning(mesg, err);
3721 int errno_save =
errno;
3722 with_warning_string(mesg, 0, fmt) {
3723 syserr_warning(mesg, errno_save);
3731rb_syserr_warning(
int err,
const char *fmt, ...)
3734 with_warning_string(mesg, 0, fmt) {
3735 syserr_warning(mesg, err);
3742rb_sys_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
3745 int errno_save =
errno;
3746 with_warning_string(mesg, enc, fmt) {
3747 syserr_warning(mesg, errno_save);
3754rb_syserr_enc_warning(
int err,
rb_encoding *enc,
const char *fmt, ...)
3757 with_warning_string(mesg, enc, fmt) {
3758 syserr_warning(mesg, err);
3764rb_load_fail(
VALUE path,
const char *err)
3769 raise_loaderror(path, mesg);
3784 va_start(args, fmt);
3793inspect_frozen_obj(
VALUE obj,
VALUE mesg,
int recur)
3808 const ID created_info = id_debug_created_info;
3809 VALUE mesg = rb_sprintf(
"can't modify frozen %"PRIsVALUE
": ",
3816 if (!
NIL_P(debug_info = rb_attr_get(frozen_obj, created_info))) {
3817 VALUE path = rb_ary_entry(debug_info, 0);
3818 VALUE line = rb_ary_entry(debug_info, 1);
3820 rb_str_catf(mesg,
", created at %"PRIsVALUE
":%"PRIsVALUE, path, line);
3825#undef rb_check_frozen
3843 rb_eNOERROR = set_syserr(0,
"NOERROR");
3844#define defined_error(name, num) set_syserr((num), (name));
3845#define undefined_error(name) set_syserr(0, (name));
3846#include "known_errors.inc"
3848#undef undefined_error
3851#include "warning.rbinc"
#define RUBY_DEBUG
Define this macro when you want assertions.
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
#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.
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 FL_SINGLETON
Old name of RUBY_FL_SINGLETON.
#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 rb_str_cat2
Old name of rb_str_cat_cstr.
#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...
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.
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_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.
VALUE rb_eNotImpError
NotImplementedError exception.
VALUE rb_eScriptError
ScriptError exception.
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.
VALUE rb_cNameErrorMesg
NameError::Message class.
VALUE rb_eSystemExit
SystemExit exception.
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...
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_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.
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.
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_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_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.
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_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_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.
#define rb_check_frozen
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.
#define rb_check_frozen_internal(obj)
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.
#define rb_str_new(str, len)
Allocates an instance of rb_cString.
#define rb_str_buf_cat
Just another name of rb_str_cat.
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_buf_new_cstr(str)
Identical to rb_str_new_cstr, except done differently.
void rb_must_asciicompat(VALUE obj)
Asserts that the given string's encoding is (Ruby's definition of) ASCII compatible.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
#define rb_str_new_cstr(str)
Identical to rb_str_new, except it assumes the passed pointer is a pointer to a C string.
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_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.
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.
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.
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
int len
Length of the buffer.
VALUE rb_str_format(int argc, const VALUE *argv, VALUE fmt)
Formats a string.
VALUE rb_vsprintf(const char *fmt, va_list ap)
Identical to rb_sprintf(), except it takes a va_list.
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Marshal format compatibility layer.
VALUE type(ANYARGS)
ANYARGS-ed function type.
void rb_ivar_foreach(VALUE q, int_type *w, VALUE e)
Iteration over each instance variable of the object.
#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.
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 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.
#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...
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given object.
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.
char * ptr
Pointer to the contents of the string.
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.