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/symbol.h"
38 #include "internal/thread.h"
39 #include "internal/variable.h"
42 #include "ruby_assert.h"
53 #define EXIT_SUCCESS 0
57 #define WIFEXITED(status) 1
61 #define WEXITSTATUS(status) (status)
66 int rb_str_end_with_asciichar(
VALUE str,
int c);
68 long rb_backtrace_length_limit = -1;
70 VALUE rb_eEWOULDBLOCK;
71 VALUE rb_eEINPROGRESS;
72 static VALUE rb_mWarning;
73 static VALUE rb_cWarningBuffer;
76 static ID id_category;
77 static ID id_deprecated;
78 static ID id_experimental;
79 static VALUE sym_category;
84 extern const char ruby_description[];
89 #define defined_error(name, num) if (err == (num)) return (name);
90 #define undefined_error(name)
91 #include "known_errors.inc"
93 #undef undefined_error
98 err_position_0(
char *buf,
long len,
const char *file,
int line)
103 else if (line == 0) {
104 return snprintf(buf, len,
"%s: ", file);
107 return snprintf(buf, len,
"%s:%d: ", file, line);
113 err_vcatf(
VALUE str, const
char *pre, const
char *file,
int line,
114 const
char *fmt, va_list args)
127 rb_syntax_error_append(
VALUE exc,
VALUE file,
int line,
int column,
133 err_vcatf(mesg, NULL, fn, line, fmt, args);
135 rb_write_error_str(mesg);
148 err_vcatf(mesg, NULL, fn, line, fmt, args);
154 static unsigned int warning_disabled_categories = (
159 rb_warning_category_mask(
VALUE category)
161 return 1U << rb_warning_category_from_name(category);
165 rb_warning_category_from_name(
VALUE category)
171 !st_lookup(warning_categories.id2enum, cat_id, &cat_value)) {
181 if (!st_lookup(warning_categories.enum2id, category, &
id)) {
188 rb_warning_category_update(
unsigned int mask,
unsigned int bits)
190 warning_disabled_categories &= ~mask;
191 warning_disabled_categories |= mask & ~bits;
194 MJIT_FUNC_EXPORTED
bool
197 return !(warning_disabled_categories & (1U << category));
221 return RBOOL(rb_warning_category_enabled_p(cat));
235 unsigned int mask = rb_warning_category_mask(category);
236 unsigned int disabled = warning_disabled_categories;
241 warning_disabled_categories = disabled;
257 rb_warning_s_warn(
int argc,
VALUE *argv,
VALUE mod)
268 if (!
NIL_P(category)) {
270 if (!rb_warning_category_enabled_p(cat))
return Qnil;
272 rb_write_error_str(str);
318 rb_warning_warn_arity(
void)
321 return me ? rb_method_entry_arity(me) : 1;
328 rb_warning_category_from_name(category);
331 if (rb_warning_warn_arity() == 1) {
332 return rb_warning_warn(rb_mWarning, str);
344 rb_write_warning_str(
VALUE str)
346 rb_warning_warn(rb_mWarning, str);
351 warn_vsprintf(
rb_encoding *enc, const
char *file,
int line, const
char *fmt, va_list args)
355 err_vcatf(str,
"warning: ", file, line, fmt, args);
368 str = warn_vsprintf(NULL, file, line, fmt, args);
370 rb_write_warning_str(str);
383 str = warn_vsprintf(NULL, file, line, fmt, args);
385 rb_write_warning_str(str);
397 str = warn_vsprintf(NULL, file, line, fmt, args);
399 rb_warn_category(str, rb_warning_category_to_name(category));
404 warning_string(
rb_encoding *enc, const
char *fmt, va_list args)
407 const char *file = rb_source_location_cstr(&line);
408 return warn_vsprintf(enc, file, line, fmt, args);
411 #define with_warning_string(mesg, enc, fmt) \
413 va_list args; va_start(args, fmt); \
414 mesg = warning_string(enc, fmt, args); \
421 with_warning_string(mesg, 0, fmt) {
422 rb_write_warning_str(mesg);
431 with_warning_string(mesg, 0, fmt) {
432 rb_warn_category(mesg, rb_warning_category_to_name(category));
438 rb_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
441 with_warning_string(mesg, enc, fmt) {
442 rb_write_warning_str(mesg);
452 with_warning_string(mesg, 0, fmt) {
453 rb_write_warning_str(mesg);
463 with_warning_string(mesg, 0, fmt) {
464 rb_warn_category(mesg, rb_warning_category_to_name(category));
470 rb_warning_string(
const char *fmt, ...)
472 with_warning_string(mesg, 0, fmt) {
479 rb_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
482 with_warning_string(mesg, enc, fmt) {
483 rb_write_warning_str(mesg);
490 deprecation_warning_enabled(
void)
498 warn_deprecated(
VALUE mesg,
const char *removal,
const char *suggest)
503 rb_str_catf(mesg,
" and will be removed in Ruby %s", removal);
505 if (suggest)
rb_str_catf(mesg,
"; use %s instead", suggest);
507 rb_warn_category(mesg,
ID2SYM(id_deprecated));
511 rb_warn_deprecated(
const char *fmt,
const char *suggest, ...)
513 if (!deprecation_warning_enabled())
return;
516 va_start(args, suggest);
517 VALUE mesg = warning_string(0, fmt, args);
520 warn_deprecated(mesg, NULL, suggest);
524 rb_warn_deprecated_to_remove(
const char *removal,
const char *fmt,
const char *suggest, ...)
526 if (!deprecation_warning_enabled())
return;
529 va_start(args, suggest);
530 VALUE mesg = warning_string(0, fmt, args);
533 warn_deprecated(mesg, removal, suggest);
537 end_with_asciichar(
VALUE str,
int c)
540 rb_str_end_with_asciichar(str, c);
545 warning_write(
int argc,
VALUE *argv,
VALUE buf)
564 if (!
NIL_P(uplevel)) {
569 location = rb_ec_backtrace_location_ary(ec, lev + 1, 1, TRUE);
570 if (!
NIL_P(location)) {
574 if (argc > 1 || !
NIL_P(uplevel) || !end_with_asciichar(str,
'\n')) {
576 if (
NIL_P(uplevel)) {
579 else if (
NIL_P(location) ||
588 RBASIC_SET_CLASS(str, rb_cWarningBuffer);
593 if (!
NIL_P(category)) {
594 category = rb_to_symbol_type(category);
595 rb_warning_category_from_name(category);
598 if (exc == rb_mWarning) {
600 rb_write_error_str(str);
603 rb_warn_category(str, category);
609 #define MAX_BUG_REPORTERS 0x100
612 void (*func)(
FILE *out,
void *data);
616 static int bug_reporters_size;
619 rb_bug_reporter_add(
void (*func)(
FILE *,
void *),
void *data)
622 if (bug_reporters_size >= MAX_BUG_REPORTERS) {
626 reporter->func = func;
627 reporter->data = data;
633 #define REPORT_BUG_BUFSIZ 256
635 bug_report_file(
const char *file,
int line)
637 char buf[REPORT_BUG_BUFSIZ];
639 int len = err_position_0(buf,
sizeof(buf), file, line);
641 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
642 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
649 FUNC_MINIMIZED(
static void bug_important_message(
FILE *out,
const char *
const msg,
size_t len));
652 bug_important_message(
FILE *out,
const char *
const msg,
size_t len)
654 const char *
const endmsg = msg + len;
658 if (isatty(fileno(out))) {
659 static const char red[] =
"\033[;31;1;7m";
660 static const char green[] =
"\033[;32;7m";
661 static const char reset[] =
"\033[m";
662 const char *e = strchr(p,
'\n');
663 const int w = (int)(e - p);
665 int i = (int)(e - p);
666 fputs(*p ==
' ' ? green : red, out);
667 fwrite(p, 1, e - p, out);
668 for (; i < w; ++i) fputc(
' ', out);
671 }
while ((p = e + 1) < endmsg && (e = strchr(p,
'\n')) != 0 && e > p + 1);
673 fwrite(p, 1, endmsg - p, out);
677 preface_dump(
FILE *out)
679 #if defined __APPLE__
680 static const char msg[] =
""
681 "-- Crash Report log information "
682 "--------------------------------------------\n"
683 " See Crash Report log file in one of the following locations:\n"
684 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
685 " * ~/Library/Logs/CrashReporter\n"
686 " * /Library/Logs/CrashReporter\n"
688 " * ~/Library/Logs/DiagnosticReports\n"
689 " * /Library/Logs/DiagnosticReports\n"
690 " for more details.\n"
691 "Don't forget to include the above Crash Report log file in bug reports.\n"
693 const size_t msglen =
sizeof(msg) - 1;
695 const char *msg = NULL;
696 const size_t msglen = 0;
698 bug_important_message(out, msg, msglen);
702 postscript_dump(
FILE *out)
704 #if defined __APPLE__
705 static const char msg[] =
""
708 "\n""Don't forget to include the Crash Report log file under\n"
709 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
712 "DiagnosticReports directory in bug reports.\n"
715 const size_t msglen =
sizeof(msg) - 1;
717 const char *msg = NULL;
718 const size_t msglen = 0;
720 bug_important_message(out, msg, msglen);
725 bug_report_begin_valist(
FILE *out, const
char *fmt, va_list args)
727 char buf[REPORT_BUG_BUFSIZ];
729 fputs(
"[BUG] ", out);
730 vsnprintf(buf,
sizeof(buf), fmt, args);
732 snprintf(buf,
sizeof(buf),
"\n%s\n\n", ruby_description);
737 #define bug_report_begin(out, fmt) do { \
739 va_start(args, fmt); \
740 bug_report_begin_valist(out, fmt, args); \
745 bug_report_end(
FILE *out)
750 for (i=0; i<bug_reporters_size; i++) {
752 (*reporter->func)(out, reporter->data);
755 postscript_dump(out);
758 #define report_bug(file, line, fmt, ctx) do { \
759 FILE *out = bug_report_file(file, line); \
761 bug_report_begin(out, fmt); \
762 rb_vm_bugreport(ctx); \
763 bug_report_end(out); \
767 #define report_bug_valist(file, line, fmt, ctx, args) do { \
768 FILE *out = bug_report_file(file, line); \
770 bug_report_begin_valist(out, fmt, args); \
771 rb_vm_bugreport(ctx); \
772 bug_report_end(out); \
776 NORETURN(
static void die(
void));
780 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
781 _set_abort_behavior( 0, _CALL_REPORTFAULT);
789 rb_bug_without_die(const
char *fmt, va_list args)
791 const char *file = NULL;
795 file = rb_source_location_cstr(&line);
798 report_bug_valist(file, line, fmt, NULL, args);
806 rb_bug_without_die(fmt, args);
812 rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler,
int sig,
const void *ctx,
const char *fmt, ...)
814 const char *file = NULL;
818 file = rb_source_location_cstr(&line);
821 report_bug(file, line, fmt, ctx);
823 if (default_sighandler) default_sighandler(sig);
833 rb_bug(
"%s: errno == 0 (NOERROR)", mesg);
835 const char *errno_str = rb_strerrno(errno_arg);
837 rb_bug(
"%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
839 rb_bug(
"%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
847 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
848 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
851 rb_async_bug_errno(
const char *mesg,
int errno_arg)
853 WRITE_CONST(2,
"[ASYNC BUG] ");
854 write_or_abort(2, mesg, strlen(mesg));
855 WRITE_CONST(2,
"\n");
857 if (errno_arg == 0) {
858 WRITE_CONST(2,
"errno == 0 (NOERROR)\n");
861 const char *errno_str = rb_strerrno(errno_arg);
864 errno_str =
"undefined errno";
865 write_or_abort(2, errno_str, strlen(errno_str));
867 WRITE_CONST(2,
"\n\n");
868 write_or_abort(2, ruby_description, strlen(ruby_description));
873 rb_report_bug_valist(
VALUE file,
int line,
const char *fmt, va_list args)
875 report_bug_valist(
RSTRING_PTR(file), line, fmt, NULL, args);
878 MJIT_FUNC_EXPORTED
void
879 rb_assert_failure(
const char *file,
int line,
const char *name,
const char *expr)
882 fprintf(out,
"Assertion Failed: %s:%d:", file, line);
883 if (name) fprintf(out,
"%s:", name);
884 fprintf(out,
"%s\n%s\n\n", expr, ruby_description);
886 rb_vm_bugreport(NULL);
891 static const char builtin_types[][10] = {
924 rb_builtin_type_name(
int t)
927 if ((
unsigned int)t >= numberof(builtin_types))
return 0;
928 name = builtin_types[t];
929 if (*name)
return name;
934 displaying_class_of(
VALUE x)
937 case Qfalse:
return rb_fstring_cstr(
"false");
938 case Qnil:
return rb_fstring_cstr(
"nil");
939 case Qtrue:
return rb_fstring_cstr(
"true");
945 builtin_class_name(
VALUE x)
971 rb_builtin_class_name(
VALUE x)
973 const char *etype = builtin_class_name(x);
981 COLDFUNC NORETURN(
static void unexpected_type(
VALUE,
int,
int));
982 #define UNDEF_LEAKED "undef leaked to the Ruby space"
985 unexpected_type(
VALUE x,
int xt,
int t)
987 const char *tname = rb_builtin_type_name(t);
991 mesg =
rb_sprintf(
"wrong argument type %"PRIsVALUE
" (expected %s)",
992 displaying_class_of(x), tname);
995 else if (xt >
T_MASK && xt <= 0x3f) {
996 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given, probably comes"
997 " from extension library for ruby 1.8)", t, xt);
1000 mesg =
rb_sprintf(
"unknown type 0x%x (0x%x given)", t, xt);
1015 if (xt != t || (xt ==
T_DATA && rbimpl_rtypeddata_p(x))) {
1024 unexpected_type(x, xt, t);
1035 unexpected_type(x,
TYPE(x), t);
1042 if (child == parent)
return 1;
1058 #undef rb_typeddata_is_instance_of
1062 return rb_typeddata_is_instance_of_inline(obj, data_type);
1071 actual = displaying_class_of(obj);
1074 actual = displaying_class_of(obj);
1121 static VALUE rb_eNOERROR;
1123 ID ruby_static_id_cause;
1124 #define id_cause ruby_static_id_cause
1125 static ID id_message, id_backtrace;
1126 static ID id_key, id_matchee, id_args, id_Errno, id_errno, id_i_path;
1127 static ID id_receiver, id_recv, id_iseq, id_local_variables;
1128 static ID id_private_call_p, id_top, id_bottom;
1130 #define id_bt_locations idBt_locations
1131 #define id_mesg idMesg
1132 #define id_name idName
1134 #undef rb_exc_new_cstr
1175 exc_initialize(
int argc,
VALUE *argv,
VALUE exc)
1180 return exc_init(exc, arg);
1197 exc_exception(
int argc,
VALUE *argv,
VALUE self)
1202 if (argc == 0)
return self;
1203 if (argc == 1 &&
self == argv[0])
return self;
1230 rb_get_message(
VALUE exc)
1245 exc_s_to_tty_p(
VALUE self)
1247 return RBOOL(rb_stderr_tty_p());
1269 exc_full_message(
int argc,
VALUE *argv,
VALUE exc)
1271 VALUE opt, str, emesg, errat;
1272 enum {kw_highlight, kw_order, kw_max_};
1273 static ID kw[kw_max_];
1279 #define INIT_KW(n) kw[kw_##n] = rb_intern_const(#n)
1285 switch (args[kw_highlight]) {
1287 rb_bool_expected(args[kw_highlight],
"highlight");
1289 case Qundef: args[kw_highlight] =
Qnil;
break;
1292 if (args[kw_order] ==
Qundef) {
1293 args[kw_order] =
Qnil;
1297 if (
id == id_bottom) args[kw_order] =
Qtrue;
1298 else if (
id == id_top) args[kw_order] =
Qfalse;
1301 "order: %+"PRIsVALUE, args[kw_order]);
1306 errat = rb_get_backtrace(exc);
1307 emesg = rb_get_message(exc);
1309 rb_error_write(exc, emesg, errat, str, args[kw_highlight], args[kw_order]);
1322 exc_message(
VALUE exc)
1335 exc_inspect(
VALUE exc)
1391 exc_backtrace(
VALUE exc)
1397 if (rb_backtrace_p(obj)) {
1398 obj = rb_backtrace_to_str_ary(obj);
1408 rb_get_backtrace(
VALUE exc)
1410 ID mid = id_backtrace;
1418 info = exc_backtrace(exc);
1425 return rb_check_backtrace(info);
1439 exc_backtrace_locations(
VALUE exc)
1445 obj = rb_backtrace_to_location_ary(obj);
1451 rb_check_backtrace(
VALUE bt)
1454 static const char err[] =
"backtrace must be Array of String";
1458 if (rb_backtrace_p(bt))
return bt;
1485 return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1488 MJIT_FUNC_EXPORTED
VALUE
1491 return exc_set_backtrace(exc, bt);
1504 exc_cause(
VALUE exc)
1510 try_convert_to_exception(
VALUE obj)
1527 VALUE mesg, backtrace;
1529 if (exc == obj)
return Qtrue;
1534 obj =
rb_protect(try_convert_to_exception, obj, &state);
1535 if (state || obj ==
Qundef) {
1547 backtrace = exc_backtrace(obj);
1552 return rb_equal(exc_backtrace(exc), backtrace);
1568 exit_initialize(
int argc,
VALUE *argv,
VALUE exc)
1576 status =
INT2FIX(EXIT_SUCCESS);
1581 status =
INT2FIX(EXIT_FAILURE);
1587 if (
NIL_P(status)) {
1588 status =
INT2FIX(EXIT_SUCCESS);
1591 #if EXIT_SUCCESS != 0
1593 status =
INT2FIX(EXIT_SUCCESS);
1602 status =
INT2FIX(EXIT_SUCCESS);
1618 exit_status(
VALUE exc)
1632 exit_success_p(
VALUE exc)
1637 if (
NIL_P(status_val))
1640 return RBOOL(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS);
1663 frozen_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1666 VALUE values[numberof(keywords)], options;
1669 keywords[0] = id_receiver;
1670 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1672 err_init_recv(
self, values[0]);
1684 #define frozen_err_receiver name_err_receiver
1692 va_start(args, fmt);
1707 va_start(args, fmt);
1721 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
1723 err_init_recv(exc, recv);
1724 if (cfp)
rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
1742 name_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1745 VALUE values[numberof(keywords)], name, options;
1748 keywords[0] = id_receiver;
1749 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1750 name = (argc > 1) ? argv[--argc] :
Qnil;
1752 name_err_init_attr(
self, values[0], name);
1761 exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
1762 return name_err_init_attr(exc, recv, method);
1769 return name_err_init(exc, mesg, recv, method);
1780 name_err_name(
VALUE self)
1796 name_err_local_variables(
VALUE self)
1802 if (!
NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
1810 nometh_err_init_attr(
VALUE exc,
VALUE args,
int priv)
1834 nometh_err_initialize(
int argc,
VALUE *argv,
VALUE self)
1837 VALUE args, options;
1839 priv = (argc > 3) && (--argc,
RTEST(argv[argc]));
1840 args = (argc > 2) ? argv[--argc] :
Qnil;
1841 if (!
NIL_P(options)) argv[argc++] = options;
1843 return nometh_err_init_attr(
self, args, priv);
1850 name_err_init(exc, mesg, recv, method);
1851 return nometh_err_init_attr(exc, args, priv);
1856 NAME_ERR_MESG__MESG,
1857 NAME_ERR_MESG__RECV,
1858 NAME_ERR_MESG__NAME,
1863 name_err_mesg_mark(
void *p)
1869 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1872 name_err_mesg_memsize(
const void *p)
1874 return NAME_ERR_MESG_COUNT *
sizeof(
VALUE);
1882 name_err_mesg_memsize,
1884 0, 0, RUBY_TYPED_FREE_IMMEDIATELY
1894 ptr[NAME_ERR_MESG__MESG] = mesg;
1895 ptr[NAME_ERR_MESG__RECV] = recv;
1896 ptr[NAME_ERR_MESG__NAME] = method;
1910 name_err_mesg_alloc(
VALUE klass)
1917 name_err_mesg_init_copy(
VALUE obj1,
VALUE obj2)
1921 if (obj1 == obj2)
return obj1;
1937 if (obj1 == obj2)
return Qtrue;
1943 for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1952 name_err_mesg_receiver_name(
VALUE obj)
1963 name_err_mesg_to_str(
VALUE obj)
1968 mesg = ptr[NAME_ERR_MESG__MESG];
1972 VALUE c, s, d = 0, args[4];
1973 int state = 0, singleton = 0;
1976 #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
1977 obj =
ptr[NAME_ERR_MESG__RECV];
1980 d = FAKE_CSTR(&d_str,
"nil");
1983 d = FAKE_CSTR(&d_str,
"true");
1986 d = FAKE_CSTR(&d_str,
"false");
1989 d =
rb_protect(name_err_mesg_receiver_name, obj, &state);
2003 s = FAKE_CSTR(&s_str,
":");
2007 c = s = FAKE_CSTR(&s_str,
"");
2022 return name_err_mesg_to_str(obj);
2040 name_err_receiver(
VALUE self)
2044 recv = rb_ivar_lookup(
self, id_recv,
Qundef);
2045 if (recv !=
Qundef)
return recv;
2052 return ptr[NAME_ERR_MESG__RECV];
2064 nometh_err_args(
VALUE self)
2077 nometh_err_private_call_p(
VALUE self)
2098 key_err_receiver(
VALUE self)
2102 recv = rb_ivar_lookup(
self, id_receiver,
Qundef);
2103 if (recv !=
Qundef)
return recv;
2115 key_err_key(
VALUE self)
2119 key = rb_ivar_lookup(
self, id_key,
Qundef);
2120 if (key !=
Qundef)
return key;
2144 key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2150 if (!
NIL_P(options)) {
2152 VALUE values[numberof(keywords)];
2154 keywords[0] = id_receiver;
2155 keywords[1] = id_key;
2156 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2157 for (i = 0; i < numberof(values); ++i) {
2158 if (values[i] !=
Qundef) {
2175 no_matching_pattern_key_err_matchee(
VALUE self)
2179 matchee = rb_ivar_lookup(
self, id_matchee,
Qundef);
2180 if (matchee !=
Qundef)
return matchee;
2192 no_matching_pattern_key_err_key(
VALUE self)
2196 key = rb_ivar_lookup(
self, id_key,
Qundef);
2197 if (key !=
Qundef)
return key;
2210 no_matching_pattern_key_err_initialize(
int argc,
VALUE *argv,
VALUE self)
2216 if (!
NIL_P(options)) {
2218 VALUE values[numberof(keywords)];
2220 keywords[0] = id_matchee;
2221 keywords[1] = id_key;
2222 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2223 for (i = 0; i < numberof(values); ++i) {
2224 if (values[i] !=
Qundef) {
2242 syntax_error_initialize(
int argc,
VALUE *argv,
VALUE self)
2246 mesg = rb_fstring_lit(
"compile error");
2286 set_syserr(
int n,
const char *name)
2290 if (!st_lookup(syserr_tbl, n, &error)) {
2298 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2303 rb_eEWOULDBLOCK = error;
2306 rb_eEINPROGRESS = error;
2311 st_add_direct(syserr_tbl, n, error);
2324 if (!st_lookup(syserr_tbl, n, &error)) {
2327 snprintf(name,
sizeof(name),
"E%03d", n);
2328 error = set_syserr(n, name);
2344 syserr_initialize(
int argc,
VALUE *argv,
VALUE self)
2346 #if !defined(_WIN32)
2350 VALUE mesg, error, func, errmsg;
2354 st_data_t data = (st_data_t)klass;
2357 error = mesg; mesg =
Qnil;
2359 if (!
NIL_P(error) && st_lookup(syserr_tbl,
NUM2LONG(error), &data)) {
2360 klass = (
VALUE)data;
2365 RBASIC_SET_CLASS(
self, klass);
2373 else err =
"unknown error";
2397 syserr_errno(
VALUE self)
2827 exception_alloc(
VALUE klass)
2829 return rb_class_allocate_instance(klass);
2833 exception_dumper(
VALUE exc)
2843 ivar_copy_i(st_data_t key, st_data_t val, st_data_t exc)
2849 void rb_exc_check_circular_cause(
VALUE exc);
2865 rb_exc_check_circular_cause(exc);
2875 Init_Exception(
void)
2954 syserr_tbl = st_init_numtable();
2990 id_iseq = rb_make_internal_id();
2991 id_recv = rb_make_internal_id();
2993 sym_category =
ID2SYM(id_category);
2995 warning_categories.id2enum = rb_init_identtable();
2999 warning_categories.enum2id = rb_init_identtable();
3011 va_start(args, fmt);
3019 rb_vraise(
VALUE exc,
const char *fmt, va_list ap)
3028 va_start(args, fmt);
3029 rb_vraise(exc, fmt, args);
3033 NORETURN(
static void raise_loaderror(
VALUE path,
VALUE mesg));
3049 va_start(args, fmt);
3052 raise_loaderror(
Qnil, mesg);
3061 va_start(args, fmt);
3064 raise_loaderror(path, mesg);
3071 "%"PRIsVALUE
"() function is unimplemented on this machine",
3081 if (! ruby_thread_has_gvl_p()) {
3084 fprintf(stderr,
"[FATAL] rb_fatal() outside of GVL\n");
3085 rb_print_backtrace();
3089 va_start(args, fmt);
3097 make_errno_exc(
const char *mesg)
3103 rb_bug(
"rb_sys_fail(%s) - errno == 0", mesg ? mesg :
"");
3109 make_errno_exc_str(
VALUE mesg)
3114 if (!mesg) mesg =
Qnil;
3117 rb_bug(
"rb_sys_fail_str(%s) - errno == 0", s);
3160 #ifdef RUBY_FUNCTION_NAME_STRING
3162 rb_sys_fail_path_in(
const char *func_name,
VALUE path)
3167 rb_syserr_fail_path_in(func_name, n, path);
3171 rb_syserr_fail_path_in(
const char *func_name,
int n,
VALUE path)
3173 rb_exc_raise(rb_syserr_new_path_in(func_name, n, path));
3177 rb_syserr_new_path_in(
const char *func_name,
int n,
VALUE path)
3181 if (!path) path =
Qnil;
3184 if (!func_name) func_name =
"(null)";
3185 rb_bug(
"rb_sys_fail_path_in(%s, %s) - errno == 0",
3194 NORETURN(
static void rb_mod_exc_raise(
VALUE exc,
VALUE mod));
3206 VALUE exc = make_errno_exc(mesg);
3207 rb_mod_exc_raise(exc, mod);
3213 VALUE exc = make_errno_exc_str(mesg);
3214 rb_mod_exc_raise(exc, mod);
3221 rb_mod_exc_raise(exc, mod);
3228 rb_mod_exc_raise(exc, mod);
3232 syserr_warning(
VALUE mesg,
int err)
3236 rb_write_warning_str(mesg);
3241 rb_sys_warn(
const char *fmt, ...)
3244 int errno_save = errno;
3245 with_warning_string(mesg, 0, fmt) {
3246 syserr_warning(mesg, errno_save);
3253 rb_syserr_warn(
int err,
const char *fmt, ...)
3256 with_warning_string(mesg, 0, fmt) {
3257 syserr_warning(mesg, err);
3263 rb_sys_enc_warn(
rb_encoding *enc,
const char *fmt, ...)
3266 int errno_save = errno;
3267 with_warning_string(mesg, enc, fmt) {
3268 syserr_warning(mesg, errno_save);
3275 rb_syserr_enc_warn(
int err,
rb_encoding *enc,
const char *fmt, ...)
3278 with_warning_string(mesg, enc, fmt) {
3279 syserr_warning(mesg, err);
3289 int errno_save = errno;
3290 with_warning_string(mesg, 0, fmt) {
3291 syserr_warning(mesg, errno_save);
3299 rb_syserr_warning(
int err,
const char *fmt, ...)
3302 with_warning_string(mesg, 0, fmt) {
3303 syserr_warning(mesg, err);
3310 rb_sys_enc_warning(
rb_encoding *enc,
const char *fmt, ...)
3313 int errno_save = errno;
3314 with_warning_string(mesg, enc, fmt) {
3315 syserr_warning(mesg, errno_save);
3322 rb_syserr_enc_warning(
int err,
rb_encoding *enc,
const char *fmt, ...)
3325 with_warning_string(mesg, enc, fmt) {
3326 syserr_warning(mesg, err);
3332 rb_load_fail(
VALUE path,
const char *err)
3337 raise_loaderror(path, mesg);
3352 va_start(args, fmt);
3361 inspect_frozen_obj(
VALUE obj,
VALUE mesg,
int recur)
3376 const ID created_info = id_debug_created_info;
3388 rb_str_catf(mesg,
", created at %"PRIsVALUE
":%"PRIsVALUE, path, line);
3393 #undef rb_check_frozen
3403 rb_warn_deprecated_to_remove_at(3.2,
"rb_error_untrusted", NULL);
3406 #undef rb_check_trusted
3410 rb_warn_deprecated_to_remove_at(3.2,
"rb_check_trusted", NULL);
3424 rb_eNOERROR = set_syserr(0,
"NOERROR");
3425 #define defined_error(name, num) set_syserr((num), (name));
3426 #define undefined_error(name) set_syserr(0, (name));
3427 #include "known_errors.inc"
3428 #undef defined_error
3429 #undef undefined_error
3432 #include "warning.rbinc"
#define RUBY_DEBUG
Define this macro when you want assertions.
#define RB_UNLIKELY(x)
Asserts that the given Boolean expression likely doesn't hold.
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
VALUE rb_enc_vsprintf(rb_encoding *enc, const char *fmt, va_list ap)
Identical to rb_enc_sprintf(), except it takes a va_list instead of variadic arguments.
#define RUBY_EVENT_C_CALL
A method, written in C, is called.
#define RUBY_EVENT_C_RETURN
Return from a method, written in C.
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
VALUE rb_singleton_class(VALUE obj)
Finds or creates the singleton class of the passed object.
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
VALUE rb_define_module(const char *name)
Defines a top-level module.
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Retrieves argument from argc and argv to given VALUE references according to the format string.
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a method.
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Keyword argument deconstructor.
#define rb_str_new2
Old name of rb_str_new_cstr.
#define TYPE(_)
Old name of rb_type.
#define T_STRING
Old name of RUBY_T_STRING.
#define T_MASK
Old name of RUBY_T_MASK.
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
#define UNREACHABLE
Old name of RBIMPL_UNREACHABLE.
#define ID2SYM
Old name of RB_ID2SYM.
#define rb_str_buf_new2
Old name of rb_str_buf_new_cstr.
#define UNREACHABLE_RETURN
Old name of RBIMPL_UNREACHABLE_RETURN.
#define T_DATA
Old name of RUBY_T_DATA.
#define CLASS_OF
Old name of rb_class_of.
#define T_MODULE
Old name of RUBY_T_MODULE.
#define T_TRUE
Old name of RUBY_T_TRUE.
#define 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...
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Identical to rb_typeddata_is_kind_of(), except it raises exceptions instead of returning false.
rb_warning_category_t
Warning categories.
void rb_category_warn(rb_warning_category_t category, const char *fmt,...)
Identical to rb_category_warning(), except it reports 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.
void rb_check_frozen(VALUE obj)
Queries if the passed object is frozen.
VALUE rb_eNotImpError
NotImplementedError exception.
VALUE rb_eScriptError
ScriptError exception.
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Checks if the given object is of given kind.
void rb_syserr_fail(int e, const char *mesg)
Raises appropriate exception that represents a C errno.
VALUE rb_eKeyError
KeyError exception.
void rb_bug(const char *fmt,...)
Interpreter panic switch.
VALUE rb_cNameErrorMesg
NameError::Message class.
VALUE rb_eSystemExit
SystemExit exception.
void rb_sys_fail(const char *mesg)
Converts a C errno into a Ruby exception, then raises it.
void rb_name_error(ID id, const char *fmt,...)
Raises an instance of rb_eNameError.
void rb_sys_warning(const char *fmt,...)
Identical to rb_sys_fail(), except it does not raise an exception to render a warning instead.
void rb_check_copyable(VALUE obj, VALUE orig)
Ensures that the passed object can be initialize_copy relationship.
VALUE rb_eStandardError
StandardError exception.
VALUE rb_mErrno
Errno module.
VALUE rb_syserr_new_str(int n, VALUE arg)
Identical to rb_syserr_new(), except it takes the message in Ruby's String instead of C's.
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Identical to rb_mod_syserr_fail(), except it takes the message in Ruby's String instead of C's.
void rb_error_frozen(const char *what)
Identical to rb_frozen_error_raise(), except its raising exception has a message like "can't modify f...
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
VALUE rb_eFrozenError
FrozenError exception.
VALUE rb_eNoMemError
NoMemoryError exception.
VALUE rb_eRangeError
RangeError exception.
void rb_error_untrusted(VALUE obj)
VALUE rb_eLoadError
LoadError exception.
void rb_syserr_fail_str(int e, VALUE mesg)
Identical to rb_syserr_fail(), except it takes the message in Ruby's String instead of C's.
#define ruby_verbose
This variable controls whether the interpreter is in debug mode.
VALUE rb_eTypeError
TypeError exception.
VALUE rb_eNoMatchingPatternError
NoMatchingPatternError exception.
void rb_name_error_str(VALUE str, const char *fmt,...)
Identical to rb_name_error(), except it takes a VALUE instead of ID.
void rb_fatal(const char *fmt,...)
Raises the unsung "fatal" exception.
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Raises an instance of rb_eFrozenError.
VALUE rb_eEncCompatError
Encoding::CompatibilityError exception.
void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt,...)
Identical to rb_compile_warn(), except it also accepts category.
VALUE rb_eFatal
fatal exception.
void rb_invalid_str(const char *str, const char *type)
Honestly I don't understand the name, but it raises an instance of rb_eArgError.
VALUE rb_eInterrupt
Interrupt exception.
VALUE rb_eNameError
NameError exception.
VALUE rb_eNoMethodError
NoMethodError exception.
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
VALUE rb_eRuntimeError
RuntimeError exception.
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
void rb_warn(const char *fmt,...)
Identical to rb_warning(), except it reports 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.
void rb_check_trusted(VALUE obj)
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_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.
rb_encoding * rb_locale_encoding(void)
Queries the encoding that represents the current locale.
rb_encoding * rb_usascii_encoding(void)
Queries the encoding that represents US-ASCII.
VALUE rb_enc_str_new_cstr(const char *ptr, rb_encoding *enc)
Identical to rb_enc_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_enc_str_new(const char *ptr, long len, rb_encoding *enc)
Identical to rb_enc_str_new(), except it additionally takes an encoding.
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
VALUE rb_funcallv_kw(VALUE recv, ID mid, int argc, const VALUE *argv, int kw_splat)
Identical to rb_funcallv(), except you can specify how to handle the last element of the given array.
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcall(), except it takes the method arguments as a C array.
VALUE rb_call_super_kw(int argc, const VALUE *argv, int kw_splat)
Identical to rb_call_super(), except you can specify how to handle the last element of the given arra...
VALUE rb_call_super(int argc, const VALUE *argv)
This resembles ruby's super.
Defines RBIMPL_HAS_BUILTIN.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_entry(VALUE ary, long off)
Queries an element of an array.
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)
ID rb_frame_this_func(void)
Queries the name of the Ruby level method that is calling this function.
void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
Marks objects between the two pointers.
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Inserts or replaces ("upsert"s) the objects into the given hash table.
VALUE rb_hash_new(void)
Creates a new, empty hash object.
VALUE rb_io_puts(int argc, const VALUE *argv, VALUE io)
Iterates over the passed array to apply rb_io_write() individually.
VALUE rb_protect(VALUE(*func)(VALUE args), VALUE args, int *state)
Protects a function call from potential global escapes from the function.
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
VALUE rb_str_tmp_new(long len)
Allocates a "temporary" string.
VALUE rb_str_buf_cat(VALUE, const char *, long)
Just another name of rb_str_cat.
VALUE rb_str_cat2(VALUE, const char *)
Just another name of rb_str_cat_cstr.
VALUE rb_str_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_str_buf_new_cstr(const char *ptr)
This is a rb_str_buf_new() + rb_str_buf_cat() combo.
VALUE rb_str_new(const char *ptr, long len)
Allocates an instance of rb_cString.
VALUE rb_check_string_type(VALUE obj)
Try converting an object to its stringised representation using its to_str method,...
VALUE rb_str_new_cstr(const char *ptr)
Identical to rb_str_new(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_str_cat_cstr(VALUE dst, const char *src)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
VALUE rb_obj_as_string(VALUE obj)
Try converting an object to its stringised representation using its to_s method, if any.
VALUE rb_exec_recursive(VALUE(*f)(VALUE g, VALUE h, int r), VALUE g, VALUE h)
"Recursion" API entry point.
VALUE rb_const_get(VALUE space, ID name)
Identical to rb_const_defined(), except it returns the actual defined value.
VALUE rb_attr_get(VALUE obj, ID name)
Identical to rb_ivar_get()
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
void rb_ivar_foreach(VALUE obj, int(*func)(ID name, VALUE val, st_data_t arg), st_data_t arg)
Iterates over an object's instance variables.
VALUE rb_class_name(VALUE obj)
Queries the name of the given object's class.
int rb_respond_to(VALUE obj, ID mid)
Queries if the object responds to the method.
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well...
void rb_attr(VALUE klass, ID name, int need_reader, int need_writer, int honour_visibility)
This function resembles now-deprecated Module#attr.
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Identical to rb_funcallv(), except it returns RUBY_Qundef instead of raising rb_eNoMethodError.
void rb_define_alloc_func(VALUE klass, rb_alloc_func_t func)
Sets the allocator function of a class.
static ID rb_intern_const(const char *str)
This is a "tiny optimisation" over rb_intern().
ID rb_check_id(volatile VALUE *namep)
Detects if the given name is already interned or not.
ID rb_intern(const char *name)
Finds or creates a symbol of the given name.
VALUE rb_id2str(ID id)
Identical to rb_id2name(), except it returns a Ruby's String instead of C's.
void rb_define_const(VALUE klass, const char *name, VALUE val)
Defines a Ruby level constant under a namespace.
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.
#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 DATA_PTR(obj)
Convenient getter macro.
#define StringValue(v)
Ensures that the parameter object is a String.
static char * RSTRING_END(VALUE str)
Queries the end of the contents pointer of the string.
static char * RSTRING_PTR(VALUE str)
Queries the contents pointer of the string.
char * rb_string_value_ptr(volatile VALUE *ptr)
Identical to rb_str_to_str(), except it returns the converted string's backend memory region.
static long RSTRING_LEN(VALUE str)
Queries the length of the string.
static bool RTYPEDDATA_P(VALUE obj)
Checks whether the passed object is RTypedData or RData.
#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.
static const struct rb_data_type_struct * RTYPEDDATA_TYPE(VALUE obj)
Queries for the type of given 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.
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.
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.