Ruby  2.7.2p137(2020-10-01revision5445e0435260b449decf2ac16f9d09bae3cafe72)
error.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  error.c -
4 
5  $Author$
6  created at: Mon Aug 9 16:11:34 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 #include "ruby/encoding.h"
13 #include "ruby/st.h"
14 #include "internal.h"
15 #include "ruby_assert.h"
16 #include "vm_core.h"
17 #include "builtin.h"
18 
19 #include <stdio.h>
20 #include <stdarg.h>
21 #ifdef HAVE_STDLIB_H
22 #include <stdlib.h>
23 #endif
24 #include <errno.h>
25 #ifdef HAVE_UNISTD_H
26 #include <unistd.h>
27 #endif
28 
29 #if defined __APPLE__
30 # include <AvailabilityMacros.h>
31 #endif
32 
38 #ifndef EXIT_SUCCESS
39 #define EXIT_SUCCESS 0
40 #endif
41 
42 #ifndef WIFEXITED
43 #define WIFEXITED(status) 1
44 #endif
45 
46 #ifndef WEXITSTATUS
47 #define WEXITSTATUS(status) (status)
48 #endif
49 
53 
57 static VALUE rb_mWarning;
58 static VALUE rb_cWarningBuffer;
59 
60 static ID id_warn;
61 
62 extern const char ruby_description[];
63 
64 static const char *
65 rb_strerrno(int err)
66 {
67 #define defined_error(name, num) if (err == (num)) return (name);
68 #define undefined_error(name)
69 #include "known_errors.inc"
70 #undef defined_error
71 #undef undefined_error
72  return NULL;
73 }
74 
75 static int
76 err_position_0(char *buf, long len, const char *file, int line)
77 {
78  if (!file) {
79  return 0;
80  }
81  else if (line == 0) {
82  return snprintf(buf, len, "%s: ", file);
83  }
84  else {
85  return snprintf(buf, len, "%s:%d: ", file, line);
86  }
87 }
88 
89 static VALUE
90 err_vcatf(VALUE str, const char *pre, const char *file, int line,
91  const char *fmt, va_list args)
92 {
93  if (file) {
94  rb_str_cat2(str, file);
95  if (line) rb_str_catf(str, ":%d", line);
96  rb_str_cat2(str, ": ");
97  }
98  if (pre) rb_str_cat2(str, pre);
99  rb_str_vcatf(str, fmt, args);
100  return str;
101 }
102 
103 VALUE
104 rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
105  rb_encoding *enc, const char *fmt, va_list args)
106 {
107  const char *fn = NIL_P(file) ? NULL : RSTRING_PTR(file);
108  if (!exc) {
109  VALUE mesg = rb_enc_str_new(0, 0, enc);
110  err_vcatf(mesg, NULL, fn, line, fmt, args);
111  rb_str_cat2(mesg, "\n");
112  rb_write_error_str(mesg);
113  }
114  else {
115  VALUE mesg;
116  if (NIL_P(exc)) {
117  mesg = rb_enc_str_new(0, 0, enc);
119  }
120  else {
121  mesg = rb_attr_get(exc, idMesg);
122  if (RSTRING_LEN(mesg) > 0 && *(RSTRING_END(mesg)-1) != '\n')
123  rb_str_cat_cstr(mesg, "\n");
124  }
125  err_vcatf(mesg, NULL, fn, line, fmt, args);
126  }
127 
128  return exc;
129 }
130 
131 static unsigned int warning_disabled_categories = (
133  0);
134 
135 static unsigned int
136 rb_warning_category_mask(VALUE category)
137 {
138  return 1U << rb_warning_category_from_name(category);
139 }
140 
143 {
145  Check_Type(category, T_SYMBOL);
146  if (category == ID2SYM(rb_intern("deprecated"))) {
148  }
149  else if (category == ID2SYM(rb_intern("experimental"))) {
151  }
152  else {
153  rb_raise(rb_eArgError, "unknown category: %"PRIsVALUE, category);
154  }
155  return cat;
156 }
157 
158 void
159 rb_warning_category_update(unsigned int mask, unsigned int bits)
160 {
161  warning_disabled_categories &= ~mask;
162  warning_disabled_categories |= mask & ~bits;
163 }
164 
167 {
168  return !(warning_disabled_categories & (1U << category));
169 }
170 
171 /*
172  * call-seq
173  * Warning[category] -> true or false
174  *
175  * Returns the flag to show the warning messages for +category+.
176  * Supported categories are:
177  *
178  * +:deprecated+ :: deprecation warnings
179  * * assignment of non-nil value to <code>$,</code> and <code>$;</code>
180  * * keyword arguments
181  * * proc/lambda without block
182  * etc.
183  *
184  * +:experimental+ :: experimental features
185  * * Pattern matching
186  */
187 
188 static VALUE
189 rb_warning_s_aref(VALUE mod, VALUE category)
190 {
193  return Qtrue;
194  return Qfalse;
195 }
196 
197 /*
198  * call-seq
199  * Warning[category] = flag -> flag
200  *
201  * Sets the warning flags for +category+.
202  * See Warning.[] for the categories.
203  */
204 
205 static VALUE
206 rb_warning_s_aset(VALUE mod, VALUE category, VALUE flag)
207 {
208  unsigned int mask = rb_warning_category_mask(category);
209  unsigned int disabled = warning_disabled_categories;
210  if (!RTEST(flag))
211  disabled |= mask;
212  else
213  disabled &= ~mask;
214  warning_disabled_categories = disabled;
215  return flag;
216 }
217 
218 /*
219  * call-seq:
220  * warn(msg) -> nil
221  *
222  * Writes warning message +msg+ to $stderr. This method is called by
223  * Ruby for all emitted warnings.
224  */
225 
226 static VALUE
227 rb_warning_s_warn(VALUE mod, VALUE str)
228 {
232  return Qnil;
233 }
234 
235 /*
236  * Document-module: Warning
237  *
238  * The Warning module contains a single method named #warn, and the
239  * module extends itself, making Warning.warn available.
240  * Warning.warn is called for all warnings issued by Ruby.
241  * By default, warnings are printed to $stderr.
242  *
243  * By overriding Warning.warn, you can change how warnings are
244  * handled by Ruby, either filtering some warnings, and/or outputting
245  * warnings somewhere other than $stderr. When Warning.warn is
246  * overridden, super can be called to get the default behavior of
247  * printing the warning to $stderr.
248  */
249 
250 static VALUE
251 rb_warning_warn(VALUE mod, VALUE str)
252 {
253  return rb_funcallv(mod, id_warn, 1, &str);
254 }
255 
256 static void
257 rb_write_warning_str(VALUE str)
258 {
259  rb_warning_warn(rb_mWarning, str);
260 }
261 
262 static VALUE
263 warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
264 {
265  VALUE str = rb_enc_str_new(0, 0, enc);
266 
267  err_vcatf(str, "warning: ", file, line, fmt, args);
268  return rb_str_cat2(str, "\n");
269 }
270 
271 void
272 rb_compile_warn(const char *file, int line, const char *fmt, ...)
273 {
274  VALUE str;
275  va_list args;
276 
277  if (NIL_P(ruby_verbose)) return;
278 
279  va_start(args, fmt);
280  str = warn_vsprintf(NULL, file, line, fmt, args);
281  va_end(args);
282  rb_write_warning_str(str);
283 }
284 
285 /* rb_compile_warning() reports only in verbose mode */
286 void
287 rb_compile_warning(const char *file, int line, const char *fmt, ...)
288 {
289  VALUE str;
290  va_list args;
291 
292  if (!RTEST(ruby_verbose)) return;
293 
294  va_start(args, fmt);
295  str = warn_vsprintf(NULL, file, line, fmt, args);
296  va_end(args);
297  rb_write_warning_str(str);
298 }
299 
300 static VALUE
301 warning_string(rb_encoding *enc, const char *fmt, va_list args)
302 {
303  int line;
304  const char *file = rb_source_location_cstr(&line);
305  return warn_vsprintf(enc, file, line, fmt, args);
306 }
307 
308 #define with_warning_string(mesg, enc, fmt) \
309  VALUE mesg; \
310  va_list args; va_start(args, fmt); \
311  mesg = warning_string(enc, fmt, args); \
312  va_end(args);
313 
314 void
315 rb_warn(const char *fmt, ...)
316 {
317  if (!NIL_P(ruby_verbose)) {
318  with_warning_string(mesg, 0, fmt) {
319  rb_write_warning_str(mesg);
320  }
321  }
322 }
323 
324 void
325 rb_enc_warn(rb_encoding *enc, const char *fmt, ...)
326 {
327  if (!NIL_P(ruby_verbose)) {
328  with_warning_string(mesg, enc, fmt) {
329  rb_write_warning_str(mesg);
330  }
331  }
332 }
333 
334 /* rb_warning() reports only in verbose mode */
335 void
336 rb_warning(const char *fmt, ...)
337 {
338  if (RTEST(ruby_verbose)) {
339  with_warning_string(mesg, 0, fmt) {
340  rb_write_warning_str(mesg);
341  }
342  }
343 }
344 
345 VALUE
346 rb_warning_string(const char *fmt, ...)
347 {
348  with_warning_string(mesg, 0, fmt) {
349  }
350  return mesg;
351 }
352 
353 #if 0
354 void
355 rb_enc_warning(rb_encoding *enc, const char *fmt, ...)
356 {
357  if (RTEST(ruby_verbose)) {
358  with_warning_string(mesg, enc, fmt) {
359  rb_write_warning_str(mesg);
360  }
361  }
362 }
363 #endif
364 
365 void
366 rb_warn_deprecated(const char *fmt, const char *suggest, ...)
367 {
368  if (NIL_P(ruby_verbose)) return;
370  va_list args;
371  va_start(args, suggest);
372  VALUE mesg = warning_string(0, fmt, args);
373  va_end(args);
374  rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1);
375  rb_str_cat_cstr(mesg, " is deprecated");
376  if (suggest) rb_str_catf(mesg, "; use %s instead", suggest);
377  rb_str_cat_cstr(mesg, "\n");
378  rb_write_warning_str(mesg);
379 }
380 
381 static inline int
382 end_with_asciichar(VALUE str, int c)
383 {
384  return RB_TYPE_P(str, T_STRING) &&
386 }
387 
388 /* :nodoc: */
389 static VALUE
390 warning_write(int argc, VALUE *argv, VALUE buf)
391 {
392  while (argc-- > 0) {
393  rb_str_append(buf, *argv++);
394  }
395  return buf;
396 }
397 
399 static VALUE
400 rb_warn_m(rb_execution_context_t *ec, VALUE exc, VALUE msgs, VALUE uplevel)
401 {
402  VALUE location = Qnil;
403  int argc = RARRAY_LENINT(msgs);
404  const VALUE *argv = RARRAY_CONST_PTR(msgs);
405 
406  if (!NIL_P(ruby_verbose) && argc > 0) {
407  VALUE str = argv[0];
408  if (!NIL_P(uplevel)) {
409  long lev = NUM2LONG(uplevel);
410  if (lev < 0) {
411  rb_raise(rb_eArgError, "negative level (%ld)", lev);
412  }
413  location = rb_ec_backtrace_location_ary(ec, lev + 1, 1);
414  if (!NIL_P(location)) {
415  location = rb_ary_entry(location, 0);
416  }
417  }
418  if (argc > 1 || !NIL_P(uplevel) || !end_with_asciichar(str, '\n')) {
419  VALUE path;
420  if (NIL_P(uplevel)) {
421  str = rb_str_tmp_new(0);
422  }
423  else if (NIL_P(location) ||
424  NIL_P(path = rb_funcall(location, rb_intern("path"), 0))) {
425  str = rb_str_new_cstr("warning: ");
426  }
427  else {
428  str = rb_sprintf("%s:%ld: warning: ",
430  NUM2LONG(rb_funcall(location, rb_intern("lineno"), 0)));
431  }
432  RBASIC_SET_CLASS(str, rb_cWarningBuffer);
433  rb_io_puts(argc, argv, str);
435  }
436  if (exc == rb_mWarning) {
439  }
440  else {
441  rb_write_warning_str(str);
442  }
443  }
444  return Qnil;
445 }
446 
447 #define MAX_BUG_REPORTERS 0x100
448 
449 static struct bug_reporters {
450  void (*func)(FILE *out, void *data);
451  void *data;
452 } bug_reporters[MAX_BUG_REPORTERS];
453 
454 static int bug_reporters_size;
455 
456 int
457 rb_bug_reporter_add(void (*func)(FILE *, void *), void *data)
458 {
459  struct bug_reporters *reporter;
460  if (bug_reporters_size >= MAX_BUG_REPORTERS) {
461  return 0; /* failed to register */
462  }
463  reporter = &bug_reporters[bug_reporters_size++];
464  reporter->func = func;
465  reporter->data = data;
466 
467  return 1;
468 }
469 
470 /* SIGSEGV handler might have a very small stack. Thus we need to use it carefully. */
471 #define REPORT_BUG_BUFSIZ 256
472 static FILE *
473 bug_report_file(const char *file, int line)
474 {
475  char buf[REPORT_BUG_BUFSIZ];
476  FILE *out = stderr;
477  int len = err_position_0(buf, sizeof(buf), file, line);
478 
479  if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
480  (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
481  return out;
482  }
483 
484  return NULL;
485 }
486 
487 FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len));
488 
489 static void
490 bug_important_message(FILE *out, const char *const msg, size_t len)
491 {
492  const char *const endmsg = msg + len;
493  const char *p = msg;
494 
495  if (!len) return;
496  if (isatty(fileno(out))) {
497  static const char red[] = "\033[;31;1;7m";
498  static const char green[] = "\033[;32;7m";
499  static const char reset[] = "\033[m";
500  const char *e = strchr(p, '\n');
501  const int w = (int)(e - p);
502  do {
503  int i = (int)(e - p);
504  fputs(*p == ' ' ? green : red, out);
505  fwrite(p, 1, e - p, out);
506  for (; i < w; ++i) fputc(' ', out);
507  fputs(reset, out);
508  fputc('\n', out);
509  } while ((p = e + 1) < endmsg && (e = strchr(p, '\n')) != 0 && e > p + 1);
510  }
511  fwrite(p, 1, endmsg - p, out);
512 }
513 
514 static void
515 preface_dump(FILE *out)
516 {
517 #if defined __APPLE__
518  static const char msg[] = ""
519  "-- Crash Report log information "
520  "--------------------------------------------\n"
521  " See Crash Report log file under the one of following:\n"
522 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
523  " * ~/Library/Logs/CrashReporter\n"
524  " * /Library/Logs/CrashReporter\n"
525 # endif
526  " * ~/Library/Logs/DiagnosticReports\n"
527  " * /Library/Logs/DiagnosticReports\n"
528  " for more details.\n"
529  "Don't forget to include the above Crash Report log file in bug reports.\n"
530  "\n";
531  const size_t msglen = sizeof(msg) - 1;
532 #else
533  const char *msg = NULL;
534  const size_t msglen = 0;
535 #endif
536  bug_important_message(out, msg, msglen);
537 }
538 
539 static void
540 postscript_dump(FILE *out)
541 {
542 #if defined __APPLE__
543  static const char msg[] = ""
544  "[IMPORTANT]"
545  /*" ------------------------------------------------"*/
546  "\n""Don't forget to include the Crash Report log file under\n"
547 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
548  "CrashReporter or "
549 # endif
550  "DiagnosticReports directory in bug reports.\n"
551  /*"------------------------------------------------------------\n"*/
552  "\n";
553  const size_t msglen = sizeof(msg) - 1;
554 #else
555  const char *msg = NULL;
556  const size_t msglen = 0;
557 #endif
558  bug_important_message(out, msg, msglen);
559 }
560 
561 static void
562 bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
563 {
564  char buf[REPORT_BUG_BUFSIZ];
565 
566  fputs("[BUG] ", out);
567  vsnprintf(buf, sizeof(buf), fmt, args);
568  fputs(buf, out);
569  snprintf(buf, sizeof(buf), "\n%s\n\n", ruby_description);
570  fputs(buf, out);
571  preface_dump(out);
572 
573 #if RUBY_DEVEL
574  const char *cmd = getenv("RUBY_ON_BUG");
575  if (cmd) {
576  snprintf(buf, sizeof(buf), "%s %"PRI_PIDT_PREFIX"d", cmd, getpid());
577  int r = system(buf);
578  if (r == -1) {
579  snprintf(buf, sizeof(buf), "Launching RUBY_ON_BUG command failed.");
580  }
581  }
582 #endif
583 }
584 
585 #define bug_report_begin(out, fmt) do { \
586  va_list args; \
587  va_start(args, fmt); \
588  bug_report_begin_valist(out, fmt, args); \
589  va_end(args); \
590 } while (0)
591 
592 static void
593 bug_report_end(FILE *out)
594 {
595  /* call additional bug reporters */
596  {
597  int i;
598  for (i=0; i<bug_reporters_size; i++) {
599  struct bug_reporters *reporter = &bug_reporters[i];
600  (*reporter->func)(out, reporter->data);
601  }
602  }
603  postscript_dump(out);
604 }
605 
606 #define report_bug(file, line, fmt, ctx) do { \
607  FILE *out = bug_report_file(file, line); \
608  if (out) { \
609  bug_report_begin(out, fmt); \
610  rb_vm_bugreport(ctx); \
611  bug_report_end(out); \
612  } \
613 } while (0) \
614 
615 #define report_bug_valist(file, line, fmt, ctx, args) do { \
616  FILE *out = bug_report_file(file, line); \
617  if (out) { \
618  bug_report_begin_valist(out, fmt, args); \
619  rb_vm_bugreport(ctx); \
620  bug_report_end(out); \
621  } \
622 } while (0) \
623 
624 NORETURN(static void die(void));
625 static void
626 die(void)
627 {
628 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
629  _set_abort_behavior( 0, _CALL_REPORTFAULT);
630 #endif
631 
632  abort();
633 }
634 
635 void
636 rb_bug(const char *fmt, ...)
637 {
638  const char *file = NULL;
639  int line = 0;
640 
641  if (GET_EC()) {
642  file = rb_source_location_cstr(&line);
643  }
644 
645  report_bug(file, line, fmt, NULL);
646 
647  die();
648 }
649 
650 void
651 rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *ctx, const char *fmt, ...)
652 {
653  const char *file = NULL;
654  int line = 0;
655 
656  if (GET_EC()) {
657  file = rb_source_location_cstr(&line);
658  }
659 
660  report_bug(file, line, fmt, ctx);
661 
662  if (default_sighandler) default_sighandler(sig);
663 
664  die();
665 }
666 
667 
668 void
669 rb_bug_errno(const char *mesg, int errno_arg)
670 {
671  if (errno_arg == 0)
672  rb_bug("%s: errno == 0 (NOERROR)", mesg);
673  else {
674  const char *errno_str = rb_strerrno(errno_arg);
675  if (errno_str)
676  rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
677  else
678  rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
679  }
680 }
681 
682 /*
683  * this is safe to call inside signal handler and timer thread
684  * (which isn't a Ruby Thread object)
685  */
686 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
687 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
688 
689 void
690 rb_async_bug_errno(const char *mesg, int errno_arg)
691 {
692  WRITE_CONST(2, "[ASYNC BUG] ");
693  write_or_abort(2, mesg, strlen(mesg));
694  WRITE_CONST(2, "\n");
695 
696  if (errno_arg == 0) {
697  WRITE_CONST(2, "errno == 0 (NOERROR)\n");
698  }
699  else {
700  const char *errno_str = rb_strerrno(errno_arg);
701 
702  if (!errno_str)
703  errno_str = "undefined errno";
704  write_or_abort(2, errno_str, strlen(errno_str));
705  }
706  WRITE_CONST(2, "\n\n");
708  abort();
709 }
710 
711 void
712 rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
713 {
714  report_bug_valist(RSTRING_PTR(file), line, fmt, NULL, args);
715 }
716 
718 rb_assert_failure(const char *file, int line, const char *name, const char *expr)
719 {
720  FILE *out = stderr;
721  fprintf(out, "Assertion Failed: %s:%d:", file, line);
722  if (name) fprintf(out, "%s:", name);
723  fprintf(out, "%s\n%s\n\n", expr, ruby_description);
724  preface_dump(out);
726  bug_report_end(out);
727  die();
728 }
729 
730 static const char builtin_types[][10] = {
731  "", /* 0x00, */
732  "Object",
733  "Class",
734  "Module",
735  "Float",
736  "String",
737  "Regexp",
738  "Array",
739  "Hash",
740  "Struct",
741  "Bignum",
742  "File",
743  "Data", /* internal use: wrapped C pointers */
744  "MatchData", /* data of $~ */
745  "Complex",
746  "Rational",
747  "", /* 0x10 */
748  "nil",
749  "true",
750  "false",
751  "Symbol", /* :symbol */
752  "Fixnum",
753  "undef", /* internal use: #undef; should not happen */
754  "", /* 0x17 */
755  "", /* 0x18 */
756  "", /* 0x19 */
757  "Memo", /* internal use: general memo */
758  "Node", /* internal use: syntax tree node */
759  "iClass", /* internal use: mixed-in module holder */
760 };
761 
762 const char *
764 {
765  const char *name;
766  if ((unsigned int)t >= numberof(builtin_types)) return 0;
767  name = builtin_types[t];
768  if (*name) return name;
769  return 0;
770 }
771 
772 static const char *
773 builtin_class_name(VALUE x)
774 {
775  const char *etype;
776 
777  if (NIL_P(x)) {
778  etype = "nil";
779  }
780  else if (FIXNUM_P(x)) {
781  etype = "Integer";
782  }
783  else if (SYMBOL_P(x)) {
784  etype = "Symbol";
785  }
786  else if (RB_TYPE_P(x, T_TRUE)) {
787  etype = "true";
788  }
789  else if (RB_TYPE_P(x, T_FALSE)) {
790  etype = "false";
791  }
792  else {
793  etype = NULL;
794  }
795  return etype;
796 }
797 
798 const char *
800 {
801  const char *etype = builtin_class_name(x);
802 
803  if (!etype) {
804  etype = rb_obj_classname(x);
805  }
806  return etype;
807 }
808 
809 NORETURN(static void unexpected_type(VALUE, int, int));
810 #define UNDEF_LEAKED "undef leaked to the Ruby space"
811 
812 static void
813 unexpected_type(VALUE x, int xt, int t)
814 {
815  const char *tname = rb_builtin_type_name(t);
816  VALUE mesg, exc = rb_eFatal;
817 
818  if (tname) {
819  const char *cname = builtin_class_name(x);
820  if (cname)
821  mesg = rb_sprintf("wrong argument type %s (expected %s)",
822  cname, tname);
823  else
824  mesg = rb_sprintf("wrong argument type %"PRIsVALUE" (expected %s)",
825  rb_obj_class(x), tname);
826  exc = rb_eTypeError;
827  }
828  else if (xt > T_MASK && xt <= 0x3f) {
829  mesg = rb_sprintf("unknown type 0x%x (0x%x given, probably comes"
830  " from extension library for ruby 1.8)", t, xt);
831  }
832  else {
833  mesg = rb_sprintf("unknown type 0x%x (0x%x given)", t, xt);
834  }
836 }
837 
838 void
840 {
841  int xt;
842 
843  if (x == Qundef) {
845  }
846 
847  xt = TYPE(x);
848  if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
849  unexpected_type(x, xt, t);
850  }
851 }
852 
853 void
855 {
856  if (x == Qundef) {
858  }
859 
860  unexpected_type(x, TYPE(x), t);
861 }
862 
863 int
865 {
866  while (child) {
867  if (child == parent) return 1;
868  child = child->parent;
869  }
870  return 0;
871 }
872 
873 int
875 {
876  if (!RB_TYPE_P(obj, T_DATA) ||
878  return 0;
879  }
880  return 1;
881 }
882 
883 #undef rb_typeddata_is_instance_of
884 int
886 {
887  return rb_typeddata_is_instance_of_inline(obj, data_type);
888 }
889 
890 void *
892 {
893  const char *etype;
894 
895  if (!RB_TYPE_P(obj, T_DATA)) {
896  wrong_type:
897  etype = builtin_class_name(obj);
898  if (!etype)
899  rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)",
900  rb_obj_class(obj), data_type->wrap_struct_name);
901  wrong_datatype:
902  rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
903  etype, data_type->wrap_struct_name);
904  }
905  if (!RTYPEDDATA_P(obj)) {
906  goto wrong_type;
907  }
908  else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
909  etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
910  goto wrong_datatype;
911  }
912  return DATA_PTR(obj);
913 }
914 
915 /* exception classes */
938 
942 
945 static VALUE rb_eNOERROR;
946 
948 #define id_cause ruby_static_id_cause
949 static ID id_message, id_backtrace;
950 static ID id_key, id_args, id_Errno, id_errno, id_i_path;
951 static ID id_receiver, id_recv, id_iseq, id_local_variables;
952 static ID id_private_call_p, id_top, id_bottom;
953 #define id_bt idBt
954 #define id_bt_locations idBt_locations
955 #define id_mesg idMesg
956 #define id_name idName
957 
958 #undef rb_exc_new_cstr
959 
960 VALUE
961 rb_exc_new(VALUE etype, const char *ptr, long len)
962 {
963  VALUE mesg = rb_str_new(ptr, len);
964  return rb_class_new_instance(1, &mesg, etype);
965 }
966 
967 VALUE
968 rb_exc_new_cstr(VALUE etype, const char *s)
969 {
970  return rb_exc_new(etype, s, strlen(s));
971 }
972 
973 VALUE
975 {
976  StringValue(str);
977  return rb_class_new_instance(1, &str, etype);
978 }
979 
980 static VALUE
981 exc_init(VALUE exc, VALUE mesg)
982 {
983  rb_ivar_set(exc, id_mesg, mesg);
985 
986  return exc;
987 }
988 
989 /*
990  * call-seq:
991  * Exception.new(msg = nil) -> exception
992  *
993  * Construct a new Exception object, optionally passing in
994  * a message.
995  */
996 
997 static VALUE
998 exc_initialize(int argc, VALUE *argv, VALUE exc)
999 {
1000  VALUE arg;
1001 
1002  arg = (!rb_check_arity(argc, 0, 1) ? Qnil : argv[0]);
1003  return exc_init(exc, arg);
1004 }
1005 
1006 /*
1007  * Document-method: exception
1008  *
1009  * call-seq:
1010  * exc.exception(string) -> an_exception or exc
1011  *
1012  * With no argument, or if the argument is the same as the receiver,
1013  * return the receiver. Otherwise, create a new
1014  * exception object of the same class as the receiver, but with a
1015  * message equal to <code>string.to_str</code>.
1016  *
1017  */
1018 
1019 static VALUE
1020 exc_exception(int argc, VALUE *argv, VALUE self)
1021 {
1022  VALUE exc;
1023 
1024  argc = rb_check_arity(argc, 0, 1);
1025  if (argc == 0) return self;
1026  if (argc == 1 && self == argv[0]) return self;
1027  exc = rb_obj_clone(self);
1028  rb_ivar_set(exc, id_mesg, argv[0]);
1029  return exc;
1030 }
1031 
1032 /*
1033  * call-seq:
1034  * exception.to_s -> string
1035  *
1036  * Returns exception's message (or the name of the exception if
1037  * no message is set).
1038  */
1039 
1040 static VALUE
1041 exc_to_s(VALUE exc)
1042 {
1043  VALUE mesg = rb_attr_get(exc, idMesg);
1044 
1045  if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
1046  return rb_String(mesg);
1047 }
1048 
1049 /* FIXME: Include eval_error.c */
1050 void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse);
1051 
1052 VALUE
1054 {
1055  VALUE e = rb_check_funcall(exc, id_message, 0, 0);
1056  if (e == Qundef) return Qnil;
1057  if (!RB_TYPE_P(e, T_STRING)) e = rb_check_string_type(e);
1058  return e;
1059 }
1060 
1061 /*
1062  * call-seq:
1063  * Exception.to_tty? -> true or false
1064  *
1065  * Returns +true+ if exception messages will be sent to a tty.
1066  */
1067 static VALUE
1068 exc_s_to_tty_p(VALUE self)
1069 {
1070  return rb_stderr_tty_p() ? Qtrue : Qfalse;
1071 }
1072 
1073 /*
1074  * call-seq:
1075  * exception.full_message(highlight: bool, order: [:top or :bottom]) -> string
1076  *
1077  * Returns formatted string of _exception_.
1078  * The returned string is formatted using the same format that Ruby uses
1079  * when printing an uncaught exceptions to stderr.
1080  *
1081  * If _highlight_ is +true+ the default error handler will send the
1082  * messages to a tty.
1083  *
1084  * _order_ must be either of +:top+ or +:bottom+, and places the error
1085  * message and the innermost backtrace come at the top or the bottom.
1086  *
1087  * The default values of these options depend on <code>$stderr</code>
1088  * and its +tty?+ at the timing of a call.
1089  */
1090 
1091 static VALUE
1092 exc_full_message(int argc, VALUE *argv, VALUE exc)
1093 {
1094  VALUE opt, str, emesg, errat;
1095  enum {kw_highlight, kw_order, kw_max_};
1096  static ID kw[kw_max_];
1097  VALUE args[kw_max_] = {Qnil, Qnil};
1098 
1099  rb_scan_args(argc, argv, "0:", &opt);
1100  if (!NIL_P(opt)) {
1101  if (!kw[0]) {
1102 #define INIT_KW(n) kw[kw_##n] = rb_intern_const(#n)
1103  INIT_KW(highlight);
1104  INIT_KW(order);
1105 #undef INIT_KW
1106  }
1107  rb_get_kwargs(opt, kw, 0, kw_max_, args);
1108  switch (args[kw_highlight]) {
1109  default:
1110  rb_raise(rb_eArgError, "expected true or false as "
1111  "highlight: %+"PRIsVALUE, args[kw_highlight]);
1112  case Qundef: args[kw_highlight] = Qnil; break;
1113  case Qtrue: case Qfalse: case Qnil: break;
1114  }
1115  if (args[kw_order] == Qundef) {
1116  args[kw_order] = Qnil;
1117  }
1118  else {
1119  ID id = rb_check_id(&args[kw_order]);
1120  if (id == id_bottom) args[kw_order] = Qtrue;
1121  else if (id == id_top) args[kw_order] = Qfalse;
1122  else {
1123  rb_raise(rb_eArgError, "expected :top or :bottom as "
1124  "order: %+"PRIsVALUE, args[kw_order]);
1125  }
1126  }
1127  }
1128  str = rb_str_new2("");
1129  errat = rb_get_backtrace(exc);
1130  emesg = rb_get_message(exc);
1131 
1132  rb_error_write(exc, emesg, errat, str, args[kw_highlight], args[kw_order]);
1133  return str;
1134 }
1135 
1136 /*
1137  * call-seq:
1138  * exception.message -> string
1139  *
1140  * Returns the result of invoking <code>exception.to_s</code>.
1141  * Normally this returns the exception's message or name.
1142  */
1143 
1144 static VALUE
1145 exc_message(VALUE exc)
1146 {
1147  return rb_funcallv(exc, idTo_s, 0, 0);
1148 }
1149 
1150 /*
1151  * call-seq:
1152  * exception.inspect -> string
1153  *
1154  * Return this exception's class name and message.
1155  */
1156 
1157 static VALUE
1158 exc_inspect(VALUE exc)
1159 {
1160  VALUE str, klass;
1161 
1162  klass = CLASS_OF(exc);
1164  if (RSTRING_LEN(exc) == 0) {
1165  return rb_class_name(klass);
1166  }
1167 
1168  str = rb_str_buf_new2("#<");
1171  rb_str_buf_cat(str, ": ", 2);
1173  rb_str_buf_cat(str, ">", 1);
1174 
1175  return str;
1176 }
1177 
1178 /*
1179  * call-seq:
1180  * exception.backtrace -> array or nil
1181  *
1182  * Returns any backtrace associated with the exception. The backtrace
1183  * is an array of strings, each containing either ``filename:lineNo: in
1184  * `method''' or ``filename:lineNo.''
1185  *
1186  * def a
1187  * raise "boom"
1188  * end
1189  *
1190  * def b
1191  * a()
1192  * end
1193  *
1194  * begin
1195  * b()
1196  * rescue => detail
1197  * print detail.backtrace.join("\n")
1198  * end
1199  *
1200  * <em>produces:</em>
1201  *
1202  * prog.rb:2:in `a'
1203  * prog.rb:6:in `b'
1204  * prog.rb:10
1205  *
1206  * In the case no backtrace has been set, +nil+ is returned
1207  *
1208  * ex = StandardError.new
1209  * ex.backtrace
1210  * #=> nil
1211 */
1212 
1213 static VALUE
1214 exc_backtrace(VALUE exc)
1215 {
1216  VALUE obj;
1217 
1218  obj = rb_attr_get(exc, id_bt);
1219 
1220  if (rb_backtrace_p(obj)) {
1222  /* rb_ivar_set(exc, id_bt, obj); */
1223  }
1224 
1225  return obj;
1226 }
1227 
1228 static VALUE rb_check_backtrace(VALUE);
1229 
1230 VALUE
1232 {
1233  ID mid = id_backtrace;
1234  VALUE info;
1235  if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) {
1238  if (NIL_P(exc))
1239  return Qnil;
1240  EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
1241  info = exc_backtrace(exc);
1242  EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
1243  }
1244  else {
1245  info = rb_funcallv(exc, mid, 0, 0);
1246  }
1247  if (NIL_P(info)) return Qnil;
1248  return rb_check_backtrace(info);
1249 }
1250 
1251 /*
1252  * call-seq:
1253  * exception.backtrace_locations -> array or nil
1254  *
1255  * Returns any backtrace associated with the exception. This method is
1256  * similar to Exception#backtrace, but the backtrace is an array of
1257  * Thread::Backtrace::Location.
1258  *
1259  * This method is not affected by Exception#set_backtrace().
1260  */
1261 static VALUE
1262 exc_backtrace_locations(VALUE exc)
1263 {
1264  VALUE obj;
1265 
1267  if (!NIL_P(obj)) {
1269  }
1270  return obj;
1271 }
1272 
1273 static VALUE
1274 rb_check_backtrace(VALUE bt)
1275 {
1276  long i;
1277  static const char err[] = "backtrace must be Array of String";
1278 
1279  if (!NIL_P(bt)) {
1280  if (RB_TYPE_P(bt, T_STRING)) return rb_ary_new3(1, bt);
1281  if (rb_backtrace_p(bt)) return bt;
1282  if (!RB_TYPE_P(bt, T_ARRAY)) {
1284  }
1285  for (i=0;i<RARRAY_LEN(bt);i++) {
1286  VALUE e = RARRAY_AREF(bt, i);
1287  if (!RB_TYPE_P(e, T_STRING)) {
1289  }
1290  }
1291  }
1292  return bt;
1293 }
1294 
1295 /*
1296  * call-seq:
1297  * exc.set_backtrace(backtrace) -> array
1298  *
1299  * Sets the backtrace information associated with +exc+. The +backtrace+ must
1300  * be an array of String objects or a single String in the format described
1301  * in Exception#backtrace.
1302  *
1303  */
1304 
1305 static VALUE
1306 exc_set_backtrace(VALUE exc, VALUE bt)
1307 {
1308  return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1309 }
1310 
1313 {
1314  return exc_set_backtrace(exc, bt);
1315 }
1316 
1317 /*
1318  * call-seq:
1319  * exception.cause -> an_exception or nil
1320  *
1321  * Returns the previous exception ($!) at the time this exception was raised.
1322  * This is useful for wrapping exceptions and retaining the original exception
1323  * information.
1324  */
1325 
1326 static VALUE
1327 exc_cause(VALUE exc)
1328 {
1329  return rb_attr_get(exc, id_cause);
1330 }
1331 
1332 static VALUE
1333 try_convert_to_exception(VALUE obj)
1334 {
1335  return rb_check_funcall(obj, idException, 0, 0);
1336 }
1337 
1338 /*
1339  * call-seq:
1340  * exc == obj -> true or false
1341  *
1342  * Equality---If <i>obj</i> is not an Exception, returns
1343  * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
1344  * <i>obj</i> share same class, messages, and backtrace.
1345  */
1346 
1347 static VALUE
1348 exc_equal(VALUE exc, VALUE obj)
1349 {
1350  VALUE mesg, backtrace;
1351 
1352  if (exc == obj) return Qtrue;
1353 
1354  if (rb_obj_class(exc) != rb_obj_class(obj)) {
1355  int state;
1356 
1357  obj = rb_protect(try_convert_to_exception, obj, &state);
1358  if (state || obj == Qundef) {
1360  return Qfalse;
1361  }
1362  if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
1363  mesg = rb_check_funcall(obj, id_message, 0, 0);
1364  if (mesg == Qundef) return Qfalse;
1365  backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
1366  if (backtrace == Qundef) return Qfalse;
1367  }
1368  else {
1369  mesg = rb_attr_get(obj, id_mesg);
1370  backtrace = exc_backtrace(obj);
1371  }
1372 
1373  if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
1374  return Qfalse;
1375  if (!rb_equal(exc_backtrace(exc), backtrace))
1376  return Qfalse;
1377  return Qtrue;
1378 }
1379 
1380 /*
1381  * call-seq:
1382  * SystemExit.new -> system_exit
1383  * SystemExit.new(status) -> system_exit
1384  * SystemExit.new(status, msg) -> system_exit
1385  * SystemExit.new(msg) -> system_exit
1386  *
1387  * Create a new +SystemExit+ exception with the given status and message.
1388  * Status is true, false, or an integer.
1389  * If status is not given, true is used.
1390  */
1391 
1392 static VALUE
1393 exit_initialize(int argc, VALUE *argv, VALUE exc)
1394 {
1395  VALUE status;
1396  if (argc > 0) {
1397  status = *argv;
1398 
1399  switch (status) {
1400  case Qtrue:
1401  status = INT2FIX(EXIT_SUCCESS);
1402  ++argv;
1403  --argc;
1404  break;
1405  case Qfalse:
1406  status = INT2FIX(EXIT_FAILURE);
1407  ++argv;
1408  --argc;
1409  break;
1410  default:
1411  status = rb_check_to_int(status);
1412  if (NIL_P(status)) {
1413  status = INT2FIX(EXIT_SUCCESS);
1414  }
1415  else {
1416 #if EXIT_SUCCESS != 0
1417  if (status == INT2FIX(0))
1418  status = INT2FIX(EXIT_SUCCESS);
1419 #endif
1420  ++argv;
1421  --argc;
1422  }
1423  break;
1424  }
1425  }
1426  else {
1427  status = INT2FIX(EXIT_SUCCESS);
1428  }
1430  rb_ivar_set(exc, id_status, status);
1431  return exc;
1432 }
1433 
1434 
1435 /*
1436  * call-seq:
1437  * system_exit.status -> integer
1438  *
1439  * Return the status value associated with this system exit.
1440  */
1441 
1442 static VALUE
1443 exit_status(VALUE exc)
1444 {
1445  return rb_attr_get(exc, id_status);
1446 }
1447 
1448 
1449 /*
1450  * call-seq:
1451  * system_exit.success? -> true or false
1452  *
1453  * Returns +true+ if exiting successful, +false+ if not.
1454  */
1455 
1456 static VALUE
1457 exit_success_p(VALUE exc)
1458 {
1459  VALUE status_val = rb_attr_get(exc, id_status);
1460  int status;
1461 
1462  if (NIL_P(status_val))
1463  return Qtrue;
1464  status = NUM2INT(status_val);
1465  if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
1466  return Qtrue;
1467 
1468  return Qfalse;
1469 }
1470 
1471 static VALUE
1472 err_init_recv(VALUE exc, VALUE recv)
1473 {
1474  if (recv != Qundef) rb_ivar_set(exc, id_recv, recv);
1475  return exc;
1476 }
1477 
1478 /*
1479  * call-seq:
1480  * FrozenError.new(msg=nil, receiver: nil) -> frozen_error
1481  *
1482  * Construct a new FrozenError exception. If given the <i>receiver</i>
1483  * parameter may subsequently be examined using the FrozenError#receiver
1484  * method.
1485  *
1486  * a = [].freeze
1487  * raise FrozenError.new("can't modify frozen array", receiver: a)
1488  */
1489 
1490 static VALUE
1491 frozen_err_initialize(int argc, VALUE *argv, VALUE self)
1492 {
1493  ID keywords[1];
1494  VALUE values[numberof(keywords)], options;
1495 
1496  argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1497  keywords[0] = id_receiver;
1498  rb_get_kwargs(options, keywords, 0, numberof(values), values);
1500  err_init_recv(self, values[0]);
1501  return self;
1502 }
1503 
1504 /*
1505  * Document-method: FrozenError#receiver
1506  * call-seq:
1507  * frozen_error.receiver -> object
1508  *
1509  * Return the receiver associated with this FrozenError exception.
1510  */
1511 
1512 #define frozen_err_receiver name_err_receiver
1513 
1514 void
1515 rb_name_error(ID id, const char *fmt, ...)
1516 {
1517  VALUE exc, argv[2];
1518  va_list args;
1519 
1520  va_start(args, fmt);
1521  argv[0] = rb_vsprintf(fmt, args);
1522  va_end(args);
1523 
1524  argv[1] = ID2SYM(id);
1526  rb_exc_raise(exc);
1527 }
1528 
1529 void
1530 rb_name_error_str(VALUE str, const char *fmt, ...)
1531 {
1532  VALUE exc, argv[2];
1533  va_list args;
1534 
1535  va_start(args, fmt);
1536  argv[0] = rb_vsprintf(fmt, args);
1537  va_end(args);
1538 
1539  argv[1] = str;
1541  rb_exc_raise(exc);
1542 }
1543 
1544 static VALUE
1545 name_err_init_attr(VALUE exc, VALUE recv, VALUE method)
1546 {
1547  const rb_execution_context_t *ec = GET_EC();
1550  rb_ivar_set(exc, id_name, method);
1551  err_init_recv(exc, recv);
1552  if (cfp) rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
1553  return exc;
1554 }
1555 
1556 /*
1557  * call-seq:
1558  * NameError.new(msg=nil, name=nil, receiver: nil) -> name_error
1559  *
1560  * Construct a new NameError exception. If given the <i>name</i>
1561  * parameter may subsequently be examined using the NameError#name
1562  * method. <i>receiver</i> parameter allows to pass object in
1563  * context of which the error happened. Example:
1564  *
1565  * [1, 2, 3].method(:rject) # NameError with name "rject" and receiver: Array
1566  * [1, 2, 3].singleton_method(:rject) # NameError with name "rject" and receiver: [1, 2, 3]
1567  */
1568 
1569 static VALUE
1570 name_err_initialize(int argc, VALUE *argv, VALUE self)
1571 {
1572  ID keywords[1];
1573  VALUE values[numberof(keywords)], name, options;
1574 
1575  argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1576  keywords[0] = id_receiver;
1577  rb_get_kwargs(options, keywords, 0, numberof(values), values);
1578  name = (argc > 1) ? argv[--argc] : Qnil;
1580  name_err_init_attr(self, values[0], name);
1581  return self;
1582 }
1583 
1584 static VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
1585 
1586 static VALUE
1587 name_err_init(VALUE exc, VALUE mesg, VALUE recv, VALUE method)
1588 {
1589  exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
1590  return name_err_init_attr(exc, recv, method);
1591 }
1592 
1593 VALUE
1594 rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
1595 {
1597  return name_err_init(exc, mesg, recv, method);
1598 }
1599 
1600 /*
1601  * call-seq:
1602  * name_error.name -> string or nil
1603  *
1604  * Return the name associated with this NameError exception.
1605  */
1606 
1607 static VALUE
1608 name_err_name(VALUE self)
1609 {
1610  return rb_attr_get(self, id_name);
1611 }
1612 
1613 /*
1614  * call-seq:
1615  * name_error.local_variables -> array
1616  *
1617  * Return a list of the local variable names defined where this
1618  * NameError exception was raised.
1619  *
1620  * Internal use only.
1621  */
1622 
1623 static VALUE
1624 name_err_local_variables(VALUE self)
1625 {
1626  VALUE vars = rb_attr_get(self, id_local_variables);
1627 
1628  if (NIL_P(vars)) {
1629  VALUE iseqw = rb_attr_get(self, id_iseq);
1630  if (!NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
1631  if (NIL_P(vars)) vars = rb_ary_new();
1632  rb_ivar_set(self, id_local_variables, vars);
1633  }
1634  return vars;
1635 }
1636 
1637 static VALUE
1638 nometh_err_init_attr(VALUE exc, VALUE args, int priv)
1639 {
1640  rb_ivar_set(exc, id_args, args);
1641  rb_ivar_set(exc, id_private_call_p, priv ? Qtrue : Qfalse);
1642  return exc;
1643 }
1644 
1645 /*
1646  * call-seq:
1647  * NoMethodError.new(msg=nil, name=nil, args=nil, private=false, receiver: nil) -> no_method_error
1648  *
1649  * Construct a NoMethodError exception for a method of the given name
1650  * called with the given arguments. The name may be accessed using
1651  * the <code>#name</code> method on the resulting object, and the
1652  * arguments using the <code>#args</code> method.
1653  *
1654  * If <i>private</i> argument were passed, it designates method was
1655  * attempted to call in private context, and can be accessed with
1656  * <code>#private_call?</code> method.
1657  *
1658  * <i>receiver</i> argument stores an object whose method was called.
1659  */
1660 
1661 static VALUE
1662 nometh_err_initialize(int argc, VALUE *argv, VALUE self)
1663 {
1664  int priv;
1665  VALUE args, options;
1666  argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1667  priv = (argc > 3) && (--argc, RTEST(argv[argc]));
1668  args = (argc > 2) ? argv[--argc] : Qnil;
1669  if (!NIL_P(options)) argv[argc++] = options;
1671  return nometh_err_init_attr(self, args, priv);
1672 }
1673 
1674 VALUE
1675 rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
1676 {
1678  name_err_init(exc, mesg, recv, method);
1679  return nometh_err_init_attr(exc, args, priv);
1680 }
1681 
1682 /* :nodoc: */
1683 enum {
1688 };
1689 
1690 static void
1691 name_err_mesg_mark(void *p)
1692 {
1693  VALUE *ptr = p;
1695 }
1696 
1697 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1698 
1699 static size_t
1700 name_err_mesg_memsize(const void *p)
1701 {
1702  return NAME_ERR_MESG_COUNT * sizeof(VALUE);
1703 }
1704 
1705 static const rb_data_type_t name_err_mesg_data_type = {
1706  "name_err_mesg",
1707  {
1708  name_err_mesg_mark,
1710  name_err_mesg_memsize,
1711  },
1713 };
1714 
1715 /* :nodoc: */
1716 static VALUE
1717 rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
1718 {
1719  VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0);
1721 
1722  ptr[NAME_ERR_MESG__MESG] = mesg;
1723  ptr[NAME_ERR_MESG__RECV] = recv;
1724  ptr[NAME_ERR_MESG__NAME] = method;
1725  RTYPEDDATA_DATA(result) = ptr;
1726  return result;
1727 }
1728 
1729 /* :nodoc: */
1730 static VALUE
1731 name_err_mesg_equal(VALUE obj1, VALUE obj2)
1732 {
1733  VALUE *ptr1, *ptr2;
1734  int i;
1735 
1736  if (obj1 == obj2) return Qtrue;
1738  return Qfalse;
1739 
1740  TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1741  TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1742  for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1743  if (!rb_equal(ptr1[i], ptr2[i]))
1744  return Qfalse;
1745  }
1746  return Qtrue;
1747 }
1748 
1749 /* :nodoc: */
1750 static VALUE
1751 name_err_mesg_to_str(VALUE obj)
1752 {
1753  VALUE *ptr, mesg;
1754  TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
1755 
1756  mesg = ptr[NAME_ERR_MESG__MESG];
1757  if (NIL_P(mesg)) return Qnil;
1758  else {
1759  struct RString s_str, d_str;
1760  VALUE c, s, d = 0, args[4];
1761  int state = 0, singleton = 0;
1762  rb_encoding *usascii = rb_usascii_encoding();
1763 
1764 #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
1766  switch (obj) {
1767  case Qnil:
1768  d = FAKE_CSTR(&d_str, "nil");
1769  break;
1770  case Qtrue:
1771  d = FAKE_CSTR(&d_str, "true");
1772  break;
1773  case Qfalse:
1774  d = FAKE_CSTR(&d_str, "false");
1775  break;
1776  default:
1777  d = rb_protect(rb_inspect, obj, &state);
1778  if (state)
1780  if (NIL_P(d) || RSTRING_LEN(d) > 65) {
1781  d = rb_any_to_s(obj);
1782  }
1783  singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#');
1784  break;
1785  }
1786  if (!singleton) {
1787  s = FAKE_CSTR(&s_str, ":");
1788  c = rb_class_name(CLASS_OF(obj));
1789  }
1790  else {
1791  c = s = FAKE_CSTR(&s_str, "");
1792  }
1794  args[1] = d;
1795  args[2] = s;
1796  args[3] = c;
1797  mesg = rb_str_format(4, args, mesg);
1798  }
1799  return mesg;
1800 }
1801 
1802 /* :nodoc: */
1803 static VALUE
1804 name_err_mesg_dump(VALUE obj, VALUE limit)
1805 {
1806  return name_err_mesg_to_str(obj);
1807 }
1808 
1809 /* :nodoc: */
1810 static VALUE
1811 name_err_mesg_load(VALUE klass, VALUE str)
1812 {
1813  return str;
1814 }
1815 
1816 /*
1817  * call-seq:
1818  * name_error.receiver -> object
1819  *
1820  * Return the receiver associated with this NameError exception.
1821  */
1822 
1823 static VALUE
1824 name_err_receiver(VALUE self)
1825 {
1826  VALUE *ptr, recv, mesg;
1827 
1828  recv = rb_ivar_lookup(self, id_recv, Qundef);
1829  if (recv != Qundef) return recv;
1830 
1831  mesg = rb_attr_get(self, id_mesg);
1832  if (!rb_typeddata_is_kind_of(mesg, &name_err_mesg_data_type)) {
1833  rb_raise(rb_eArgError, "no receiver is available");
1834  }
1835  ptr = DATA_PTR(mesg);
1836  return ptr[NAME_ERR_MESG__RECV];
1837 }
1838 
1839 /*
1840  * call-seq:
1841  * no_method_error.args -> obj
1842  *
1843  * Return the arguments passed in as the third parameter to
1844  * the constructor.
1845  */
1846 
1847 static VALUE
1848 nometh_err_args(VALUE self)
1849 {
1850  return rb_attr_get(self, id_args);
1851 }
1852 
1853 /*
1854  * call-seq:
1855  * no_method_error.private_call? -> true or false
1856  *
1857  * Return true if the caused method was called as private.
1858  */
1859 
1860 static VALUE
1861 nometh_err_private_call_p(VALUE self)
1862 {
1863  return rb_attr_get(self, id_private_call_p);
1864 }
1865 
1866 void
1867 rb_invalid_str(const char *str, const char *type)
1868 {
1869  VALUE s = rb_str_new2(str);
1870 
1871  rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
1872 }
1873 
1874 /*
1875  * call-seq:
1876  * key_error.receiver -> object
1877  *
1878  * Return the receiver associated with this KeyError exception.
1879  */
1880 
1881 static VALUE
1882 key_err_receiver(VALUE self)
1883 {
1884  VALUE recv;
1885 
1886  recv = rb_ivar_lookup(self, id_receiver, Qundef);
1887  if (recv != Qundef) return recv;
1888  rb_raise(rb_eArgError, "no receiver is available");
1889 }
1890 
1891 /*
1892  * call-seq:
1893  * key_error.key -> object
1894  *
1895  * Return the key caused this KeyError exception.
1896  */
1897 
1898 static VALUE
1899 key_err_key(VALUE self)
1900 {
1901  VALUE key;
1902 
1903  key = rb_ivar_lookup(self, id_key, Qundef);
1904  if (key != Qundef) return key;
1905  rb_raise(rb_eArgError, "no key is available");
1906 }
1907 
1908 VALUE
1910 {
1912  rb_ivar_set(exc, id_mesg, mesg);
1914  rb_ivar_set(exc, id_key, key);
1915  rb_ivar_set(exc, id_receiver, recv);
1916  return exc;
1917 }
1918 
1919 /*
1920  * call-seq:
1921  * KeyError.new(message=nil, receiver: nil, key: nil) -> key_error
1922  *
1923  * Construct a new +KeyError+ exception with the given message,
1924  * receiver and key.
1925  */
1926 
1927 static VALUE
1928 key_err_initialize(int argc, VALUE *argv, VALUE self)
1929 {
1930  VALUE options;
1931 
1932  rb_call_super(rb_scan_args(argc, argv, "01:", NULL, &options), argv);
1933 
1934  if (!NIL_P(options)) {
1935  ID keywords[2];
1936  VALUE values[numberof(keywords)];
1937  int i;
1938  keywords[0] = id_receiver;
1939  keywords[1] = id_key;
1940  rb_get_kwargs(options, keywords, 0, numberof(values), values);
1941  for (i = 0; i < numberof(values); ++i) {
1942  if (values[i] != Qundef) {
1943  rb_ivar_set(self, keywords[i], values[i]);
1944  }
1945  }
1946  }
1947 
1948  return self;
1949 }
1950 
1951 /*
1952  * call-seq:
1953  * SyntaxError.new([msg]) -> syntax_error
1954  *
1955  * Construct a SyntaxError exception.
1956  */
1957 
1958 static VALUE
1959 syntax_error_initialize(int argc, VALUE *argv, VALUE self)
1960 {
1961  VALUE mesg;
1962  if (argc == 0) {
1963  mesg = rb_fstring_lit("compile error");
1964  argc = 1;
1965  argv = &mesg;
1966  }
1967  return rb_call_super(argc, argv);
1968 }
1969 
1970 /*
1971  * Document-module: Errno
1972  *
1973  * Ruby exception objects are subclasses of Exception. However,
1974  * operating systems typically report errors using plain
1975  * integers. Module Errno is created dynamically to map these
1976  * operating system errors to Ruby classes, with each error number
1977  * generating its own subclass of SystemCallError. As the subclass
1978  * is created in module Errno, its name will start
1979  * <code>Errno::</code>.
1980  *
1981  * The names of the <code>Errno::</code> classes depend on the
1982  * environment in which Ruby runs. On a typical Unix or Windows
1983  * platform, there are Errno classes such as Errno::EACCES,
1984  * Errno::EAGAIN, Errno::EINTR, and so on.
1985  *
1986  * The integer operating system error number corresponding to a
1987  * particular error is available as the class constant
1988  * <code>Errno::</code><em>error</em><code>::Errno</code>.
1989  *
1990  * Errno::EACCES::Errno #=> 13
1991  * Errno::EAGAIN::Errno #=> 11
1992  * Errno::EINTR::Errno #=> 4
1993  *
1994  * The full list of operating system errors on your particular platform
1995  * are available as the constants of Errno.
1996  *
1997  * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
1998  */
1999 
2000 static st_table *syserr_tbl;
2001 
2002 static VALUE
2003 set_syserr(int n, const char *name)
2004 {
2005  st_data_t error;
2006 
2007  if (!st_lookup(syserr_tbl, n, &error)) {
2009 
2010  /* capture nonblock errnos for WaitReadable/WaitWritable subclasses */
2011  switch (n) {
2012  case EAGAIN:
2013  rb_eEAGAIN = error;
2014 
2015 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2016  break;
2017  case EWOULDBLOCK:
2018 #endif
2019 
2021  break;
2022  case EINPROGRESS:
2024  break;
2025  }
2026 
2027  rb_define_const(error, "Errno", INT2NUM(n));
2028  st_add_direct(syserr_tbl, n, error);
2029  }
2030  else {
2032  }
2033  return error;
2034 }
2035 
2036 static VALUE
2037 get_syserr(int n)
2038 {
2039  st_data_t error;
2040 
2041  if (!st_lookup(syserr_tbl, n, &error)) {
2042  char name[8]; /* some Windows' errno have 5 digits. */
2043 
2044  snprintf(name, sizeof(name), "E%03d", n);
2045  error = set_syserr(n, name);
2046  }
2047  return error;
2048 }
2049 
2050 /*
2051  * call-seq:
2052  * SystemCallError.new(msg, errno) -> system_call_error_subclass
2053  *
2054  * If _errno_ corresponds to a known system error code, constructs the
2055  * appropriate Errno class for that error, otherwise constructs a
2056  * generic SystemCallError object. The error number is subsequently
2057  * available via the #errno method.
2058  */
2059 
2060 static VALUE
2061 syserr_initialize(int argc, VALUE *argv, VALUE self)
2062 {
2063 #if !defined(_WIN32)
2064  char *strerror();
2065 #endif
2066  const char *err;
2067  VALUE mesg, error, func, errmsg;
2068  VALUE klass = rb_obj_class(self);
2069 
2070  if (klass == rb_eSystemCallError) {
2071  st_data_t data = (st_data_t)klass;
2072  rb_scan_args(argc, argv, "12", &mesg, &error, &func);
2073  if (argc == 1 && FIXNUM_P(mesg)) {
2074  error = mesg; mesg = Qnil;
2075  }
2076  if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
2077  klass = (VALUE)data;
2078  /* change class */
2079  if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
2080  rb_raise(rb_eTypeError, "invalid instance type");
2081  }
2082  RBASIC_SET_CLASS(self, klass);
2083  }
2084  }
2085  else {
2086  rb_scan_args(argc, argv, "02", &mesg, &func);
2087  error = rb_const_get(klass, id_Errno);
2088  }
2089  if (!NIL_P(error)) err = strerror(NUM2INT(error));
2090  else err = "unknown error";
2091 
2093  if (!NIL_P(mesg)) {
2094  VALUE str = StringValue(mesg);
2095 
2096  if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
2097  rb_str_catf(errmsg, " - %"PRIsVALUE, str);
2098  }
2099  mesg = errmsg;
2100 
2101  rb_call_super(1, &mesg);
2102  rb_ivar_set(self, id_errno, error);
2103  return self;
2104 }
2105 
2106 /*
2107  * call-seq:
2108  * system_call_error.errno -> integer
2109  *
2110  * Return this SystemCallError's error number.
2111  */
2112 
2113 static VALUE
2114 syserr_errno(VALUE self)
2115 {
2116  return rb_attr_get(self, id_errno);
2117 }
2118 
2119 /*
2120  * call-seq:
2121  * system_call_error === other -> true or false
2122  *
2123  * Return +true+ if the receiver is a generic +SystemCallError+, or
2124  * if the error numbers +self+ and _other_ are the same.
2125  */
2126 
2127 static VALUE
2128 syserr_eqq(VALUE self, VALUE exc)
2129 {
2130  VALUE num, e;
2131 
2133  if (!rb_respond_to(exc, id_errno)) return Qfalse;
2134  }
2135  else if (self == rb_eSystemCallError) return Qtrue;
2136 
2137  num = rb_attr_get(exc, id_errno);
2138  if (NIL_P(num)) {
2139  num = rb_funcallv(exc, id_errno, 0, 0);
2140  }
2141  e = rb_const_get(self, id_Errno);
2142  if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
2143  return Qtrue;
2144  return Qfalse;
2145 }
2146 
2147 
2148 /*
2149  * Document-class: StandardError
2150  *
2151  * The most standard error types are subclasses of StandardError. A
2152  * rescue clause without an explicit Exception class will rescue all
2153  * StandardErrors (and only those).
2154  *
2155  * def foo
2156  * raise "Oups"
2157  * end
2158  * foo rescue "Hello" #=> "Hello"
2159  *
2160  * On the other hand:
2161  *
2162  * require 'does/not/exist' rescue "Hi"
2163  *
2164  * <em>raises the exception:</em>
2165  *
2166  * LoadError: no such file to load -- does/not/exist
2167  *
2168  */
2169 
2170 /*
2171  * Document-class: SystemExit
2172  *
2173  * Raised by +exit+ to initiate the termination of the script.
2174  */
2175 
2176 /*
2177  * Document-class: SignalException
2178  *
2179  * Raised when a signal is received.
2180  *
2181  * begin
2182  * Process.kill('HUP',Process.pid)
2183  * sleep # wait for receiver to handle signal sent by Process.kill
2184  * rescue SignalException => e
2185  * puts "received Exception #{e}"
2186  * end
2187  *
2188  * <em>produces:</em>
2189  *
2190  * received Exception SIGHUP
2191  */
2192 
2193 /*
2194  * Document-class: Interrupt
2195  *
2196  * Raised when the interrupt signal is received, typically because the
2197  * user has pressed Control-C (on most posix platforms). As such, it is a
2198  * subclass of +SignalException+.
2199  *
2200  * begin
2201  * puts "Press ctrl-C when you get bored"
2202  * loop {}
2203  * rescue Interrupt => e
2204  * puts "Note: You will typically use Signal.trap instead."
2205  * end
2206  *
2207  * <em>produces:</em>
2208  *
2209  * Press ctrl-C when you get bored
2210  *
2211  * <em>then waits until it is interrupted with Control-C and then prints:</em>
2212  *
2213  * Note: You will typically use Signal.trap instead.
2214  */
2215 
2216 /*
2217  * Document-class: TypeError
2218  *
2219  * Raised when encountering an object that is not of the expected type.
2220  *
2221  * [1, 2, 3].first("two")
2222  *
2223  * <em>raises the exception:</em>
2224  *
2225  * TypeError: no implicit conversion of String into Integer
2226  *
2227  */
2228 
2229 /*
2230  * Document-class: ArgumentError
2231  *
2232  * Raised when the arguments are wrong and there isn't a more specific
2233  * Exception class.
2234  *
2235  * Ex: passing the wrong number of arguments
2236  *
2237  * [1, 2, 3].first(4, 5)
2238  *
2239  * <em>raises the exception:</em>
2240  *
2241  * ArgumentError: wrong number of arguments (given 2, expected 1)
2242  *
2243  * Ex: passing an argument that is not acceptable:
2244  *
2245  * [1, 2, 3].first(-4)
2246  *
2247  * <em>raises the exception:</em>
2248  *
2249  * ArgumentError: negative array size
2250  */
2251 
2252 /*
2253  * Document-class: IndexError
2254  *
2255  * Raised when the given index is invalid.
2256  *
2257  * a = [:foo, :bar]
2258  * a.fetch(0) #=> :foo
2259  * a[4] #=> nil
2260  * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
2261  *
2262  */
2263 
2264 /*
2265  * Document-class: KeyError
2266  *
2267  * Raised when the specified key is not found. It is a subclass of
2268  * IndexError.
2269  *
2270  * h = {"foo" => :bar}
2271  * h.fetch("foo") #=> :bar
2272  * h.fetch("baz") #=> KeyError: key not found: "baz"
2273  *
2274  */
2275 
2276 /*
2277  * Document-class: RangeError
2278  *
2279  * Raised when a given numerical value is out of range.
2280  *
2281  * [1, 2, 3].drop(1 << 100)
2282  *
2283  * <em>raises the exception:</em>
2284  *
2285  * RangeError: bignum too big to convert into `long'
2286  */
2287 
2288 /*
2289  * Document-class: ScriptError
2290  *
2291  * ScriptError is the superclass for errors raised when a script
2292  * can not be executed because of a +LoadError+,
2293  * +NotImplementedError+ or a +SyntaxError+. Note these type of
2294  * +ScriptErrors+ are not +StandardError+ and will not be
2295  * rescued unless it is specified explicitly (or its ancestor
2296  * +Exception+).
2297  */
2298 
2299 /*
2300  * Document-class: SyntaxError
2301  *
2302  * Raised when encountering Ruby code with an invalid syntax.
2303  *
2304  * eval("1+1=2")
2305  *
2306  * <em>raises the exception:</em>
2307  *
2308  * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
2309  */
2310 
2311 /*
2312  * Document-class: LoadError
2313  *
2314  * Raised when a file required (a Ruby script, extension library, ...)
2315  * fails to load.
2316  *
2317  * require 'this/file/does/not/exist'
2318  *
2319  * <em>raises the exception:</em>
2320  *
2321  * LoadError: no such file to load -- this/file/does/not/exist
2322  */
2323 
2324 /*
2325  * Document-class: NotImplementedError
2326  *
2327  * Raised when a feature is not implemented on the current platform. For
2328  * example, methods depending on the +fsync+ or +fork+ system calls may
2329  * raise this exception if the underlying operating system or Ruby
2330  * runtime does not support them.
2331  *
2332  * Note that if +fork+ raises a +NotImplementedError+, then
2333  * <code>respond_to?(:fork)</code> returns +false+.
2334  */
2335 
2336 /*
2337  * Document-class: NameError
2338  *
2339  * Raised when a given name is invalid or undefined.
2340  *
2341  * puts foo
2342  *
2343  * <em>raises the exception:</em>
2344  *
2345  * NameError: undefined local variable or method `foo' for main:Object
2346  *
2347  * Since constant names must start with a capital:
2348  *
2349  * Integer.const_set :answer, 42
2350  *
2351  * <em>raises the exception:</em>
2352  *
2353  * NameError: wrong constant name answer
2354  */
2355 
2356 /*
2357  * Document-class: NoMethodError
2358  *
2359  * Raised when a method is called on a receiver which doesn't have it
2360  * defined and also fails to respond with +method_missing+.
2361  *
2362  * "hello".to_ary
2363  *
2364  * <em>raises the exception:</em>
2365  *
2366  * NoMethodError: undefined method `to_ary' for "hello":String
2367  */
2368 
2369 /*
2370  * Document-class: FrozenError
2371  *
2372  * Raised when there is an attempt to modify a frozen object.
2373  *
2374  * [1, 2, 3].freeze << 4
2375  *
2376  * <em>raises the exception:</em>
2377  *
2378  * FrozenError: can't modify frozen Array
2379  */
2380 
2381 /*
2382  * Document-class: RuntimeError
2383  *
2384  * A generic error class raised when an invalid operation is attempted.
2385  * Kernel#raise will raise a RuntimeError if no Exception class is
2386  * specified.
2387  *
2388  * raise "ouch"
2389  *
2390  * <em>raises the exception:</em>
2391  *
2392  * RuntimeError: ouch
2393  */
2394 
2395 /*
2396  * Document-class: SecurityError
2397  *
2398  * No longer used by internal code.
2399  */
2400 
2401 /*
2402  * Document-class: NoMemoryError
2403  *
2404  * Raised when memory allocation fails.
2405  */
2406 
2407 /*
2408  * Document-class: SystemCallError
2409  *
2410  * SystemCallError is the base class for all low-level
2411  * platform-dependent errors.
2412  *
2413  * The errors available on the current platform are subclasses of
2414  * SystemCallError and are defined in the Errno module.
2415  *
2416  * File.open("does/not/exist")
2417  *
2418  * <em>raises the exception:</em>
2419  *
2420  * Errno::ENOENT: No such file or directory - does/not/exist
2421  */
2422 
2423 /*
2424  * Document-class: EncodingError
2425  *
2426  * EncodingError is the base class for encoding errors.
2427  */
2428 
2429 /*
2430  * Document-class: Encoding::CompatibilityError
2431  *
2432  * Raised by Encoding and String methods when the source encoding is
2433  * incompatible with the target encoding.
2434  */
2435 
2436 /*
2437  * Document-class: fatal
2438  *
2439  * fatal is an Exception that is raised when Ruby has encountered a fatal
2440  * error and must exit.
2441  */
2442 
2443 /*
2444  * Document-class: NameError::message
2445  * :nodoc:
2446  */
2447 
2448 /*
2449  * \Class Exception and its subclasses are used to communicate between
2450  * Kernel#raise and +rescue+ statements in <code>begin ... end</code> blocks.
2451  *
2452  * An Exception object carries information about an exception:
2453  * - Its type (the exception's class).
2454  * - An optional descriptive message.
2455  * - Optional backtrace information.
2456  *
2457  * Some built-in subclasses of Exception have additional methods: e.g., NameError#name.
2458  *
2459  * == Defaults
2460  *
2461  * Two Ruby statements have default exception classes:
2462  * - +raise+: defaults to RuntimeError.
2463  * - +rescue+: defaults to StandardError.
2464  *
2465  * == Global Variables
2466  *
2467  * When an exception has been raised but not yet handled (in +rescue+,
2468  * +ensure+, +at_exit+ and +END+ blocks), two global variables are set:
2469  * - <code>$!</code> contains the current exception.
2470  * - <code>$@</code> contains its backtrace.
2471  *
2472  * == Custom Exceptions
2473  *
2474  * To provide additional or alternate information,
2475  * a program may create custom exception classes
2476  * that derive from the built-in exception classes.
2477  *
2478  * A good practice is for a library to create a single "generic" exception class
2479  * (typically a subclass of StandardError or RuntimeError)
2480  * and have its other exception classes derive from that class.
2481  * This allows the user to rescue the generic exception, thus catching all exceptions
2482  * the library may raise even if future versions of the library add new
2483  * exception subclasses.
2484  *
2485  * For example:
2486  *
2487  * class MyLibrary
2488  * class Error < ::StandardError
2489  * end
2490  *
2491  * class WidgetError < Error
2492  * end
2493  *
2494  * class FrobError < Error
2495  * end
2496  *
2497  * end
2498  *
2499  * To handle both MyLibrary::WidgetError and MyLibrary::FrobError the library
2500  * user can rescue MyLibrary::Error.
2501  *
2502  * == Built-In Exception Classes
2503  *
2504  * The built-in subclasses of Exception are:
2505  *
2506  * * NoMemoryError
2507  * * ScriptError
2508  * * LoadError
2509  * * NotImplementedError
2510  * * SyntaxError
2511  * * SecurityError
2512  * * SignalException
2513  * * Interrupt
2514  * * StandardError
2515  * * ArgumentError
2516  * * UncaughtThrowError
2517  * * EncodingError
2518  * * FiberError
2519  * * IOError
2520  * * EOFError
2521  * * IndexError
2522  * * KeyError
2523  * * StopIteration
2524  * * ClosedQueueError
2525  * * LocalJumpError
2526  * * NameError
2527  * * NoMethodError
2528  * * RangeError
2529  * * FloatDomainError
2530  * * RegexpError
2531  * * RuntimeError
2532  * * FrozenError
2533  * * SystemCallError
2534  * * Errno::*
2535  * * ThreadError
2536  * * TypeError
2537  * * ZeroDivisionError
2538  * * SystemExit
2539  * * SystemStackError
2540  * * fatal
2541  */
2542 
2543 void
2545 {
2546  rb_eException = rb_define_class("Exception", rb_cObject);
2548  rb_define_singleton_method(rb_eException, "to_tty?", exc_s_to_tty_p, 0);
2549  rb_define_method(rb_eException, "exception", exc_exception, -1);
2550  rb_define_method(rb_eException, "initialize", exc_initialize, -1);
2551  rb_define_method(rb_eException, "==", exc_equal, 1);
2552  rb_define_method(rb_eException, "to_s", exc_to_s, 0);
2553  rb_define_method(rb_eException, "message", exc_message, 0);
2554  rb_define_method(rb_eException, "full_message", exc_full_message, -1);
2555  rb_define_method(rb_eException, "inspect", exc_inspect, 0);
2556  rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
2557  rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);
2558  rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
2559  rb_define_method(rb_eException, "cause", exc_cause, 0);
2560 
2561  rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
2562  rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
2563  rb_define_method(rb_eSystemExit, "status", exit_status, 0);
2564  rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);
2565 
2567  rb_eSignal = rb_define_class("SignalException", rb_eException);
2568  rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal);
2569 
2570  rb_eStandardError = rb_define_class("StandardError", rb_eException);
2572  rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
2575  rb_define_method(rb_eKeyError, "initialize", key_err_initialize, -1);
2576  rb_define_method(rb_eKeyError, "receiver", key_err_receiver, 0);
2577  rb_define_method(rb_eKeyError, "key", key_err_key, 0);
2579 
2580  rb_eScriptError = rb_define_class("ScriptError", rb_eException);
2582  rb_define_method(rb_eSyntaxError, "initialize", syntax_error_initialize, -1);
2583 
2585  /* the path failed to load */
2586  rb_attr(rb_eLoadError, rb_intern_const("path"), 1, 0, Qfalse);
2587 
2588  rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
2589 
2591  rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
2592  rb_define_method(rb_eNameError, "name", name_err_name, 0);
2593  rb_define_method(rb_eNameError, "receiver", name_err_receiver, 0);
2594  rb_define_method(rb_eNameError, "local_variables", name_err_local_variables, 0);
2596  rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
2597  rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
2598  rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
2599  rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
2600  rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
2601  rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
2602  rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
2603  rb_define_method(rb_eNoMethodError, "private_call?", nometh_err_private_call_p, 0);
2604 
2607  rb_define_method(rb_eFrozenError, "initialize", frozen_err_initialize, -1);
2609  rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
2610  rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
2613  rb_eNoMatchingPatternError = rb_define_class("NoMatchingPatternError", rb_eRuntimeError);
2614 
2615  syserr_tbl = st_init_numtable();
2617  rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
2618  rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
2619  rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
2620 
2621  rb_mErrno = rb_define_module("Errno");
2622 
2623  rb_mWarning = rb_define_module("Warning");
2624  rb_define_singleton_method(rb_mWarning, "[]", rb_warning_s_aref, 1);
2625  rb_define_singleton_method(rb_mWarning, "[]=", rb_warning_s_aset, 2);
2626  rb_define_method(rb_mWarning, "warn", rb_warning_s_warn, 1);
2627  rb_extend_object(rb_mWarning, rb_mWarning);
2628 
2629  /* :nodoc: */
2630  rb_cWarningBuffer = rb_define_class_under(rb_mWarning, "buffer", rb_cString);
2631  rb_define_method(rb_cWarningBuffer, "write", warning_write, -1);
2632 
2633  id_cause = rb_intern_const("cause");
2634  id_message = rb_intern_const("message");
2635  id_backtrace = rb_intern_const("backtrace");
2636  id_key = rb_intern_const("key");
2637  id_args = rb_intern_const("args");
2638  id_receiver = rb_intern_const("receiver");
2639  id_private_call_p = rb_intern_const("private_call?");
2640  id_local_variables = rb_intern_const("local_variables");
2641  id_Errno = rb_intern_const("Errno");
2642  id_errno = rb_intern_const("errno");
2643  id_i_path = rb_intern_const("@path");
2644  id_warn = rb_intern_const("warn");
2645  id_top = rb_intern_const("top");
2646  id_bottom = rb_intern_const("bottom");
2647  id_iseq = rb_make_internal_id();
2648  id_recv = rb_make_internal_id();
2649 }
2650 
2651 void
2652 rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
2653 {
2654  va_list args;
2655  VALUE mesg;
2656 
2657  va_start(args, fmt);
2658  mesg = rb_enc_vsprintf(enc, fmt, args);
2659  va_end(args);
2660 
2661  rb_exc_raise(rb_exc_new3(exc, mesg));
2662 }
2663 
2664 void
2665 rb_vraise(VALUE exc, const char *fmt, va_list ap)
2666 {
2668 }
2669 
2670 void
2671 rb_raise(VALUE exc, const char *fmt, ...)
2672 {
2673  va_list args;
2674  va_start(args, fmt);
2675  rb_vraise(exc, fmt, args);
2676  va_end(args);
2677 }
2678 
2679 NORETURN(static void raise_loaderror(VALUE path, VALUE mesg));
2680 
2681 static void
2682 raise_loaderror(VALUE path, VALUE mesg)
2683 {
2685  rb_ivar_set(err, id_i_path, path);
2686  rb_exc_raise(err);
2687 }
2688 
2689 void
2690 rb_loaderror(const char *fmt, ...)
2691 {
2692  va_list args;
2693  VALUE mesg;
2694 
2695  va_start(args, fmt);
2696  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2697  va_end(args);
2698  raise_loaderror(Qnil, mesg);
2699 }
2700 
2701 void
2703 {
2704  va_list args;
2705  VALUE mesg;
2706 
2707  va_start(args, fmt);
2708  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2709  va_end(args);
2710  raise_loaderror(path, mesg);
2711 }
2712 
2713 void
2715 {
2717  "%"PRIsVALUE"() function is unimplemented on this machine",
2719 }
2720 
2721 void
2722 rb_fatal(const char *fmt, ...)
2723 {
2724  va_list args;
2725  VALUE mesg;
2726 
2727  if (! ruby_thread_has_gvl_p()) {
2728  /* The thread has no GVL. Object allocation impossible (cant run GC),
2729  * thus no message can be printed out. */
2730  fprintf(stderr, "[FATAL] rb_fatal() outside of GVL\n");
2732  die();
2733  }
2734 
2735  va_start(args, fmt);
2736  mesg = rb_vsprintf(fmt, args);
2737  va_end(args);
2738 
2740 }
2741 
2742 static VALUE
2743 make_errno_exc(const char *mesg)
2744 {
2745  int n = errno;
2746 
2747  errno = 0;
2748  if (n == 0) {
2749  rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
2750  }
2751  return rb_syserr_new(n, mesg);
2752 }
2753 
2754 static VALUE
2755 make_errno_exc_str(VALUE mesg)
2756 {
2757  int n = errno;
2758 
2759  errno = 0;
2760  if (!mesg) mesg = Qnil;
2761  if (n == 0) {
2762  const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
2763  rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
2764  }
2765  return rb_syserr_new_str(n, mesg);
2766 }
2767 
2768 VALUE
2769 rb_syserr_new(int n, const char *mesg)
2770 {
2771  VALUE arg;
2772  arg = mesg ? rb_str_new2(mesg) : Qnil;
2773  return rb_syserr_new_str(n, arg);
2774 }
2775 
2776 VALUE
2778 {
2779  return rb_class_new_instance(1, &arg, get_syserr(n));
2780 }
2781 
2782 void
2783 rb_syserr_fail(int e, const char *mesg)
2784 {
2785  rb_exc_raise(rb_syserr_new(e, mesg));
2786 }
2787 
2788 void
2790 {
2791  rb_exc_raise(rb_syserr_new_str(e, mesg));
2792 }
2793 
2794 void
2795 rb_sys_fail(const char *mesg)
2796 {
2797  rb_exc_raise(make_errno_exc(mesg));
2798 }
2799 
2800 void
2802 {
2803  rb_exc_raise(make_errno_exc_str(mesg));
2804 }
2805 
2806 #ifdef RUBY_FUNCTION_NAME_STRING
2807 void
2808 rb_sys_fail_path_in(const char *func_name, VALUE path)
2809 {
2810  int n = errno;
2811 
2812  errno = 0;
2813  rb_syserr_fail_path_in(func_name, n, path);
2814 }
2815 
2816 void
2817 rb_syserr_fail_path_in(const char *func_name, int n, VALUE path)
2818 {
2819  VALUE args[2];
2820 
2821  if (!path) path = Qnil;
2822  if (n == 0) {
2823  const char *s = !NIL_P(path) ? RSTRING_PTR(path) : "";
2824  if (!func_name) func_name = "(null)";
2825  rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0",
2826  func_name, s);
2827  }
2828  args[0] = path;
2829  args[1] = rb_str_new_cstr(func_name);
2830  rb_exc_raise(rb_class_new_instance(2, args, get_syserr(n)));
2831 }
2832 #endif
2833 
2834 void
2835 rb_mod_sys_fail(VALUE mod, const char *mesg)
2836 {
2837  VALUE exc = make_errno_exc(mesg);
2839  rb_exc_raise(exc);
2840 }
2841 
2842 void
2844 {
2845  VALUE exc = make_errno_exc_str(mesg);
2847  rb_exc_raise(exc);
2848 }
2849 
2850 void
2851 rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
2852 {
2853  VALUE exc = rb_syserr_new(e, mesg);
2855  rb_exc_raise(exc);
2856 }
2857 
2858 void
2860 {
2861  VALUE exc = rb_syserr_new_str(e, mesg);
2863  rb_exc_raise(exc);
2864 }
2865 
2866 static void
2867 syserr_warning(VALUE mesg, int err)
2868 {
2869  rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2870  rb_str_catf(mesg, ": %s\n", strerror(err));
2871  rb_write_warning_str(mesg);
2872 }
2873 
2874 #if 0
2875 void
2876 rb_sys_warn(const char *fmt, ...)
2877 {
2878  if (!NIL_P(ruby_verbose)) {
2879  int errno_save = errno;
2880  with_warning_string(mesg, 0, fmt) {
2881  syserr_warning(mesg, errno_save);
2882  }
2883  errno = errno_save;
2884  }
2885 }
2886 
2887 void
2888 rb_syserr_warn(int err, const char *fmt, ...)
2889 {
2890  if (!NIL_P(ruby_verbose)) {
2891  with_warning_string(mesg, 0, fmt) {
2892  syserr_warning(mesg, err);
2893  }
2894  }
2895 }
2896 
2897 void
2898 rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...)
2899 {
2900  if (!NIL_P(ruby_verbose)) {
2901  int errno_save = errno;
2902  with_warning_string(mesg, enc, fmt) {
2903  syserr_warning(mesg, errno_save);
2904  }
2905  errno = errno_save;
2906  }
2907 }
2908 
2909 void
2910 rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...)
2911 {
2912  if (!NIL_P(ruby_verbose)) {
2913  with_warning_string(mesg, enc, fmt) {
2914  syserr_warning(mesg, err);
2915  }
2916  }
2917 }
2918 #endif
2919 
2920 void
2921 rb_sys_warning(const char *fmt, ...)
2922 {
2923  if (RTEST(ruby_verbose)) {
2924  int errno_save = errno;
2925  with_warning_string(mesg, 0, fmt) {
2926  syserr_warning(mesg, errno_save);
2927  }
2928  errno = errno_save;
2929  }
2930 }
2931 
2932 #if 0
2933 void
2934 rb_syserr_warning(int err, const char *fmt, ...)
2935 {
2936  if (RTEST(ruby_verbose)) {
2937  with_warning_string(mesg, 0, fmt) {
2938  syserr_warning(mesg, err);
2939  }
2940  }
2941 }
2942 #endif
2943 
2944 void
2945 rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...)
2946 {
2947  if (RTEST(ruby_verbose)) {
2948  int errno_save = errno;
2949  with_warning_string(mesg, enc, fmt) {
2950  syserr_warning(mesg, errno_save);
2951  }
2952  errno = errno_save;
2953  }
2954 }
2955 
2956 void
2957 rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...)
2958 {
2959  if (RTEST(ruby_verbose)) {
2960  with_warning_string(mesg, enc, fmt) {
2961  syserr_warning(mesg, err);
2962  }
2963  }
2964 }
2965 
2966 void
2968 {
2969  VALUE mesg = rb_str_buf_new_cstr(err);
2970  rb_str_cat2(mesg, " -- ");
2971  rb_str_append(mesg, path); /* should be ASCII compatible */
2972  raise_loaderror(path, mesg);
2973 }
2974 
2975 void
2976 rb_error_frozen(const char *what)
2977 {
2978  rb_raise(rb_eFrozenError, "can't modify frozen %s", what);
2979 }
2980 
2981 void
2982 rb_frozen_error_raise(VALUE frozen_obj, const char *fmt, ...)
2983 {
2984  va_list args;
2985  VALUE exc, mesg;
2986 
2987  va_start(args, fmt);
2988  mesg = rb_vsprintf(fmt, args);
2989  va_end(args);
2990  exc = rb_exc_new3(rb_eFrozenError, mesg);
2991  rb_ivar_set(exc, id_recv, frozen_obj);
2992  rb_exc_raise(exc);
2993 }
2994 
2995 static VALUE
2996 inspect_frozen_obj(VALUE obj, VALUE mesg, int recur)
2997 {
2998  if (recur) {
2999  rb_str_cat_cstr(mesg, " ...");
3000  }
3001  else {
3002  rb_str_append(mesg, rb_inspect(obj));
3003  }
3004  return mesg;
3005 }
3006 
3007 void
3009 {
3010  VALUE debug_info;
3011  const ID created_info = id_debug_created_info;
3012  VALUE mesg = rb_sprintf("can't modify frozen %"PRIsVALUE": ",
3013  CLASS_OF(frozen_obj));
3015 
3016  rb_ivar_set(exc, id_recv, frozen_obj);
3017  rb_exec_recursive(inspect_frozen_obj, frozen_obj, mesg);
3018 
3019  if (!NIL_P(debug_info = rb_attr_get(frozen_obj, created_info))) {
3020  VALUE path = rb_ary_entry(debug_info, 0);
3021  VALUE line = rb_ary_entry(debug_info, 1);
3022 
3023  rb_str_catf(mesg, ", created at %"PRIsVALUE":%"PRIsVALUE, path, line);
3024  }
3025  rb_exc_raise(exc);
3026 }
3027 
3028 #undef rb_check_frozen
3029 void
3031 {
3033 }
3034 
3035 void
3037 {
3038  rb_warning("rb_error_untrusted is deprecated and will be removed in Ruby 3.2.");
3039 }
3040 
3041 #undef rb_check_trusted
3042 void
3044 {
3045  rb_warning("rb_check_trusted is deprecated and will be removed in Ruby 3.2.");
3046 }
3047 
3048 void
3050 {
3051  if (!FL_ABLE(obj)) return;
3053  if (!FL_ABLE(orig)) return;
3054 }
3055 
3056 void
3058 {
3059  rb_eNOERROR = set_syserr(0, "NOERROR");
3060 #define defined_error(name, num) set_syserr((num), (name));
3061 #define undefined_error(name) set_syserr(0, (name));
3062 #include "known_errors.inc"
3063 #undef defined_error
3064 #undef undefined_error
3065 }
3066 
3067 #include "warning.rbinc"
3068 
3069 void
3071 {
3072  load_warning();
3073 }
3074 
rb_eEAGAIN
VALUE rb_eEAGAIN
Definition: error.c:54
va_end
#define va_end(v)
Definition: rb_mjit_min_header-2.7.2.h:3982
rb_str_end_with_asciichar
int rb_str_end_with_asciichar(VALUE str, int c)
Definition: io.c:7685
rb_io_puts
VALUE rb_io_puts(int, const VALUE *, VALUE)
Definition: io.c:7747
abort
void abort(void) __attribute__((__noreturn__))
rb_get_kwargs
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Definition: class.c:1886
ID
unsigned long ID
Definition: ruby.h:103
rb_check_funcall
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:505
rb_define_class
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:649
T_FALSE
#define T_FALSE
Definition: ruby.h:537
Check_Type
#define Check_Type(v, t)
Definition: ruby.h:595
rb_str_vcatf
VALUE rb_str_vcatf(VALUE, const char *, va_list)
Definition: sprintf.c:1210
error
const rb_iseq_t const char * error
Definition: rb_mjit_min_header-2.7.2.h:13471
rb_check_id
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:919
rb_exc_new
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:961
rb_str_new2
#define rb_str_new2
Definition: intern.h:903
rb_eScriptError
VALUE rb_eScriptError
Definition: error.c:939
rb_cData
RUBY_EXTERN VALUE rb_cData
Definition: ruby.h:2018
rb_check_type
void rb_check_type(VALUE x, int t)
Definition: error.c:839
rb_exc_new_str
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:974
rb_warning_category_update
void rb_warning_category_update(unsigned int mask, unsigned int bits)
Definition: error.c:159
rb_exc_new3
#define rb_exc_new3
Definition: intern.h:293
RB_PASS_CALLED_KEYWORDS
#define RB_PASS_CALLED_KEYWORDS
Definition: ruby.h:1980
rb_iseq_struct
Definition: vm_core.h:456
cfp
rb_control_frame_t * cfp
Definition: rb_mjit_min_header-2.7.2.h:14524
id_bt
#define id_bt
Definition: error.c:953
report_bug
#define report_bug(file, line, fmt, ctx)
Definition: error.c:606
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:315
rb_bug_reporter_add
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:457
idMesg
@ idMesg
Definition: rb_mjit_min_header-2.7.2.h:8692
rb_warning
void rb_warning(const char *fmt,...)
Definition: error.c:336
int
__inline__ int
Definition: rb_mjit_min_header-2.7.2.h:2845
EWOULDBLOCK
#define EWOULDBLOCK
Definition: rubysocket.h:134
fputc
int fputc(int, FILE *)
sig
int sig
Definition: rb_mjit_min_header-2.7.2.h:10390
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
rb_make_internal_id
ID rb_make_internal_id(void)
Definition: symbol.c:810
T_MASK
#define T_MASK
Definition: md5.c:131
strchr
char * strchr(char *, char)
ruby_sighandler_t
RETSIGTYPE(* ruby_sighandler_t)(int)
Definition: vm_core.h:1642
rb_warning_category_enabled_p
MJIT_FUNC_EXPORTED bool rb_warning_category_enabled_p(rb_warning_category_t category)
Definition: error.c:166
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
i
uint32_t i
Definition: rb_mjit_min_header-2.7.2.h:5460
rb_gc_mark_locations
void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
Definition: gc.c:4702
system
int system(const char *__string)
UNDEF_LEAKED
#define UNDEF_LEAKED
Definition: error.c:810
rb_str_cat_cstr
#define rb_str_cat_cstr(str, ptr)
Definition: rb_mjit_min_header-2.7.2.h:6122
NUM2LONG
#define NUM2LONG(x)
Definition: ruby.h:679
RTYPEDDATA_TYPE
#define RTYPEDDATA_TYPE(v)
Definition: ruby.h:1178
rb_bug_errno
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:669
rb_attr_get
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1084
EXEC_EVENT_HOOK
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:1935
rb_data_type_struct::parent
const rb_data_type_t * parent
Definition: ruby.h:1158
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:653
rb_equal
VALUE rb_equal(VALUE, VALUE)
Same as Object#===, case equality.
Definition: object.c:124
rb_locale_encoding
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1372
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_obj_as_string
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1440
rb_eArgError
VALUE rb_eArgError
Definition: error.c:925
va_list
__gnuc_va_list va_list
Definition: rb_mjit_min_header-2.7.2.h:834
rb_key_err_new
VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE key)
Definition: error.c:1909
encoding.h
ruby_verbose
#define ruby_verbose
Definition: ruby.h:1925
rb_intern
#define rb_intern(str)
rb_eSyntaxError
VALUE rb_eSyntaxError
Definition: error.c:940
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
rb_intern_const
#define rb_intern_const(str)
Definition: ruby.h:1879
obj2
VALUE obj2
Definition: rb_mjit_min_header-2.7.2.h:7546
TYPE
#define TYPE(x)
Definition: ruby.h:554
st_add_direct
void st_add_direct(st_table *tab, st_data_t key, st_data_t value)
Definition: st.c:1251
rb_name_err_new
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1594
rb_enc_vsprintf
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1145
rb_assert_failure
MJIT_FUNC_EXPORTED void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
Definition: error.c:718
rb_define_module
VALUE rb_define_module(const char *name)
Definition: class.c:772
isatty
int isatty(int __fildes)
getenv
#define getenv(name)
Definition: win32.c:73
EINPROGRESS
#define EINPROGRESS
Definition: win32.h:498
rb_call_super
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:306
rb_eSignal
VALUE rb_eSignal
Definition: error.c:919
rb_error_write
void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
Definition: eval_error.c:300
rb_inspect
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
Definition: object.c:551
fputs
int fputs(const char *__restrict, FILE *__restrict)
exc
const rb_iseq_t const VALUE exc
Definition: rb_mjit_min_header-2.7.2.h:13469
rb_eIndexError
VALUE rb_eIndexError
Definition: error.c:926
RB_WARN_CATEGORY_NONE
@ RB_WARN_CATEGORY_NONE
Definition: internal.h:1561
rb_str_cat2
#define rb_str_cat2
Definition: intern.h:912
rb_check_string_type
VALUE rb_check_string_type(VALUE)
Definition: string.c:2314
Qundef
#define Qundef
Definition: ruby.h:470
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1755
rb_mod_syserr_fail
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Definition: error.c:2851
fileno
int fileno(FILE *)
EXIT_FAILURE
#define EXIT_FAILURE
Definition: eval_intern.h:32
NAME_ERR_MESG__MESG
@ NAME_ERR_MESG__MESG
Definition: error.c:1684
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1551
GET_EC
#define GET_EC()
Definition: vm_core.h:1766
rb_eNameError
VALUE rb_eNameError
Definition: error.c:929
INT2NUM
#define INT2NUM(x)
Definition: ruby.h:1609
ptr
struct RIMemo * ptr
Definition: debug.c:65
rb_str_buf_new_cstr
#define rb_str_buf_new_cstr(str)
Definition: rb_mjit_min_header-2.7.2.h:6121
rb_check_frozen
void rb_check_frozen(VALUE obj)
Definition: error.c:3030
T_DATA
#define T_DATA
Definition: ruby.h:538
PRI_PIDT_PREFIX
#define PRI_PIDT_PREFIX
Definition: rb_mjit_min_header-2.7.2.h:103
rb_loaderror
void rb_loaderror(const char *fmt,...)
Definition: error.c:2690
Qfalse
#define Qfalse
Definition: ruby.h:467
rb_name_error
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:1515
id_cause
#define id_cause
Definition: error.c:948
rb_ivar_lookup
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
Definition: variable.c:1035
rb_id2str
#define rb_id2str(id)
Definition: vm_backtrace.c:30
rb_stderr_tty_p
int rb_stderr_tty_p(void)
Definition: io.c:7958
rb_ary_new3
#define rb_ary_new3
Definition: intern.h:104
st.h
NULL
#define NULL
Definition: _sdbm.c:101
rb_print_backtrace
void rb_print_backtrace(void)
Definition: vm_dump.c:750
Init_syserr
void Init_syserr(void)
Definition: error.c:3057
rb_typeddata_inherited_p
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Definition: error.c:864
fmt
const VALUE int int int int int int VALUE char * fmt
Definition: rb_mjit_min_header-2.7.2.h:6458
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
RBASIC_SET_CLASS
#define RBASIC_SET_CLASS(obj, cls)
Definition: internal.h:1989
name_err_mesg_free
#define name_err_mesg_free
Definition: error.c:1697
REPORT_BUG_BUFSIZ
#define REPORT_BUG_BUFSIZ
Definition: error.c:471
rb_fatal
void rb_fatal(const char *fmt,...)
Definition: error.c:2722
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:414
strlen
size_t strlen(const char *)
rb_check_frozen_internal
#define rb_check_frozen_internal(obj)
Definition: intern.h:305
rb_bug_for_fatal_signal
void rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *ctx, const char *fmt,...)
Definition: error.c:651
T_SYMBOL
#define T_SYMBOL
Definition: ruby.h:540
T_OBJECT
#define T_OBJECT
Definition: ruby.h:523
RB_WARN_CATEGORY_EXPERIMENTAL
@ RB_WARN_CATEGORY_EXPERIMENTAL
Definition: internal.h:1563
NAME_ERR_MESG__RECV
@ NAME_ERR_MESG__RECV
Definition: error.c:1685
rb_eEncodingError
VALUE rb_eEncodingError
Definition: error.c:930
rb_respond_to
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:2190
rb_data_type_struct::wrap_struct_name
const char * wrap_struct_name
Definition: ruby.h:1149
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
Definition: eval.c:1072
rb_check_arity
#define rb_check_arity
Definition: intern.h:347
rb_eNoMatchingPatternError
VALUE rb_eNoMatchingPatternError
Definition: error.c:937
rb_backtrace_to_location_ary
VALUE rb_backtrace_to_location_ary(VALUE obj)
Definition: vm_backtrace.c:686
rb_enc_str_new_cstr
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
Definition: string.c:836
RARRAY_LENINT
#define RARRAY_LENINT(ary)
Definition: ruby.h:1071
rb_error_frozen
void rb_error_frozen(const char *what)
Definition: error.c:2976
fwrite
size_t fwrite(const void *__restrict, size_t _size, size_t _n, FILE *)
ALLOC_N
#define ALLOC_N(type, n)
Definition: ruby.h:1663
with_warning_string
#define with_warning_string(mesg, enc, fmt)
Definition: error.c:308
void
void
Definition: rb_mjit_min_header-2.7.2.h:13241
rb_vsprintf
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1191
frozen_err_receiver
#define frozen_err_receiver
Definition: error.c:1512
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2671
rb_ary_entry
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:1512
rb_notimplement
void rb_notimplement(void)
Definition: error.c:2714
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:847
rb_eRangeError
VALUE rb_eRangeError
Definition: error.c:928
idTo_s
@ idTo_s
Definition: rb_mjit_min_header-2.7.2.h:8685
rb_obj_class
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
WRITE_CONST
#define WRITE_CONST(fd, str)
Definition: error.c:687
rb_str_format
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:204
rb_vraise
void rb_vraise(VALUE exc, const char *fmt, va_list ap)
Definition: error.c:2665
rb_load_fail
void rb_load_fail(VALUE path, const char *err)
Definition: error.c:2967
rb_syserr_fail
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:2783
stdout
#define stdout
Definition: rb_mjit_min_header-2.7.2.h:1515
snprintf
int snprintf(char *__restrict, size_t, const char *__restrict,...) __attribute__((__format__(__printf__
strerror
RUBY_EXTERN char * strerror(int)
Definition: strerror.c:11
WEXITSTATUS
#define WEXITSTATUS(status)
Definition: error.c:47
DATA_PTR
#define DATA_PTR(dta)
Definition: ruby.h:1175
rb_backtrace_to_str_ary
VALUE rb_backtrace_to_str_ary(VALUE obj)
Definition: vm_backtrace.c:620
rb_syserr_new
VALUE rb_syserr_new(int n, const char *mesg)
Definition: error.c:2769
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.2.h:13222
rb_sys_enc_warning
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
Definition: error.c:2945
FL_ABLE
#define FL_ABLE(x)
Definition: ruby.h:1351
rb_must_asciicompat
void rb_must_asciicompat(VALUE)
Definition: string.c:2166
rb_iseqw_new
VALUE rb_iseqw_new(const rb_iseq_t *)
Definition: iseq.c:1157
rb_nomethod_err_new
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
Definition: error.c:1675
INIT_KW
#define INIT_KW(n)
rb_frame_this_func
ID rb_frame_this_func(void)
The original name of the current method.
Definition: eval.c:1183
rb_error_untrusted
void rb_error_untrusted(VALUE obj)
Definition: error.c:3036
rb_ec_backtrace_location_ary
VALUE rb_ec_backtrace_location_ary(rb_execution_context_t *ec, long lev, long n)
rb_iseqw_local_variables
VALUE rb_iseqw_local_variables(VALUE iseqval)
Definition: iseq.c:3325
rb_check_trusted
void rb_check_trusted(VALUE obj)
Definition: error.c:3043
OnigEncodingTypeST
Definition: onigmo.h:160
rb_compile_warning
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:287
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
rb_builtin_type_name
const char * rb_builtin_type_name(int t)
Definition: error.c:763
ruby_static_id_cause
ID ruby_static_id_cause
Definition: error.c:947
rb_get_message
VALUE rb_get_message(VALUE exc)
Definition: error.c:1053
NAME_ERR_MESG__NAME
@ NAME_ERR_MESG__NAME
Definition: error.c:1686
Init_Exception
void Init_Exception(void)
Definition: error.c:2544
getpid
pid_t getpid(void)
rb_cEncoding
VALUE rb_cEncoding
Definition: encoding.c:46
rb_method_basic_definition_p
#define rb_method_basic_definition_p(klass, mid)
Definition: rb_mjit_min_header-2.7.2.h:7863
rb_mod_sys_fail
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:2835
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition: psych_emitter.c:7
TypedData_Wrap_Struct
#define TypedData_Wrap_Struct(klass, data_type, sval)
Definition: ruby.h:1231
vm_core.h
rb_error_frozen_object
void rb_error_frozen_object(VALUE frozen_obj)
Definition: error.c:3008
rb_sys_fail
void rb_sys_fail(const char *mesg)
Definition: error.c:2795
rb_source_location_cstr
const char * rb_source_location_cstr(int *pline)
Definition: vm.c:1376
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:924
vars
const VALUE int int int int int int VALUE * vars[]
Definition: rb_mjit_min_header-2.7.2.h:6458
id_status
#define id_status
Definition: internal.h:1591
EXIT_SUCCESS
#define EXIT_SUCCESS
Definition: error.c:39
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:922
MAX_BUG_REPORTERS
#define MAX_BUG_REPORTERS
Definition: error.c:447
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_control_frame_struct
Definition: vm_core.h:760
rb_async_bug_errno
void rb_async_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:690
RTYPEDDATA_DATA
#define RTYPEDDATA_DATA(v)
Definition: ruby.h:1179
rb_str_set_len
void rb_str_set_len(VALUE, long)
Definition: string.c:2692
rb_syserr_new_str
VALUE rb_syserr_new_str(int n, VALUE arg)
Definition: error.c:2777
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
RString
Definition: ruby.h:988
rb_eEWOULDBLOCK
VALUE rb_eEWOULDBLOCK
Definition: error.c:55
rb_typeddata_is_instance_of
int rb_typeddata_is_instance_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:885
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.2.h:5597
rb_frozen_error_raise
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Definition: error.c:2982
vsnprintf
int int vsnprintf(char *__restrict, size_t, const char *__restrict, __gnuc_va_list) __attribute__((__format__(__printf__
rb_check_to_int
VALUE rb_check_to_int(VALUE)
Tries to convert val into Integer.
Definition: object.c:3036
rb_syntax_error_append
VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args)
Definition: error.c:104
rb_invalid_str
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:1867
mask
enum @0::@2::@3 mask
rb_extend_object
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
Definition: eval.c:1701
rb_sys_warning
void rb_sys_warning(const char *fmt,...)
Definition: error.c:2921
key
key
Definition: openssl_missing.h:181
rb_scan_args
#define rb_scan_args(argc, argvp, fmt,...)
Definition: rb_mjit_min_header-2.7.2.h:6368
rb_eLoadError
VALUE rb_eLoadError
Definition: error.c:941
rb_report_bug_valist
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
Definition: error.c:712
rb_typeddata_is_kind_of
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:874
rb_mod_syserr_fail_str
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Definition: error.c:2859
rb_eNotImpError
VALUE rb_eNotImpError
Definition: error.c:934
CLASS_OF
#define CLASS_OF(v)
Definition: ruby.h:484
rb_str_buf_append
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:2950
rb_eNoMethodError
VALUE rb_eNoMethodError
Definition: error.c:932
U
Definition: dtoa.c:290
RARRAY_LEN
#define RARRAY_LEN(a)
Definition: ruby.h:1070
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:2010
buf
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4322
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:668
NORETURN
NORETURN(static void die(void))
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.2.h:5738
TypedData_Get_Struct
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:1252
FAKE_CSTR
#define FAKE_CSTR(v, str)
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2965
rb_bug
void rb_bug(const char *fmt,...)
Definition: error.c:636
rb_exc_new_cstr
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Definition: error.c:968
rb_backtrace_p
int rb_backtrace_p(VALUE obj)
Definition: vm_backtrace.c:446
internal.h
T_ARRAY
#define T_ARRAY
Definition: ruby.h:530
argv
char ** argv
Definition: ruby.c:223
rb_set_errinfo
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
Definition: eval.c:1896
rb_eSecurityError
VALUE rb_eSecurityError
Definition: error.c:933
rb_write_error_str
RUBY_EXTERN void rb_write_error_str(VALUE mesg)
Definition: io.c:7936
ruby_thread_has_gvl_p
int ruby_thread_has_gvl_p(void)
Definition: thread.c:1705
rb_vm_get_ruby_level_next_cfp
MJIT_FUNC_EXPORTED rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
Definition: vm.c:553
rb_warn_deprecated
void rb_warn_deprecated(const char *fmt, const char *suggest,...)
Definition: error.c:366
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1197
rb_syserr_enc_warning
void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt,...)
Definition: error.c:2957
StringValue
use StringValue() instead")))
Init_warning
void Init_warning(void)
Definition: error.c:3070
EAGAIN
#define EAGAIN
Definition: rb_mjit_min_header-2.7.2.h:10916
rb_obj_alloc
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
Definition: object.c:1895
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_control_frame_struct::iseq
const rb_iseq_t * iseq
Definition: vm_core.h:763
RARRAY_CONST_PTR
#define RARRAY_CONST_PTR(s)
Definition: psych_emitter.c:4
RUBY_TYPED_FREE_IMMEDIATELY
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1207
path
VALUE path
Definition: rb_mjit_min_header-2.7.2.h:7336
rb_cString
RUBY_EXTERN VALUE rb_cString
Definition: ruby.h:2044
ssize_t
_ssize_t ssize_t
Definition: rb_mjit_min_header-2.7.2.h:1327
idException
@ idException
Definition: rb_mjit_min_header-2.7.2.h:8693
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.2.h:6581
rb_enc_raise
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Definition: error.c:2652
va_start
#define va_start(v, l)
Definition: rb_mjit_min_header-2.7.2.h:3981
rb_warning_string
VALUE rb_warning_string(const char *fmt,...)
Definition: error.c:346
argc
int argc
Definition: ruby.c:222
write_or_abort
#define write_or_abort(fd, str, len)
Definition: error.c:686
rb_enc_warn
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
Definition: error.c:325
rb_exec_recursive
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
Definition: thread.c:5075
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:289
rb_sys_fail_str
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:2801
rb_vm_bugreport
void rb_vm_bugreport(const void *)
Definition: vm_dump.c:918
rb_eKeyError
VALUE rb_eKeyError
Definition: error.c:927
rb_name_error_str
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:1530
rb_define_const
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2891
recur
#define recur(fmt)
Definition: date_strptime.c:152
rb_eSystemCallError
VALUE rb_eSystemCallError
Definition: error.c:943
err
int err
Definition: win32.c:135
id_mesg
#define id_mesg
Definition: error.c:955
rb_data_type_struct
Definition: ruby.h:1148
rb_String
VALUE rb_String(VALUE)
Equivalent to Kernel#String in Ruby.
Definition: object.c:3652
rb_eException
VALUE rb_eException
Definition: error.c:916
st_data_t
unsigned long st_data_t
Definition: rb_mjit_min_header-2.7.2.h:5359
ruby_description
const char ruby_description[]
Definition: version.c:43
rb_eFatal
VALUE rb_eFatal
Definition: error.c:920
MJIT_FUNC_EXPORTED
#define MJIT_FUNC_EXPORTED
Definition: defines.h:396
rb_check_typeddata
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:891
RUBY_EVENT_C_RETURN
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:2248
rb_compile_warn
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:272
Qtrue
#define Qtrue
Definition: ruby.h:468
errno
int errno
rb_str_catf
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1237
rb_get_backtrace
VALUE rb_get_backtrace(VALUE exc)
Definition: error.c:1231
rb_class_name
VALUE rb_class_name(VALUE)
Definition: variable.c:274
rb_mErrno
VALUE rb_mErrno
Definition: error.c:944
len
uint8_t len
Definition: escape.c:17
rb_call_super_kw
VALUE rb_call_super_kw(int, const VALUE *, int)
Definition: vm_eval.c:298
SYMBOL_P
#define SYMBOL_P(x)
Definition: ruby.h:413
rb_check_copyable
void rb_check_copyable(VALUE obj, VALUE orig)
Definition: error.c:3049
rb_eEncCompatError
VALUE rb_eEncCompatError
Definition: error.c:931
rb_eEINPROGRESS
VALUE rb_eEINPROGRESS
Definition: error.c:56
rb_class_new_instance
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
Definition: object.c:1955
stderr
#define stderr
Definition: rb_mjit_min_header-2.7.2.h:1516
FUNC_MINIMIZED
FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len))
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1300
RTYPEDDATA_P
#define RTYPEDDATA_P(v)
Definition: ruby.h:1177
rb_exc_fatal
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
Definition: eval.c:684
T_STRING
#define T_STRING
Definition: ruby.h:528
rb_funcallv
#define rb_funcallv(recv, mid, argc, argv)
Definition: rb_mjit_min_header-2.7.2.h:7862
rb_string_value_ptr
char * rb_string_value_ptr(volatile VALUE *)
Definition: string.c:2186
NAME_ERR_MESG_COUNT
@ NAME_ERR_MESG_COUNT
Definition: error.c:1687
RUBY_EVENT_C_CALL
#define RUBY_EVENT_C_CALL
Definition: ruby.h:2247
rb_define_class_under
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:698
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: rb_mjit_min_header-2.7.2.h:6113
rb_builtin_class_name
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:799
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:723
RB_WARN_CATEGORY_DEPRECATED
@ RB_WARN_CATEGORY_DEPRECATED
Definition: internal.h:1562
rb_cNameErrorMesg
VALUE rb_cNameErrorMesg
Definition: error.c:936
builtin.h
id_name
#define id_name
Definition: error.c:956
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
Qnil
#define Qnil
Definition: ruby.h:469
rb_str_new
#define rb_str_new(str, len)
Definition: rb_mjit_min_header-2.7.2.h:6112
rb_fstring_lit
#define rb_fstring_lit(str)
Definition: internal.h:2129
rb_str_buf_cat
#define rb_str_buf_cat
Definition: intern.h:910
st_lookup
int st_lookup(st_table *tab, st_data_t key, st_data_t *value)
Definition: st.c:1101
rb_eInterrupt
VALUE rb_eInterrupt
Definition: error.c:918
rb_warning_category_from_name
rb_warning_category_t rb_warning_category_from_name(VALUE category)
Definition: error.c:142
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:921
numberof
#define numberof(array)
Definition: etc.c:618
rb_str_tmp_new
VALUE rb_str_tmp_new(long)
Definition: string.c:1343
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:1005
rb_loaderror_with_path
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Definition: error.c:2702
rb_eNoMemError
VALUE rb_eNoMemError
Definition: error.c:935
st_table
Definition: st.h:79
ruby_assert.h
id_debug_created_info
@ id_debug_created_info
Definition: id.h:129
RUBY_VM_PREVIOUS_CONTROL_FRAME
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1384
rb_any_to_s
VALUE rb_any_to_s(VALUE)
Default implementation of #to_s.
Definition: object.c:527
rb_attr
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:1163
rb_enc_str_new
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:796
T_TRUE
#define T_TRUE
Definition: ruby.h:536
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:692
rb_warning_category_t
rb_warning_category_t
Definition: internal.h:1560
RTEST
#define RTEST(v)
Definition: ruby.h:481
report_bug_valist
#define report_bug_valist(file, line, fmt, ctx, args)
Definition: error.c:615
ruby::backward::cxxanyargs::type
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:39
rb_str_buf_new2
#define rb_str_buf_new2
Definition: intern.h:908
rb_exc_set_backtrace
MJIT_FUNC_EXPORTED VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:1312
id_bt_locations
#define id_bt_locations
Definition: error.c:954
rb_unexpected_type
void rb_unexpected_type(VALUE x, int t)
Definition: error.c:854
rb_mod_sys_fail_str
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Definition: error.c:2843
__sFILE
Definition: vsnprintf.c:169
rb_eSystemExit
VALUE rb_eSystemExit
Definition: error.c:917
rb_obj_clone
VALUE rb_obj_clone(VALUE)
Almost same as Object::clone.
Definition: object.c:410
WIFEXITED
#define WIFEXITED(status)
Definition: error.c:43
rb_eFrozenError
VALUE rb_eFrozenError
Definition: error.c:923
rb_usascii_encoding
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1340
rb_syserr_fail_str
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:2789
RSTRING_END
#define RSTRING_END(str)
Definition: ruby.h:1013
name
const char * name
Definition: nkf.c:208
rb_execution_context_struct
Definition: vm_core.h:843
n
const char size_t n
Definition: rb_mjit_min_header-2.7.2.h:5452
rb_const_get
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:2391