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