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