Ruby  2.4.2p198(2017-09-14revision59899)
error.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  error.c -
4 
5  $Author: naruse $
6  created at: Mon Aug 9 16:11:34 JST 1993
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9 
10 **********************************************************************/
11 
12 #include "internal.h"
13 #include "ruby/st.h"
14 #include "ruby_assert.h"
15 #include "vm_core.h"
16 
17 #include <stdio.h>
18 #include <stdarg.h>
19 #ifdef HAVE_STDLIB_H
20 #include <stdlib.h>
21 #endif
22 #include <errno.h>
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h>
25 #endif
26 
27 #if defined __APPLE__
28 # include <AvailabilityMacros.h>
29 #endif
30 
31 #ifndef EXIT_SUCCESS
32 #define EXIT_SUCCESS 0
33 #endif
34 
35 #ifndef WIFEXITED
36 #define WIFEXITED(status) 1
37 #endif
38 
39 #ifndef WEXITSTATUS
40 #define WEXITSTATUS(status) (status)
41 #endif
42 
45 
50 
51 static ID id_warn;
52 
53 extern const char ruby_description[];
54 
55 static const char REPORTBUG_MSG[] =
56  "[NOTE]\n" \
57  "You may have encountered a bug in the Ruby interpreter" \
58  " or extension libraries.\n" \
59  "Bug reports are welcome.\n" \
60  ""
61  "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
62  ;
63 
64 static const char *
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);
118  exc = rb_class_new_instance(1, &mesg, rb_eSyntaxError);
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 void
132 rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
133 {
134  ONLY_FOR_INTERNAL_USE("rb_compile_error_with_enc()");
135 }
136 
137 void
138 rb_compile_error(const char *file, int line, const char *fmt, ...)
139 {
140  ONLY_FOR_INTERNAL_USE("rb_compile_error()");
141 }
142 
143 void
144 rb_compile_error_append(const char *fmt, ...)
145 {
146  ONLY_FOR_INTERNAL_USE("rb_compile_error_append()");
147 }
148 
149 void
151 {
153  rb_fatal("%s is only for internal use and deprecated; do not use", func);
154 }
155 
156 static VALUE
158 {
159  Check_Type(str, T_STRING);
160  rb_must_asciicompat(str);
161  rb_write_error_str(str);
162  return Qnil;
163 }
164 
165 static void
167 {
168  rb_funcall(rb_mWarning, id_warn, 1, str);
169 }
170 
171 static VALUE
172 warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
173 {
174  VALUE str = rb_enc_str_new(0, 0, enc);
175 
176  err_vcatf(str, "warning: ", file, line, fmt, args);
177  return rb_str_cat2(str, "\n");
178 }
179 
180 void
181 rb_compile_warn(const char *file, int line, const char *fmt, ...)
182 {
183  VALUE str;
184  va_list args;
185 
186  if (NIL_P(ruby_verbose)) return;
187 
188  va_start(args, fmt);
189  str = warn_vsprintf(NULL, file, line, fmt, args);
190  va_end(args);
192 }
193 
194 /* rb_compile_warning() reports only in verbose mode */
195 void
196 rb_compile_warning(const char *file, int line, const char *fmt, ...)
197 {
198  VALUE str;
199  va_list args;
200 
201  if (!RTEST(ruby_verbose)) return;
202 
203  va_start(args, fmt);
204  str = warn_vsprintf(NULL, file, line, fmt, args);
205  va_end(args);
207 }
208 
209 static VALUE
210 warning_string(rb_encoding *enc, const char *fmt, va_list args)
211 {
212  int line;
213  VALUE file = rb_source_location(&line);
214 
215  return warn_vsprintf(enc,
216  NIL_P(file) ? NULL : RSTRING_PTR(file), line,
217  fmt, args);
218 }
219 
220 void
221 rb_warn(const char *fmt, ...)
222 {
223  VALUE mesg;
224  va_list args;
225 
226  if (NIL_P(ruby_verbose)) return;
227 
228  va_start(args, fmt);
229  mesg = warning_string(0, fmt, args);
230  va_end(args);
231  rb_write_warning_str(mesg);
232 }
233 
234 void
235 rb_enc_warn(rb_encoding *enc, const char *fmt, ...)
236 {
237  VALUE mesg;
238  va_list args;
239 
240  if (NIL_P(ruby_verbose)) return;
241 
242  va_start(args, fmt);
243  mesg = warning_string(enc, fmt, args);
244  va_end(args);
245  rb_write_warning_str(mesg);
246 }
247 
248 /* rb_warning() reports only in verbose mode */
249 void
250 rb_warning(const char *fmt, ...)
251 {
252  VALUE mesg;
253  va_list args;
254 
255  if (!RTEST(ruby_verbose)) return;
256 
257  va_start(args, fmt);
258  mesg = warning_string(0, fmt, args);
259  va_end(args);
260  rb_write_warning_str(mesg);
261 }
262 
263 #if 0
264 void
265 rb_enc_warning(rb_encoding *enc, const char *fmt, ...)
266 {
267  VALUE mesg;
268  va_list args;
269 
270  if (!RTEST(ruby_verbose)) return;
271 
272  va_start(args, fmt);
273  mesg = warning_string(enc, fmt, args);
274  va_end(args);
275  rb_write_warning_str(mesg);
276 }
277 #endif
278 
279 /*
280  * call-seq:
281  * warn(msg, ...) -> nil
282  *
283  * Displays each of the given messages followed by a record separator on
284  * STDERR unless warnings have been disabled (for example with the
285  * <code>-W0</code> flag).
286  *
287  * warn("warning 1", "warning 2")
288  *
289  * <em>produces:</em>
290  *
291  * warning 1
292  * warning 2
293  */
294 
295 static VALUE
297 {
298  if (!NIL_P(ruby_verbose) && argc > 0) {
299  rb_io_puts(argc, argv, rb_stderr);
300  }
301  return Qnil;
302 }
303 
304 #define MAX_BUG_REPORTERS 0x100
305 
306 static struct bug_reporters {
307  void (*func)(FILE *out, void *data);
308  void *data;
310 
312 
313 int
314 rb_bug_reporter_add(void (*func)(FILE *, void *), void *data)
315 {
316  struct bug_reporters *reporter;
318  return 0; /* failed to register */
319  }
320  reporter = &bug_reporters[bug_reporters_size++];
321  reporter->func = func;
322  reporter->data = data;
323 
324  return 1;
325 }
326 
327 /* SIGSEGV handler might have a very small stack. Thus we need to use it carefully. */
328 #define REPORT_BUG_BUFSIZ 256
329 static FILE *
330 bug_report_file(const char *file, int line)
331 {
332  char buf[REPORT_BUG_BUFSIZ];
333  FILE *out = stderr;
334  int len = err_position_0(buf, sizeof(buf), file, line);
335 
336  if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
337  (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
338  return out;
339  }
340  return NULL;
341 }
342 
343 FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len));
344 
345 static void
346 bug_important_message(FILE *out, const char *const msg, size_t len)
347 {
348  const char *const endmsg = msg + len;
349  const char *p = msg;
350 
351  if (!len) return;
352  if (isatty(fileno(out))) {
353  static const char red[] = "\033[;31;1;7m";
354  static const char green[] = "\033[;32;7m";
355  static const char reset[] = "\033[m";
356  const char *e = strchr(p, '\n');
357  const int w = (int)(e - p);
358  do {
359  int i = (int)(e - p);
360  fputs(*p == ' ' ? green : red, out);
361  fwrite(p, 1, e - p, out);
362  for (; i < w; ++i) fputc(' ', out);
363  fputs(reset, out);
364  fputc('\n', out);
365  } while ((p = e + 1) < endmsg && (e = strchr(p, '\n')) != 0 && e > p + 1);
366  }
367  fwrite(p, 1, endmsg - p, out);
368 }
369 
370 static void
372 {
373 #if defined __APPLE__
374  static const char msg[] = ""
375  "-- Crash Report log information "
376  "--------------------------------------------\n"
377  " See Crash Report log file under the one of following:\n"
378 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
379  " * ~/Library/Logs/CrashReporter\n"
380  " * /Library/Logs/CrashReporter\n"
381 # endif
382  " * ~/Library/Logs/DiagnosticReports\n"
383  " * /Library/Logs/DiagnosticReports\n"
384  " for more details.\n"
385  "Don't forget to include the above Crash Report log file in bug reports.\n"
386  "\n";
387  const size_t msglen = sizeof(msg) - 1;
388 #else
389  const char *msg = NULL;
390  const size_t msglen = 0;
391 #endif
392  bug_important_message(out, msg, msglen);
393 }
394 
395 static void
397 {
398 #if defined __APPLE__
399  static const char msg[] = ""
400  "[IMPORTANT]"
401  /*" ------------------------------------------------"*/
402  "\n""Don't forget to include the Crash Report log file under\n"
403 # if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
404  "CrashReporter or "
405 # endif
406  "DiagnosticReports directory in bug reports.\n"
407  /*"------------------------------------------------------------\n"*/
408  "\n";
409  const size_t msglen = sizeof(msg) - 1;
410 #else
411  const char *msg = NULL;
412  const size_t msglen = 0;
413 #endif
414  bug_important_message(out, msg, msglen);
415 }
416 
417 static void
418 bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
419 {
420  char buf[REPORT_BUG_BUFSIZ];
421 
422  fputs("[BUG] ", out);
423  vsnprintf(buf, sizeof(buf), fmt, args);
424  fputs(buf, out);
425  snprintf(buf, sizeof(buf), "\n%s\n\n", ruby_description);
426  fputs(buf, out);
427  preface_dump(out);
428 }
429 
430 #define bug_report_begin(out, fmt) do { \
431  va_list args; \
432  va_start(args, fmt); \
433  bug_report_begin_valist(out, fmt, args); \
434  va_end(args); \
435 } while (0)
436 
437 static void
439 {
440  /* call additional bug reporters */
441  {
442  int i;
443  for (i=0; i<bug_reporters_size; i++) {
444  struct bug_reporters *reporter = &bug_reporters[i];
445  (*reporter->func)(out, reporter->data);
446  }
447  }
448  fputs(REPORTBUG_MSG, out);
449  postscript_dump(out);
450 }
451 
452 #define report_bug(file, line, fmt, ctx) do { \
453  FILE *out = bug_report_file(file, line); \
454  if (out) { \
455  bug_report_begin(out, fmt); \
456  rb_vm_bugreport(ctx); \
457  bug_report_end(out); \
458  } \
459 } while (0) \
460 
461 #define report_bug_valist(file, line, fmt, ctx, args) do { \
462  FILE *out = bug_report_file(file, line); \
463  if (out) { \
464  bug_report_begin_valist(out, fmt, args); \
465  rb_vm_bugreport(ctx); \
466  bug_report_end(out); \
467  } \
468 } while (0) \
469 
470 NORETURN(static void die(void));
471 static void
472 die(void)
473 {
474 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
475  _set_abort_behavior( 0, _CALL_REPORTFAULT);
476 #endif
477 
478  abort();
479 }
480 
481 void
482 rb_bug(const char *fmt, ...)
483 {
484  const char *file = NULL;
485  int line = 0;
486 
487  if (GET_THREAD()) {
488  file = rb_source_loc(&line);
489  }
490 
491  report_bug(file, line, fmt, NULL);
492 
493  die();
494 }
495 
496 void
497 rb_bug_context(const void *ctx, const char *fmt, ...)
498 {
499  const char *file = NULL;
500  int line = 0;
501 
502  if (GET_THREAD()) {
503  file = rb_source_loc(&line);
504  }
505 
506  report_bug(file, line, fmt, ctx);
507 
508  die();
509 }
510 
511 
512 void
513 rb_bug_errno(const char *mesg, int errno_arg)
514 {
515  if (errno_arg == 0)
516  rb_bug("%s: errno == 0 (NOERROR)", mesg);
517  else {
518  const char *errno_str = rb_strerrno(errno_arg);
519  if (errno_str)
520  rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
521  else
522  rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
523  }
524 }
525 
526 /*
527  * this is safe to call inside signal handler and timer thread
528  * (which isn't a Ruby Thread object)
529  */
530 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
531 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
532 
533 void
534 rb_async_bug_errno(const char *mesg, int errno_arg)
535 {
536  WRITE_CONST(2, "[ASYNC BUG] ");
537  write_or_abort(2, mesg, strlen(mesg));
538  WRITE_CONST(2, "\n");
539 
540  if (errno_arg == 0) {
541  WRITE_CONST(2, "errno == 0 (NOERROR)\n");
542  }
543  else {
544  const char *errno_str = rb_strerrno(errno_arg);
545 
546  if (!errno_str)
547  errno_str = "undefined errno";
548  write_or_abort(2, errno_str, strlen(errno_str));
549  }
550  WRITE_CONST(2, "\n\n");
552  WRITE_CONST(2, "\n\n");
554  abort();
555 }
556 
557 void
558 rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
559 {
560  report_bug_valist(RSTRING_PTR(file), line, fmt, NULL, args);
561 }
562 
563 void
564 rb_assert_failure(const char *file, int line, const char *name, const char *expr)
565 {
566  FILE *out = stderr;
567  fprintf(out, "Assertion Failed: %s:%d:", file, line);
568  if (name) fprintf(out, "%s:", name);
569  fprintf(out, "%s\n%s\n\n", expr, ruby_description);
570  preface_dump(out);
572  bug_report_end(out);
573  die();
574 }
575 
576 static const char builtin_types[][10] = {
577  "", /* 0x00, */
578  "Object",
579  "Class",
580  "Module",
581  "Float",
582  "String",
583  "Regexp",
584  "Array",
585  "Hash",
586  "Struct",
587  "Bignum",
588  "File",
589  "Data", /* internal use: wrapped C pointers */
590  "MatchData", /* data of $~ */
591  "Complex",
592  "Rational",
593  "", /* 0x10 */
594  "nil",
595  "true",
596  "false",
597  "Symbol", /* :symbol */
598  "Fixnum",
599  "undef", /* internal use: #undef; should not happen */
600  "", /* 0x17 */
601  "", /* 0x18 */
602  "", /* 0x19 */
603  "Memo", /* internal use: general memo */
604  "Node", /* internal use: syntax tree node */
605  "iClass", /* internal use: mixed-in module holder */
606 };
607 
608 const char *
610 {
611  const char *name;
612  if ((unsigned int)t >= numberof(builtin_types)) return 0;
613  name = builtin_types[t];
614  if (*name) return name;
615  return 0;
616 }
617 
618 static const char *
620 {
621  const char *etype;
622 
623  if (NIL_P(x)) {
624  etype = "nil";
625  }
626  else if (FIXNUM_P(x)) {
627  etype = "Integer";
628  }
629  else if (SYMBOL_P(x)) {
630  etype = "Symbol";
631  }
632  else if (RB_TYPE_P(x, T_TRUE)) {
633  etype = "true";
634  }
635  else if (RB_TYPE_P(x, T_FALSE)) {
636  etype = "false";
637  }
638  else {
639  etype = NULL;
640  }
641  return etype;
642 }
643 
644 const char *
646 {
647  const char *etype = builtin_class_name(x);
648 
649  if (!etype) {
650  etype = rb_obj_classname(x);
651  }
652  return etype;
653 }
654 
655 NORETURN(static void unexpected_type(VALUE, int, int));
656 #define UNDEF_LEAKED "undef leaked to the Ruby space"
657 
658 static void
659 unexpected_type(VALUE x, int xt, int t)
660 {
661  const char *tname = rb_builtin_type_name(t);
662  VALUE mesg, exc = rb_eFatal;
663 
664  if (tname) {
665  const char *cname = builtin_class_name(x);
666  if (cname)
667  mesg = rb_sprintf("wrong argument type %s (expected %s)",
668  cname, tname);
669  else
670  mesg = rb_sprintf("wrong argument type %"PRIsVALUE" (expected %s)",
671  rb_obj_class(x), tname);
672  exc = rb_eTypeError;
673  }
674  else if (xt > T_MASK && xt <= 0x3f) {
675  mesg = rb_sprintf("unknown type 0x%x (0x%x given, probably comes"
676  " from extension library for ruby 1.8)", t, xt);
677  }
678  else {
679  mesg = rb_sprintf("unknown type 0x%x (0x%x given)", t, xt);
680  }
681  rb_exc_raise(rb_exc_new_str(exc, mesg));
682 }
683 
684 void
686 {
687  int xt;
688 
689  if (x == Qundef) {
691  }
692 
693  xt = TYPE(x);
694  if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
695  unexpected_type(x, xt, t);
696  }
697 }
698 
699 void
701 {
702  if (x == Qundef) {
704  }
705 
706  unexpected_type(x, TYPE(x), t);
707 }
708 
709 int
711 {
712  while (child) {
713  if (child == parent) return 1;
714  child = child->parent;
715  }
716  return 0;
717 }
718 
719 int
721 {
722  if (!RB_TYPE_P(obj, T_DATA) ||
723  !RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
724  return 0;
725  }
726  return 1;
727 }
728 
729 void *
731 {
732  const char *etype;
733 
734  if (!RB_TYPE_P(obj, T_DATA)) {
735  wrong_type:
736  etype = builtin_class_name(obj);
737  if (!etype)
738  rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)",
739  rb_obj_class(obj), data_type->wrap_struct_name);
740  wrong_datatype:
741  rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
742  etype, data_type->wrap_struct_name);
743  }
744  if (!RTYPEDDATA_P(obj)) {
745  goto wrong_type;
746  }
747  else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
748  etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
749  goto wrong_datatype;
750  }
751  return DATA_PTR(obj);
752 }
753 
754 /* exception classes */
775 
779 
783 
789 #define id_bt idBt
790 #define id_bt_locations idBt_locations
791 #define id_mesg idMesg
792 #define id_status ruby_static_id_status
793 
794 #undef rb_exc_new_cstr
795 
796 VALUE
797 rb_exc_new(VALUE etype, const char *ptr, long len)
798 {
799  return rb_funcall(etype, id_new, 1, rb_str_new(ptr, len));
800 }
801 
802 VALUE
803 rb_exc_new_cstr(VALUE etype, const char *s)
804 {
805  return rb_exc_new(etype, s, strlen(s));
806 }
807 
808 VALUE
810 {
811  StringValue(str);
812  return rb_funcall(etype, id_new, 1, str);
813 }
814 
815 /*
816  * call-seq:
817  * Exception.new(msg = nil) -> exception
818  *
819  * Construct a new Exception object, optionally passing in
820  * a message.
821  */
822 
823 static VALUE
825 {
826  VALUE arg;
827 
828  rb_scan_args(argc, argv, "01", &arg);
829  rb_ivar_set(exc, id_mesg, arg);
830  rb_ivar_set(exc, id_bt, Qnil);
831 
832  return exc;
833 }
834 
835 /*
836  * Document-method: exception
837  *
838  * call-seq:
839  * exc.exception(string) -> an_exception or exc
840  *
841  * With no argument, or if the argument is the same as the receiver,
842  * return the receiver. Otherwise, create a new
843  * exception object of the same class as the receiver, but with a
844  * message equal to <code>string.to_str</code>.
845  *
846  */
847 
848 static VALUE
850 {
851  VALUE exc;
852 
853  if (argc == 0) return self;
854  if (argc == 1 && self == argv[0]) return self;
855  exc = rb_obj_clone(self);
856  exc_initialize(argc, argv, exc);
857 
858  return exc;
859 }
860 
861 /*
862  * call-seq:
863  * exception.to_s -> string
864  *
865  * Returns exception's message (or the name of the exception if
866  * no message is set).
867  */
868 
869 static VALUE
871 {
872  VALUE mesg = rb_attr_get(exc, idMesg);
873 
874  if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
875  return rb_String(mesg);
876 }
877 
878 /*
879  * call-seq:
880  * exception.message -> string
881  *
882  * Returns the result of invoking <code>exception.to_s</code>.
883  * Normally this returns the exception's message or name.
884  */
885 
886 static VALUE
888 {
889  return rb_funcallv(exc, idTo_s, 0, 0);
890 }
891 
892 /*
893  * call-seq:
894  * exception.inspect -> string
895  *
896  * Return this exception's class name and message
897  */
898 
899 static VALUE
901 {
902  VALUE str, klass;
903 
904  klass = CLASS_OF(exc);
905  exc = rb_obj_as_string(exc);
906  if (RSTRING_LEN(exc) == 0) {
907  return rb_str_dup(rb_class_name(klass));
908  }
909 
910  str = rb_str_buf_new2("#<");
911  klass = rb_class_name(klass);
912  rb_str_buf_append(str, klass);
913  rb_str_buf_cat(str, ": ", 2);
914  rb_str_buf_append(str, exc);
915  rb_str_buf_cat(str, ">", 1);
916 
917  return str;
918 }
919 
920 /*
921  * call-seq:
922  * exception.backtrace -> array
923  *
924  * Returns any backtrace associated with the exception. The backtrace
925  * is an array of strings, each containing either ``filename:lineNo: in
926  * `method''' or ``filename:lineNo.''
927  *
928  * def a
929  * raise "boom"
930  * end
931  *
932  * def b
933  * a()
934  * end
935  *
936  * begin
937  * b()
938  * rescue => detail
939  * print detail.backtrace.join("\n")
940  * end
941  *
942  * <em>produces:</em>
943  *
944  * prog.rb:2:in `a'
945  * prog.rb:6:in `b'
946  * prog.rb:10
947 */
948 
949 static VALUE
951 {
952  VALUE obj;
953 
954  obj = rb_attr_get(exc, id_bt);
955 
956  if (rb_backtrace_p(obj)) {
957  obj = rb_backtrace_to_str_ary(obj);
958  /* rb_ivar_set(exc, id_bt, obj); */
959  }
960 
961  return obj;
962 }
963 
964 VALUE
966 {
967  ID mid = id_backtrace;
968  if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) {
969  VALUE info, klass = rb_eException;
970  rb_thread_t *th = GET_THREAD();
971  if (NIL_P(exc))
972  return Qnil;
973  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
974  info = exc_backtrace(exc);
975  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
976  if (NIL_P(info))
977  return Qnil;
978  return rb_check_backtrace(info);
979  }
980  return rb_funcall(exc, mid, 0, 0);
981 }
982 
983 /*
984  * call-seq:
985  * exception.backtrace_locations -> array
986  *
987  * Returns any backtrace associated with the exception. This method is
988  * similar to Exception#backtrace, but the backtrace is an array of
989  * Thread::Backtrace::Location.
990  *
991  * Now, this method is not affected by Exception#set_backtrace().
992  */
993 static VALUE
995 {
996  VALUE obj;
997 
998  obj = rb_attr_get(exc, id_bt_locations);
999  if (!NIL_P(obj)) {
1000  obj = rb_backtrace_to_location_ary(obj);
1001  }
1002  return obj;
1003 }
1004 
1005 VALUE
1007 {
1008  long i;
1009  static const char err[] = "backtrace must be Array of String";
1010 
1011  if (!NIL_P(bt)) {
1012  if (RB_TYPE_P(bt, T_STRING)) return rb_ary_new3(1, bt);
1013  if (rb_backtrace_p(bt)) return bt;
1014  if (!RB_TYPE_P(bt, T_ARRAY)) {
1015  rb_raise(rb_eTypeError, err);
1016  }
1017  for (i=0;i<RARRAY_LEN(bt);i++) {
1018  VALUE e = RARRAY_AREF(bt, i);
1019  if (!RB_TYPE_P(e, T_STRING)) {
1020  rb_raise(rb_eTypeError, err);
1021  }
1022  }
1023  }
1024  return bt;
1025 }
1026 
1027 /*
1028  * call-seq:
1029  * exc.set_backtrace(backtrace) -> array
1030  *
1031  * Sets the backtrace information associated with +exc+. The +backtrace+ must
1032  * be an array of String objects or a single String in the format described
1033  * in Exception#backtrace.
1034  *
1035  */
1036 
1037 static VALUE
1039 {
1040  return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1041 }
1042 
1043 VALUE
1045 {
1046  return exc_set_backtrace(exc, bt);
1047 }
1048 
1049 /*
1050  * call-seq:
1051  * exception.cause -> an_exception or nil
1052  *
1053  * Returns the previous exception ($!) at the time this exception was raised.
1054  * This is useful for wrapping exceptions and retaining the original exception
1055  * information.
1056  */
1057 
1058 static VALUE
1060 {
1061  return rb_attr_get(exc, id_cause);
1062 }
1063 
1064 static VALUE
1066 {
1067  return rb_check_funcall(obj, idException, 0, 0);
1068 }
1069 
1070 /*
1071  * call-seq:
1072  * exc == obj -> true or false
1073  *
1074  * Equality---If <i>obj</i> is not an <code>Exception</code>, returns
1075  * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
1076  * <i>obj</i> share same class, messages, and backtrace.
1077  */
1078 
1079 static VALUE
1081 {
1082  VALUE mesg, backtrace;
1083 
1084  if (exc == obj) return Qtrue;
1085 
1086  if (rb_obj_class(exc) != rb_obj_class(obj)) {
1087  int status = 0;
1088 
1089  obj = rb_protect(try_convert_to_exception, obj, &status);
1090  if (status || obj == Qundef) {
1092  return Qfalse;
1093  }
1094  if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
1095  mesg = rb_check_funcall(obj, id_message, 0, 0);
1096  if (mesg == Qundef) return Qfalse;
1097  backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
1098  if (backtrace == Qundef) return Qfalse;
1099  }
1100  else {
1101  mesg = rb_attr_get(obj, id_mesg);
1102  backtrace = exc_backtrace(obj);
1103  }
1104 
1105  if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
1106  return Qfalse;
1107  if (!rb_equal(exc_backtrace(exc), backtrace))
1108  return Qfalse;
1109  return Qtrue;
1110 }
1111 
1112 /*
1113  * call-seq:
1114  * SystemExit.new -> system_exit
1115  * SystemExit.new(status) -> system_exit
1116  * SystemExit.new(status, msg) -> system_exit
1117  * SystemExit.new(msg) -> system_exit
1118  *
1119  * Create a new +SystemExit+ exception with the given status and message.
1120  * Status is true, false, or an integer.
1121  * If status is not given, true is used.
1122  */
1123 
1124 static VALUE
1126 {
1127  VALUE status;
1128  if (argc > 0) {
1129  status = *argv;
1130 
1131  switch (status) {
1132  case Qtrue:
1133  status = INT2FIX(EXIT_SUCCESS);
1134  ++argv;
1135  --argc;
1136  break;
1137  case Qfalse:
1138  status = INT2FIX(EXIT_FAILURE);
1139  ++argv;
1140  --argc;
1141  break;
1142  default:
1143  status = rb_check_to_int(status);
1144  if (NIL_P(status)) {
1145  status = INT2FIX(EXIT_SUCCESS);
1146  }
1147  else {
1148 #if EXIT_SUCCESS != 0
1149  if (status == INT2FIX(0))
1150  status = INT2FIX(EXIT_SUCCESS);
1151 #endif
1152  ++argv;
1153  --argc;
1154  }
1155  break;
1156  }
1157  }
1158  else {
1159  status = INT2FIX(EXIT_SUCCESS);
1160  }
1161  rb_call_super(argc, argv);
1162  rb_ivar_set(exc, id_status, status);
1163  return exc;
1164 }
1165 
1166 
1167 /*
1168  * call-seq:
1169  * system_exit.status -> integer
1170  *
1171  * Return the status value associated with this system exit.
1172  */
1173 
1174 static VALUE
1176 {
1177  return rb_attr_get(exc, id_status);
1178 }
1179 
1180 
1181 /*
1182  * call-seq:
1183  * system_exit.success? -> true or false
1184  *
1185  * Returns +true+ if exiting successful, +false+ if not.
1186  */
1187 
1188 static VALUE
1190 {
1191  VALUE status_val = rb_attr_get(exc, id_status);
1192  int status;
1193 
1194  if (NIL_P(status_val))
1195  return Qtrue;
1196  status = NUM2INT(status_val);
1197  if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
1198  return Qtrue;
1199 
1200  return Qfalse;
1201 }
1202 
1203 void
1204 rb_name_error(ID id, const char *fmt, ...)
1205 {
1206  VALUE exc, argv[2];
1207  va_list args;
1208 
1209  va_start(args, fmt);
1210  argv[0] = rb_vsprintf(fmt, args);
1211  va_end(args);
1212 
1213  argv[1] = ID2SYM(id);
1214  exc = rb_class_new_instance(2, argv, rb_eNameError);
1215  rb_exc_raise(exc);
1216 }
1217 
1218 void
1219 rb_name_error_str(VALUE str, const char *fmt, ...)
1220 {
1221  VALUE exc, argv[2];
1222  va_list args;
1223 
1224  va_start(args, fmt);
1225  argv[0] = rb_vsprintf(fmt, args);
1226  va_end(args);
1227 
1228  argv[1] = str;
1229  exc = rb_class_new_instance(2, argv, rb_eNameError);
1230  rb_exc_raise(exc);
1231 }
1232 
1233 /*
1234  * call-seq:
1235  * NameError.new([msg, *, name]) -> name_error
1236  *
1237  * Construct a new NameError exception. If given the <i>name</i>
1238  * parameter may subsequently be examined using the <code>NameError.name</code>
1239  * method.
1240  */
1241 
1242 static VALUE
1244 {
1245  VALUE name;
1246  VALUE iseqw = Qnil;
1247 
1248  name = (argc > 1) ? argv[--argc] : Qnil;
1249  rb_call_super(argc, argv);
1250  rb_ivar_set(self, id_name, name);
1251  {
1252  rb_thread_t *th = GET_THREAD();
1253  rb_control_frame_t *cfp =
1255  if (cfp) iseqw = rb_iseqw_new(cfp->iseq);
1256  }
1257  rb_ivar_set(self, id_iseq, iseqw);
1258  return self;
1259 }
1260 
1261 /*
1262  * call-seq:
1263  * name_error.name -> string or nil
1264  *
1265  * Return the name associated with this NameError exception.
1266  */
1267 
1268 static VALUE
1270 {
1271  return rb_attr_get(self, id_name);
1272 }
1273 
1274 /*
1275  * call-seq:
1276  * name_error.local_variables -> array
1277  *
1278  * Return a list of the local variable names defined where this
1279  * NameError exception was raised.
1280  *
1281  * Internal use only.
1282  */
1283 
1284 static VALUE
1286 {
1287  VALUE vars = rb_attr_get(self, id_local_variables);
1288 
1289  if (NIL_P(vars)) {
1290  VALUE iseqw = rb_attr_get(self, id_iseq);
1291  if (!NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
1292  if (NIL_P(vars)) vars = rb_ary_new();
1293  rb_ivar_set(self, id_local_variables, vars);
1294  }
1295  return vars;
1296 }
1297 
1298 /*
1299  * call-seq:
1300  * NoMethodError.new([msg, *, name [, args]]) -> no_method_error
1301  *
1302  * Construct a NoMethodError exception for a method of the given name
1303  * called with the given arguments. The name may be accessed using
1304  * the <code>#name</code> method on the resulting object, and the
1305  * arguments using the <code>#args</code> method.
1306  */
1307 
1308 static VALUE
1310 {
1311  VALUE priv = (argc > 3) && (--argc, RTEST(argv[argc])) ? Qtrue : Qfalse;
1312  VALUE args = (argc > 2) ? argv[--argc] : Qnil;
1313  name_err_initialize(argc, argv, self);
1314  rb_ivar_set(self, id_args, args);
1315  rb_ivar_set(self, id_private_call_p, RTEST(priv) ? Qtrue : Qfalse);
1316  return self;
1317 }
1318 
1319 /* :nodoc: */
1320 enum {
1325 };
1326 
1327 static void
1329 {
1330  VALUE *ptr = p;
1332 }
1333 
1334 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1335 
1336 static size_t
1338 {
1339  return NAME_ERR_MESG_COUNT * sizeof(VALUE);
1340 }
1341 
1343  "name_err_mesg",
1344  {
1348  },
1350 };
1351 
1352 /* :nodoc: */
1353 VALUE
1355 {
1356  VALUE result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, 0);
1358 
1359  ptr[NAME_ERR_MESG__MESG] = mesg;
1360  ptr[NAME_ERR_MESG__RECV] = recv;
1361  ptr[NAME_ERR_MESG__NAME] = method;
1362  RTYPEDDATA_DATA(result) = ptr;
1363  return result;
1364 }
1365 
1366 VALUE
1367 rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
1368 {
1369  VALUE exc = rb_obj_alloc(rb_eNameError);
1370  rb_ivar_set(exc, id_mesg, rb_name_err_mesg_new(mesg, recv, method));
1371  rb_ivar_set(exc, id_bt, Qnil);
1372  rb_ivar_set(exc, id_name, method);
1373  rb_ivar_set(exc, id_receiver, recv);
1374  return exc;
1375 }
1376 
1377 /* :nodoc: */
1378 static VALUE
1380 {
1381  VALUE *ptr1, *ptr2;
1382  int i;
1383 
1384  if (obj1 == obj2) return Qtrue;
1385  if (rb_obj_class(obj2) != rb_cNameErrorMesg)
1386  return Qfalse;
1387 
1388  TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1389  TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1390  for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1391  if (!rb_equal(ptr1[i], ptr2[i]))
1392  return Qfalse;
1393  }
1394  return Qtrue;
1395 }
1396 
1397 /* :nodoc: */
1398 static VALUE
1400 {
1401  VALUE *ptr, mesg;
1402  TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
1403 
1404  mesg = ptr[NAME_ERR_MESG__MESG];
1405  if (NIL_P(mesg)) return Qnil;
1406  else {
1407  struct RString s_str, d_str;
1408  VALUE c, s, d = 0, args[4];
1409  int state = 0, singleton = 0;
1410  rb_encoding *usascii = rb_usascii_encoding();
1411 
1412 #define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
1413  obj = ptr[NAME_ERR_MESG__RECV];
1414  switch (obj) {
1415  case Qnil:
1416  d = FAKE_CSTR(&d_str, "nil");
1417  break;
1418  case Qtrue:
1419  d = FAKE_CSTR(&d_str, "true");
1420  break;
1421  case Qfalse:
1422  d = FAKE_CSTR(&d_str, "false");
1423  break;
1424  default:
1425  d = rb_protect(rb_inspect, obj, &state);
1426  if (state)
1428  if (NIL_P(d) || RSTRING_LEN(d) > 65) {
1429  d = rb_any_to_s(obj);
1430  }
1431  singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#');
1432  d = QUOTE(d);
1433  break;
1434  }
1435  if (!singleton) {
1436  s = FAKE_CSTR(&s_str, ":");
1437  c = rb_class_name(CLASS_OF(obj));
1438  }
1439  else {
1440  c = s = FAKE_CSTR(&s_str, "");
1441  }
1442  args[0] = QUOTE(rb_obj_as_string(ptr[NAME_ERR_MESG__NAME]));
1443  args[1] = d;
1444  args[2] = s;
1445  args[3] = c;
1446  mesg = rb_str_format(4, args, mesg);
1447  }
1448  return mesg;
1449 }
1450 
1451 /* :nodoc: */
1452 static VALUE
1454 {
1455  return name_err_mesg_to_str(obj);
1456 }
1457 
1458 /* :nodoc: */
1459 static VALUE
1461 {
1462  return str;
1463 }
1464 
1465 /*
1466  * call-seq:
1467  * name_error.receiver -> object
1468  *
1469  * Return the receiver associated with this NameError exception.
1470  */
1471 
1472 static VALUE
1474 {
1475  VALUE *ptr, recv, mesg;
1476 
1477  recv = rb_ivar_lookup(self, id_receiver, Qundef);
1478  if (recv != Qundef) return recv;
1479 
1480  mesg = rb_attr_get(self, id_mesg);
1481  if (!rb_typeddata_is_kind_of(mesg, &name_err_mesg_data_type)) {
1482  rb_raise(rb_eArgError, "no receiver is available");
1483  }
1484  ptr = DATA_PTR(mesg);
1485  return ptr[NAME_ERR_MESG__RECV];
1486 }
1487 
1488 /*
1489  * call-seq:
1490  * no_method_error.args -> obj
1491  *
1492  * Return the arguments passed in as the third parameter to
1493  * the constructor.
1494  */
1495 
1496 static VALUE
1498 {
1499  return rb_attr_get(self, id_args);
1500 }
1501 
1502 static VALUE
1504 {
1505  return rb_attr_get(self, id_private_call_p);
1506 }
1507 
1508 void
1509 rb_invalid_str(const char *str, const char *type)
1510 {
1511  VALUE s = rb_str_new2(str);
1512 
1513  rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
1514 }
1515 
1516 /*
1517  * call-seq:
1518  * SyntaxError.new([msg]) -> syntax_error
1519  *
1520  * Construct a SyntaxError exception.
1521  */
1522 
1523 static VALUE
1525 {
1526  VALUE mesg;
1527  if (argc == 0) {
1528  mesg = rb_fstring_cstr("compile error");
1529  argc = 1;
1530  argv = &mesg;
1531  }
1532  return rb_call_super(argc, argv);
1533 }
1534 
1535 /*
1536  * Document-module: Errno
1537  *
1538  * Ruby exception objects are subclasses of <code>Exception</code>.
1539  * However, operating systems typically report errors using plain
1540  * integers. Module <code>Errno</code> is created dynamically to map
1541  * these operating system errors to Ruby classes, with each error
1542  * number generating its own subclass of <code>SystemCallError</code>.
1543  * As the subclass is created in module <code>Errno</code>, its name
1544  * will start <code>Errno::</code>.
1545  *
1546  * The names of the <code>Errno::</code> classes depend on
1547  * the environment in which Ruby runs. On a typical Unix or Windows
1548  * platform, there are <code>Errno</code> classes such as
1549  * <code>Errno::EACCES</code>, <code>Errno::EAGAIN</code>,
1550  * <code>Errno::EINTR</code>, and so on.
1551  *
1552  * The integer operating system error number corresponding to a
1553  * particular error is available as the class constant
1554  * <code>Errno::</code><em>error</em><code>::Errno</code>.
1555  *
1556  * Errno::EACCES::Errno #=> 13
1557  * Errno::EAGAIN::Errno #=> 11
1558  * Errno::EINTR::Errno #=> 4
1559  *
1560  * The full list of operating system errors on your particular platform
1561  * are available as the constants of <code>Errno</code>.
1562  *
1563  * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
1564  */
1565 
1567 
1568 static VALUE
1569 set_syserr(int n, const char *name)
1570 {
1571  st_data_t error;
1572 
1573  if (!st_lookup(syserr_tbl, n, &error)) {
1574  error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
1575 
1576  /* capture nonblock errnos for WaitReadable/WaitWritable subclasses */
1577  switch (n) {
1578  case EAGAIN:
1579  rb_eEAGAIN = error;
1580 
1581 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
1582  break;
1583  case EWOULDBLOCK:
1584 #endif
1585 
1586  rb_eEWOULDBLOCK = error;
1587  break;
1588  case EINPROGRESS:
1589  rb_eEINPROGRESS = error;
1590  break;
1591  }
1592 
1593  rb_define_const(error, "Errno", INT2NUM(n));
1594  st_add_direct(syserr_tbl, n, error);
1595  }
1596  else {
1597  rb_define_const(rb_mErrno, name, error);
1598  }
1599  return error;
1600 }
1601 
1602 static VALUE
1604 {
1605  st_data_t error;
1606 
1607  if (!st_lookup(syserr_tbl, n, &error)) {
1608  char name[8]; /* some Windows' errno have 5 digits. */
1609 
1610  snprintf(name, sizeof(name), "E%03d", n);
1611  error = set_syserr(n, name);
1612  }
1613  return error;
1614 }
1615 
1616 /*
1617  * call-seq:
1618  * SystemCallError.new(msg, errno) -> system_call_error_subclass
1619  *
1620  * If _errno_ corresponds to a known system error code, constructs
1621  * the appropriate <code>Errno</code> class for that error, otherwise
1622  * constructs a generic <code>SystemCallError</code> object. The
1623  * error number is subsequently available via the <code>errno</code>
1624  * method.
1625  */
1626 
1627 static VALUE
1629 {
1630 #if !defined(_WIN32)
1631  char *strerror();
1632 #endif
1633  const char *err;
1634  VALUE mesg, error, func, errmsg;
1635  VALUE klass = rb_obj_class(self);
1636 
1637  if (klass == rb_eSystemCallError) {
1638  st_data_t data = (st_data_t)klass;
1639  rb_scan_args(argc, argv, "12", &mesg, &error, &func);
1640  if (argc == 1 && FIXNUM_P(mesg)) {
1641  error = mesg; mesg = Qnil;
1642  }
1643  if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
1644  klass = (VALUE)data;
1645  /* change class */
1646  if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
1647  rb_raise(rb_eTypeError, "invalid instance type");
1648  }
1649  RBASIC_SET_CLASS(self, klass);
1650  }
1651  }
1652  else {
1653  rb_scan_args(argc, argv, "02", &mesg, &func);
1654  error = rb_const_get(klass, id_Errno);
1655  }
1656  if (!NIL_P(error)) err = strerror(NUM2INT(error));
1657  else err = "unknown error";
1658 
1659  errmsg = rb_enc_str_new_cstr(err, rb_locale_encoding());
1660  if (!NIL_P(mesg)) {
1661  VALUE str = StringValue(mesg);
1662 
1663  if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
1664  rb_str_catf(errmsg, " - %"PRIsVALUE, str);
1665  OBJ_INFECT(errmsg, mesg);
1666  }
1667  mesg = errmsg;
1668 
1669  rb_call_super(1, &mesg);
1670  rb_ivar_set(self, id_errno, error);
1671  return self;
1672 }
1673 
1674 /*
1675  * call-seq:
1676  * system_call_error.errno -> integer
1677  *
1678  * Return this SystemCallError's error number.
1679  */
1680 
1681 static VALUE
1683 {
1684  return rb_attr_get(self, id_errno);
1685 }
1686 
1687 /*
1688  * call-seq:
1689  * system_call_error === other -> true or false
1690  *
1691  * Return +true+ if the receiver is a generic +SystemCallError+, or
1692  * if the error numbers +self+ and _other_ are the same.
1693  */
1694 
1695 static VALUE
1697 {
1698  VALUE num, e;
1699 
1700  if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
1701  if (!rb_respond_to(exc, id_errno)) return Qfalse;
1702  }
1703  else if (self == rb_eSystemCallError) return Qtrue;
1704 
1705  num = rb_attr_get(exc, id_errno);
1706  if (NIL_P(num)) {
1707  num = rb_funcallv(exc, id_errno, 0, 0);
1708  }
1709  e = rb_const_get(self, id_Errno);
1710  if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
1711  return Qtrue;
1712  return Qfalse;
1713 }
1714 
1715 
1716 /*
1717  * Document-class: StandardError
1718  *
1719  * The most standard error types are subclasses of StandardError. A
1720  * rescue clause without an explicit Exception class will rescue all
1721  * StandardErrors (and only those).
1722  *
1723  * def foo
1724  * raise "Oups"
1725  * end
1726  * foo rescue "Hello" #=> "Hello"
1727  *
1728  * On the other hand:
1729  *
1730  * require 'does/not/exist' rescue "Hi"
1731  *
1732  * <em>raises the exception:</em>
1733  *
1734  * LoadError: no such file to load -- does/not/exist
1735  *
1736  */
1737 
1738 /*
1739  * Document-class: SystemExit
1740  *
1741  * Raised by +exit+ to initiate the termination of the script.
1742  */
1743 
1744 /*
1745  * Document-class: SignalException
1746  *
1747  * Raised when a signal is received.
1748  *
1749  * begin
1750  * Process.kill('HUP',Process.pid)
1751  * sleep # wait for receiver to handle signal sent by Process.kill
1752  * rescue SignalException => e
1753  * puts "received Exception #{e}"
1754  * end
1755  *
1756  * <em>produces:</em>
1757  *
1758  * received Exception SIGHUP
1759  */
1760 
1761 /*
1762  * Document-class: Interrupt
1763  *
1764  * Raised with the interrupt signal is received, typically because the
1765  * user pressed on Control-C (on most posix platforms). As such, it is a
1766  * subclass of +SignalException+.
1767  *
1768  * begin
1769  * puts "Press ctrl-C when you get bored"
1770  * loop {}
1771  * rescue Interrupt => e
1772  * puts "Note: You will typically use Signal.trap instead."
1773  * end
1774  *
1775  * <em>produces:</em>
1776  *
1777  * Press ctrl-C when you get bored
1778  *
1779  * <em>then waits until it is interrupted with Control-C and then prints:</em>
1780  *
1781  * Note: You will typically use Signal.trap instead.
1782  */
1783 
1784 /*
1785  * Document-class: TypeError
1786  *
1787  * Raised when encountering an object that is not of the expected type.
1788  *
1789  * [1, 2, 3].first("two")
1790  *
1791  * <em>raises the exception:</em>
1792  *
1793  * TypeError: no implicit conversion of String into Integer
1794  *
1795  */
1796 
1797 /*
1798  * Document-class: ArgumentError
1799  *
1800  * Raised when the arguments are wrong and there isn't a more specific
1801  * Exception class.
1802  *
1803  * Ex: passing the wrong number of arguments
1804  *
1805  * [1, 2, 3].first(4, 5)
1806  *
1807  * <em>raises the exception:</em>
1808  *
1809  * ArgumentError: wrong number of arguments (given 2, expected 1)
1810  *
1811  * Ex: passing an argument that is not acceptable:
1812  *
1813  * [1, 2, 3].first(-4)
1814  *
1815  * <em>raises the exception:</em>
1816  *
1817  * ArgumentError: negative array size
1818  */
1819 
1820 /*
1821  * Document-class: IndexError
1822  *
1823  * Raised when the given index is invalid.
1824  *
1825  * a = [:foo, :bar]
1826  * a.fetch(0) #=> :foo
1827  * a[4] #=> nil
1828  * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
1829  *
1830  */
1831 
1832 /*
1833  * Document-class: KeyError
1834  *
1835  * Raised when the specified key is not found. It is a subclass of
1836  * IndexError.
1837  *
1838  * h = {"foo" => :bar}
1839  * h.fetch("foo") #=> :bar
1840  * h.fetch("baz") #=> KeyError: key not found: "baz"
1841  *
1842  */
1843 
1844 /*
1845  * Document-class: RangeError
1846  *
1847  * Raised when a given numerical value is out of range.
1848  *
1849  * [1, 2, 3].drop(1 << 100)
1850  *
1851  * <em>raises the exception:</em>
1852  *
1853  * RangeError: bignum too big to convert into `long'
1854  */
1855 
1856 /*
1857  * Document-class: ScriptError
1858  *
1859  * ScriptError is the superclass for errors raised when a script
1860  * can not be executed because of a +LoadError+,
1861  * +NotImplementedError+ or a +SyntaxError+. Note these type of
1862  * +ScriptErrors+ are not +StandardError+ and will not be
1863  * rescued unless it is specified explicitly (or its ancestor
1864  * +Exception+).
1865  */
1866 
1867 /*
1868  * Document-class: SyntaxError
1869  *
1870  * Raised when encountering Ruby code with an invalid syntax.
1871  *
1872  * eval("1+1=2")
1873  *
1874  * <em>raises the exception:</em>
1875  *
1876  * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
1877  */
1878 
1879 /*
1880  * Document-class: LoadError
1881  *
1882  * Raised when a file required (a Ruby script, extension library, ...)
1883  * fails to load.
1884  *
1885  * require 'this/file/does/not/exist'
1886  *
1887  * <em>raises the exception:</em>
1888  *
1889  * LoadError: no such file to load -- this/file/does/not/exist
1890  */
1891 
1892 /*
1893  * Document-class: NotImplementedError
1894  *
1895  * Raised when a feature is not implemented on the current platform. For
1896  * example, methods depending on the +fsync+ or +fork+ system calls may
1897  * raise this exception if the underlying operating system or Ruby
1898  * runtime does not support them.
1899  *
1900  * Note that if +fork+ raises a +NotImplementedError+, then
1901  * <code>respond_to?(:fork)</code> returns +false+.
1902  */
1903 
1904 /*
1905  * Document-class: NameError
1906  *
1907  * Raised when a given name is invalid or undefined.
1908  *
1909  * puts foo
1910  *
1911  * <em>raises the exception:</em>
1912  *
1913  * NameError: undefined local variable or method `foo' for main:Object
1914  *
1915  * Since constant names must start with a capital:
1916  *
1917  * Integer.const_set :answer, 42
1918  *
1919  * <em>raises the exception:</em>
1920  *
1921  * NameError: wrong constant name answer
1922  */
1923 
1924 /*
1925  * Document-class: NoMethodError
1926  *
1927  * Raised when a method is called on a receiver which doesn't have it
1928  * defined and also fails to respond with +method_missing+.
1929  *
1930  * "hello".to_ary
1931  *
1932  * <em>raises the exception:</em>
1933  *
1934  * NoMethodError: undefined method `to_ary' for "hello":String
1935  */
1936 
1937 /*
1938  * Document-class: RuntimeError
1939  *
1940  * A generic error class raised when an invalid operation is attempted.
1941  *
1942  * [1, 2, 3].freeze << 4
1943  *
1944  * <em>raises the exception:</em>
1945  *
1946  * RuntimeError: can't modify frozen Array
1947  *
1948  * Kernel.raise will raise a RuntimeError if no Exception class is
1949  * specified.
1950  *
1951  * raise "ouch"
1952  *
1953  * <em>raises the exception:</em>
1954  *
1955  * RuntimeError: ouch
1956  */
1957 
1958 /*
1959  * Document-class: SecurityError
1960  *
1961  * Raised when attempting a potential unsafe operation, typically when
1962  * the $SAFE level is raised above 0.
1963  *
1964  * foo = "bar"
1965  * proc = Proc.new do
1966  * $SAFE = 3
1967  * foo.untaint
1968  * end
1969  * proc.call
1970  *
1971  * <em>raises the exception:</em>
1972  *
1973  * SecurityError: Insecure: Insecure operation `untaint' at level 3
1974  */
1975 
1976 /*
1977  * Document-class: NoMemoryError
1978  *
1979  * Raised when memory allocation fails.
1980  */
1981 
1982 /*
1983  * Document-class: SystemCallError
1984  *
1985  * SystemCallError is the base class for all low-level
1986  * platform-dependent errors.
1987  *
1988  * The errors available on the current platform are subclasses of
1989  * SystemCallError and are defined in the Errno module.
1990  *
1991  * File.open("does/not/exist")
1992  *
1993  * <em>raises the exception:</em>
1994  *
1995  * Errno::ENOENT: No such file or directory - does/not/exist
1996  */
1997 
1998 /*
1999  * Document-class: EncodingError
2000  *
2001  * EncodingError is the base class for encoding errors.
2002  */
2003 
2004 /*
2005  * Document-class: Encoding::CompatibilityError
2006  *
2007  * Raised by Encoding and String methods when the source encoding is
2008  * incompatible with the target encoding.
2009  */
2010 
2011 /*
2012  * Document-class: fatal
2013  *
2014  * fatal is an Exception that is raised when ruby has encountered a fatal
2015  * error and must exit. You are not able to rescue fatal.
2016  */
2017 
2018 /*
2019  * Document-class: NameError::message
2020  * :nodoc:
2021  */
2022 
2023 /*
2024  * Descendants of class Exception are used to communicate between
2025  * Kernel#raise and +rescue+ statements in <code>begin ... end</code> blocks.
2026  * Exception objects carry information about the exception -- its type (the
2027  * exception's class name), an optional descriptive string, and optional
2028  * traceback information. Exception subclasses may add additional
2029  * information like NameError#name.
2030  *
2031  * Programs may make subclasses of Exception, typically of StandardError or
2032  * RuntimeError, to provide custom classes and add additional information.
2033  * See the subclass list below for defaults for +raise+ and +rescue+.
2034  *
2035  * When an exception has been raised but not yet handled (in +rescue+,
2036  * +ensure+, +at_exit+ and +END+ blocks) the global variable <code>$!</code>
2037  * will contain the current exception and <code>$@</code> contains the
2038  * current exception's backtrace.
2039  *
2040  * It is recommended that a library should have one subclass of StandardError
2041  * or RuntimeError and have specific exception types inherit from it. This
2042  * allows the user to rescue a generic exception type to catch all exceptions
2043  * the library may raise even if future versions of the library add new
2044  * exception subclasses.
2045  *
2046  * For example:
2047  *
2048  * class MyLibrary
2049  * class Error < RuntimeError
2050  * end
2051  *
2052  * class WidgetError < Error
2053  * end
2054  *
2055  * class FrobError < Error
2056  * end
2057  *
2058  * end
2059  *
2060  * To handle both WidgetError and FrobError the library user can rescue
2061  * MyLibrary::Error.
2062  *
2063  * The built-in subclasses of Exception are:
2064  *
2065  * * NoMemoryError
2066  * * ScriptError
2067  * * LoadError
2068  * * NotImplementedError
2069  * * SyntaxError
2070  * * SecurityError
2071  * * SignalException
2072  * * Interrupt
2073  * * StandardError -- default for +rescue+
2074  * * ArgumentError
2075  * * UncaughtThrowError
2076  * * EncodingError
2077  * * FiberError
2078  * * IOError
2079  * * EOFError
2080  * * IndexError
2081  * * KeyError
2082  * * StopIteration
2083  * * LocalJumpError
2084  * * NameError
2085  * * NoMethodError
2086  * * RangeError
2087  * * FloatDomainError
2088  * * RegexpError
2089  * * RuntimeError -- default for +raise+
2090  * * SystemCallError
2091  * * Errno::*
2092  * * ThreadError
2093  * * TypeError
2094  * * ZeroDivisionError
2095  * * SystemExit
2096  * * SystemStackError
2097  * * fatal -- impossible to rescue
2098  */
2099 
2100 void
2102 {
2103  rb_eException = rb_define_class("Exception", rb_cObject);
2104  rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
2105  rb_define_method(rb_eException, "exception", exc_exception, -1);
2106  rb_define_method(rb_eException, "initialize", exc_initialize, -1);
2107  rb_define_method(rb_eException, "==", exc_equal, 1);
2108  rb_define_method(rb_eException, "to_s", exc_to_s, 0);
2109  rb_define_method(rb_eException, "message", exc_message, 0);
2110  rb_define_method(rb_eException, "inspect", exc_inspect, 0);
2111  rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
2112  rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);
2113  rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
2114  rb_define_method(rb_eException, "cause", exc_cause, 0);
2115 
2116  rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
2117  rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
2118  rb_define_method(rb_eSystemExit, "status", exit_status, 0);
2119  rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);
2120 
2121  rb_eFatal = rb_define_class("fatal", rb_eException);
2122  rb_eSignal = rb_define_class("SignalException", rb_eException);
2123  rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal);
2124 
2125  rb_eStandardError = rb_define_class("StandardError", rb_eException);
2126  rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
2127  rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
2128  rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
2129  rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
2130  rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
2131 
2132  rb_eScriptError = rb_define_class("ScriptError", rb_eException);
2133  rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
2134  rb_define_method(rb_eSyntaxError, "initialize", syntax_error_initialize, -1);
2135 
2136  rb_eLoadError = rb_define_class("LoadError", rb_eScriptError);
2137  /* the path failed to load */
2138  rb_attr(rb_eLoadError, rb_intern_const("path"), 1, 0, Qfalse);
2139 
2140  rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
2141 
2142  rb_eNameError = rb_define_class("NameError", rb_eStandardError);
2143  rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
2144  rb_define_method(rb_eNameError, "name", name_err_name, 0);
2145  rb_define_method(rb_eNameError, "receiver", name_err_receiver, 0);
2146  rb_define_method(rb_eNameError, "local_variables", name_err_local_variables, 0);
2147  rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData);
2148  rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
2149  rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
2150  rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
2151  rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
2152  rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
2153  rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
2154  rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
2155  rb_define_method(rb_eNoMethodError, "private_call?", nometh_err_private_call_p, 0);
2156 
2157  rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
2158  rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
2159  rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
2160  rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError);
2161  rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError);
2162 
2163  syserr_tbl = st_init_numtable();
2164  rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
2165  rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
2166  rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
2167  rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
2168 
2169  rb_mErrno = rb_define_module("Errno");
2170 
2171  rb_mWarning = rb_define_module("Warning");
2174 
2175  rb_define_global_function("warn", rb_warn_m, -1);
2176 
2177  id_new = rb_intern_const("new");
2178  id_cause = rb_intern_const("cause");
2179  id_message = rb_intern_const("message");
2180  id_backtrace = rb_intern_const("backtrace");
2181  id_name = rb_intern_const("name");
2182  id_args = rb_intern_const("args");
2183  id_receiver = rb_intern_const("receiver");
2184  id_private_call_p = rb_intern_const("private_call?");
2185  id_local_variables = rb_intern_const("local_variables");
2186  id_Errno = rb_intern_const("Errno");
2187  id_errno = rb_intern_const("errno");
2188  id_i_path = rb_intern_const("@path");
2189  id_warn = rb_intern_const("warn");
2190  id_iseq = rb_make_internal_id();
2191 }
2192 
2193 void
2194 rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
2195 {
2196  va_list args;
2197  VALUE mesg;
2198 
2199  va_start(args, fmt);
2200  mesg = rb_enc_vsprintf(enc, fmt, args);
2201  va_end(args);
2202 
2203  rb_exc_raise(rb_exc_new3(exc, mesg));
2204 }
2205 
2206 void
2207 rb_raise(VALUE exc, const char *fmt, ...)
2208 {
2209  va_list args;
2210  VALUE mesg;
2211 
2212  va_start(args, fmt);
2213  mesg = rb_vsprintf(fmt, args);
2214  va_end(args);
2215  rb_exc_raise(rb_exc_new3(exc, mesg));
2216 }
2217 
2218 NORETURN(static void raise_loaderror(VALUE path, VALUE mesg));
2219 
2220 static void
2222 {
2223  VALUE err = rb_exc_new3(rb_eLoadError, mesg);
2224  rb_ivar_set(err, id_i_path, path);
2225  rb_exc_raise(err);
2226 }
2227 
2228 void
2229 rb_loaderror(const char *fmt, ...)
2230 {
2231  va_list args;
2232  VALUE mesg;
2233 
2234  va_start(args, fmt);
2235  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2236  va_end(args);
2237  raise_loaderror(Qnil, mesg);
2238 }
2239 
2240 void
2241 rb_loaderror_with_path(VALUE path, const char *fmt, ...)
2242 {
2243  va_list args;
2244  VALUE mesg;
2245 
2246  va_start(args, fmt);
2247  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2248  va_end(args);
2249  raise_loaderror(path, mesg);
2250 }
2251 
2252 void
2254 {
2255  rb_raise(rb_eNotImpError,
2256  "%"PRIsVALUE"() function is unimplemented on this machine",
2258 }
2259 
2260 void
2261 rb_fatal(const char *fmt, ...)
2262 {
2263  va_list args;
2264  VALUE mesg;
2265 
2266  va_start(args, fmt);
2267  mesg = rb_vsprintf(fmt, args);
2268  va_end(args);
2269 
2270  rb_exc_fatal(rb_exc_new3(rb_eFatal, mesg));
2271 }
2272 
2273 static VALUE
2274 make_errno_exc(const char *mesg)
2275 {
2276  int n = errno;
2277 
2278  errno = 0;
2279  if (n == 0) {
2280  rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
2281  }
2282  return rb_syserr_new(n, mesg);
2283 }
2284 
2285 static VALUE
2287 {
2288  int n = errno;
2289 
2290  errno = 0;
2291  if (!mesg) mesg = Qnil;
2292  if (n == 0) {
2293  const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
2294  rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
2295  }
2296  return rb_syserr_new_str(n, mesg);
2297 }
2298 
2299 VALUE
2300 rb_syserr_new(int n, const char *mesg)
2301 {
2302  VALUE arg;
2303  arg = mesg ? rb_str_new2(mesg) : Qnil;
2304  return rb_syserr_new_str(n, arg);
2305 }
2306 
2307 VALUE
2309 {
2310  return rb_class_new_instance(1, &arg, get_syserr(n));
2311 }
2312 
2313 void
2314 rb_syserr_fail(int e, const char *mesg)
2315 {
2316  rb_exc_raise(rb_syserr_new(e, mesg));
2317 }
2318 
2319 void
2321 {
2322  rb_exc_raise(rb_syserr_new_str(e, mesg));
2323 }
2324 
2325 void
2326 rb_sys_fail(const char *mesg)
2327 {
2329 }
2330 
2331 void
2333 {
2335 }
2336 
2337 #ifdef RUBY_FUNCTION_NAME_STRING
2338 void
2339 rb_sys_fail_path_in(const char *func_name, VALUE path)
2340 {
2341  int n = errno;
2342 
2343  errno = 0;
2344  rb_syserr_fail_path_in(func_name, n, path);
2345 }
2346 
2347 void
2348 rb_syserr_fail_path_in(const char *func_name, int n, VALUE path)
2349 {
2350  VALUE args[2];
2351 
2352  if (!path) path = Qnil;
2353  if (n == 0) {
2354  const char *s = !NIL_P(path) ? RSTRING_PTR(path) : "";
2355  if (!func_name) func_name = "(null)";
2356  rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0",
2357  func_name, s);
2358  }
2359  args[0] = path;
2360  args[1] = rb_str_new_cstr(func_name);
2362 }
2363 #endif
2364 
2365 void
2366 rb_mod_sys_fail(VALUE mod, const char *mesg)
2367 {
2368  VALUE exc = make_errno_exc(mesg);
2369  rb_extend_object(exc, mod);
2370  rb_exc_raise(exc);
2371 }
2372 
2373 void
2375 {
2376  VALUE exc = make_errno_exc_str(mesg);
2377  rb_extend_object(exc, mod);
2378  rb_exc_raise(exc);
2379 }
2380 
2381 void
2382 rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
2383 {
2384  VALUE exc = rb_syserr_new(e, mesg);
2385  rb_extend_object(exc, mod);
2386  rb_exc_raise(exc);
2387 }
2388 
2389 void
2391 {
2392  VALUE exc = rb_syserr_new_str(e, mesg);
2393  rb_extend_object(exc, mod);
2394  rb_exc_raise(exc);
2395 }
2396 
2397 void
2398 rb_sys_warning(const char *fmt, ...)
2399 {
2400  VALUE mesg;
2401  va_list args;
2402  int errno_save;
2403 
2404  errno_save = errno;
2405 
2406  if (!RTEST(ruby_verbose)) return;
2407 
2408  va_start(args, fmt);
2409  mesg = warning_string(0, fmt, args);
2410  va_end(args);
2411  rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2412  rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2413  rb_write_warning_str(mesg);
2414  errno = errno_save;
2415 }
2416 
2417 void
2418 rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...)
2419 {
2420  VALUE mesg;
2421  va_list args;
2422  int errno_save;
2423 
2424  errno_save = errno;
2425 
2426  if (!RTEST(ruby_verbose)) return;
2427 
2428  va_start(args, fmt);
2429  mesg = warning_string(enc, fmt, args);
2430  va_end(args);
2431  rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
2432  rb_str_catf(mesg, ": %s\n", strerror(errno_save));
2433  rb_write_warning_str(mesg);
2434  errno = errno_save;
2435 }
2436 
2437 void
2438 rb_load_fail(VALUE path, const char *err)
2439 {
2440  VALUE mesg = rb_str_buf_new_cstr(err);
2441  rb_str_cat2(mesg, " -- ");
2442  rb_str_append(mesg, path); /* should be ASCII compatible */
2443  raise_loaderror(path, mesg);
2444 }
2445 
2446 void
2447 rb_error_frozen(const char *what)
2448 {
2449  rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
2450 }
2451 
2452 void
2454 {
2455  VALUE debug_info;
2456  const ID created_info = id_debug_created_info;
2457 
2458  if (!NIL_P(debug_info = rb_attr_get(frozen_obj, created_info))) {
2459  VALUE path = rb_ary_entry(debug_info, 0);
2460  VALUE line = rb_ary_entry(debug_info, 1);
2461 
2462  rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE", created at %"PRIsVALUE":%"PRIsVALUE,
2463  CLASS_OF(frozen_obj), path, line);
2464  }
2465  else {
2466  rb_raise(rb_eRuntimeError, "can't modify frozen %"PRIsVALUE,
2467  CLASS_OF(frozen_obj));
2468  }
2469 }
2470 
2471 #undef rb_check_frozen
2472 void
2474 {
2476 }
2477 
2478 void
2480 {
2481 }
2482 
2483 #undef rb_check_trusted
2484 void
2486 {
2487 }
2488 
2489 void
2491 {
2492  if (!FL_ABLE(obj)) return;
2494  if (!FL_ABLE(orig)) return;
2495  if ((~RBASIC(obj)->flags & RBASIC(orig)->flags) & FL_TAINT) {
2496  if (rb_safe_level() > 0) {
2497  rb_raise(rb_eSecurityError, "Insecure: can't modify %"PRIsVALUE,
2498  RBASIC(obj)->klass);
2499  }
2500  }
2501 }
2502 
2503 void
2505 {
2506  rb_eNOERROR = set_syserr(0, "NOERROR");
2507 #define defined_error(name, num) set_syserr((num), (name));
2508 #define undefined_error(name) set_syserr(0, (name));
2509 #include "known_errors.inc"
2510 #undef defined_error
2511 #undef undefined_error
2512 }
#define id_mesg
Definition: error.c:791
VALUE rb_eScriptError
Definition: error.c:776
#define UNDEF_LEAKED
Definition: error.c:656
rb_control_frame_t * cfp
Definition: vm_core.h:708
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:645
static VALUE syserr_errno(VALUE self)
Definition: error.c:1682
#define T_OBJECT
Definition: ruby.h:491
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:489
VALUE rb_eStandardError
Definition: error.c:760
static VALUE make_errno_exc_str(VALUE mesg)
Definition: error.c:2286
static void preface_dump(FILE *out)
Definition: error.c:371
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:797
static VALUE exc_backtrace(VALUE exc)
Definition: error.c:950
RUBY_EXTERN VALUE rb_cData
Definition: ruby.h:1881
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:1196
#define RARRAY_LEN(a)
Definition: ruby.h:1026
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:2065
void rb_bug(const char *fmt,...)
Definition: error.c:482
static const rb_data_type_t name_err_mesg_data_type
Definition: error.c:1342
static VALUE get_syserr(int n)
Definition: error.c:1603
void rb_compile_error(const char *file, int line, const char *fmt,...)
Definition: error.c:138
#define RUBY_TYPED_FREE_IMMEDIATELY
Definition: ruby.h:1145
static void die(void)
Definition: error.c:472
size_t strlen(const char *)
#define INT2NUM(x)
Definition: ruby.h:1538
Definition: st.h:79
VALUE rb_String(VALUE)
Definition: object.c:3097
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:2314
VALUE rb_cEncoding
Definition: encoding.c:45
VALUE rb_eSignal
Definition: error.c:758
static VALUE exc_message(VALUE exc)
Definition: error.c:887
#define NUM2INT(x)
Definition: ruby.h:684
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1716
VALUE rb_eEWOULDBLOCK
Definition: error.c:47
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1172
VALUE rb_eKeyError
Definition: error.c:765
#define REPORT_BUG_BUFSIZ
Definition: error.c:328
void rb_error_frozen_object(VALUE frozen_obj)
Definition: error.c:2453
#define FL_TAINT
Definition: ruby.h:1220
#define CLASS_OF(v)
Definition: ruby.h:453
VALUE rb_iseqw_new(const rb_iseq_t *)
Definition: iseq.c:754
VALUE rb_fstring_cstr(const char *str)
Definition: string.c:387
#define Qtrue
Definition: ruby.h:437
void rb_error_frozen(const char *what)
Definition: error.c:2447
static size_t name_err_mesg_memsize(const void *p)
Definition: error.c:1337
#define TypedData_Wrap_Struct(klass, data_type, sval)
Definition: ruby.h:1169
VALUE rb_backtrace_to_location_ary(VALUE obj)
Definition: vm_backtrace.c:631
VALUE rb_syserr_new_str(int n, VALUE arg)
Definition: error.c:2308
#define rb_id2str(id)
Definition: vm_backtrace.c:29
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: ruby.h:1190
static ID id_warn
Definition: error.c:51
const char * rb_builtin_type_name(int t)
Definition: error.c:609
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:809
#define rb_check_frozen_internal(obj)
Definition: intern.h:260
#define id_bt
Definition: error.c:789
ID rb_frame_this_func(void)
Definition: eval.c:979
static VALUE exc_to_s(VALUE exc)
Definition: error.c:870
VALUE rb_eTypeError
Definition: error.c:762
VALUE rb_cNameErrorMesg
Definition: error.c:774
static VALUE name_err_name(VALUE self)
Definition: error.c:1269
void rb_must_asciicompat(VALUE)
Definition: string.c:2032
#define FAKE_CSTR(v, str)
VALUE rb_str_buf_new2(const char *)
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
VALUE rb_eEncodingError
Definition: error.c:768
static VALUE name_err_local_variables(VALUE self)
Definition: error.c:1285
#define WIFEXITED(status)
Definition: error.c:36
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:821
void rb_async_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:534
void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
Definition: error.c:564
void rb_str_set_len(VALUE, long)
Definition: string.c:2545
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:891
#define RBASIC_SET_CLASS(obj, cls)
Definition: internal.h:1314
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:693
#define Check_Type(v, t)
Definition: ruby.h:562
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2207
const rb_data_type_t * parent
Definition: ruby.h:1096
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:181
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1367
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:690
VALUE rb_eSecurityError
Definition: error.c:771
static VALUE warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
Definition: error.c:172
#define DATA_PTR(dta)
Definition: ruby.h:1113
static ID id_iseq
Definition: error.c:786
static VALUE exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:1038
#define T_ARRAY
Definition: ruby.h:498
static VALUE name_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1243
#define st_lookup
Definition: regint.h:185
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1745
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1388
static VALUE syserr_eqq(VALUE self, VALUE exc)
Definition: error.c:1696
#define WEXITSTATUS(status)
Definition: error.c:40
static ID id_errno
Definition: error.c:785
static VALUE nometh_err_private_call_p(VALUE self)
Definition: error.c:1503
#define EINPROGRESS
Definition: win32.h:477
VALUE rb_eSyntaxError
Definition: error.c:777
#define FIXNUM_P(f)
Definition: ruby.h:365
void rb_load_fail(VALUE path, const char *err)
Definition: error.c:2438
const char * rb_source_loc(int *pline)
Definition: vm.c:1291
#define id_bt_locations
Definition: error.c:790
void rb_loaderror(const char *fmt,...)
Definition: error.c:2229
static st_table * syserr_tbl
Definition: error.c:1566
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:2802
void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
Definition: gc.c:4008
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
NORETURN(static void die(void))
VALUE rb_eRangeError
Definition: error.c:766
const char * rb_obj_classname(VALUE)
Definition: variable.c:458
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:1219
static VALUE exc_exception(int argc, VALUE *argv, VALUE self)
Definition: error.c:849
#define report_bug_valist(file, line, fmt, ctx, args)
Definition: error.c:461
#define GET_THREAD()
Definition: vm_core.h:1513
VALUE rb_str_buf_cat(VALUE, const char *, long)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:1204
VALUE rb_eEAGAIN
Definition: error.c:46
static VALUE exc_backtrace_locations(VALUE exc)
Definition: error.c:994
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Definition: error.c:2241
void rb_exc_raise(VALUE mesg)
Definition: eval.c:620
#define RB_TYPE_P(obj, type)
Definition: ruby.h:527
VALUE rb_eNameError
Definition: error.c:767
static ID id_local_variables
Definition: error.c:786
Definition: ruby.h:961
const rb_iseq_t * iseq
Definition: vm_core.h:634
static VALUE exc_cause(VALUE exc)
Definition: error.c:1059
VALUE rb_class_name(VALUE)
Definition: variable.c:443
#define ALLOC_N(type, n)
Definition: ruby.h:1587
void rb_compile_error_append(const char *fmt,...)
Definition: error.c:144
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
Definition: error.c:132
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1872
VALUE rb_eRuntimeError
Definition: error.c:761
static const char * builtin_class_name(VALUE x)
Definition: error.c:619
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:1138
#define RSTRING_END(str)
Definition: ruby.h:986
static VALUE name_err_mesg_dump(VALUE obj, VALUE limit)
Definition: error.c:1453
VALUE rb_syserr_new(int n, const char *mesg)
Definition: error.c:2300
static VALUE exc_equal(VALUE exc, VALUE obj)
Definition: error.c:1080
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:720
VALUE rb_str_cat2(VALUE, const char *)
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1364
VALUE rb_ary_new(void)
Definition: array.c:493
#define T_TRUE
Definition: ruby.h:504
void rb_check_trusted(VALUE obj)
Definition: error.c:2485
VALUE rb_iseqw_local_variables(VALUE iseqval)
Definition: iseq.c:2350
#define snprintf
Definition: subst.h:6
#define NIL_P(v)
Definition: ruby.h:451
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:646
static char msg[50]
Definition: strerror.c:8
static VALUE name_err_receiver(VALUE self)
Definition: error.c:1473
static VALUE try_convert_to_exception(VALUE obj)
Definition: error.c:1065
VALUE rb_eNoMethodError
Definition: error.c:770
static void rb_write_warning_str(VALUE str)
Definition: error.c:166
static VALUE exit_success_p(VALUE exc)
Definition: error.c:1189
#define name_err_mesg_free
Definition: error.c:1334
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2734
void rb_unexpected_type(VALUE x, int t)
Definition: error.c:700
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:2332
static VALUE nometh_err_args(VALUE self)
Definition: error.c:1497
VALUE rb_eNoMemError
Definition: error.c:773
static VALUE name_err_mesg_to_str(VALUE obj)
Definition: error.c:1399
#define TYPE(x)
Definition: ruby.h:521
void rb_check_type(VALUE x, int t)
Definition: error.c:685
int argc
Definition: ruby.c:183
static ID id_cause
Definition: error.c:784
#define write_or_abort(fd, str, len)
Definition: error.c:530
#define Qfalse
Definition: ruby.h:436
static VALUE set_syserr(int n, const char *name)
Definition: error.c:1569
static VALUE exit_status(VALUE exc)
Definition: error.c:1175
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Definition: error.c:2390
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Definition: error.c:2194
VALUE rb_eEncCompatError
Definition: error.c:769
#define rb_str_new2
Definition: intern.h:857
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1845
#define RUBY_EVENT_C_CALL
Definition: ruby.h:2064
int err
Definition: win32.c:135
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:1044
#define EXIT_FAILURE
Definition: eval_intern.h:33
VALUE rb_mErrno
Definition: error.c:781
#define MAX_BUG_REPORTERS
Definition: error.c:304
void Init_Exception(void)
Definition: error.c:2101
VALUE rb_eLoadError
Definition: error.c:778
#define id_status
Definition: error.c:792
VALUE rb_eIndexError
Definition: error.c:764
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Definition: object.c:1891
int rb_backtrace_p(VALUE obj)
Definition: vm_backtrace.c:410
#define numberof(array)
Definition: etc.c:616
static VALUE name_err_mesg_equal(VALUE obj1, VALUE obj2)
Definition: error.c:1379
ID ruby_static_id_status
Definition: eval.c:27
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:2335
static ID id_message
Definition: error.c:784
VALUE rb_backtrace_to_str_ary(VALUE obj)
Definition: vm_backtrace.c:584
#define FL_ABLE(x)
Definition: ruby.h:1282
#define RSTRING_LEN(str)
Definition: ruby.h:978
void Init_syserr(void)
Definition: error.c:2504
int errno
#define T_DATA
Definition: ruby.h:506
#define EXIT_SUCCESS
Definition: error.c:32
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1440
static const char builtin_types[][10]
Definition: error.c:576
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:461
void rb_print_backtrace(void)
Definition: vm_dump.c:679
static int bug_reporters_size
Definition: error.c:311
void rb_fatal(const char *fmt,...)
Definition: error.c:2261
VALUE rb_eSystemCallError
Definition: error.c:780
static FILE * bug_report_file(const char *file, int line)
Definition: error.c:330
static ID id_backtrace
Definition: error.c:784
VALUE rb_str_vcatf(VALUE, const char *, va_list)
Definition: sprintf.c:1453
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1919
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1364
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4309
#define PRIsVALUE
Definition: ruby.h:135
VALUE rb_eInterrupt
Definition: error.c:757
unsigned long ID
Definition: ruby.h:86
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1335
void rb_vm_bugreport(const void *)
Definition: vm_dump.c:931
static VALUE exc_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:824
#define report_bug(file, line, fmt, ctx)
Definition: error.c:452
#define Qnil
Definition: ruby.h:438
void rb_check_frozen(VALUE obj)
Definition: error.c:2473
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
Definition: error.c:558
unsigned long VALUE
Definition: ruby.h:85
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1370
static VALUE result
Definition: nkf.c:40
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:1628
static int err_position_0(char *buf, long len, const char *file, int line)
Definition: error.c:76
VALUE rb_eEINPROGRESS
Definition: error.c:48
#define RBASIC(obj)
Definition: ruby.h:1204
char * strchr(char *, char)
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1429
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Definition: error.c:2382
static VALUE rb_warn_m(int argc, VALUE *argv, VALUE exc)
Definition: error.c:296
VALUE rb_io_puts(int, const VALUE *, VALUE)
Definition: io.c:7212
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
Definition: error.c:235
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:513
static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:1125
#define rb_ary_new3
Definition: intern.h:91
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:439
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:287
void rb_check_copyable(VALUE obj, VALUE orig)
Definition: error.c:2490
VALUE rb_str_new_cstr(const char *)
Definition: string.c:770
void rb_sys_fail(const char *mesg)
Definition: error.c:2326
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1628
VALUE rb_str_dup(VALUE)
Definition: string.c:1436
void(* func)(FILE *out, void *data)
Definition: error.c:307
static void postscript_dump(FILE *out)
Definition: error.c:396
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
Definition: error.c:2418
#define RTYPEDDATA_P(v)
Definition: ruby.h:1115
static const char * rb_strerrno(int err)
Definition: error.c:65
#define rb_funcallv
Definition: console.c:21
#define WRITE_CONST(fd, str)
Definition: error.c:531
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1995
register unsigned int len
Definition: zonetab.h:51
static ID id_Errno
Definition: error.c:785
VALUE rb_mWarning
Definition: error.c:49
VALUE rb_check_to_int(VALUE)
Definition: object.c:2693
#define RSTRING_PTR(str)
Definition: ruby.h:982
static ID id_private_call_p
Definition: error.c:787
#define rb_exc_new3
Definition: intern.h:246
VALUE rb_equal(VALUE, VALUE)
Definition: object.c:86
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Definition: error.c:2374
RUBY_EXTERN VALUE rb_stderr
Definition: ruby.h:1950
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Definition: error.c:803
#define INT2FIX(i)
Definition: ruby.h:232
int rb_safe_level(void)
Definition: safe.c:35
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:730
#define RARRAY_AREF(a, i)
Definition: ruby.h:1040
static VALUE nometh_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1309
#define st_init_numtable
Definition: regint.h:178
void rb_set_errinfo(VALUE err)
Definition: eval.c:1630
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:2366
VALUE rb_str_buf_new_cstr(const char *)
Definition: string.c:1263
static void bug_report_end(FILE *out)
Definition: error.c:438
static VALUE err_vcatf(VALUE str, const char *pre, const char *file, int line, const char *fmt, va_list args)
Definition: error.c:90
static VALUE exc_inspect(VALUE exc)
Definition: error.c:900
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1480
static ID id_receiver
Definition: error.c:786
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:2320
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:196
static VALUE make_errno_exc(const char *mesg)
Definition: error.c:2274
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:314
static VALUE rb_warning_s_warn(VALUE mod, VALUE str)
Definition: error.c:157
VALUE rb_any_to_s(VALUE)
Definition: object.c:500
RUBY_EXTERN char * strerror(int)
Definition: strerror.c:11
#define RTEST(v)
Definition: ruby.h:450
static void bug_important_message(FILE *out, const char *const msg, size_t len)
Definition: error.c:346
#define T_STRING
Definition: ruby.h:496
static VALUE syntax_error_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1524
#define OBJ_INFECT(x, s)
Definition: ruby.h:1304
static ID id_name
Definition: error.c:785
#define st_add_direct
Definition: regint.h:187
int rb_method_basic_definition_p(VALUE, ID)
Definition: vm_method.c:1880
static ID id_args
Definition: error.c:785
VALUE rb_str_cat_cstr(VALUE, const char *)
Definition: string.c:2674
#define T_FALSE
Definition: ruby.h:505
#define EWOULDBLOCK
Definition: rubysocket.h:128
#define ONLY_FOR_INTERNAL_USE(func)
Definition: internal.h:1027
VALUE rb_check_backtrace(VALUE bt)
Definition: error.c:1006
void rb_notimplement(void)
Definition: error.c:2253
VALUE rb_eNotImpError
Definition: error.c:772
static void raise_loaderror(VALUE path, VALUE mesg)
Definition: error.c:2221
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:758
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Definition: error.c:710
const char ruby_description[]
Definition: version.c:33
const char * name
Definition: nkf.c:208
#define ID2SYM(x)
Definition: ruby.h:383
VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1354
static VALUE warning_string(rb_encoding *enc, const char *fmt, va_list args)
Definition: error.c:210
VALUE rb_eFatal
Definition: error.c:759
const lazyenum_funcs * fn
Definition: enumerator.c:146
void * data
Definition: error.c:308
static ID id_i_path
Definition: error.c:785
void rb_error_untrusted(VALUE obj)
Definition: error.c:2479
VALUE rb_source_location(int *pline)
Definition: vm.c:1275
VALUE rb_get_backtrace(VALUE exc)
Definition: error.c:965
VALUE rb_inspect(VALUE)
Definition: object.c:519
void ruby_only_for_internal_use(const char *func)
Definition: error.c:150
#define RTYPEDDATA_DATA(v)
Definition: ruby.h:1117
void rb_warning(const char *fmt,...)
Definition: error.c:250
#define fileno(p)
Definition: vsnprintf.c:217
#define QUOTE(str)
Definition: internal.h:1472
const char * wrap_struct_name
Definition: ruby.h:1088
#define rb_intern_const(str)
Definition: ruby.h:1756
static const char REPORTBUG_MSG[]
Definition: error.c:55
void rb_bug_context(const void *ctx, const char *fmt,...)
Definition: error.c:497
#define vsnprintf
Definition: subst.h:7
FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len))
VALUE rb_define_module(const char *name)
Definition: class.c:768
#define SYMBOL_P(x)
Definition: ruby.h:382
#define mod(x, y)
Definition: date_strftime.c:28
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1434
void rb_exc_fatal(VALUE mesg)
Definition: eval.c:629
VALUE rb_eSystemExit
Definition: error.c:756
#define NULL
Definition: _sdbm.c:102
#define RTYPEDDATA_TYPE(v)
Definition: ruby.h:1116
#define Qundef
Definition: ruby.h:439
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1515
#define ruby_verbose
Definition: ruby.h:1792
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2818
void rb_warn(const char *fmt,...)
Definition: error.c:221
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:1509
VALUE rb_eArgError
Definition: error.c:763
#define NUM2LONG(x)
Definition: ruby.h:648
#define T_MASK
Definition: md5.c:131
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
Definition: variable.c:1225
ID rb_make_internal_id(void)
Definition: symbol.c:768
VALUE rb_obj_clone(VALUE)
Definition: object.c:388
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
Definition: string.c:793
static void bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
Definition: error.c:418
static VALUE name_err_mesg_load(VALUE klass, VALUE str)
Definition: error.c:1460
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1273
static ID id_new
Definition: error.c:784
char ** argv
Definition: ruby.c:184
void rb_sys_warning(const char *fmt,...)
Definition: error.c:2398
char * ptr
Definition: ruby.h:966
static void name_err_mesg_mark(void *p)
Definition: error.c:1328
#define StringValue(v)
Definition: ruby.h:569
RUBY_EXTERN void rb_write_error_str(VALUE mesg)
Definition: io.c:7393
VALUE rb_eException
Definition: error.c:755
static VALUE rb_eNOERROR
Definition: error.c:782
VALUE rb_str_new(const char *, long)
Definition: string.c:736
VALUE rb_obj_class(VALUE)
Definition: object.c:229
static void unexpected_type(VALUE x, int xt, int t)
Definition: error.c:659