12#include "ruby/internal/config.h"
27# include <AvailabilityMacros.h>
31#include "internal/error.h"
32#include "internal/eval.h"
33#include "internal/hash.h"
34#include "internal/io.h"
35#include "internal/load.h"
36#include "internal/object.h"
37#include "internal/string.h"
38#include "internal/symbol.h"
39#include "internal/thread.h"
40#include "internal/variable.h"
43#include "ruby_assert.h"
58#define WIFEXITED(status) 1
62#define WEXITSTATUS(status) (status)
67int rb_str_end_with_asciichar(
VALUE str,
int c);
69long rb_backtrace_length_limit = -1;
73static VALUE rb_mWarning;
74static VALUE rb_cWarningBuffer;
78static ID id_deprecated;
79static ID id_experimental;
80static VALUE sym_category;
81static VALUE sym_highlight;
86extern const char *rb_dynamic_description;
91#define defined_error(name, num) if (err == (num)) return (name);
92#define undefined_error(name)
93#include "known_errors.inc"
100err_position_0(
char *buf,
long len,
const char *file,
int line)
105 else if (line == 0) {
106 return snprintf(buf, len,
"%s: ", file);
109 return snprintf(buf, len,
"%s:%d: ", file, line);
115err_vcatf(
VALUE str, const
char *pre, const
char *file,
int line,
116 const
char *fmt, va_list args)
131rb_syntax_error_append(
VALUE exc,
VALUE file,
int line,
int column,
134 const char *fn =
NIL_P(file) ? NULL : RSTRING_PTR(file);
136 VALUE mesg = rb_enc_str_new(0, 0, enc);
137 err_vcatf(mesg, NULL, fn, line, fmt, args);
139 rb_write_error_str(mesg);
143 exc = syntax_error_with_path(exc, file, &mesg, enc);
144 err_vcatf(mesg, NULL, fn, line, fmt, args);
150static unsigned int warning_disabled_categories = (
155rb_warning_category_mask(
VALUE category)
157 return 1U << rb_warning_category_from_name(category);
161rb_warning_category_from_name(
VALUE category)
167 !st_lookup(warning_categories.id2enum, cat_id, &cat_value)) {
177 if (!st_lookup(warning_categories.enum2id, category, &
id)) {
184rb_warning_category_update(
unsigned int mask,
unsigned int bits)
186 warning_disabled_categories &= ~mask;
187 warning_disabled_categories |= mask & ~bits;
190MJIT_FUNC_EXPORTED
bool
193 return !(warning_disabled_categories & (1U << category));
217 return RBOOL(rb_warning_category_enabled_p(cat));
231 unsigned int mask = rb_warning_category_mask(category);
232 unsigned int disabled = warning_disabled_categories;
237 warning_disabled_categories = disabled;
253rb_warning_s_warn(
int argc,
VALUE *argv,
VALUE mod)
259 rb_scan_args(argc, argv,
"1:", &str, &opt);
264 if (!
NIL_P(category)) {
266 if (!rb_warning_category_enabled_p(cat))
return Qnil;
268 rb_write_error_str(str);
309 return rb_funcallv(mod, id_warn, 1, &str);
314rb_warning_warn_arity(
void)
317 return me ? rb_method_entry_arity(me) : 1;
324 rb_warning_category_from_name(category);
327 if (rb_warning_warn_arity() == 1) {
328 return rb_warning_warn(rb_mWarning, str);
333 args[1] = rb_hash_new();
334 rb_hash_aset(args[1], sym_category, category);
340rb_write_warning_str(
VALUE str)
342 rb_warning_warn(rb_mWarning, str);
347warn_vsprintf(
rb_encoding *enc, const
char *file,
int line, const
char *fmt, va_list args)
349 VALUE str = rb_enc_str_new(0, 0, enc);
351 err_vcatf(str,
"warning: ", file, line, fmt, args);
355#define with_warn_vsprintf(file, line, fmt) \
358 va_start(args, fmt); \
359 str = warn_vsprintf(NULL, file, line, fmt, args); \
366 with_warn_vsprintf(file, line, fmt) {
367 rb_write_warning_str(str);
377 with_warn_vsprintf(file, line, fmt) {
378 rb_write_warning_str(str);
387 with_warn_vsprintf(file, line, fmt) {
388 rb_warn_category(str, rb_warning_category_to_name(category));
395warning_string(
rb_encoding *enc, const
char *fmt, va_list args)
398 const char *file = rb_source_location_cstr(&line);
399 return warn_vsprintf(enc, file, line, fmt, args);
402#define with_warning_string(mesg, enc, fmt) \
403 with_warning_string_from(mesg, enc, fmt, fmt)
404#define with_warning_string_from(mesg, enc, fmt, last_arg) \
406 va_list args; va_start(args, last_arg); \
407 mesg = warning_string(enc, fmt, args); \
414 with_warning_string(mesg, 0, fmt) {
415 rb_write_warning_str(mesg);
424 with_warning_string(mesg, 0, fmt) {
425 rb_warn_category(mesg, rb_warning_category_to_name(category));
434 with_warning_string(mesg, enc, fmt) {
435 rb_write_warning_str(mesg);
445 with_warning_string(mesg, 0, fmt) {
446 rb_write_warning_str(mesg);
456 with_warning_string(mesg, 0, fmt) {
457 rb_warn_category(mesg, rb_warning_category_to_name(category));
463rb_warning_string(
const char *fmt, ...)
465 with_warning_string(mesg, 0, fmt) {
472rb_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
475 with_warning_string(mesg, enc, fmt) {
476 rb_write_warning_str(mesg);
483deprecation_warning_enabled(
void)
491warn_deprecated(
VALUE mesg,
const char *removal,
const char *suggest)
496 rb_str_catf(mesg,
" and will be removed in Ruby %s", removal);
498 if (suggest)
rb_str_catf(mesg,
"; use %s instead", suggest);
500 rb_warn_category(mesg,
ID2SYM(id_deprecated));
504rb_warn_deprecated(
const char *fmt,
const char *suggest, ...)
506 if (!deprecation_warning_enabled())
return;
508 with_warning_string_from(mesg, 0, fmt, suggest) {
509 warn_deprecated(mesg, NULL, suggest);
514rb_warn_deprecated_to_remove(
const char *removal,
const char *fmt,
const char *suggest, ...)
516 if (!deprecation_warning_enabled())
return;
518 with_warning_string_from(mesg, 0, fmt, suggest) {
519 warn_deprecated(mesg, removal, suggest);
524end_with_asciichar(
VALUE str,
int c)
527 rb_str_end_with_asciichar(str, c);
532warning_write(
int argc,
VALUE *argv,
VALUE buf)
546 int argc = RARRAY_LENINT(msgs);
551 if (!
NIL_P(uplevel)) {
556 location = rb_ec_backtrace_location_ary(ec, lev + 1, 1, TRUE);
557 if (!
NIL_P(location)) {
558 location = rb_ary_entry(location, 0);
561 if (argc > 1 || !
NIL_P(uplevel) || !end_with_asciichar(str,
'\n')) {
563 if (
NIL_P(uplevel)) {
566 else if (
NIL_P(location) ||
567 NIL_P(path = rb_funcall(location, rb_intern(
"path"), 0))) {
573 NUM2LONG(rb_funcall(location, rb_intern(
"lineno"), 0)));
575 RBASIC_SET_CLASS(str, rb_cWarningBuffer);
580 if (!
NIL_P(category)) {
581 category = rb_to_symbol_type(category);
582 rb_warning_category_from_name(category);
585 if (exc == rb_mWarning) {
587 rb_write_error_str(str);
590 rb_warn_category(str, category);
596#define MAX_BUG_REPORTERS 0x100
599 void (*func)(
FILE *out,
void *data);
603static int bug_reporters_size;
606rb_bug_reporter_add(
void (*func)(
FILE *,
void *),
void *data)
609 if (bug_reporters_size >= MAX_BUG_REPORTERS) {
613 reporter->func = func;
614 reporter->data = data;
620#define REPORT_BUG_BUFSIZ 256
622bug_report_file(
const char *file,
int line)
624 char buf[REPORT_BUG_BUFSIZ];
626 int len = err_position_0(buf,
sizeof(buf), file, line);
628 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
629 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
636FUNC_MINIMIZED(
static void bug_important_message(
FILE *out,
const char *
const msg,
size_t len));
639bug_important_message(
FILE *out,
const char *
const msg,
size_t len)
641 const char *
const endmsg = msg + len;
645 if (isatty(fileno(out))) {
646 static const char red[] =
"\033[;31;1;7m";
647 static const char green[] =
"\033[;32;7m";
648 static const char reset[] =
"\033[m";
649 const char *e = strchr(p,
'\n');
650 const int w = (int)(e - p);
652 int i = (int)(e - p);
653 fputs(*p ==
' ' ? green : red, out);
654 fwrite(p, 1, e - p, out);
655 for (; i < w; ++i) fputc(
' ', out);
658 }
while ((p = e + 1) < endmsg && (e = strchr(p,
'\n')) != 0 && e > p + 1);
660 fwrite(p, 1, endmsg - p, out);
663#undef CRASH_REPORTER_MAY_BE_CREATED
664#if defined(__APPLE__) && \
665 (!defined(MAC_OS_X_VERSION_10_6) || MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6 || defined(__POWERPC__))
666# define CRASH_REPORTER_MAY_BE_CREATED
669preface_dump(
FILE *out)
672 static const char msg[] =
""
673 "-- Crash Report log information "
674 "--------------------------------------------\n"
675 " See Crash Report log file in one of the following locations:\n"
676# ifdef CRASH_REPORTER_MAY_BE_CREATED
677 " * ~/Library/Logs/CrashReporter\n"
678 " * /Library/Logs/CrashReporter\n"
680 " * ~/Library/Logs/DiagnosticReports\n"
681 " * /Library/Logs/DiagnosticReports\n"
682 " for more details.\n"
683 "Don't forget to include the above Crash Report log file in bug reports.\n"
685 const size_t msglen =
sizeof(msg) - 1;
687 const char *msg = NULL;
688 const size_t msglen = 0;
690 bug_important_message(out, msg, msglen);
694postscript_dump(
FILE *out)
697 static const char msg[] =
""
700 "\n""Don't forget to include the Crash Report log file under\n"
701# ifdef CRASH_REPORTER_MAY_BE_CREATED
704 "DiagnosticReports directory in bug reports.\n"
707 const size_t msglen =
sizeof(msg) - 1;
709 const char *msg = NULL;
710 const size_t msglen = 0;
712 bug_important_message(out, msg, msglen);
717bug_report_begin_valist(
FILE *out, const
char *fmt, va_list args)
719 char buf[REPORT_BUG_BUFSIZ];
721 fputs(
"[BUG] ", out);
722 vsnprintf(buf,
sizeof(buf), fmt, args);
724 snprintf(buf,
sizeof(buf),
"\n%s\n\n", rb_dynamic_description);
729#define bug_report_begin(out, fmt) do { \
731 va_start(args, fmt); \
732 bug_report_begin_valist(out, fmt, args); \
737bug_report_end(
FILE *out)
742 for (i=0; i<bug_reporters_size; i++) {
744 (*reporter->func)(out, reporter->data);
747 postscript_dump(out);
750#define report_bug(file, line, fmt, ctx) do { \
751 FILE *out = bug_report_file(file, line); \
753 bug_report_begin(out, fmt); \
754 rb_vm_bugreport(ctx); \
755 bug_report_end(out); \
759#define report_bug_valist(file, line, fmt, ctx, args) do { \
760 FILE *out = bug_report_file(file, line); \
762 bug_report_begin_valist(out, fmt, args); \
763 rb_vm_bugreport(ctx); \
764 bug_report_end(out); \
768NORETURN(
static void die(
void));
772#if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
773 _set_abort_behavior( 0, _CALL_REPORTFAULT);
781rb_bug_without_die(const
char *fmt, va_list args)
783 const char *file = NULL;
787 file = rb_source_location_cstr(&line);
790 report_bug_valist(file, line, fmt, NULL, args);
798 rb_bug_without_die(fmt, args);
804rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler,
int sig,
const void *ctx,
const char *fmt, ...)
806 const char *file = NULL;
810 file = rb_source_location_cstr(&line);
813 report_bug(file, line, fmt, ctx);
815 if (default_sighandler) default_sighandler(sig);
825 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
827 const char *errno_str = rb_strerrno(errno_arg);
829 rb_bug(
"%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
831 rb_bug(
"%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
839#define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
840#define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
843rb_async_bug_errno(
const char *mesg,
int errno_arg)
845 WRITE_CONST(2,
"[ASYNC BUG] ");
846 write_or_abort(2, mesg, strlen(mesg));
847 WRITE_CONST(2,
"\n");
849 if (errno_arg == 0) {
850 WRITE_CONST(2,
"errno == 0 (NOERROR)\n");
853 const char *errno_str = rb_strerrno(errno_arg);
856 errno_str =
"undefined errno";
857 write_or_abort(2, errno_str, strlen(errno_str));
859 WRITE_CONST(2,
"\n\n");
860 write_or_abort(2, rb_dynamic_description, strlen(rb_dynamic_description));
865rb_report_bug_valist(
VALUE file,
int line,
const char *fmt, va_list args)
867 report_bug_valist(RSTRING_PTR(file), line, fmt, NULL, args);
870MJIT_FUNC_EXPORTED
void
871rb_assert_failure(
const char *file,
int line,
const char *name,
const char *expr)
874 fprintf(out,
"Assertion Failed: %s:%d:", file, line);
875 if (name) fprintf(out,
"%s:", name);
876 fprintf(out,
"%s\n%s\n\n", expr, rb_dynamic_description);
878 rb_vm_bugreport(NULL);
883static const char builtin_types[][10] = {
916rb_builtin_type_name(
int t)
919 if ((
unsigned int)t >= numberof(builtin_types))
return 0;
920 name = builtin_types[t];
921 if (*name)
return name;
926displaying_class_of(
VALUE x)
929 case Qfalse:
return rb_fstring_cstr(
"false");
930 case Qnil:
return rb_fstring_cstr(
"nil");
931 case Qtrue:
return rb_fstring_cstr(
"true");
937builtin_class_name(
VALUE x)
950 else if (RB_TYPE_P(x,
T_TRUE)) {
953 else if (RB_TYPE_P(x,
T_FALSE)) {
963rb_builtin_class_name(
VALUE x)
965 const char *etype = builtin_class_name(x);
973COLDFUNC NORETURN(
static void unexpected_type(
VALUE,
int,
int));
974#define UNDEF_LEAKED "undef leaked to the Ruby space"
977unexpected_type(
VALUE x,
int xt,
int t)
979 const char *tname = rb_builtin_type_name(t);
983 mesg =
rb_sprintf(
"wrong argument type %"PRIsVALUE
" (expected %s)",
984 displaying_class_of(x), tname);
987 else if (xt >
T_MASK && xt <= 0x3f) {
988 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given, probably comes"
989 " from extension library for ruby 1.8)", t, xt);
992 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given)", t, xt);
1002 if (RB_UNLIKELY(UNDEF_P(x))) {
1007 if (xt != t || (xt ==
T_DATA && rbimpl_rtypeddata_p(x))) {
1016 unexpected_type(x, xt, t);
1023 if (RB_UNLIKELY(UNDEF_P(x))) {
1027 unexpected_type(x,
TYPE(x), t);
1034 if (child == parent)
return 1;
1043 if (!RB_TYPE_P(obj,
T_DATA) ||
1050#undef rb_typeddata_is_instance_of
1054 return rb_typeddata_is_instance_of_inline(obj, data_type);
1062 if (!RB_TYPE_P(obj,
T_DATA)) {
1063 actual = displaying_class_of(obj);
1065 else if (!RTYPEDDATA_P(obj)) {
1066 actual = displaying_class_of(obj);
1069 const char *name = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
1113static VALUE rb_eNOERROR;
1115ID ruby_static_id_cause;
1116#define id_cause ruby_static_id_cause
1117static ID id_message, id_detailed_message, id_backtrace;
1118static ID id_key, id_matchee, id_args, id_Errno, id_errno, id_i_path;
1119static ID id_receiver, id_recv, id_iseq, id_local_variables;
1120static ID id_private_call_p, id_top, id_bottom;
1122#define id_bt_locations idBt_locations
1123#define id_mesg idMesg
1124#define id_name idName
1126#undef rb_exc_new_cstr
1167exc_initialize(
int argc,
VALUE *argv,
VALUE exc)
1171 arg = (!rb_check_arity(argc, 0, 1) ?
Qnil : argv[0]);
1172 return exc_init(exc, arg);
1189exc_exception(
int argc,
VALUE *argv,
VALUE self)
1193 argc = rb_check_arity(argc, 0, 1);
1194 if (argc == 0)
return self;
1195 if (argc == 1 && self == argv[0])
return self;
1222rb_get_message(
VALUE exc)
1225 if (UNDEF_P(e))
return Qnil;
1240 if (UNDEF_P(e))
return Qnil;
1252exc_s_to_tty_p(
VALUE self)
1254 return RBOOL(rb_stderr_tty_p());
1258check_highlight_keyword(
VALUE opt,
int auto_tty_detect)
1263 highlight = rb_hash_lookup(opt, sym_highlight);
1265 switch (highlight) {
1267 rb_bool_expected(highlight,
"highlight", TRUE);
1273 if (
NIL_P(highlight)) {
1274 highlight = RBOOL(auto_tty_detect && rb_stderr_tty_p());
1281check_order_keyword(
VALUE opt)
1286 static VALUE kw_order;
1287 if (!kw_order) kw_order =
ID2SYM(rb_intern_const(
"order"));
1289 order = rb_hash_lookup(opt, kw_order);
1291 if (order !=
Qnil) {
1293 if (
id == id_bottom) order =
Qtrue;
1294 else if (
id == id_top) order =
Qfalse;
1297 "order: %+"PRIsVALUE, order);
1326exc_full_message(
int argc,
VALUE *argv,
VALUE exc)
1328 VALUE opt, str, emesg, errat;
1329 VALUE highlight, order;
1331 rb_scan_args(argc, argv,
"0:", &opt);
1333 highlight = check_highlight_keyword(opt, 1);
1334 order = check_order_keyword(opt);
1337 if (
NIL_P(opt)) opt = rb_hash_new();
1338 rb_hash_aset(opt, sym_highlight, highlight);
1342 errat = rb_get_backtrace(exc);
1343 emesg = rb_get_detailed_message(exc, opt);
1345 rb_error_write(exc, emesg, errat, str, opt, highlight, order);
1358exc_message(
VALUE exc)
1360 return rb_funcallv(exc, idTo_s, 0, 0);
1404exc_detailed_message(
int argc,
VALUE *argv,
VALUE exc)
1408 rb_scan_args(argc, argv,
"0:", &opt);
1410 VALUE highlight = check_highlight_keyword(opt, 0);
1412 extern VALUE rb_decorate_message(
const VALUE eclass,
const VALUE emesg,
int highlight);
1414 return rb_decorate_message(
CLASS_OF(exc), rb_get_message(exc),
RTEST(highlight));
1425exc_inspect(
VALUE exc)
1431 if (RSTRING_LEN(exc) == 0) {
1488exc_backtrace(
VALUE exc)
1494 if (rb_backtrace_p(obj)) {
1495 obj = rb_backtrace_to_str_ary(obj);
1505rb_get_backtrace(
VALUE exc)
1507 ID mid = id_backtrace;
1509 if (rb_method_basic_definition_p(
CLASS_OF(exc), id_backtrace)) {
1515 info = exc_backtrace(exc);
1519 info = rb_funcallv(exc, mid, 0, 0);
1522 return rb_check_backtrace(info);
1536exc_backtrace_locations(
VALUE exc)
1542 obj = rb_backtrace_to_location_ary(obj);
1548rb_check_backtrace(
VALUE bt)
1551 static const char err[] =
"backtrace must be Array of String";
1555 if (rb_backtrace_p(bt))
return bt;
1556 if (!RB_TYPE_P(bt,
T_ARRAY)) {
1582 return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1585MJIT_FUNC_EXPORTED
VALUE
1588 return exc_set_backtrace(exc, bt);
1607try_convert_to_exception(
VALUE obj)
1624 VALUE mesg, backtrace;
1626 if (exc == obj)
return Qtrue;
1631 obj = rb_protect(try_convert_to_exception, obj, &state);
1632 if (state || UNDEF_P(obj)) {
1638 if (UNDEF_P(mesg))
return Qfalse;
1640 if (UNDEF_P(backtrace))
return Qfalse;
1644 backtrace = exc_backtrace(obj);
1649 return rb_equal(exc_backtrace(exc), backtrace);
1665exit_initialize(
int argc,
VALUE *argv,
VALUE exc)
1673 status =
INT2FIX(EXIT_SUCCESS);
1678 status =
INT2FIX(EXIT_FAILURE);
1684 if (
NIL_P(status)) {
1685 status =
INT2FIX(EXIT_SUCCESS);
1688#if EXIT_SUCCESS != 0
1690 status =
INT2FIX(EXIT_SUCCESS);
1699 status =
INT2FIX(EXIT_SUCCESS);
1715exit_status(
VALUE exc)
1729exit_success_p(
VALUE exc)
1734 if (
NIL_P(status_val))
1737 return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
1743 if (!UNDEF_P(recv))
rb_ivar_set(exc, id_recv, recv);
1760frozen_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1763 VALUE values[numberof(keywords)], options;
1765 argc = rb_scan_args(argc, argv,
"*:", NULL, &options);
1766 keywords[0] = id_receiver;
1767 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1769 err_init_recv(self, values[0]);
1781#define frozen_err_receiver name_err_receiver
1789 va_start(args, fmt);
1804 va_start(args, fmt);
1818 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
1820 err_init_recv(exc, recv);
1821 if (cfp)
rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
1839name_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1842 VALUE values[numberof(keywords)], name, options;
1844 argc = rb_scan_args(argc, argv,
"*:", NULL, &options);
1845 keywords[0] = id_receiver;
1846 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1847 name = (argc > 1) ? argv[--argc] :
Qnil;
1849 name_err_init_attr(self, values[0], name);
1858 exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
1859 return name_err_init_attr(exc, recv, method);
1866 return name_err_init(exc, mesg, recv, method);
1877name_err_name(
VALUE self)
1893name_err_local_variables(
VALUE self)
1899 if (!
NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
1900 if (
NIL_P(vars)) vars = rb_ary_new();
1907nometh_err_init_attr(
VALUE exc,
VALUE args,
int priv)
1931nometh_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1934 VALUE args, options;
1935 argc = rb_scan_args(argc, argv,
"*:", NULL, &options);
1936 priv = (argc > 3) && (--argc,
RTEST(argv[argc]));
1937 args = (argc > 2) ? argv[--argc] :
Qnil;
1938 if (!
NIL_P(options)) argv[argc++] = options;
1940 return nometh_err_init_attr(self, args, priv);
1947 name_err_init(exc, mesg, recv, method);
1948 return nometh_err_init_attr(exc, args, priv);
1953 NAME_ERR_MESG__MESG,
1954 NAME_ERR_MESG__RECV,
1955 NAME_ERR_MESG__NAME,
1960name_err_mesg_mark(
void *p)
1963 rb_gc_mark_locations(ptr, ptr+NAME_ERR_MESG_COUNT);
1966#define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1969name_err_mesg_memsize(
const void *p)
1971 return NAME_ERR_MESG_COUNT *
sizeof(
VALUE);
1979 name_err_mesg_memsize,
1981 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1991 ptr[NAME_ERR_MESG__MESG] = mesg;
1992 ptr[NAME_ERR_MESG__RECV] = recv;
1993 ptr[NAME_ERR_MESG__NAME] = method;
2007name_err_mesg_alloc(
VALUE klass)
2014name_err_mesg_init_copy(
VALUE obj1,
VALUE obj2)
2018 if (obj1 == obj2)
return obj1;
2034 if (obj1 == obj2)
return Qtrue;
2040 for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
2049name_err_mesg_receiver_name(
VALUE obj)
2051 if (RB_SPECIAL_CONST_P(obj))
return Qundef;
2052 if (RB_BUILTIN_TYPE(obj) ==
T_MODULE || RB_BUILTIN_TYPE(obj) ==
T_CLASS) {
2060name_err_mesg_to_str(
VALUE obj)
2065 mesg = ptr[NAME_ERR_MESG__MESG];
2069 VALUE c, s, d = 0, args[4];
2070 int state = 0, singleton = 0;
2073#define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
2074 obj =
ptr[NAME_ERR_MESG__RECV];
2077 d = FAKE_CSTR(&d_str,
"nil");
2080 d = FAKE_CSTR(&d_str,
"true");
2083 d = FAKE_CSTR(&d_str,
"false");
2086 d = rb_protect(name_err_mesg_receiver_name, obj, &state);
2087 if (state || NIL_OR_UNDEF_P(d))
2096 singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] ==
'#');
2100 s = FAKE_CSTR(&s_str,
":");
2104 c = s = FAKE_CSTR(&s_str,
"");
2119 return name_err_mesg_to_str(obj);
2137name_err_receiver(
VALUE self)
2141 recv = rb_ivar_lookup(self, id_recv,
Qundef);
2142 if (!UNDEF_P(recv))
return recv;
2149 return ptr[NAME_ERR_MESG__RECV];
2161nometh_err_args(
VALUE self)
2174nometh_err_private_call_p(
VALUE self)
2195key_err_receiver(
VALUE self)
2199 recv = rb_ivar_lookup(self, id_receiver,
Qundef);
2200 if (!UNDEF_P(recv))
return recv;
2212key_err_key(
VALUE self)
2216 key = rb_ivar_lookup(self, id_key,
Qundef);
2217 if (!UNDEF_P(key))
return key;
2241key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2245 rb_call_super(rb_scan_args(argc, argv,
"01:", NULL, &options), argv);
2247 if (!
NIL_P(options)) {
2249 VALUE values[numberof(keywords)];
2251 keywords[0] = id_receiver;
2252 keywords[1] = id_key;
2253 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2254 for (i = 0; i < numberof(values); ++i) {
2255 if (!UNDEF_P(values[i])) {
2272no_matching_pattern_key_err_matchee(
VALUE self)
2276 matchee = rb_ivar_lookup(self, id_matchee,
Qundef);
2277 if (!UNDEF_P(matchee))
return matchee;
2289no_matching_pattern_key_err_key(
VALUE self)
2293 key = rb_ivar_lookup(self, id_key,
Qundef);
2294 if (!UNDEF_P(key))
return key;
2307no_matching_pattern_key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2311 rb_call_super(rb_scan_args(argc, argv,
"01:", NULL, &options), argv);
2313 if (!
NIL_P(options)) {
2315 VALUE values[numberof(keywords)];
2317 keywords[0] = id_matchee;
2318 keywords[1] = id_key;
2319 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2320 for (i = 0; i < numberof(values); ++i) {
2321 if (!UNDEF_P(values[i])) {
2339syntax_error_initialize(
int argc,
VALUE *argv,
VALUE self)
2343 mesg = rb_fstring_lit(
"compile error");
2354 *mesg = rb_enc_str_new(0, 0, enc);
2363 if (RSTRING_LEN(s) > 0 && *(RSTRING_END(s)-1) !=
'\n')
2402set_syserr(
int n,
const char *name)
2406 if (!st_lookup(syserr_tbl, n, &error)) {
2414#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2419 rb_eEWOULDBLOCK = error;
2422 rb_eEINPROGRESS = error;
2427 st_add_direct(syserr_tbl, n, error);
2440 if (!st_lookup(syserr_tbl, n, &error)) {
2443 snprintf(name,
sizeof(name),
"E%03d", n);
2444 error = set_syserr(n, name);
2460syserr_initialize(
int argc,
VALUE *argv,
VALUE self)
2463 VALUE mesg, error, func, errmsg;
2467 st_data_t data = (st_data_t)klass;
2468 rb_scan_args(argc, argv,
"12", &mesg, &error, &func);
2470 error = mesg; mesg =
Qnil;
2472 if (!
NIL_P(error) && st_lookup(syserr_tbl,
NUM2LONG(error), &data)) {
2473 klass = (
VALUE)data;
2478 RBASIC_SET_CLASS(self, klass);
2482 rb_scan_args(argc, argv,
"02", &mesg, &func);
2486 else err =
"unknown error";
2488 errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding());
2510syserr_errno(
VALUE self)
2535 num = rb_funcallv(exc, id_errno, 0, 0);
2940exception_alloc(
VALUE klass)
2942 return rb_class_allocate_instance(klass);
2946exception_dumper(
VALUE exc)
2956ivar_copy_i(st_data_t key, st_data_t val, st_data_t exc)
2962void rb_exc_check_circular_cause(
VALUE exc);
2974 if (RB_TYPE_P(exc,
T_CLASS))
return obj;
2978 rb_exc_check_circular_cause(exc);
3075 syserr_tbl = st_init_numtable();
3093 id_cause = rb_intern_const(
"cause");
3094 id_message = rb_intern_const(
"message");
3095 id_detailed_message = rb_intern_const(
"detailed_message");
3096 id_backtrace = rb_intern_const(
"backtrace");
3097 id_key = rb_intern_const(
"key");
3098 id_matchee = rb_intern_const(
"matchee");
3099 id_args = rb_intern_const(
"args");
3100 id_receiver = rb_intern_const(
"receiver");
3101 id_private_call_p = rb_intern_const(
"private_call?");
3102 id_local_variables = rb_intern_const(
"local_variables");
3103 id_Errno = rb_intern_const(
"Errno");
3104 id_errno = rb_intern_const(
"errno");
3105 id_i_path = rb_intern_const(
"@path");
3106 id_warn = rb_intern_const(
"warn");
3107 id_category = rb_intern_const(
"category");
3108 id_deprecated = rb_intern_const(
"deprecated");
3109 id_experimental = rb_intern_const(
"experimental");
3110 id_top = rb_intern_const(
"top");
3111 id_bottom = rb_intern_const(
"bottom");
3112 id_iseq = rb_make_internal_id();
3113 id_recv = rb_make_internal_id();
3115 sym_category =
ID2SYM(id_category);
3116 sym_highlight =
ID2SYM(rb_intern_const(
"highlight"));
3118 warning_categories.id2enum = rb_init_identtable();
3122 warning_categories.enum2id = rb_init_identtable();
3134 va_start(args, fmt);
3142rb_vraise(
VALUE exc,
const char *fmt, va_list ap)
3151 va_start(args, fmt);
3152 rb_vraise(exc, fmt, args);
3156NORETURN(
static void raise_loaderror(
VALUE path,
VALUE mesg));
3172 va_start(args, fmt);
3175 raise_loaderror(
Qnil, mesg);
3184 va_start(args, fmt);
3187 raise_loaderror(path, mesg);
3194 "%"PRIsVALUE
"() function is unimplemented on this machine",
3195 rb_id2str(rb_frame_this_func()));
3204 if (! ruby_thread_has_gvl_p()) {
3207 fprintf(stderr,
"[FATAL] rb_fatal() outside of GVL\n");
3208 rb_print_backtrace();
3212 va_start(args, fmt);
3220make_errno_exc(
const char *mesg)
3226 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
3232make_errno_exc_str(
VALUE mesg)
3237 if (!mesg) mesg =
Qnil;
3239 const char *s = !
NIL_P(mesg) ? RSTRING_PTR(mesg) :
"";
3240 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
3283#ifdef RUBY_FUNCTION_NAME_STRING
3285rb_sys_fail_path_in(
const char *func_name,
VALUE path)
3290 rb_syserr_fail_path_in(func_name, n, path);
3294rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
3296 rb_exc_raise(rb_syserr_new_path_in(func_name, n, path));
3300rb_syserr_new_path_in(
const char *func_name,
int n,
VALUE path)
3304 if (!path) path =
Qnil;
3306 const char *s = !
NIL_P(path) ? RSTRING_PTR(path) :
"";
3307 if (!func_name) func_name =
"(null)";
3308 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
3317NORETURN(
static void rb_mod_exc_raise(
VALUE exc,
VALUE mod));
3329 VALUE exc = make_errno_exc(mesg);
3330 rb_mod_exc_raise(exc, mod);
3336 VALUE exc = make_errno_exc_str(mesg);
3337 rb_mod_exc_raise(exc, mod);
3344 rb_mod_exc_raise(exc, mod);
3351 rb_mod_exc_raise(exc, mod);
3355syserr_warning(
VALUE mesg,
int err)
3359 rb_write_warning_str(mesg);
3364rb_sys_warn(
const char *fmt, ...)
3367 int errno_save = errno;
3368 with_warning_string(mesg, 0, fmt) {
3369 syserr_warning(mesg, errno_save);
3376rb_syserr_warn(
int err,
const char *fmt, ...)
3379 with_warning_string(mesg, 0, fmt) {
3380 syserr_warning(mesg, err);
3386rb_sys_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
3389 int errno_save = errno;
3390 with_warning_string(mesg, enc, fmt) {
3391 syserr_warning(mesg, errno_save);
3398rb_syserr_enc_warn(
int err,
rb_encoding *enc,
const char *fmt, ...)
3401 with_warning_string(mesg, enc, fmt) {
3402 syserr_warning(mesg, err);
3412 int errno_save = errno;
3413 with_warning_string(mesg, 0, fmt) {
3414 syserr_warning(mesg, errno_save);
3422rb_syserr_warning(
int err,
const char *fmt, ...)
3425 with_warning_string(mesg, 0, fmt) {
3426 syserr_warning(mesg, err);
3433rb_sys_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
3436 int errno_save = errno;
3437 with_warning_string(mesg, enc, fmt) {
3438 syserr_warning(mesg, errno_save);
3445rb_syserr_enc_warning(
int err,
rb_encoding *enc,
const char *fmt, ...)
3448 with_warning_string(mesg, enc, fmt) {
3449 syserr_warning(mesg, err);
3455rb_load_fail(
VALUE path,
const char *err)
3460 raise_loaderror(path, mesg);
3475 va_start(args, fmt);
3484inspect_frozen_obj(
VALUE obj,
VALUE mesg,
int recur)
3499 const ID created_info = id_debug_created_info;
3508 VALUE path = rb_ary_entry(debug_info, 0);
3509 VALUE line = rb_ary_entry(debug_info, 1);
3511 rb_str_catf(mesg,
", created at %"PRIsVALUE
":%"PRIsVALUE, path, line);
3516#undef rb_check_frozen
3534 rb_eNOERROR = set_syserr(0,
"NOERROR");
3535#define defined_error(name, num) set_syserr((num), (name));
3536#define undefined_error(name) set_syserr(0, (name));
3537#include "known_errors.inc"
3539#undef undefined_error
3542#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_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 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 ALLOC_N
Old name of RB_ALLOC_N.
#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 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 always regardless of runtime -W flag.
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 always regardless of runtime -W flag.
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.
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.
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 always regardless of runtime -W flag.
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_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_cObject
Documented in include/ruby/internal/globals.h.
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_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.
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.
Defines RBIMPL_HAS_BUILTIN.
#define rb_check_frozen
Just another name of rb_check_frozen.
#define rb_check_frozen_internal(obj)
VALUE rb_io_puts(int argc, const VALUE *argv, VALUE io)
Iterates over the passed array to apply rb_io_write() individually.
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.
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.
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_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_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.
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.
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.
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 MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
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 RARRAY_LEN
Just another name of rb_array_len.
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
#define DATA_PTR(obj)
Convenient getter macro.
#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.
#define RTYPEDDATA_DATA(v)
Convenient getter macro.
#define TypedData_Get_Struct(obj, type, data_type, sval)
Obtains a C struct from inside of a wrapper Ruby object.
#define TypedData_Wrap_Struct(klass, data_type, sval)
Converts sval, a pointer to your struct, into a Ruby object.
const char * rb_obj_classname(VALUE obj)
Queries the name of the class of the passed object.
#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.
#define RTEST
This is an old name of RB_TEST.
char * ptr
Pointer to the contents of the string.
const char * wrap_struct_name
Name of structs of this kind.
const rb_data_type_t * parent
Parent of this class.
uintptr_t VALUE
Type that represents a Ruby object.
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.