Ruby  2.1.10p492(2016-04-01revision54464)
error.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  error.c -
4 
5  $Author: nagachika $
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/ruby.h"
13 #include "ruby/st.h"
14 #include "ruby/encoding.h"
15 #include "internal.h"
16 #include "vm_core.h"
17 
18 #include <stdio.h>
19 #include <stdarg.h>
20 #ifdef HAVE_STDLIB_H
21 #include <stdlib.h>
22 #endif
23 #include <errno.h>
24 #ifdef HAVE_UNISTD_H
25 #include <unistd.h>
26 #endif
27 
28 #ifndef EXIT_SUCCESS
29 #define EXIT_SUCCESS 0
30 #endif
31 
32 #ifndef WIFEXITED
33 #define WIFEXITED(status) 1
34 #endif
35 
36 #ifndef WEXITSTATUS
37 #define WEXITSTATUS(status) (status)
38 #endif
39 
43 
44 extern const char ruby_description[];
45 
46 static const char REPORTBUG_MSG[] =
47  "[NOTE]\n" \
48  "You may have encountered a bug in the Ruby interpreter" \
49  " or extension libraries.\n" \
50  "Bug reports are welcome.\n" \
51  ""
52 #if defined __APPLE__
53  "Don't forget to include the above Crash Report log file.\n"
54 #endif
55  "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
56  ;
57 
58 static const char *
60 {
61 #define defined_error(name, num) if (err == (num)) return (name);
62 #define undefined_error(name)
63 #include "known_errors.inc"
64 #undef defined_error
65 #undef undefined_error
66  return NULL;
67 }
68 
69 static int
70 err_position_0(char *buf, long len, const char *file, int line)
71 {
72  if (!file) {
73  return 0;
74  }
75  else if (line == 0) {
76  return snprintf(buf, len, "%s: ", file);
77  }
78  else {
79  return snprintf(buf, len, "%s:%d: ", file, line);
80  }
81 }
82 
83 static VALUE
84 compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
85 {
86  VALUE str = rb_enc_str_new(0, 0, enc);
87 
88  if (file) {
89  rb_str_cat2(str, file);
90  if (line) rb_str_catf(str, ":%d", line);
91  rb_str_cat2(str, ": ");
92  }
93  if (pre) rb_str_cat2(str, pre);
94  rb_str_vcatf(str, fmt, args);
95  return str;
96 }
97 
98 static void
100 {
102  VALUE err = th->errinfo;
103  rb_block_t *prev_base_block = th->base_block;
104  th->base_block = 0;
105  /* base_block should be zero while normal Ruby execution */
106  /* after this line, any Ruby code *can* run */
107 
108  if (th->mild_compile_error) {
109  if (RTEST(err)) {
110  VALUE str = rb_obj_as_string(err);
111 
112  rb_str_cat2(str, "\n");
113  rb_str_append(str, mesg);
114  mesg = str;
115  }
116  err = rb_exc_new3(rb_eSyntaxError, mesg);
117  th->errinfo = err;
118  }
119  else {
120  if (!RTEST(err)) {
121  err = rb_exc_new2(rb_eSyntaxError, "compile error");
122  th->errinfo = err;
123  }
124  rb_str_cat2(mesg, "\n");
125  rb_write_error_str(mesg);
126  }
127 
128  /* returned to the parser world */
129  th->base_block = prev_base_block;
130 }
131 
132 void
133 rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
134 {
135  va_list args;
136  VALUE str;
137 
138  va_start(args, fmt);
139  str = compile_snprintf(enc, NULL, file, line, fmt, args);
140  va_end(args);
141  compile_err_append(str);
142 }
143 
144 void
145 rb_compile_error(const char *file, int line, const char *fmt, ...)
146 {
147  va_list args;
148  VALUE str;
149 
150  va_start(args, fmt);
151  str = compile_snprintf(NULL, NULL, file, line, fmt, args);
152  va_end(args);
153  compile_err_append(str);
154 }
155 
156 void
157 rb_compile_error_append(const char *fmt, ...)
158 {
159  va_list args;
160  VALUE str;
161 
162  va_start(args, fmt);
163  str = rb_vsprintf(fmt, args);
164  va_end(args);
165  compile_err_append(str);
166 }
167 
168 static void
169 compile_warn_print(const char *file, int line, const char *fmt, va_list args)
170 {
171  VALUE str;
172 
173  str = compile_snprintf(NULL, "warning: ", file, line, fmt, args);
174  rb_str_cat2(str, "\n");
175  rb_write_error_str(str);
176 }
177 
178 void
179 rb_compile_warn(const char *file, int line, const char *fmt, ...)
180 {
181  va_list args;
182 
183  if (NIL_P(ruby_verbose)) return;
184 
185  va_start(args, fmt);
186  compile_warn_print(file, line, fmt, args);
187  va_end(args);
188 }
189 
190 /* rb_compile_warning() reports only in verbose mode */
191 void
192 rb_compile_warning(const char *file, int line, const char *fmt, ...)
193 {
194  va_list args;
195 
196  if (!RTEST(ruby_verbose)) return;
197 
198  va_start(args, fmt);
199  compile_warn_print(file, line, fmt, args);
200  va_end(args);
201 }
202 
203 static void
204 warn_print(const char *fmt, va_list args)
205 {
206  VALUE str = rb_str_new(0, 0);
207  VALUE file = rb_sourcefilename();
208 
209  if (!NIL_P(file)) {
210  int line = rb_sourceline();
211  str = rb_str_append(str, file);
212  if (line) rb_str_catf(str, ":%d", line);
213  rb_str_cat2(str, ": ");
214  }
215 
216  rb_str_cat2(str, "warning: ");
217  rb_str_vcatf(str, fmt, args);
218  rb_str_cat2(str, "\n");
219  rb_write_error_str(str);
220 }
221 
222 void
223 rb_warn(const char *fmt, ...)
224 {
225  va_list args;
226 
227  if (NIL_P(ruby_verbose)) return;
228 
229  va_start(args, fmt);
230  warn_print(fmt, args);
231  va_end(args);
232 }
233 
234 /* rb_warning() reports only in verbose mode */
235 void
236 rb_warning(const char *fmt, ...)
237 {
238  va_list args;
239 
240  if (!RTEST(ruby_verbose)) return;
241 
242  va_start(args, fmt);
243  warn_print(fmt, args);
244  va_end(args);
245 }
246 
247 /*
248  * call-seq:
249  * warn(msg, ...) -> nil
250  *
251  * Displays each of the given messages followed by a record separator on
252  * STDERR unless warnings have been disabled (for example with the
253  * <code>-W0</code> flag).
254  *
255  * warn("warning 1", "warning 2")
256  *
257  * <em>produces:</em>
258  *
259  * warning 1
260  * warning 2
261  */
262 
263 static VALUE
265 {
266  if (!NIL_P(ruby_verbose) && argc > 0) {
267  rb_io_puts(argc, argv, rb_stderr);
268  }
269  return Qnil;
270 }
271 
272 #define MAX_BUG_REPORTERS 0x100
273 
274 static struct bug_reporters {
275  void (*func)(FILE *out, void *data);
276  void *data;
278 
280 
281 int
282 rb_bug_reporter_add(void (*func)(FILE *, void *), void *data)
283 {
284  struct bug_reporters *reporter;
286  return 0; /* failed to register */
287  }
288  reporter = &bug_reporters[bug_reporters_size++];
289  reporter->func = func;
290  reporter->data = data;
291 
292  return 1;
293 }
294 
295 static void
296 report_bug(const char *file, int line, const char *fmt, va_list args)
297 {
298  /* SIGSEGV handler might have a very small stack. Thus we need to use it carefully. */
299  char buf[256];
300  FILE *out = stderr;
301  int len = err_position_0(buf, 256, file, line);
302 
303  if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
304  (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
305 
306  fputs("[BUG] ", out);
307  vsnprintf(buf, 256, fmt, args);
308  fputs(buf, out);
309  snprintf(buf, 256, "\n%s\n\n", ruby_description);
310  fputs(buf, out);
311 
312  rb_vm_bugreport();
313 
314  /* call additional bug reporters */
315  {
316  int i;
317  for (i=0; i<bug_reporters_size; i++) {
318  struct bug_reporters *reporter = &bug_reporters[i];
319  (*reporter->func)(out, reporter->data);
320  }
321  }
322  fprintf(out, REPORTBUG_MSG);
323  }
324 }
325 
326 void
327 rb_bug(const char *fmt, ...)
328 {
329  va_list args;
330  const char *file = NULL;
331  int line = 0;
332 
333  if (GET_THREAD()) {
334  file = rb_sourcefile();
335  line = rb_sourceline();
336  }
337 
338  va_start(args, fmt);
339  report_bug(file, line, fmt, args);
340  va_end(args);
341 
342 #if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
343  _set_abort_behavior( 0, _CALL_REPORTFAULT);
344 #endif
345 
346  abort();
347 }
348 
349 void
350 rb_bug_errno(const char *mesg, int errno_arg)
351 {
352  if (errno_arg == 0)
353  rb_bug("%s: errno == 0 (NOERROR)", mesg);
354  else {
355  const char *errno_str = rb_strerrno(errno_arg);
356  if (errno_str)
357  rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
358  else
359  rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
360  }
361 }
362 
363 /*
364  * this is safe to call inside signal handler and timer thread
365  * (which isn't a Ruby Thread object)
366  */
367 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
368 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
369 
370 void
371 rb_async_bug_errno(const char *mesg, int errno_arg)
372 {
373  WRITE_CONST(2, "[ASYNC BUG] ");
374  write_or_abort(2, mesg, strlen(mesg));
375  WRITE_CONST(2, "\n");
376 
377  if (errno_arg == 0) {
378  WRITE_CONST(2, "errno == 0 (NOERROR)\n");
379  }
380  else {
381  const char *errno_str = rb_strerrno(errno_arg);
382 
383  if (!errno_str)
384  errno_str = "undefined errno";
385  write_or_abort(2, errno_str, strlen(errno_str));
386  }
387  WRITE_CONST(2, "\n\n");
389  WRITE_CONST(2, "\n\n");
391  abort();
392 }
393 
394 void
395 rb_compile_bug(const char *file, int line, const char *fmt, ...)
396 {
397  va_list args;
398 
399  va_start(args, fmt);
400  report_bug(file, line, fmt, args);
401  va_end(args);
402 
403  abort();
404 }
405 
406 static const char builtin_types[][10] = {
407  "", /* 0x00, */
408  "Object",
409  "Class",
410  "Module",
411  "Float",
412  "String",
413  "Regexp",
414  "Array",
415  "Hash",
416  "Struct",
417  "Bignum",
418  "File",
419  "Data", /* internal use: wrapped C pointers */
420  "MatchData", /* data of $~ */
421  "Complex",
422  "Rational",
423  "", /* 0x10 */
424  "nil",
425  "true",
426  "false",
427  "Symbol", /* :symbol */
428  "Fixnum",
429  "", /* 0x16 */
430  "", /* 0x17 */
431  "", /* 0x18 */
432  "", /* 0x19 */
433  "", /* 0x1a */
434  "undef", /* internal use: #undef; should not happen */
435  "Node", /* internal use: syntax tree node */
436  "iClass", /* internal use: mixed-in module holder */
437 };
438 
439 const char *
441 {
442  const char *name;
443  if ((unsigned int)t >= numberof(builtin_types)) return 0;
444  name = builtin_types[t];
445  if (*name) return name;
446  return 0;
447 }
448 
449 #define builtin_class_name rb_builtin_class_name
450 const char *
452 {
453  const char *etype;
454 
455  if (NIL_P(x)) {
456  etype = "nil";
457  }
458  else if (FIXNUM_P(x)) {
459  etype = "Fixnum";
460  }
461  else if (SYMBOL_P(x)) {
462  etype = "Symbol";
463  }
464  else if (RB_TYPE_P(x, T_TRUE)) {
465  etype = "true";
466  }
467  else if (RB_TYPE_P(x, T_FALSE)) {
468  etype = "false";
469  }
470  else {
471  etype = rb_obj_classname(x);
472  }
473  return etype;
474 }
475 
476 void
478 {
479  int xt;
480 
481  if (x == Qundef) {
482  rb_bug("undef leaked to the Ruby space");
483  }
484 
485  xt = TYPE(x);
486  if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
487  const char *tname = rb_builtin_type_name(t);
488  if (tname) {
489  rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
490  builtin_class_name(x), tname);
491  }
492  if (xt > T_MASK && xt <= 0x3f) {
493  rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
494  }
495  rb_bug("unknown type 0x%x (0x%x given)", t, xt);
496  }
497 }
498 
499 int
501 {
502  while (child) {
503  if (child == parent) return 1;
504  child = child->parent;
505  }
506  return 0;
507 }
508 
509 int
511 {
512  if (!RB_TYPE_P(obj, T_DATA) ||
513  !RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
514  return 0;
515  }
516  return 1;
517 }
518 
519 void *
521 {
522  const char *etype;
523  static const char mesg[] = "wrong argument type %s (expected %s)";
524 
525  if (!RB_TYPE_P(obj, T_DATA)) {
526  etype = builtin_class_name(obj);
527  rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
528  }
529  if (!RTYPEDDATA_P(obj)) {
530  etype = rb_obj_classname(obj);
531  rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
532  }
533  else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
534  etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
535  rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
536  }
537  return DATA_PTR(obj);
538 }
539 
540 /* exception classes */
561 
565 
569 
570 #undef rb_exc_new_cstr
571 
572 VALUE
573 rb_exc_new(VALUE etype, const char *ptr, long len)
574 {
575  return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
576 }
577 
578 VALUE
579 rb_exc_new_cstr(VALUE etype, const char *s)
580 {
581  return rb_exc_new(etype, s, strlen(s));
582 }
583 
584 VALUE
586 {
587  StringValue(str);
588  return rb_funcall(etype, rb_intern("new"), 1, str);
589 }
590 
591 /*
592  * call-seq:
593  * Exception.new(msg = nil) -> exception
594  *
595  * Construct a new Exception object, optionally passing in
596  * a message.
597  */
598 
599 static VALUE
601 {
602  VALUE arg;
603 
604  rb_scan_args(argc, argv, "01", &arg);
605  rb_iv_set(exc, "mesg", arg);
606  rb_iv_set(exc, "bt", Qnil);
607 
608  return exc;
609 }
610 
611 /*
612  * Document-method: exception
613  *
614  * call-seq:
615  * exc.exception(string) -> an_exception or exc
616  *
617  * With no argument, or if the argument is the same as the receiver,
618  * return the receiver. Otherwise, create a new
619  * exception object of the same class as the receiver, but with a
620  * message equal to <code>string.to_str</code>.
621  *
622  */
623 
624 static VALUE
626 {
627  VALUE exc;
628 
629  if (argc == 0) return self;
630  if (argc == 1 && self == argv[0]) return self;
631  exc = rb_obj_clone(self);
632  exc_initialize(argc, argv, exc);
633 
634  return exc;
635 }
636 
637 /*
638  * call-seq:
639  * exception.to_s -> string
640  *
641  * Returns exception's message (or the name of the exception if
642  * no message is set).
643  */
644 
645 static VALUE
647 {
648  VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
649 
650  if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
651  return rb_String(mesg);
652 }
653 
654 /*
655  * call-seq:
656  * exception.message -> string
657  *
658  * Returns the result of invoking <code>exception.to_s</code>.
659  * Normally this returns the exception's message or name. By
660  * supplying a to_str method, exceptions are agreeing to
661  * be used where Strings are expected.
662  */
663 
664 static VALUE
666 {
667  return rb_funcall(exc, rb_intern("to_s"), 0, 0);
668 }
669 
670 /*
671  * call-seq:
672  * exception.inspect -> string
673  *
674  * Return this exception's class name and message
675  */
676 
677 static VALUE
679 {
680  VALUE str, klass;
681 
682  klass = CLASS_OF(exc);
683  exc = rb_obj_as_string(exc);
684  if (RSTRING_LEN(exc) == 0) {
685  return rb_str_dup(rb_class_name(klass));
686  }
687 
688  str = rb_str_buf_new2("#<");
689  klass = rb_class_name(klass);
690  rb_str_buf_append(str, klass);
691  rb_str_buf_cat(str, ": ", 2);
692  rb_str_buf_append(str, exc);
693  rb_str_buf_cat(str, ">", 1);
694 
695  return str;
696 }
697 
698 /*
699  * call-seq:
700  * exception.backtrace -> array
701  *
702  * Returns any backtrace associated with the exception. The backtrace
703  * is an array of strings, each containing either ``filename:lineNo: in
704  * `method''' or ``filename:lineNo.''
705  *
706  * def a
707  * raise "boom"
708  * end
709  *
710  * def b
711  * a()
712  * end
713  *
714  * begin
715  * b()
716  * rescue => detail
717  * print detail.backtrace.join("\n")
718  * end
719  *
720  * <em>produces:</em>
721  *
722  * prog.rb:2:in `a'
723  * prog.rb:6:in `b'
724  * prog.rb:10
725 */
726 
727 static VALUE
729 {
730  ID bt;
731  VALUE obj;
732 
733  CONST_ID(bt, "bt");
734  obj = rb_attr_get(exc, bt);
735 
736  if (rb_backtrace_p(obj)) {
737  obj = rb_backtrace_to_str_ary(obj);
738  /* rb_iv_set(exc, "bt", obj); */
739  }
740 
741  return obj;
742 }
743 
744 /*
745  * call-seq:
746  * exception.backtrace_locations -> array
747  *
748  * Returns any backtrace associated with the exception. This method is
749  * similar to Exception#backtrace, but the backtrace is an array of
750  * Thread::Backtrace::Location.
751  *
752  * Now, this method is not affected by Exception#set_backtrace().
753  */
754 static VALUE
756 {
757  ID bt_locations;
758  VALUE obj;
759 
760  CONST_ID(bt_locations, "bt_locations");
761  obj = rb_attr_get(exc, bt_locations);
762  if (!NIL_P(obj)) {
763  obj = rb_backtrace_to_location_ary(obj);
764  }
765  return obj;
766 }
767 
768 VALUE
770 {
771  long i;
772  static const char err[] = "backtrace must be Array of String";
773 
774  if (!NIL_P(bt)) {
775  if (RB_TYPE_P(bt, T_STRING)) return rb_ary_new3(1, bt);
776  if (rb_backtrace_p(bt)) return bt;
777  if (!RB_TYPE_P(bt, T_ARRAY)) {
778  rb_raise(rb_eTypeError, err);
779  }
780  for (i=0;i<RARRAY_LEN(bt);i++) {
781  VALUE e = RARRAY_AREF(bt, i);
782  if (!RB_TYPE_P(e, T_STRING)) {
783  rb_raise(rb_eTypeError, err);
784  }
785  }
786  }
787  return bt;
788 }
789 
790 /*
791  * call-seq:
792  * exc.set_backtrace(backtrace) -> array
793  *
794  * Sets the backtrace information associated with +exc+. The +backtrace+ must
795  * be an array of String objects or a single String in the format described
796  * in Exception#backtrace.
797  *
798  */
799 
800 static VALUE
802 {
803  return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
804 }
805 
806 VALUE
808 {
809  return exc_set_backtrace(exc, bt);
810 }
811 
812 VALUE
814 {
815  ID id_cause;
816  CONST_ID(id_cause, "cause");
817  return rb_attr_get(exc, id_cause);
818 }
819 
820 static VALUE
822 {
823  ID id_exception;
824  CONST_ID(id_exception, "exception");
825  return rb_check_funcall(obj, id_exception, 0, 0);
826 }
827 
828 /*
829  * call-seq:
830  * exc == obj -> true or false
831  *
832  * Equality---If <i>obj</i> is not an <code>Exception</code>, returns
833  * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
834  * <i>obj</i> share same class, messages, and backtrace.
835  */
836 
837 static VALUE
839 {
840  VALUE mesg, backtrace;
841  ID id_mesg;
842 
843  if (exc == obj) return Qtrue;
844  CONST_ID(id_mesg, "mesg");
845 
846  if (rb_obj_class(exc) != rb_obj_class(obj)) {
847  int status = 0;
848  ID id_message, id_backtrace;
849  CONST_ID(id_message, "message");
850  CONST_ID(id_backtrace, "backtrace");
851 
852  obj = rb_protect(try_convert_to_exception, obj, &status);
853  if (status || obj == Qundef) {
855  return Qfalse;
856  }
857  if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
858  mesg = rb_check_funcall(obj, id_message, 0, 0);
859  if (mesg == Qundef) return Qfalse;
860  backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
861  if (backtrace == Qundef) return Qfalse;
862  }
863  else {
864  mesg = rb_attr_get(obj, id_mesg);
865  backtrace = exc_backtrace(obj);
866  }
867 
868  if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
869  return Qfalse;
870  if (!rb_equal(exc_backtrace(exc), backtrace))
871  return Qfalse;
872  return Qtrue;
873 }
874 
875 /*
876  * call-seq:
877  * SystemExit.new -> system_exit
878  * SystemExit.new(status) -> system_exit
879  * SystemExit.new(status, msg) -> system_exit
880  * SystemExit.new(msg) -> system_exit
881  *
882  * Create a new +SystemExit+ exception with the given status and message.
883  * Status is true, false, or an integer.
884  * If status is not given, true is used.
885  */
886 
887 static VALUE
889 {
890  VALUE status;
891  if (argc > 0) {
892  status = *argv;
893 
894  switch (status) {
895  case Qtrue:
896  status = INT2FIX(EXIT_SUCCESS);
897  ++argv;
898  --argc;
899  break;
900  case Qfalse:
901  status = INT2FIX(EXIT_FAILURE);
902  ++argv;
903  --argc;
904  break;
905  default:
906  status = rb_check_to_int(status);
907  if (NIL_P(status)) {
908  status = INT2FIX(EXIT_SUCCESS);
909  }
910  else {
911 #if EXIT_SUCCESS != 0
912  if (status == INT2FIX(0))
913  status = INT2FIX(EXIT_SUCCESS);
914 #endif
915  ++argv;
916  --argc;
917  }
918  break;
919  }
920  }
921  else {
922  status = INT2FIX(EXIT_SUCCESS);
923  }
924  rb_call_super(argc, argv);
925  rb_iv_set(exc, "status", status);
926  return exc;
927 }
928 
929 
930 /*
931  * call-seq:
932  * system_exit.status -> fixnum
933  *
934  * Return the status value associated with this system exit.
935  */
936 
937 static VALUE
939 {
940  return rb_attr_get(exc, rb_intern("status"));
941 }
942 
943 
944 /*
945  * call-seq:
946  * system_exit.success? -> true or false
947  *
948  * Returns +true+ if exiting successful, +false+ if not.
949  */
950 
951 static VALUE
953 {
954  VALUE status_val = rb_attr_get(exc, rb_intern("status"));
955  int status;
956 
957  if (NIL_P(status_val))
958  return Qtrue;
959  status = NUM2INT(status_val);
960  if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
961  return Qtrue;
962 
963  return Qfalse;
964 }
965 
966 void
967 rb_name_error(ID id, const char *fmt, ...)
968 {
969  VALUE exc, argv[2];
970  va_list args;
971 
972  va_start(args, fmt);
973  argv[0] = rb_vsprintf(fmt, args);
974  va_end(args);
975 
976  argv[1] = ID2SYM(id);
977  exc = rb_class_new_instance(2, argv, rb_eNameError);
978  rb_exc_raise(exc);
979 }
980 
981 void
982 rb_name_error_str(VALUE str, const char *fmt, ...)
983 {
984  VALUE exc, argv[2];
985  va_list args;
986 
987  va_start(args, fmt);
988  argv[0] = rb_vsprintf(fmt, args);
989  va_end(args);
990 
991  argv[1] = str;
992  exc = rb_class_new_instance(2, argv, rb_eNameError);
993  rb_exc_raise(exc);
994 }
995 
996 /*
997  * call-seq:
998  * NameError.new(msg [, name]) -> name_error
999  *
1000  * Construct a new NameError exception. If given the <i>name</i>
1001  * parameter may subsequently be examined using the <code>NameError.name</code>
1002  * method.
1003  */
1004 
1005 static VALUE
1007 {
1008  VALUE name;
1009 
1010  name = (argc > 1) ? argv[--argc] : Qnil;
1011  rb_call_super(argc, argv);
1012  rb_iv_set(self, "name", name);
1013  return self;
1014 }
1015 
1016 /*
1017  * call-seq:
1018  * name_error.name -> string or nil
1019  *
1020  * Return the name associated with this NameError exception.
1021  */
1022 
1023 static VALUE
1025 {
1026  return rb_attr_get(self, rb_intern("name"));
1027 }
1028 
1029 /*
1030  * call-seq:
1031  * NoMethodError.new(msg, name [, args]) -> no_method_error
1032  *
1033  * Construct a NoMethodError exception for a method of the given name
1034  * called with the given arguments. The name may be accessed using
1035  * the <code>#name</code> method on the resulting object, and the
1036  * arguments using the <code>#args</code> method.
1037  */
1038 
1039 static VALUE
1041 {
1042  VALUE args = (argc > 2) ? argv[--argc] : Qnil;
1043  name_err_initialize(argc, argv, self);
1044  rb_iv_set(self, "args", args);
1045  return self;
1046 }
1047 
1048 /* :nodoc: */
1049 #define NAME_ERR_MESG_COUNT 3
1050 
1051 static void
1053 {
1054  VALUE *ptr = p;
1056 }
1057 
1058 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1059 
1060 static size_t
1062 {
1063  return p ? (NAME_ERR_MESG_COUNT * sizeof(VALUE)) : 0;
1064 }
1065 
1067  "name_err_mesg",
1068  {
1072  },
1074 };
1075 
1076 /* :nodoc: */
1077 VALUE
1079 {
1081  VALUE result;
1082 
1083  ptr[0] = mesg;
1084  ptr[1] = recv;
1085  ptr[2] = method;
1086  result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, ptr);
1087  RB_GC_GUARD(mesg);
1088  RB_GC_GUARD(recv);
1089  RB_GC_GUARD(method);
1090  return result;
1091 }
1092 
1093 /* :nodoc: */
1094 static VALUE
1096 {
1097  VALUE *ptr1, *ptr2;
1098  int i;
1099 
1100  if (obj1 == obj2) return Qtrue;
1101  if (rb_obj_class(obj2) != rb_cNameErrorMesg)
1102  return Qfalse;
1103 
1104  TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1105  TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1106  for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1107  if (!rb_equal(ptr1[i], ptr2[i]))
1108  return Qfalse;
1109  }
1110  return Qtrue;
1111 }
1112 
1113 /* :nodoc: */
1114 static VALUE
1116 {
1117  VALUE *ptr, mesg;
1118  TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
1119 
1120  mesg = ptr[0];
1121  if (NIL_P(mesg)) return Qnil;
1122  else {
1123  const char *desc = 0;
1125  int state = 0;
1126 
1127  obj = ptr[1];
1128  switch (obj) {
1129  case Qnil:
1130  desc = "nil";
1131  break;
1132  case Qtrue:
1133  desc = "true";
1134  break;
1135  case Qfalse:
1136  desc = "false";
1137  break;
1138  default:
1139  d = rb_protect(rb_inspect, obj, &state);
1140  if (state)
1142  if (NIL_P(d) || RSTRING_LEN(d) > 65) {
1143  d = rb_any_to_s(obj);
1144  }
1145  desc = RSTRING_PTR(d);
1146  break;
1147  }
1148  if (desc && desc[0] != '#') {
1149  d = d ? rb_str_dup(d) : rb_str_new2(desc);
1150  rb_str_cat2(d, ":");
1152  }
1153  args[0] = mesg;
1154  args[1] = ptr[2];
1155  args[2] = d;
1157  }
1158  return mesg;
1159 }
1160 
1161 /* :nodoc: */
1162 static VALUE
1164 {
1165  return name_err_mesg_to_str(obj);
1166 }
1167 
1168 /* :nodoc: */
1169 static VALUE
1171 {
1172  return str;
1173 }
1174 
1175 /*
1176  * call-seq:
1177  * no_method_error.args -> obj
1178  *
1179  * Return the arguments passed in as the third parameter to
1180  * the constructor.
1181  */
1182 
1183 static VALUE
1185 {
1186  return rb_attr_get(self, rb_intern("args"));
1187 }
1188 
1189 void
1190 rb_invalid_str(const char *str, const char *type)
1191 {
1192  VALUE s = rb_str_new2(str);
1193 
1194  rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
1195 }
1196 
1197 /*
1198  * Document-module: Errno
1199  *
1200  * Ruby exception objects are subclasses of <code>Exception</code>.
1201  * However, operating systems typically report errors using plain
1202  * integers. Module <code>Errno</code> is created dynamically to map
1203  * these operating system errors to Ruby classes, with each error
1204  * number generating its own subclass of <code>SystemCallError</code>.
1205  * As the subclass is created in module <code>Errno</code>, its name
1206  * will start <code>Errno::</code>.
1207  *
1208  * The names of the <code>Errno::</code> classes depend on
1209  * the environment in which Ruby runs. On a typical Unix or Windows
1210  * platform, there are <code>Errno</code> classes such as
1211  * <code>Errno::EACCES</code>, <code>Errno::EAGAIN</code>,
1212  * <code>Errno::EINTR</code>, and so on.
1213  *
1214  * The integer operating system error number corresponding to a
1215  * particular error is available as the class constant
1216  * <code>Errno::</code><em>error</em><code>::Errno</code>.
1217  *
1218  * Errno::EACCES::Errno #=> 13
1219  * Errno::EAGAIN::Errno #=> 11
1220  * Errno::EINTR::Errno #=> 4
1221  *
1222  * The full list of operating system errors on your particular platform
1223  * are available as the constants of <code>Errno</code>.
1224  *
1225  * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
1226  */
1227 
1229 
1230 static VALUE
1231 set_syserr(int n, const char *name)
1232 {
1233  st_data_t error;
1234 
1235  if (!st_lookup(syserr_tbl, n, &error)) {
1236  error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
1237 
1238  /* capture nonblock errnos for WaitReadable/WaitWritable subclasses */
1239  switch (n) {
1240  case EAGAIN:
1241  rb_eEAGAIN = error;
1242 
1243 #if EAGAIN != EWOULDBLOCK
1244  break;
1245  case EWOULDBLOCK:
1246 #endif
1247 
1248  rb_eEWOULDBLOCK = error;
1249  break;
1250  case EINPROGRESS:
1251  rb_eEINPROGRESS = error;
1252  break;
1253  }
1254 
1255  rb_define_const(error, "Errno", INT2NUM(n));
1256  st_add_direct(syserr_tbl, n, error);
1257  }
1258  else {
1259  rb_define_const(rb_mErrno, name, error);
1260  }
1261  return error;
1262 }
1263 
1264 static VALUE
1266 {
1267  st_data_t error;
1268 
1269  if (!st_lookup(syserr_tbl, n, &error)) {
1270  char name[8]; /* some Windows' errno have 5 digits. */
1271 
1272  snprintf(name, sizeof(name), "E%03d", n);
1273  error = set_syserr(n, name);
1274  }
1275  return error;
1276 }
1277 
1278 /*
1279  * call-seq:
1280  * SystemCallError.new(msg, errno) -> system_call_error_subclass
1281  *
1282  * If _errno_ corresponds to a known system error code, constructs
1283  * the appropriate <code>Errno</code> class for that error, otherwise
1284  * constructs a generic <code>SystemCallError</code> object. The
1285  * error number is subsequently available via the <code>errno</code>
1286  * method.
1287  */
1288 
1289 static VALUE
1291 {
1292 #if !defined(_WIN32)
1293  char *strerror();
1294 #endif
1295  const char *err;
1296  VALUE mesg, error, func;
1297  VALUE klass = rb_obj_class(self);
1298 
1299  if (klass == rb_eSystemCallError) {
1300  st_data_t data = (st_data_t)klass;
1301  rb_scan_args(argc, argv, "12", &mesg, &error, &func);
1302  if (argc == 1 && FIXNUM_P(mesg)) {
1303  error = mesg; mesg = Qnil;
1304  }
1305  if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
1306  klass = (VALUE)data;
1307  /* change class */
1308  if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
1309  rb_raise(rb_eTypeError, "invalid instance type");
1310  }
1311  RBASIC_SET_CLASS(self, klass);
1312  }
1313  }
1314  else {
1315  rb_scan_args(argc, argv, "02", &mesg, &func);
1316  error = rb_const_get(klass, rb_intern("Errno"));
1317  }
1318  if (!NIL_P(error)) err = strerror(NUM2INT(error));
1319  else err = "unknown error";
1320  if (!NIL_P(mesg)) {
1322  VALUE str = StringValue(mesg);
1323  rb_encoding *me = rb_enc_get(mesg);
1324 
1325  if (NIL_P(func))
1326  mesg = rb_sprintf("%s - %"PRIsVALUE, err, mesg);
1327  else
1328  mesg = rb_sprintf("%s @ %"PRIsVALUE" - %"PRIsVALUE, err, func, mesg);
1329  if (le != me && rb_enc_asciicompat(me)) {
1330  le = me;
1331  }/* else assume err is non ASCII string. */
1332  OBJ_INFECT(mesg, str);
1333  rb_enc_associate(mesg, le);
1334  }
1335  else {
1336  mesg = rb_str_new2(err);
1338  }
1339  rb_call_super(1, &mesg);
1340  rb_iv_set(self, "errno", error);
1341  return self;
1342 }
1343 
1344 /*
1345  * call-seq:
1346  * system_call_error.errno -> fixnum
1347  *
1348  * Return this SystemCallError's error number.
1349  */
1350 
1351 static VALUE
1353 {
1354  return rb_attr_get(self, rb_intern("errno"));
1355 }
1356 
1357 /*
1358  * call-seq:
1359  * system_call_error === other -> true or false
1360  *
1361  * Return +true+ if the receiver is a generic +SystemCallError+, or
1362  * if the error numbers +self+ and _other_ are the same.
1363  */
1364 
1365 static VALUE
1367 {
1368  VALUE num, e;
1369  ID en;
1370 
1371  CONST_ID(en, "errno");
1372 
1373  if (!rb_obj_is_kind_of(exc, rb_eSystemCallError)) {
1374  if (!rb_respond_to(exc, en)) return Qfalse;
1375  }
1376  else if (self == rb_eSystemCallError) return Qtrue;
1377 
1378  num = rb_attr_get(exc, rb_intern("errno"));
1379  if (NIL_P(num)) {
1380  num = rb_funcall(exc, en, 0, 0);
1381  }
1382  e = rb_const_get(self, rb_intern("Errno"));
1383  if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
1384  return Qtrue;
1385  return Qfalse;
1386 }
1387 
1388 
1389 /*
1390  * Document-class: StandardError
1391  *
1392  * The most standard error types are subclasses of StandardError. A
1393  * rescue clause without an explicit Exception class will rescue all
1394  * StandardErrors (and only those).
1395  *
1396  * def foo
1397  * raise "Oups"
1398  * end
1399  * foo rescue "Hello" #=> "Hello"
1400  *
1401  * On the other hand:
1402  *
1403  * require 'does/not/exist' rescue "Hi"
1404  *
1405  * <em>raises the exception:</em>
1406  *
1407  * LoadError: no such file to load -- does/not/exist
1408  *
1409  */
1410 
1411 /*
1412  * Document-class: SystemExit
1413  *
1414  * Raised by +exit+ to initiate the termination of the script.
1415  */
1416 
1417 /*
1418  * Document-class: SignalException
1419  *
1420  * Raised when a signal is received.
1421  *
1422  * begin
1423  * Process.kill('HUP',Process.pid)
1424  * sleep # wait for receiver to handle signal sent by Process.kill
1425  * rescue SignalException => e
1426  * puts "received Exception #{e}"
1427  * end
1428  *
1429  * <em>produces:</em>
1430  *
1431  * received Exception SIGHUP
1432  */
1433 
1434 /*
1435  * Document-class: Interrupt
1436  *
1437  * Raised with the interrupt signal is received, typically because the
1438  * user pressed on Control-C (on most posix platforms). As such, it is a
1439  * subclass of +SignalException+.
1440  *
1441  * begin
1442  * puts "Press ctrl-C when you get bored"
1443  * loop {}
1444  * rescue Interrupt => e
1445  * puts "Note: You will typically use Signal.trap instead."
1446  * end
1447  *
1448  * <em>produces:</em>
1449  *
1450  * Press ctrl-C when you get bored
1451  *
1452  * <em>then waits until it is interrupted with Control-C and then prints:</em>
1453  *
1454  * Note: You will typically use Signal.trap instead.
1455  */
1456 
1457 /*
1458  * Document-class: TypeError
1459  *
1460  * Raised when encountering an object that is not of the expected type.
1461  *
1462  * [1, 2, 3].first("two")
1463  *
1464  * <em>raises the exception:</em>
1465  *
1466  * TypeError: no implicit conversion of String into Integer
1467  *
1468  */
1469 
1470 /*
1471  * Document-class: ArgumentError
1472  *
1473  * Raised when the arguments are wrong and there isn't a more specific
1474  * Exception class.
1475  *
1476  * Ex: passing the wrong number of arguments
1477  *
1478  * [1, 2, 3].first(4, 5)
1479  *
1480  * <em>raises the exception:</em>
1481  *
1482  * ArgumentError: wrong number of arguments (2 for 1)
1483  *
1484  * Ex: passing an argument that is not acceptable:
1485  *
1486  * [1, 2, 3].first(-4)
1487  *
1488  * <em>raises the exception:</em>
1489  *
1490  * ArgumentError: negative array size
1491  */
1492 
1493 /*
1494  * Document-class: IndexError
1495  *
1496  * Raised when the given index is invalid.
1497  *
1498  * a = [:foo, :bar]
1499  * a.fetch(0) #=> :foo
1500  * a[4] #=> nil
1501  * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
1502  *
1503  */
1504 
1505 /*
1506  * Document-class: KeyError
1507  *
1508  * Raised when the specified key is not found. It is a subclass of
1509  * IndexError.
1510  *
1511  * h = {"foo" => :bar}
1512  * h.fetch("foo") #=> :bar
1513  * h.fetch("baz") #=> KeyError: key not found: "baz"
1514  *
1515  */
1516 
1517 /*
1518  * Document-class: RangeError
1519  *
1520  * Raised when a given numerical value is out of range.
1521  *
1522  * [1, 2, 3].drop(1 << 100)
1523  *
1524  * <em>raises the exception:</em>
1525  *
1526  * RangeError: bignum too big to convert into `long'
1527  */
1528 
1529 /*
1530  * Document-class: ScriptError
1531  *
1532  * ScriptError is the superclass for errors raised when a script
1533  * can not be executed because of a +LoadError+,
1534  * +NotImplementedError+ or a +SyntaxError+. Note these type of
1535  * +ScriptErrors+ are not +StandardError+ and will not be
1536  * rescued unless it is specified explicitly (or its ancestor
1537  * +Exception+).
1538  */
1539 
1540 /*
1541  * Document-class: SyntaxError
1542  *
1543  * Raised when encountering Ruby code with an invalid syntax.
1544  *
1545  * eval("1+1=2")
1546  *
1547  * <em>raises the exception:</em>
1548  *
1549  * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
1550  */
1551 
1552 /*
1553  * Document-class: LoadError
1554  *
1555  * Raised when a file required (a Ruby script, extension library, ...)
1556  * fails to load.
1557  *
1558  * require 'this/file/does/not/exist'
1559  *
1560  * <em>raises the exception:</em>
1561  *
1562  * LoadError: no such file to load -- this/file/does/not/exist
1563  */
1564 
1565 /*
1566  * Document-class: NotImplementedError
1567  *
1568  * Raised when a feature is not implemented on the current platform. For
1569  * example, methods depending on the +fsync+ or +fork+ system calls may
1570  * raise this exception if the underlying operating system or Ruby
1571  * runtime does not support them.
1572  *
1573  * Note that if +fork+ raises a +NotImplementedError+, then
1574  * <code>respond_to?(:fork)</code> returns +false+.
1575  */
1576 
1577 /*
1578  * Document-class: NameError
1579  *
1580  * Raised when a given name is invalid or undefined.
1581  *
1582  * puts foo
1583  *
1584  * <em>raises the exception:</em>
1585  *
1586  * NameError: undefined local variable or method `foo' for main:Object
1587  *
1588  * Since constant names must start with a capital:
1589  *
1590  * Fixnum.const_set :answer, 42
1591  *
1592  * <em>raises the exception:</em>
1593  *
1594  * NameError: wrong constant name answer
1595  */
1596 
1597 /*
1598  * Document-class: NoMethodError
1599  *
1600  * Raised when a method is called on a receiver which doesn't have it
1601  * defined and also fails to respond with +method_missing+.
1602  *
1603  * "hello".to_ary
1604  *
1605  * <em>raises the exception:</em>
1606  *
1607  * NoMethodError: undefined method `to_ary' for "hello":String
1608  */
1609 
1610 /*
1611  * Document-class: RuntimeError
1612  *
1613  * A generic error class raised when an invalid operation is attempted.
1614  *
1615  * [1, 2, 3].freeze << 4
1616  *
1617  * <em>raises the exception:</em>
1618  *
1619  * RuntimeError: can't modify frozen array
1620  *
1621  * Kernel.raise will raise a RuntimeError if no Exception class is
1622  * specified.
1623  *
1624  * raise "ouch"
1625  *
1626  * <em>raises the exception:</em>
1627  *
1628  * RuntimeError: ouch
1629  */
1630 
1631 /*
1632  * Document-class: SecurityError
1633  *
1634  * Raised when attempting a potential unsafe operation, typically when
1635  * the $SAFE level is raised above 0.
1636  *
1637  * foo = "bar"
1638  * proc = Proc.new do
1639  * $SAFE = 3
1640  * foo.untaint
1641  * end
1642  * proc.call
1643  *
1644  * <em>raises the exception:</em>
1645  *
1646  * SecurityError: Insecure: Insecure operation `untaint' at level 3
1647  */
1648 
1649 /*
1650  * Document-class: NoMemoryError
1651  *
1652  * Raised when memory allocation fails.
1653  */
1654 
1655 /*
1656  * Document-class: SystemCallError
1657  *
1658  * SystemCallError is the base class for all low-level
1659  * platform-dependent errors.
1660  *
1661  * The errors available on the current platform are subclasses of
1662  * SystemCallError and are defined in the Errno module.
1663  *
1664  * File.open("does/not/exist")
1665  *
1666  * <em>raises the exception:</em>
1667  *
1668  * Errno::ENOENT: No such file or directory - does/not/exist
1669  */
1670 
1671 /*
1672  * Document-class: EncodingError
1673  *
1674  * EncodingError is the base class for encoding errors.
1675  */
1676 
1677 /*
1678  * Document-class: Encoding::CompatibilityError
1679  *
1680  * Raised by Encoding and String methods when the source encoding is
1681  * incompatible with the target encoding.
1682  */
1683 
1684 /*
1685  * Document-class: fatal
1686  *
1687  * fatal is an Exception that is raised when ruby has encountered a fatal
1688  * error and must exit. You are not able to rescue fatal.
1689  */
1690 
1691 /*
1692  * Document-class: NameError::message
1693  * :nodoc:
1694  */
1695 
1696 /*
1697  * Descendants of class Exception are used to communicate between
1698  * Kernel#raise and +rescue+ statements in <code>begin ... end</code> blocks.
1699  * Exception objects carry information about the exception -- its type (the
1700  * exception's class name), an optional descriptive string, and optional
1701  * traceback information. Exception subclasses may add additional
1702  * information like NameError#name.
1703  *
1704  * Programs may make subclasses of Exception, typically of StandardError or
1705  * RuntimeError, to provide custom classes and add additional information.
1706  * See the subclass list below for defaults for +raise+ and +rescue+.
1707  *
1708  * When an exception has been raised but not yet handled (in +rescue+,
1709  * +ensure+, +at_exit+ and +END+ blocks) the global variable <code>$!</code>
1710  * will contain the current exception and <code>$@</code> contains the
1711  * current exception's backtrace.
1712  *
1713  * It is recommended that a library should have one subclass of StandardError
1714  * or RuntimeError and have specific exception types inherit from it. This
1715  * allows the user to rescue a generic exception type to catch all exceptions
1716  * the library may raise even if future versions of the library add new
1717  * exception subclasses.
1718  *
1719  * For example:
1720  *
1721  * class MyLibrary
1722  * class Error < RuntimeError
1723  * end
1724  *
1725  * class WidgetError < Error
1726  * end
1727  *
1728  * class FrobError < Error
1729  * end
1730  *
1731  * end
1732  *
1733  * To handle both WidgetError and FrobError the library user can rescue
1734  * MyLibrary::Error.
1735  *
1736  * The built-in subclasses of Exception are:
1737  *
1738  * * NoMemoryError
1739  * * ScriptError
1740  * * LoadError
1741  * * NotImplementedError
1742  * * SyntaxError
1743  * * SecurityError
1744  * * SignalException
1745  * * Interrupt
1746  * * StandardError -- default for +rescue+
1747  * * ArgumentError
1748  * * EncodingError
1749  * * FiberError
1750  * * IOError
1751  * * EOFError
1752  * * IndexError
1753  * * KeyError
1754  * * StopIteration
1755  * * LocalJumpError
1756  * * NameError
1757  * * NoMethodError
1758  * * RangeError
1759  * * FloatDomainError
1760  * * RegexpError
1761  * * RuntimeError -- default for +raise+
1762  * * SystemCallError
1763  * * Errno::*
1764  * * ThreadError
1765  * * TypeError
1766  * * ZeroDivisionError
1767  * * SystemExit
1768  * * SystemStackError
1769  * * fatal -- impossible to rescue
1770  */
1771 
1772 void
1774 {
1775  rb_eException = rb_define_class("Exception", rb_cObject);
1776  rb_define_singleton_method(rb_eException, "exception", rb_class_new_instance, -1);
1777  rb_define_method(rb_eException, "exception", exc_exception, -1);
1778  rb_define_method(rb_eException, "initialize", exc_initialize, -1);
1779  rb_define_method(rb_eException, "==", exc_equal, 1);
1780  rb_define_method(rb_eException, "to_s", exc_to_s, 0);
1781  rb_define_method(rb_eException, "message", exc_message, 0);
1782  rb_define_method(rb_eException, "inspect", exc_inspect, 0);
1783  rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
1784  rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);
1785  rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
1786  rb_define_method(rb_eException, "cause", exc_cause, 0);
1787 
1788  rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
1789  rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
1790  rb_define_method(rb_eSystemExit, "status", exit_status, 0);
1791  rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);
1792 
1793  rb_eFatal = rb_define_class("fatal", rb_eException);
1794  rb_eSignal = rb_define_class("SignalException", rb_eException);
1795  rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal);
1796 
1797  rb_eStandardError = rb_define_class("StandardError", rb_eException);
1798  rb_eTypeError = rb_define_class("TypeError", rb_eStandardError);
1799  rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
1800  rb_eIndexError = rb_define_class("IndexError", rb_eStandardError);
1801  rb_eKeyError = rb_define_class("KeyError", rb_eIndexError);
1802  rb_eRangeError = rb_define_class("RangeError", rb_eStandardError);
1803 
1804  rb_eScriptError = rb_define_class("ScriptError", rb_eException);
1805  rb_eSyntaxError = rb_define_class("SyntaxError", rb_eScriptError);
1806 
1807  rb_eLoadError = rb_define_class("LoadError", rb_eScriptError);
1808  /* the path failed to load */
1809  rb_attr(rb_eLoadError, rb_intern("path"), 1, 0, Qfalse);
1810 
1811  rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
1812 
1813  rb_eNameError = rb_define_class("NameError", rb_eStandardError);
1814  rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
1815  rb_define_method(rb_eNameError, "name", name_err_name, 0);
1816  rb_cNameErrorMesg = rb_define_class_under(rb_eNameError, "message", rb_cData);
1818  rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
1819  rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
1820  rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
1821  rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
1822  rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
1823  rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
1824  rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
1825 
1826  rb_eRuntimeError = rb_define_class("RuntimeError", rb_eStandardError);
1827  rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
1828  rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
1829  rb_eEncodingError = rb_define_class("EncodingError", rb_eStandardError);
1830  rb_eEncCompatError = rb_define_class_under(rb_cEncoding, "CompatibilityError", rb_eEncodingError);
1831 
1832  syserr_tbl = st_init_numtable();
1833  rb_eSystemCallError = rb_define_class("SystemCallError", rb_eStandardError);
1834  rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
1835  rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
1836  rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
1837 
1838  rb_mErrno = rb_define_module("Errno");
1839 
1840  rb_define_global_function("warn", rb_warn_m, -1);
1841 }
1842 
1843 void
1844 rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
1845 {
1846  va_list args;
1847  VALUE mesg;
1848 
1849  va_start(args, fmt);
1850  mesg = rb_enc_vsprintf(enc, fmt, args);
1851  va_end(args);
1852 
1853  rb_exc_raise(rb_exc_new3(exc, mesg));
1854 }
1855 
1856 void
1857 rb_raise(VALUE exc, const char *fmt, ...)
1858 {
1859  va_list args;
1860  VALUE mesg;
1861 
1862  va_start(args, fmt);
1863  mesg = rb_vsprintf(fmt, args);
1864  va_end(args);
1865  rb_exc_raise(rb_exc_new3(exc, mesg));
1866 }
1867 
1868 NORETURN(static void raise_loaderror(VALUE path, VALUE mesg));
1869 
1870 static void
1872 {
1873  VALUE err = rb_exc_new3(rb_eLoadError, mesg);
1874  rb_ivar_set(err, rb_intern("@path"), path);
1875  rb_exc_raise(err);
1876 }
1877 
1878 void
1879 rb_loaderror(const char *fmt, ...)
1880 {
1881  va_list args;
1882  VALUE mesg;
1883 
1884  va_start(args, fmt);
1885  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
1886  va_end(args);
1887  raise_loaderror(Qnil, mesg);
1888 }
1889 
1890 void
1892 {
1893  va_list args;
1894  VALUE mesg;
1895 
1896  va_start(args, fmt);
1897  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
1898  va_end(args);
1899  raise_loaderror(path, mesg);
1900 }
1901 
1902 void
1904 {
1905  rb_raise(rb_eNotImpError,
1906  "%s() function is unimplemented on this machine",
1908 }
1909 
1910 void
1911 rb_fatal(const char *fmt, ...)
1912 {
1913  va_list args;
1914  VALUE mesg;
1915 
1916  va_start(args, fmt);
1917  mesg = rb_vsprintf(fmt, args);
1918  va_end(args);
1919 
1920  rb_exc_fatal(rb_exc_new3(rb_eFatal, mesg));
1921 }
1922 
1923 static VALUE
1924 make_errno_exc(const char *mesg)
1925 {
1926  int n = errno;
1927 
1928  errno = 0;
1929  if (n == 0) {
1930  rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
1931  }
1932  return rb_syserr_new(n, mesg);
1933 }
1934 
1935 static VALUE
1937 {
1938  int n = errno;
1939 
1940  errno = 0;
1941  if (!mesg) mesg = Qnil;
1942  if (n == 0) {
1943  const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
1944  rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
1945  }
1946  return rb_syserr_new_str(n, mesg);
1947 }
1948 
1949 VALUE
1950 rb_syserr_new(int n, const char *mesg)
1951 {
1952  VALUE arg;
1953  arg = mesg ? rb_str_new2(mesg) : Qnil;
1954  return rb_syserr_new_str(n, arg);
1955 }
1956 
1957 VALUE
1959 {
1960  return rb_class_new_instance(1, &arg, get_syserr(n));
1961 }
1962 
1963 void
1964 rb_syserr_fail(int e, const char *mesg)
1965 {
1966  rb_exc_raise(rb_syserr_new(e, mesg));
1967 }
1968 
1969 void
1971 {
1972  rb_exc_raise(rb_syserr_new_str(e, mesg));
1973 }
1974 
1975 void
1976 rb_sys_fail(const char *mesg)
1977 {
1979 }
1980 
1981 void
1983 {
1985 }
1986 
1987 #ifdef RUBY_FUNCTION_NAME_STRING
1988 void
1989 rb_sys_fail_path_in(const char *func_name, VALUE path)
1990 {
1991  int n = errno;
1992 
1993  errno = 0;
1994  rb_syserr_fail_path_in(func_name, n, path);
1995 }
1996 
1997 void
1998 rb_syserr_fail_path_in(const char *func_name, int n, VALUE path)
1999 {
2000  VALUE args[2];
2001 
2002  if (!path) path = Qnil;
2003  if (n == 0) {
2004  const char *s = !NIL_P(path) ? RSTRING_PTR(path) : "";
2005  if (!func_name) func_name = "(null)";
2006  rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0",
2007  func_name, s);
2008  }
2009  args[0] = path;
2010  args[1] = rb_str_new_cstr(func_name);
2012 }
2013 #endif
2014 
2015 void
2016 rb_mod_sys_fail(VALUE mod, const char *mesg)
2017 {
2018  VALUE exc = make_errno_exc(mesg);
2019  rb_extend_object(exc, mod);
2020  rb_exc_raise(exc);
2021 }
2022 
2023 void
2025 {
2026  VALUE exc = make_errno_exc_str(mesg);
2027  rb_extend_object(exc, mod);
2028  rb_exc_raise(exc);
2029 }
2030 
2031 void
2032 rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
2033 {
2034  VALUE exc = rb_syserr_new(e, mesg);
2035  rb_extend_object(exc, mod);
2036  rb_exc_raise(exc);
2037 }
2038 
2039 void
2041 {
2042  VALUE exc = rb_syserr_new_str(e, mesg);
2043  rb_extend_object(exc, mod);
2044  rb_exc_raise(exc);
2045 }
2046 
2047 void
2048 rb_sys_warning(const char *fmt, ...)
2049 {
2050  char buf[BUFSIZ];
2051  va_list args;
2052  int errno_save;
2053 
2054  errno_save = errno;
2055 
2056  if (!RTEST(ruby_verbose)) return;
2057 
2058  snprintf(buf, BUFSIZ, "warning: %s", fmt);
2059  snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
2060 
2061  va_start(args, fmt);
2062  warn_print(buf, args);
2063  va_end(args);
2064  errno = errno_save;
2065 }
2066 
2067 void
2068 rb_load_fail(VALUE path, const char *err)
2069 {
2070  VALUE mesg = rb_str_buf_new_cstr(err);
2071  rb_str_cat2(mesg, " -- ");
2072  rb_str_append(mesg, path); /* should be ASCII compatible */
2073  raise_loaderror(path, mesg);
2074 }
2075 
2076 void
2077 rb_error_frozen(const char *what)
2078 {
2079  rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
2080 }
2081 
2082 #undef rb_check_frozen
2083 void
2085 {
2087 }
2088 
2089 void
2091 {
2092 }
2093 
2094 #undef rb_check_trusted
2095 void
2097 {
2098 }
2099 
2100 void
2102 {
2103  if (!FL_ABLE(obj)) return;
2105  if (!FL_ABLE(orig)) return;
2106  if ((~RBASIC(obj)->flags & RBASIC(orig)->flags) & FL_TAINT) {
2107  if (rb_safe_level() > 0) {
2108  rb_raise(rb_eSecurityError, "Insecure: can't modify %"PRIsVALUE,
2109  RBASIC(obj)->klass);
2110  }
2111  }
2112 }
2113 
2114 void
2116 {
2117  rb_eNOERROR = set_syserr(0, "NOERROR");
2118 #define defined_error(name, num) set_syserr((num), (name));
2119 #define undefined_error(name) set_syserr(0, (name));
2120 #include "known_errors.inc"
2121 #undef defined_error
2122 #undef undefined_error
2123 }
VALUE data
Definition: tcltklib.c:3360
VALUE rb_eScriptError
Definition: error.c:562
#define RB_TYPE_P(obj, type)
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: ripper.y:20
#define rb_check_frozen_internal(obj)
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:451
static VALUE syserr_errno(VALUE self)
Definition: error.c:1352
VALUE rb_eStandardError
Definition: error.c:546
static void compile_err_append(VALUE mesg)
Definition: error.c:99
static VALUE make_errno_exc_str(VALUE mesg)
Definition: error.c:1936
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:573
static VALUE exc_backtrace(VALUE exc)
Definition: error.c:728
VALUE rb_any_to_s(VALUE)
Definition: object.c:452
void rb_bug(const char *fmt,...)
Definition: error.c:327
static const rb_data_type_t name_err_mesg_data_type
Definition: error.c:1066
static VALUE get_syserr(int n)
Definition: error.c:1265
void rb_compile_error(const char *file, int line, const char *fmt,...)
Definition: error.c:145
static VALUE VALUE th
Definition: tcltklib.c:2944
#define rb_gc_mark_locations(start, end)
Definition: gc.c:3319
size_t strlen(const char *)
#define OBJ_INFECT(x, s)
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1857
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:2612
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:1964
VALUE rb_cEncoding
Definition: encoding.c:37
VALUE rb_eSignal
Definition: error.c:544
static VALUE exc_message(VALUE exc)
Definition: error.c:665
void(* func)(FILE *out, void *data)
Definition: error.c:275
int st_lookup(st_table *, st_data_t, st_data_t *)
void st_add_direct(st_table *, st_data_t, st_data_t)
Definition: st.c:629
#define rb_check_trusted(obj)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1646
VALUE rb_eEWOULDBLOCK
Definition: error.c:41
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:2281
VALUE rb_eKeyError
Definition: error.c:551
C_block * out
Definition: crypt.c:308
VALUE rb_io_puts(int, VALUE *, VALUE)
Definition: io.c:7011
st_table * st_init_numtable(void)
Definition: st.c:272
rb_funcall(memo->yielder, id_lshift, 1, rb_assoc_new(memo->prev_value, memo->prev_elts))
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:113
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1880
void rb_error_frozen(const char *what)
Definition: error.c:2077
static size_t name_err_mesg_memsize(const void *p)
Definition: error.c:1061
VALUE rb_syserr_new_str(int n, VALUE arg)
Definition: error.c:1958
#define rb_check_frozen(obj)
#define rb_exc_new2
const char * rb_builtin_type_name(int t)
Definition: error.c:440
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:585
VALUE rb_str_new_cstr(const char *)
Definition: string.c:560
ID rb_frame_this_func(void)
Definition: eval.c:943
int status
Definition: tcltklib.c:2197
static VALUE exc_to_s(VALUE exc)
Definition: error.c:646
VALUE rb_eTypeError
Definition: error.c:548
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1078
VALUE rb_cNameErrorMesg
Definition: error.c:560
static VALUE name_err_name(VALUE self)
Definition: error.c:1024
RB_GC_GUARD(args)
VALUE exc
Definition: tcltklib.c:3088
VALUE enc
Definition: tcltklib.c:10318
VALUE rb_eEncodingError
Definition: error.c:554
gz path
Definition: zlib.c:2279
#define TYPE(x)
rb_str_append(str, i)
#define RSTRING_PTR(str)
#define CLASS_OF(v)
NIL_P(eventloop_thread)
Definition: tcltklib.c:4056
#define T_ARRAY
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:548
#define WIFEXITED(status)
Definition: error.c:33
void rb_async_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:371
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:807
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:657
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
return Qtrue
Definition: tcltklib.c:9618
VALUE rb_enc_associate(VALUE obj, rb_encoding *enc)
Definition: encoding.c:826
VALUE rb_obj_class(VALUE)
Definition: object.c:226
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:179
VALUE rb_class_name(VALUE)
Definition: variable.c:391
VALUE rb_backtrace_to_str_ary(VALUE obj)
Definition: vm_backtrace.c:590
VALUE rb_eSecurityError
Definition: error.c:557
static VALUE exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:801
static VALUE name_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1006
#define vsnprintf
#define rb_str_new2
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1675
static VALUE syserr_eqq(VALUE self, VALUE exc)
Definition: error.c:1366
#define WEXITSTATUS(status)
Definition: error.c:37
#define EINPROGRESS
Definition: win32.h:512
VALUE rb_eSyntaxError
Definition: error.c:563
#define ID2SYM(x)
void rb_load_fail(VALUE path, const char *err)
Definition: error.c:2068
void rb_loaderror(const char *fmt,...)
Definition: error.c:1879
memo state
Definition: enum.c:2432
#define T_OBJECT
static st_table * syserr_tbl
Definition: error.c:1228
VALUE rb_f_sprintf(int, const VALUE *)
Definition: sprintf.c:415
VALUE rb_equal(VALUE, VALUE)
Definition: object.c:89
VALUE rb_eRangeError
Definition: error.c:552
d
Definition: strlcat.c:58
i
Definition: enum.c:446
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:982
const char * fmt
Definition: tcltklib.c:846
static VALUE exc_exception(int argc, VALUE *argv, VALUE self)
Definition: error.c:625
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:967
VALUE rb_eEAGAIN
Definition: error.c:40
static VALUE exc_backtrace_locations(VALUE exc)
Definition: error.c:755
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Definition: error.c:1891
#define NORETURN(x)
Definition: ruby.h:33
void rb_exc_raise(VALUE mesg)
Definition: eval.c:567
#define rb_exc_new3
VALUE rb_eNameError
Definition: error.c:553
#define le(x, y)
Definition: time.c:69
return Qfalse
Definition: tcltklib.c:6790
#define FIXNUM_P(f)
void rb_compile_bug(const char *file, int line, const char *fmt,...)
Definition: error.c:395
#define TypedData_Get_Struct(obj, type, data_type, sval)
void rb_compile_error_append(const char *fmt,...)
Definition: error.c:157
void rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt,...)
Definition: error.c:133
#define RARRAY_LEN(a)
#define Qnil
Definition: enum.c:67
VALUE rb_eRuntimeError
Definition: error.c:547
const rb_data_type_t * parent
Definition: ripper.y:975
static VALUE name_err_mesg_dump(VALUE obj, VALUE limit)
Definition: error.c:1163
VALUE rb_syserr_new(int n, const char *mesg)
Definition: error.c:1950
static VALUE char * str
Definition: tcltklib.c:3539
static VALUE exc_equal(VALUE exc, VALUE obj)
Definition: error.c:838
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:510
#define RARRAY_AREF(a, i)
int flags
Definition: tcltklib.c:3015
unsigned long ID
Definition: ripper.y:89
va_end(args)
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:2228
VALUE rb_str_cat2(VALUE, const char *)
Definition: string.c:2158
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:611
static VALUE try_convert_to_exception(VALUE obj)
Definition: error.c:821
VALUE rb_eNoMethodError
Definition: error.c:556
static VALUE VALUE obj
Definition: tcltklib.c:3150
#define RSTRING_LEN(str)
static VALUE exit_success_p(VALUE exc)
Definition: error.c:952
#define INT2FIX(i)
#define name_err_mesg_free
Definition: error.c:1058
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:1982
static VALUE nometh_err_args(VALUE self)
Definition: error.c:1184
VALUE rb_eNoMemError
Definition: error.c:559
#define T_STRING
static VALUE name_err_mesg_to_str(VALUE obj)
Definition: error.c:1115
void rb_check_type(VALUE x, int t)
Definition: error.c:477
volatile ID method
Definition: tcltklib.c:3591
void rb_vm_bugreport(void)
Definition: vm_dump.c:713
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:275
#define write_or_abort(fd, str, len)
Definition: error.c:367
#define rb_sourcefile()
Definition: tcltklib.c:98
static VALUE set_syserr(int n, const char *name)
Definition: error.c:1231
#define TypedData_Wrap_Struct(klass, data_type, sval)
static VALUE exit_status(VALUE exc)
Definition: error.c:938
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Definition: error.c:2040
rb_block_t * base_block
Definition: vm_core.h:555
unsigned char buf[MIME_BUF_SIZE]
Definition: nkf.c:4308
void rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt,...)
Definition: error.c:1844
VALUE rb_eEncCompatError
Definition: error.c:555
int err
Definition: win32.c:114
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:807
#define EXIT_FAILURE
Definition: eval_intern.h:24
VALUE rb_mErrno
Definition: error.c:567
VALUE rb_str_buf_new_cstr(const char *)
Definition: string.c:907
#define MAX_BUG_REPORTERS
Definition: error.c:272
void Init_Exception(void)
Definition: error.c:1773
VALUE rb_eLoadError
Definition: error.c:564
VALUE rb_eIndexError
Definition: error.c:550
int len
Definition: enumerator.c:1332
#define numberof(array)
Definition: etc.c:602
VALUE arg
Definition: enum.c:2427
VALUE rb_str_buf_cat(VALUE, const char *, long)
Definition: string.c:2123
VALUE rb_str_dup(VALUE)
Definition: string.c:1062
static VALUE name_err_mesg_equal(VALUE obj1, VALUE obj2)
Definition: error.c:1095
static VALUE compile_snprintf(rb_encoding *enc, const char *pre, const char *file, int line, const char *fmt, va_list args)
Definition: error.c:84
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1011
VALUE * argv
Definition: tcltklib.c:1969
#define RTEST(v)
void Init_syserr(void)
Definition: error.c:2115
VALUE rb_obj_clone(VALUE)
Definition: object.c:337
int errno
#define EXIT_SUCCESS
Definition: error.c:29
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1250
static const char builtin_types[][10]
Definition: error.c:406
#define StringValue(v)
static int bug_reporters_size
Definition: error.c:279
#define RUBY_TYPED_FREE_IMMEDIATELY
void rb_fatal(const char *fmt,...)
Definition: error.c:1911
#define RTYPEDDATA_P(v)
VALUE rb_eSystemCallError
Definition: error.c:566
register char * s
Definition: os2.c:56
#define CONST_ID(var, str)
VALUE rb_String(VALUE)
Definition: object.c:3009
VP_EXPORT void
Definition: bigdecimal.c:5207
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1719
VALUE rb_eInterrupt
Definition: error.c:543
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:872
static VALUE exc_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:600
int type
Definition: tcltklib.c:112
#define FL_TAINT
int argc
Definition: tcltklib.c:1968
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1309
static int err_position_0(char *buf, long len, const char *file, int line)
Definition: error.c:70
VALUE rb_eEINPROGRESS
Definition: error.c:42
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1318
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Definition: error.c:2032
static VALUE rb_warn_m(int argc, VALUE *argv, VALUE exc)
Definition: error.c:264
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:350
static VALUE exit_initialize(int argc, VALUE *argv, VALUE exc)
Definition: error.c:888
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1198
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1127
void rb_check_copyable(VALUE obj, VALUE orig)
Definition: error.c:2101
int rb_sourceline(void)
Definition: vm.c:1001
void rb_sys_fail(const char *mesg)
Definition: error.c:1976
static VALUE syserr_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1290
ruby_verbose
Definition: tcltklib.c:5796
return ptr
Definition: tcltklib.c:789
#define FL_ABLE(x)
static const char * rb_strerrno(int err)
Definition: error.c:59
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1244
#define WRITE_CONST(fd, str)
Definition: error.c:368
RUBY_EXTERN char * strerror(int)
Definition: strerror.c:11
#define T_TRUE
#define NAME_ERR_MESG_COUNT
Definition: error.c:1049
RUBY_EXTERN VALUE rb_stderr
Definition: ripper.y:1635
#define rb_str_buf_new2
rb_encoding * rb_enc_get(VALUE obj)
Definition: encoding.c:832
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Definition: error.c:2024
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Definition: error.c:579
#define NUM2LONG(x)
#define SYMBOL_P(x)
VALUE rb_check_to_int(VALUE)
Definition: object.c:2706
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:520
#define Qundef
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:646
int mild_compile_error
Thread-local state of compiling context.
Definition: vm_core.h:608
VALUE name
Definition: enum.c:572
static VALUE nometh_err_initialize(int argc, VALUE *argv, VALUE self)
Definition: error.c:1040
int t
Definition: ripper.c:14879
void rb_set_errinfo(VALUE err)
Definition: eval.c:1517
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:2016
DATA_PTR(self)
args[0]
Definition: enum.c:585
static VALUE exc_inspect(VALUE exc)
Definition: error.c:678
VALUE exc_cause(VALUE exc)
Definition: error.c:813
VALUE rb_str_catf(VALUE str, const char *format,...)
Definition: sprintf.c:1290
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:1970
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:192
static VALUE make_errno_exc(const char *mesg)
Definition: error.c:1924
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1561
#define ALLOC_N(type, n)
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:282
#define RBASIC(obj)
const char * wrap_struct_name
Definition: ripper.y:967
klass
Definition: tcltklib.c:3496
#define INT2NUM(x)
VALUE rb_str_vcatf(VALUE, const char *, va_list)
Definition: sprintf.c:1263
#define EWOULDBLOCK
Definition: rubysocket.h:126
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1651
VALUE rb_check_backtrace(VALUE bt)
Definition: error.c:769
#define RBASIC_SET_CLASS(obj, cls)
void rb_notimplement(void)
Definition: error.c:1903
register C_block * p
Definition: crypt.c:309
rb_ivar_set(yielder, id_memo, LONG2NUM(++count))
VALUE rb_eNotImpError
Definition: error.c:558
static void raise_loaderror(VALUE path, VALUE mesg)
Definition: error.c:1871
VALUE rb_str_new(const char *, long)
Definition: string.c:534
#define rb_safe_level()
Definition: tcltklib.c:95
#define builtin_class_name
Definition: error.c:449
data n
Definition: enum.c:860
#define rb_ary_new3
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Definition: error.c:500
static void compile_warn_print(const char *file, int line, const char *fmt, va_list args)
Definition: error.c:169
int rb_backtrace_p(VALUE obj)
Definition: vm_backtrace.c:417
const char ruby_description[]
Definition: version.c:32
static void report_bug(const char *file, int line, const char *fmt, va_list args)
Definition: error.c:296
#define rb_enc_asciicompat(enc)
#define NUM2INT(x)
const char * rb_id2name(ID id)
Definition: ripper.c:17271
VALUE rb_eFatal
Definition: error.c:545
void * data
Definition: error.c:276
void rb_error_untrusted(VALUE obj)
Definition: error.c:2090
#define PRIsVALUE
BDIGIT e
Definition: bigdecimal.c:5209
static void warn_print(const char *fmt, va_list args)
Definition: error.c:204
unsigned long VALUE
Definition: ripper.y:88
VALUE rb_backtrace_to_location_ary(VALUE obj)
Definition: vm_backtrace.c:637
void rb_warning(const char *fmt,...)
Definition: error.c:236
static const char REPORTBUG_MSG[]
Definition: error.c:46
#define snprintf
VALUE rb_define_module(const char *name)
Definition: class.c:727
#define rb_intern(str)
#define mod(x, y)
Definition: date_strftime.c:28
RUBY_EXTERN VALUE rb_cData
Definition: ripper.y:1568
void rb_exc_fatal(VALUE mesg)
Definition: eval.c:576
VALUE rb_eSystemExit
Definition: error.c:542
#define NULL
Definition: _sdbm.c:102
#define T_DATA
void rb_write_error_str(VALUE mesg)
Definition: io.c:7191
volatile VALUE result
Definition: enum.c:1989
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:410
void rb_warn(const char *fmt,...)
Definition: error.c:223
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:1190
VALUE rb_eArgError
Definition: error.c:549
#define T_MASK
Definition: md5.c:131
#define RTYPEDDATA_TYPE(v)
#define T_FALSE
static VALUE name_err_mesg_load(VALUE klass, VALUE str)
Definition: error.c:1170
void rb_sys_warning(const char *fmt,...)
Definition: error.c:2048
static void name_err_mesg_mark(void *p)
Definition: error.c:1052
VALUE rb_eException
Definition: error.c:541
VALUE rb_inspect(VALUE)
Definition: object.c:470
static VALUE rb_eNOERROR
Definition: error.c:568
VALUE rb_sourcefilename(void)
Definition: vm.c:973