Ruby  1.9.3p484(2013-11-22revision43786)
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 #ifndef EXIT_SUCCESS
29 #define EXIT_SUCCESS 0
30 #endif
31 
32 #ifndef WIFEXITED
33 #define WIFEXITED(status) 1
34 #endif
35 
36 #ifndef WEXITSTATUS
37 #define WEXITSTATUS(status) (status)
38 #endif
39 
40 extern const char ruby_description[];
41 
42 #define REPORTBUG_MSG \
43  "[NOTE]\n" \
44  "You may have encountered a bug in the Ruby interpreter" \
45  " or extension libraries.\n" \
46  "Bug reports are welcome.\n" \
47  "For details: http://www.ruby-lang.org/bugreport.html\n\n" \
48 
49 static const char *
51 {
52 #define defined_error(name, num) if (err == (num)) return (name);
53 #define undefined_error(name)
54 #include "known_errors.inc"
55 #undef defined_error
56 #undef undefined_error
57  return NULL;
58 }
59 
60 static int
61 err_position_0(char *buf, long len, const char *file, int line)
62 {
63  if (!file) {
64  return 0;
65  }
66  else if (line == 0) {
67  return snprintf(buf, len, "%s: ", file);
68  }
69  else {
70  return snprintf(buf, len, "%s:%d: ", file, line);
71  }
72 }
73 
74 static int
75 err_position(char *buf, long len)
76 {
77  return err_position_0(buf, len, rb_sourcefile(), rb_sourceline());
78 }
79 
80 static void
81 err_snprintf(char *buf, long len, const char *fmt, va_list args)
82 {
83  long n;
84 
85  n = err_position(buf, len);
86  if (len > n) {
87  vsnprintf((char*)buf+n, len-n, fmt, args);
88  }
89 }
90 
91 static void
92 compile_snprintf(char *buf, long len, const char *file, int line, const char *fmt, va_list args)
93 {
94  long n;
95 
96  n = err_position_0(buf, len, file, line);
97  if (len > n) {
98  vsnprintf((char*)buf+n, len-n, fmt, args);
99  }
100 }
101 
102 static void err_append(const char*, rb_encoding *);
103 
104 void
105 rb_compile_error_with_enc(const char *file, int line, void *enc, const char *fmt, ...)
106 {
107  va_list args;
108  char buf[BUFSIZ];
109 
110  va_start(args, fmt);
111  compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
112  va_end(args);
113  err_append(buf, (rb_encoding *)enc);
114 }
115 
116 void
117 rb_compile_error(const char *file, int line, const char *fmt, ...)
118 {
119  va_list args;
120  char buf[BUFSIZ];
121 
122  va_start(args, fmt);
123  compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
124  va_end(args);
125  err_append(buf, NULL);
126 }
127 
128 void
129 rb_compile_error_append(const char *fmt, ...)
130 {
131  va_list args;
132  char buf[BUFSIZ];
133 
134  va_start(args, fmt);
135  vsnprintf(buf, BUFSIZ, fmt, args);
136  va_end(args);
137  err_append(buf, NULL);
138 }
139 
140 static void
141 compile_warn_print(const char *file, int line, const char *fmt, va_list args)
142 {
143  char buf[BUFSIZ];
144  int len;
145 
146  compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
147  len = (int)strlen(buf);
148  buf[len++] = '\n';
149  rb_write_error2(buf, len);
150 }
151 
152 void
153 rb_compile_warn(const char *file, int line, const char *fmt, ...)
154 {
155  char buf[BUFSIZ];
156  va_list args;
157 
158  if (NIL_P(ruby_verbose)) return;
159 
160  snprintf(buf, BUFSIZ, "warning: %s", fmt);
161 
162  va_start(args, fmt);
163  compile_warn_print(file, line, buf, args);
164  va_end(args);
165 }
166 
167 /* rb_compile_warning() reports only in verbose mode */
168 void
169 rb_compile_warning(const char *file, int line, const char *fmt, ...)
170 {
171  char buf[BUFSIZ];
172  va_list args;
173 
174  if (!RTEST(ruby_verbose)) return;
175 
176  snprintf(buf, BUFSIZ, "warning: %s", fmt);
177 
178  va_start(args, fmt);
179  compile_warn_print(file, line, buf, args);
180  va_end(args);
181 }
182 
183 static void
184 warn_print(const char *fmt, va_list args)
185 {
186  char buf[BUFSIZ];
187  int len;
188 
189  err_snprintf(buf, BUFSIZ, fmt, args);
190  len = (int)strlen(buf);
191  buf[len++] = '\n';
192  rb_write_error2(buf, len);
193 }
194 
195 void
196 rb_warn(const char *fmt, ...)
197 {
198  char buf[BUFSIZ];
199  va_list args;
200 
201  if (NIL_P(ruby_verbose)) return;
202 
203  snprintf(buf, BUFSIZ, "warning: %s", fmt);
204 
205  va_start(args, fmt);
206  warn_print(buf, args);
207  va_end(args);
208 }
209 
210 /* rb_warning() reports only in verbose mode */
211 void
212 rb_warning(const char *fmt, ...)
213 {
214  char buf[BUFSIZ];
215  va_list args;
216 
217  if (!RTEST(ruby_verbose)) return;
218 
219  snprintf(buf, BUFSIZ, "warning: %s", fmt);
220 
221  va_start(args, fmt);
222  warn_print(buf, args);
223  va_end(args);
224 }
225 
226 /*
227  * call-seq:
228  * warn(msg) -> nil
229  *
230  * Display the given message (followed by a newline) on STDERR unless
231  * warnings are disabled (for example with the <code>-W0</code> flag).
232  */
233 
234 static VALUE
235 rb_warn_m(VALUE self, VALUE mesg)
236 {
237  if (!NIL_P(ruby_verbose)) {
238  rb_io_write(rb_stderr, mesg);
240  }
241  return Qnil;
242 }
243 
244 static void
245 report_bug(const char *file, int line, const char *fmt, va_list args)
246 {
247  char buf[BUFSIZ];
248  FILE *out = stderr;
249  int len = err_position_0(buf, BUFSIZ, file, line);
250 
251  if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
252  (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
253 
254  fputs("[BUG] ", out);
255  vfprintf(out, fmt, args);
256  fprintf(out, "\n%s\n\n", ruby_description);
257 
258  rb_vm_bugreport();
259 
260  fprintf(out, REPORTBUG_MSG);
261  }
262 }
263 
264 void
265 rb_bug(const char *fmt, ...)
266 {
267  va_list args;
268  const char *file = NULL;
269  int line = 0;
270 
271  if (GET_THREAD()) {
272  file = rb_sourcefile();
273  line = rb_sourceline();
274  }
275 
276  va_start(args, fmt);
277  report_bug(file, line, fmt, args);
278  va_end(args);
279 
280 #if defined(_WIN32) && defined(RT_VER) && RT_VER >= 80
281  _set_abort_behavior( 0, _CALL_REPORTFAULT);
282 #endif
283 
284  abort();
285 }
286 
287 void
288 rb_bug_errno(const char *mesg, int errno_arg)
289 {
290  if (errno_arg == 0)
291  rb_bug("%s: errno == 0 (NOERROR)", mesg);
292  else {
293  const char *errno_str = rb_strerrno(errno_arg);
294  if (errno_str)
295  rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
296  else
297  rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
298  }
299 }
300 
301 /*
302  * this is safe to call inside signal handler and timer thread
303  * (which isn't a Ruby Thread object)
304  */
305 #define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
306 #define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
307 
308 void
309 rb_async_bug_errno(const char *mesg, int errno_arg)
310 {
311  WRITE_CONST(2, "[ASYNC BUG] ");
312  write_or_abort(2, mesg, strlen(mesg));
313  WRITE_CONST(2, "\n");
314 
315  if (errno_arg == 0) {
316  WRITE_CONST(2, "errno == 0 (NOERROR)\n");
317  }
318  else {
319  const char *errno_str = rb_strerrno(errno_arg);
320 
321  if (!errno_str)
322  errno_str = "undefined errno";
323  write_or_abort(2, errno_str, strlen(errno_str));
324  }
325  WRITE_CONST(2, "\n\n");
327  WRITE_CONST(2, "\n\n");
329  abort();
330 }
331 
332 void
333 rb_compile_bug(const char *file, int line, const char *fmt, ...)
334 {
335  va_list args;
336 
337  va_start(args, fmt);
338  report_bug(file, line, fmt, args);
339  va_end(args);
340 
341  abort();
342 }
343 
344 static const struct types {
345  int type;
346  const char *name;
347 } builtin_types[] = {
348  {T_NIL, "nil"},
349  {T_OBJECT, "Object"},
350  {T_CLASS, "Class"},
351  {T_ICLASS, "iClass"}, /* internal use: mixed-in module holder */
352  {T_MODULE, "Module"},
353  {T_FLOAT, "Float"},
354  {T_STRING, "String"},
355  {T_REGEXP, "Regexp"},
356  {T_ARRAY, "Array"},
357  {T_FIXNUM, "Fixnum"},
358  {T_HASH, "Hash"},
359  {T_STRUCT, "Struct"},
360  {T_BIGNUM, "Bignum"},
361  {T_FILE, "File"},
362  {T_RATIONAL,"Rational"},
363  {T_COMPLEX, "Complex"},
364  {T_TRUE, "true"},
365  {T_FALSE, "false"},
366  {T_SYMBOL, "Symbol"}, /* :symbol */
367  {T_DATA, "Data"}, /* internal use: wrapped C pointers */
368  {T_MATCH, "MatchData"}, /* data of $~ */
369  {T_NODE, "Node"}, /* internal use: syntax tree node */
370  {T_UNDEF, "undef"}, /* internal use: #undef; should not happen */
371 };
372 
373 void
375 {
376  const struct types *type = builtin_types;
377  const struct types *const typeend = builtin_types +
378  sizeof(builtin_types) / sizeof(builtin_types[0]);
379  int xt;
380 
381  if (x == Qundef) {
382  rb_bug("undef leaked to the Ruby space");
383  }
384 
385  xt = TYPE(x);
386  if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
387  while (type < typeend) {
388  if (type->type == t) {
389  const char *etype;
390 
391  if (NIL_P(x)) {
392  etype = "nil";
393  }
394  else if (FIXNUM_P(x)) {
395  etype = "Fixnum";
396  }
397  else if (SYMBOL_P(x)) {
398  etype = "Symbol";
399  }
400  else if (rb_special_const_p(x)) {
401  x = rb_obj_as_string(x);
402  etype = StringValuePtr(x);
403  }
404  else {
405  etype = rb_obj_classname(x);
406  }
407  rb_raise(rb_eTypeError, "wrong argument type %s (expected %s)",
408  etype, type->name);
409  }
410  type++;
411  }
412  if (xt > T_MASK && xt <= 0x3f) {
413  rb_fatal("unknown type 0x%x (0x%x given, probably comes from extension library for ruby 1.8)", t, xt);
414  }
415  rb_bug("unknown type 0x%x (0x%x given)", t, xt);
416  }
417 }
418 
419 int
421 {
422  while (child) {
423  if (child == parent) return 1;
424  child = child->parent;
425  }
426  return 0;
427 }
428 
429 int
431 {
432  if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA ||
433  !RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
434  return 0;
435  }
436  return 1;
437 }
438 
439 void *
441 {
442  const char *etype;
443  static const char mesg[] = "wrong argument type %s (expected %s)";
444 
445  if (SPECIAL_CONST_P(obj) || BUILTIN_TYPE(obj) != T_DATA) {
446  Check_Type(obj, T_DATA);
447  }
448  if (!RTYPEDDATA_P(obj)) {
449  etype = rb_obj_classname(obj);
450  rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
451  }
452  else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
453  etype = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
454  rb_raise(rb_eTypeError, mesg, etype, data_type->wrap_struct_name);
455  }
456  return DATA_PTR(obj);
457 }
458 
459 /* exception classes */
480 
484 
488 
489 #undef rb_exc_new2
490 
491 VALUE
492 rb_exc_new(VALUE etype, const char *ptr, long len)
493 {
494  return rb_funcall(etype, rb_intern("new"), 1, rb_str_new(ptr, len));
495 }
496 
497 VALUE
498 rb_exc_new2(VALUE etype, const char *s)
499 {
500  return rb_exc_new(etype, s, strlen(s));
501 }
502 
503 VALUE
505 {
506  StringValue(str);
507  return rb_funcall(etype, rb_intern("new"), 1, str);
508 }
509 
510 /*
511  * call-seq:
512  * Exception.new(msg = nil) -> exception
513  *
514  * Construct a new Exception object, optionally passing in
515  * a message.
516  */
517 
518 static VALUE
520 {
521  VALUE arg;
522 
523  rb_scan_args(argc, argv, "01", &arg);
524  rb_iv_set(exc, "mesg", arg);
525  rb_iv_set(exc, "bt", Qnil);
526 
527  return exc;
528 }
529 
530 /*
531  * Document-method: exception
532  *
533  * call-seq:
534  * exc.exception(string) -> an_exception or exc
535  *
536  * With no argument, or if the argument is the same as the receiver,
537  * return the receiver. Otherwise, create a new
538  * exception object of the same class as the receiver, but with a
539  * message equal to <code>string.to_str</code>.
540  *
541  */
542 
543 static VALUE
545 {
546  VALUE exc;
547 
548  if (argc == 0) return self;
549  if (argc == 1 && self == argv[0]) return self;
550  exc = rb_obj_clone(self);
551  exc_initialize(argc, argv, exc);
552 
553  return exc;
554 }
555 
556 /*
557  * call-seq:
558  * exception.to_s -> string
559  *
560  * Returns exception's message (or the name of the exception if
561  * no message is set).
562  */
563 
564 static VALUE
566 {
567  VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
568  VALUE r = Qnil;
569 
570  if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
571  r = rb_String(mesg);
572  return r;
573 }
574 
575 /*
576  * call-seq:
577  * exception.message -> string
578  *
579  * Returns the result of invoking <code>exception.to_s</code>.
580  * Normally this returns the exception's message or name. By
581  * supplying a to_str method, exceptions are agreeing to
582  * be used where Strings are expected.
583  */
584 
585 static VALUE
587 {
588  return rb_funcall(exc, rb_intern("to_s"), 0, 0);
589 }
590 
591 /*
592  * call-seq:
593  * exception.inspect -> string
594  *
595  * Return this exception's class name an message
596  */
597 
598 static VALUE
600 {
601  VALUE str, klass;
602 
603  klass = CLASS_OF(exc);
604  exc = rb_obj_as_string(exc);
605  if (RSTRING_LEN(exc) == 0) {
606  return rb_str_dup(rb_class_name(klass));
607  }
608 
609  str = rb_str_buf_new2("#<");
610  klass = rb_class_name(klass);
611  rb_str_buf_append(str, klass);
612  rb_str_buf_cat(str, ": ", 2);
613  rb_str_buf_append(str, exc);
614  rb_str_buf_cat(str, ">", 1);
615 
616  return str;
617 }
618 
619 /*
620  * call-seq:
621  * exception.backtrace -> array
622  *
623  * Returns any backtrace associated with the exception. The backtrace
624  * is an array of strings, each containing either ``filename:lineNo: in
625  * `method''' or ``filename:lineNo.''
626  *
627  * def a
628  * raise "boom"
629  * end
630  *
631  * def b
632  * a()
633  * end
634  *
635  * begin
636  * b()
637  * rescue => detail
638  * print detail.backtrace.join("\n")
639  * end
640  *
641  * <em>produces:</em>
642  *
643  * prog.rb:2:in `a'
644  * prog.rb:6:in `b'
645  * prog.rb:10
646 */
647 
648 static VALUE
650 {
651  ID bt;
652 
653  CONST_ID(bt, "bt");
654  return rb_attr_get(exc, bt);
655 }
656 
657 VALUE
659 {
660  long i;
661  static const char err[] = "backtrace must be Array of String";
662 
663  if (!NIL_P(bt)) {
664  int t = TYPE(bt);
665 
666  if (t == T_STRING) return rb_ary_new3(1, bt);
667  if (t != T_ARRAY) {
668  rb_raise(rb_eTypeError, err);
669  }
670  for (i=0;i<RARRAY_LEN(bt);i++) {
671  if (TYPE(RARRAY_PTR(bt)[i]) != T_STRING) {
672  rb_raise(rb_eTypeError, err);
673  }
674  }
675  }
676  return bt;
677 }
678 
679 /*
680  * call-seq:
681  * exc.set_backtrace(array) -> array
682  *
683  * Sets the backtrace information associated with <i>exc</i>. The
684  * argument must be an array of <code>String</code> objects in the
685  * format described in <code>Exception#backtrace</code>.
686  *
687  */
688 
689 static VALUE
691 {
692  return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
693 }
694 
695 /*
696  * call-seq:
697  * exc == obj -> true or false
698  *
699  * Equality---If <i>obj</i> is not an <code>Exception</code>, returns
700  * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
701  * <i>obj</i> share same class, messages, and backtrace.
702  */
703 
704 static VALUE
706 {
707  VALUE mesg, backtrace;
708  ID id_mesg;
709 
710  if (exc == obj) return Qtrue;
711  CONST_ID(id_mesg, "mesg");
712 
713  if (rb_obj_class(exc) != rb_obj_class(obj)) {
714  ID id_message, id_backtrace;
715  CONST_ID(id_message, "message");
716  CONST_ID(id_backtrace, "backtrace");
717 
718  mesg = rb_check_funcall(obj, id_message, 0, 0);
719  if (mesg == Qundef) return Qfalse;
720  backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
721  if (backtrace == Qundef) return Qfalse;
722  }
723  else {
724  mesg = rb_attr_get(obj, id_mesg);
725  backtrace = exc_backtrace(obj);
726  }
727 
728  if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
729  return Qfalse;
730  if (!rb_equal(exc_backtrace(exc), backtrace))
731  return Qfalse;
732  return Qtrue;
733 }
734 
735 /*
736  * call-seq:
737  * SystemExit.new(status=0) -> system_exit
738  *
739  * Create a new +SystemExit+ exception with the given status.
740  */
741 
742 static VALUE
744 {
745  VALUE status = INT2FIX(EXIT_SUCCESS);
746  if (argc > 0 && FIXNUM_P(argv[0])) {
747  status = *argv++;
748  --argc;
749  }
750  rb_call_super(argc, argv);
751  rb_iv_set(exc, "status", status);
752  return exc;
753 }
754 
755 
756 /*
757  * call-seq:
758  * system_exit.status -> fixnum
759  *
760  * Return the status value associated with this system exit.
761  */
762 
763 static VALUE
765 {
766  return rb_attr_get(exc, rb_intern("status"));
767 }
768 
769 
770 /*
771  * call-seq:
772  * system_exit.success? -> true or false
773  *
774  * Returns +true+ if exiting successful, +false+ if not.
775  */
776 
777 static VALUE
779 {
780  VALUE status_val = rb_attr_get(exc, rb_intern("status"));
781  int status;
782 
783  if (NIL_P(status_val))
784  return Qtrue;
785  status = NUM2INT(status_val);
786  if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
787  return Qtrue;
788 
789  return Qfalse;
790 }
791 
792 void
793 rb_name_error(ID id, const char *fmt, ...)
794 {
795  VALUE exc, argv[2];
796  va_list args;
797 
798  va_start(args, fmt);
799  argv[0] = rb_vsprintf(fmt, args);
800  va_end(args);
801 
802  argv[1] = ID2SYM(id);
803  exc = rb_class_new_instance(2, argv, rb_eNameError);
804  rb_exc_raise(exc);
805 }
806 
807 /*
808  * call-seq:
809  * NameError.new(msg [, name]) -> name_error
810  *
811  * Construct a new NameError exception. If given the <i>name</i>
812  * parameter may subsequently be examined using the <code>NameError.name</code>
813  * method.
814  */
815 
816 static VALUE
818 {
819  VALUE name;
820 
821  name = (argc > 1) ? argv[--argc] : Qnil;
822  rb_call_super(argc, argv);
823  rb_iv_set(self, "name", name);
824  return self;
825 }
826 
827 /*
828  * call-seq:
829  * name_error.name -> string or nil
830  *
831  * Return the name associated with this NameError exception.
832  */
833 
834 static VALUE
836 {
837  return rb_attr_get(self, rb_intern("name"));
838 }
839 
840 /*
841  * call-seq:
842  * name_error.to_s -> string
843  *
844  * Produce a nicely-formatted string representing the +NameError+.
845  */
846 
847 static VALUE
849 {
850  VALUE mesg = rb_attr_get(exc, rb_intern("mesg"));
851  VALUE str = mesg;
852 
853  if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
854  StringValue(str);
855  return str;
856 }
857 
858 /*
859  * call-seq:
860  * NoMethodError.new(msg, name [, args]) -> no_method_error
861  *
862  * Construct a NoMethodError exception for a method of the given name
863  * called with the given arguments. The name may be accessed using
864  * the <code>#name</code> method on the resulting object, and the
865  * arguments using the <code>#args</code> method.
866  */
867 
868 static VALUE
870 {
871  VALUE args = (argc > 2) ? argv[--argc] : Qnil;
872  name_err_initialize(argc, argv, self);
873  rb_iv_set(self, "args", args);
874  return self;
875 }
876 
877 /* :nodoc: */
878 #define NAME_ERR_MESG_COUNT 3
879 
880 static void
882 {
883  VALUE *ptr = p;
885 }
886 
887 #define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
888 
889 static size_t
891 {
892  return p ? (NAME_ERR_MESG_COUNT * sizeof(VALUE)) : 0;
893 }
894 
896  "name_err_mesg",
897  {
901  },
902 };
903 
904 /* :nodoc: */
905 VALUE
906 rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
907 {
909  VALUE result;
910 
911  ptr[0] = mesg;
912  ptr[1] = recv;
913  ptr[2] = method;
914  result = TypedData_Wrap_Struct(rb_cNameErrorMesg, &name_err_mesg_data_type, ptr);
915  RB_GC_GUARD(mesg);
916  RB_GC_GUARD(recv);
917  RB_GC_GUARD(method);
918  return result;
919 }
920 
921 /* :nodoc: */
922 static VALUE
924 {
925  VALUE *ptr1, *ptr2;
926  int i;
927 
928  if (obj1 == obj2) return Qtrue;
929  if (rb_obj_class(obj2) != rb_cNameErrorMesg)
930  return Qfalse;
931 
932  TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
933  TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
934  for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
935  if (!rb_equal(ptr1[i], ptr2[i]))
936  return Qfalse;
937  }
938  return Qtrue;
939 }
940 
941 /* :nodoc: */
942 static VALUE
944 {
945  VALUE *ptr, mesg;
946  TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
947 
948  mesg = ptr[0];
949  if (NIL_P(mesg)) return Qnil;
950  else {
951  const char *desc = 0;
953  int state = 0;
954 
955  obj = ptr[1];
956  switch (TYPE(obj)) {
957  case T_NIL:
958  desc = "nil";
959  break;
960  case T_TRUE:
961  desc = "true";
962  break;
963  case T_FALSE:
964  desc = "false";
965  break;
966  default:
967  d = rb_protect(rb_inspect, obj, &state);
968  if (state)
970  if (NIL_P(d) || RSTRING_LEN(d) > 65) {
971  d = rb_any_to_s(obj);
972  }
973  desc = RSTRING_PTR(d);
974  break;
975  }
976  if (desc && desc[0] != '#') {
977  d = d ? rb_str_dup(d) : rb_str_new2(desc);
978  rb_str_cat2(d, ":");
979  rb_str_cat2(d, rb_obj_classname(obj));
980  }
981  args[0] = mesg;
982  args[1] = ptr[2];
983  args[2] = d;
985  }
986  return mesg;
987 }
988 
989 /* :nodoc: */
990 static VALUE
992 {
993  return str;
994 }
995 
996 /*
997  * call-seq:
998  * no_method_error.args -> obj
999  *
1000  * Return the arguments passed in as the third parameter to
1001  * the constructor.
1002  */
1003 
1004 static VALUE
1006 {
1007  return rb_attr_get(self, rb_intern("args"));
1008 }
1009 
1010 void
1011 rb_invalid_str(const char *str, const char *type)
1012 {
1013  volatile VALUE s = rb_str_inspect(rb_str_new2(str));
1014 
1015  rb_raise(rb_eArgError, "invalid value for %s: %s", type, RSTRING_PTR(s));
1016 }
1017 
1018 /*
1019  * Document-module: Errno
1020  *
1021  * Ruby exception objects are subclasses of <code>Exception</code>.
1022  * However, operating systems typically report errors using plain
1023  * integers. Module <code>Errno</code> is created dynamically to map
1024  * these operating system errors to Ruby classes, with each error
1025  * number generating its own subclass of <code>SystemCallError</code>.
1026  * As the subclass is created in module <code>Errno</code>, its name
1027  * will start <code>Errno::</code>.
1028  *
1029  * The names of the <code>Errno::</code> classes depend on
1030  * the environment in which Ruby runs. On a typical Unix or Windows
1031  * platform, there are <code>Errno</code> classes such as
1032  * <code>Errno::EACCES</code>, <code>Errno::EAGAIN</code>,
1033  * <code>Errno::EINTR</code>, and so on.
1034  *
1035  * The integer operating system error number corresponding to a
1036  * particular error is available as the class constant
1037  * <code>Errno::</code><em>error</em><code>::Errno</code>.
1038  *
1039  * Errno::EACCES::Errno #=> 13
1040  * Errno::EAGAIN::Errno #=> 11
1041  * Errno::EINTR::Errno #=> 4
1042  *
1043  * The full list of operating system errors on your particular platform
1044  * are available as the constants of <code>Errno</code>.
1045  *
1046  * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
1047  */
1048 
1050 
1051 static VALUE
1052 set_syserr(int n, const char *name)
1053 {
1054  st_data_t error;
1055 
1056  if (!st_lookup(syserr_tbl, n, &error)) {
1058  rb_define_const(error, "Errno", INT2NUM(n));
1059  st_add_direct(syserr_tbl, n, error);
1060  }
1061  else {
1062  rb_define_const(rb_mErrno, name, error);
1063  }
1064  return error;
1065 }
1066 
1067 static VALUE
1069 {
1070  st_data_t error;
1071 
1072  if (!st_lookup(syserr_tbl, n, &error)) {
1073  char name[8]; /* some Windows' errno have 5 digits. */
1074 
1075  snprintf(name, sizeof(name), "E%03d", n);
1076  error = set_syserr(n, name);
1077  }
1078  return error;
1079 }
1080 
1081 /*
1082  * call-seq:
1083  * SystemCallError.new(msg, errno) -> system_call_error_subclass
1084  *
1085  * If _errno_ corresponds to a known system error code, constructs
1086  * the appropriate <code>Errno</code> class for that error, otherwise
1087  * constructs a generic <code>SystemCallError</code> object. The
1088  * error number is subsequently available via the <code>errno</code>
1089  * method.
1090  */
1091 
1092 static VALUE
1094 {
1095 #if !defined(_WIN32)
1096  char *strerror();
1097 #endif
1098  const char *err;
1099  VALUE mesg, error;
1100  VALUE klass = rb_obj_class(self);
1101 
1102  if (klass == rb_eSystemCallError) {
1103  st_data_t data = (st_data_t)klass;
1104  rb_scan_args(argc, argv, "11", &mesg, &error);
1105  if (argc == 1 && FIXNUM_P(mesg)) {
1106  error = mesg; mesg = Qnil;
1107  }
1108  if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
1109  klass = (VALUE)data;
1110  /* change class */
1111  if (TYPE(self) != T_OBJECT) { /* insurance to avoid type crash */
1112  rb_raise(rb_eTypeError, "invalid instance type");
1113  }
1114  RBASIC(self)->klass = klass;
1115  }
1116  }
1117  else {
1118  rb_scan_args(argc, argv, "01", &mesg);
1119  error = rb_const_get(klass, rb_intern("Errno"));
1120  }
1121  if (!NIL_P(error)) err = strerror(NUM2INT(error));
1122  else err = "unknown error";
1123  if (!NIL_P(mesg)) {
1125  VALUE str = StringValue(mesg);
1126  rb_encoding *me = rb_enc_get(mesg);
1127 
1128  mesg = rb_sprintf("%s - %.*s", err,
1129  (int)RSTRING_LEN(str), RSTRING_PTR(str));
1130  if (le != me && rb_enc_asciicompat(me)) {
1131  le = me;
1132  }/* else assume err is non ASCII string. */
1133  OBJ_INFECT(mesg, str);
1134  rb_enc_associate(mesg, le);
1135  }
1136  else {
1137  mesg = rb_str_new2(err);
1139  }
1140  rb_call_super(1, &mesg);
1141  rb_iv_set(self, "errno", error);
1142  return self;
1143 }
1144 
1145 /*
1146  * call-seq:
1147  * system_call_error.errno -> fixnum
1148  *
1149  * Return this SystemCallError's error number.
1150  */
1151 
1152 static VALUE
1154 {
1155  return rb_attr_get(self, rb_intern("errno"));
1156 }
1157 
1158 /*
1159  * call-seq:
1160  * system_call_error === other -> true or false
1161  *
1162  * Return +true+ if the receiver is a generic +SystemCallError+, or
1163  * if the error numbers +self+ and _other_ are the same.
1164  */
1165 
1166 static VALUE
1168 {
1169  VALUE num, e;
1170  ID en;
1171 
1172  CONST_ID(en, "errno");
1173 
1175  if (!rb_respond_to(exc, en)) return Qfalse;
1176  }
1177  else if (self == rb_eSystemCallError) return Qtrue;
1178 
1179  num = rb_attr_get(exc, rb_intern("errno"));
1180  if (NIL_P(num)) {
1181  num = rb_funcall(exc, en, 0, 0);
1182  }
1183  e = rb_const_get(self, rb_intern("Errno"));
1184  if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
1185  return Qtrue;
1186  return Qfalse;
1187 }
1188 
1189 
1190 /*
1191  * Document-class: StandardError
1192  *
1193  * The most standard error types are subclasses of StandardError. A
1194  * rescue clause without an explicit Exception class will rescue all
1195  * StandardErrors (and only those).
1196  *
1197  * def foo
1198  * raise "Oups"
1199  * end
1200  * foo rescue "Hello" #=> "Hello"
1201  *
1202  * On the other hand:
1203  *
1204  * require 'does/not/exist' rescue "Hi"
1205  *
1206  * <em>raises the exception:</em>
1207  *
1208  * LoadError: no such file to load -- does/not/exist
1209  *
1210  */
1211 
1212 /*
1213  * Document-class: SystemExit
1214  *
1215  * Raised by +exit+ to initiate the termination of the script.
1216  */
1217 
1218 /*
1219  * Document-class: SignalException
1220  *
1221  * Raised when a signal is received.
1222  *
1223  * begin
1224  * Process.kill('HUP',Process.pid)
1225  * rescue SignalException => e
1226  * puts "received Exception #{e}"
1227  * end
1228  *
1229  * <em>produces:</em>
1230  *
1231  * received Exception SIGHUP
1232  */
1233 
1234 /*
1235  * Document-class: Interrupt
1236  *
1237  * Raised with the interrupt signal is received, typically because the
1238  * user pressed on Control-C (on most posix platforms). As such, it is a
1239  * subclass of +SignalException+.
1240  *
1241  * begin
1242  * puts "Press ctrl-C when you get bored"
1243  * loop {}
1244  * rescue Interrupt => e
1245  * puts "Note: You will typically use Signal.trap instead."
1246  * end
1247  *
1248  * <em>produces:</em>
1249  *
1250  * Press ctrl-C when you get bored
1251  *
1252  * <em>then waits until it is interrupted with Control-C and then prints:</em>
1253  *
1254  * Note: You will typically use Signal.trap instead.
1255  */
1256 
1257 /*
1258  * Document-class: TypeError
1259  *
1260  * Raised when encountering an object that is not of the expected type.
1261  *
1262  * [1, 2, 3].first("two")
1263  *
1264  * <em>raises the exception:</em>
1265  *
1266  * TypeError: can't convert String into Integer
1267  *
1268  */
1269 
1270 /*
1271  * Document-class: ArgumentError
1272  *
1273  * Raised when the arguments are wrong and there isn't a more specific
1274  * Exception class.
1275  *
1276  * Ex: passing the wrong number of arguments
1277  *
1278  * [1, 2, 3].first(4, 5)
1279  *
1280  * <em>raises the exception:</em>
1281  *
1282  * ArgumentError: wrong number of arguments (2 for 1)
1283  *
1284  * Ex: passing an argument that is not acceptable:
1285  *
1286  * [1, 2, 3].first(-4)
1287  *
1288  * <em>raises the exception:</em>
1289  *
1290  * ArgumentError: negative array size
1291  */
1292 
1293 /*
1294  * Document-class: IndexError
1295  *
1296  * Raised when the given index is invalid.
1297  *
1298  * a = [:foo, :bar]
1299  * a.fetch(0) #=> :foo
1300  * a[4] #=> nil
1301  * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
1302  *
1303  */
1304 
1305 /*
1306  * Document-class: KeyError
1307  *
1308  * Raised when the specified key is not found. It is a subclass of
1309  * IndexError.
1310  *
1311  * h = {"foo" => :bar}
1312  * h.fetch("foo") #=> :bar
1313  * h.fetch("baz") #=> KeyError: key not found: "baz"
1314  *
1315  */
1316 
1317 /*
1318  * Document-class: RangeError
1319  *
1320  * Raised when a given numerical value is out of range.
1321  *
1322  * [1, 2, 3].drop(1 << 100)
1323  *
1324  * <em>raises the exception:</em>
1325  *
1326  * RangeError: bignum too big to convert into `long'
1327  */
1328 
1329 /*
1330  * Document-class: ScriptError
1331  *
1332  * ScriptError is the superclass for errors raised when a script
1333  * can not be executed because of a +LoadError+,
1334  * +NotImplementedError+ or a +SyntaxError+. Note these type of
1335  * +ScriptErrors+ are not +StandardError+ and will not be
1336  * rescued unless it is specified explicitly (or its ancestor
1337  * +Exception+).
1338  */
1339 
1340 /*
1341  * Document-class: SyntaxError
1342  *
1343  * Raised when encountering Ruby code with an invalid syntax.
1344  *
1345  * eval("1+1=2")
1346  *
1347  * <em>raises the exception:</em>
1348  *
1349  * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
1350  */
1351 
1352 /*
1353  * Document-class: LoadError
1354  *
1355  * Raised when a file required (a Ruby script, extension library, ...)
1356  * fails to load.
1357  *
1358  * require 'this/file/does/not/exist'
1359  *
1360  * <em>raises the exception:</em>
1361  *
1362  * LoadError: no such file to load -- this/file/does/not/exist
1363  */
1364 
1365 /*
1366  * Document-class: NotImplementedError
1367  *
1368  * Raised when a feature is not implemented on the current platform. For
1369  * example, methods depending on the +fsync+ or +fork+ system calls may
1370  * raise this exception if the underlying operating system or Ruby
1371  * runtime does not support them.
1372  *
1373  * Note that if +fork+ raises a +NotImplementedError+, then
1374  * <code>respond_to?(:fork)</code> returns +false+.
1375  */
1376 
1377 /*
1378  * Document-class: NameError
1379  *
1380  * Raised when a given name is invalid or undefined.
1381  *
1382  * puts foo
1383  *
1384  * <em>raises the exception:</em>
1385  *
1386  * NameError: undefined local variable or method `foo' for main:Object
1387  *
1388  * Since constant names must start with a capital:
1389  *
1390  * Fixnum.const_set :answer, 42
1391  *
1392  * <em>raises the exception:</em>
1393  *
1394  * NameError: wrong constant name answer
1395  */
1396 
1397 /*
1398  * Document-class: NoMethodError
1399  *
1400  * Raised when a method is called on a receiver which doesn't have it
1401  * defined and also fails to respond with +method_missing+.
1402  *
1403  * "hello".to_ary
1404  *
1405  * <em>raises the exception:</em>
1406  *
1407  * NoMethodError: undefined method `to_ary' for "hello":String
1408  */
1409 
1410 /*
1411  * Document-class: RuntimeError
1412  *
1413  * A generic error class raised when an invalid operation is attempted.
1414  *
1415  * [1, 2, 3].freeze << 4
1416  *
1417  * <em>raises the exception:</em>
1418  *
1419  * RuntimeError: can't modify frozen array
1420  *
1421  * Kernel.raise will raise a RuntimeError if no Exception class is
1422  * specified.
1423  *
1424  * raise "ouch"
1425  *
1426  * <em>raises the exception:</em>
1427  *
1428  * RuntimeError: ouch
1429  */
1430 
1431 /*
1432  * Document-class: SecurityError
1433  *
1434  * Raised when attempting a potential unsafe operation, typically when
1435  * the $SAFE level is raised above 0.
1436  *
1437  * foo = "bar"
1438  * proc = Proc.new do
1439  * $SAFE = 4
1440  * foo.gsub! "a", "*"
1441  * end
1442  * proc.call
1443  *
1444  * <em>raises the exception:</em>
1445  *
1446  * SecurityError: Insecure: can't modify string
1447  */
1448 
1449 /*
1450  * Document-class: NoMemoryError
1451  *
1452  * Raised when memory allocation fails.
1453  */
1454 
1455 /*
1456  * Document-class: SystemCallError
1457  *
1458  * SystemCallError is the base class for all low-level
1459  * platform-dependent errors.
1460  *
1461  * The errors available on the current platform are subclasses of
1462  * SystemCallError and are defined in the Errno module.
1463  *
1464  * File.open("does/not/exist")
1465  *
1466  * <em>raises the exception:</em>
1467  *
1468  * Errno::ENOENT: No such file or directory - does/not/exist
1469  */
1470 
1471 /*
1472  * Document-class: EncodingError
1473  *
1474  * EncodingError is the base class for encoding errors.
1475  */
1476 
1477 /*
1478  * Document-class: Encoding::CompatibilityError
1479  *
1480  * Raised by Encoding and String methods when the source encoding is
1481  * incompatible with the target encoding.
1482  */
1483 
1484 /*
1485  * Document-class: fatal
1486  *
1487  * fatal is an Exception that is raised when ruby has encountered a fatal
1488  * error and must exit. You are not able to rescue fatal.
1489  */
1490 
1491 /*
1492  * Document-class: NameError::message
1493  * :nodoc:
1494  */
1495 
1496 /*
1497  * Descendants of class <code>Exception</code> are used to communicate
1498  * between <code>raise</code> methods and <code>rescue</code>
1499  * statements in <code>begin/end</code> blocks. <code>Exception</code>
1500  * objects carry information about the exception---its type (the
1501  * exception's class name), an optional descriptive string, and
1502  * optional traceback information. Programs may subclass
1503  * <code>Exception</code>, or more typically <code>StandardError</code>
1504  * to provide custom classes and add additional information.
1505  */
1506 
1507 void
1509 {
1510  rb_eException = rb_define_class("Exception", rb_cObject);
1512  rb_define_method(rb_eException, "exception", exc_exception, -1);
1513  rb_define_method(rb_eException, "initialize", exc_initialize, -1);
1516  rb_define_method(rb_eException, "message", exc_message, 0);
1517  rb_define_method(rb_eException, "inspect", exc_inspect, 0);
1518  rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
1519  rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
1520 
1521  rb_eSystemExit = rb_define_class("SystemExit", rb_eException);
1522  rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
1525 
1527  rb_eSignal = rb_define_class("SignalException", rb_eException);
1528  rb_eInterrupt = rb_define_class("Interrupt", rb_eSignal);
1529 
1530  rb_eStandardError = rb_define_class("StandardError", rb_eException);
1532  rb_eArgError = rb_define_class("ArgumentError", rb_eStandardError);
1536 
1537  rb_eScriptError = rb_define_class("ScriptError", rb_eException);
1540  rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
1541 
1552  rb_eNoMethodError = rb_define_class("NoMethodError", rb_eNameError);
1555 
1557  rb_eSecurityError = rb_define_class("SecurityError", rb_eException);
1558  rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
1561 
1562  syserr_tbl = st_init_numtable();
1567 
1568  rb_mErrno = rb_define_module("Errno");
1569 
1571 }
1572 
1573 void
1574 rb_raise(VALUE exc, const char *fmt, ...)
1575 {
1576  va_list args;
1577  VALUE mesg;
1578 
1579  va_start(args, fmt);
1580  mesg = rb_vsprintf(fmt, args);
1581  va_end(args);
1582  rb_exc_raise(rb_exc_new3(exc, mesg));
1583 }
1584 
1585 void
1586 rb_loaderror(const char *fmt, ...)
1587 {
1588  va_list args;
1589  VALUE mesg;
1590 
1591  va_start(args, fmt);
1592  mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
1593  va_end(args);
1595 }
1596 
1597 void
1599 {
1601  "%s() function is unimplemented on this machine",
1603 }
1604 
1605 void
1606 rb_fatal(const char *fmt, ...)
1607 {
1608  va_list args;
1609  VALUE mesg;
1610 
1611  va_start(args, fmt);
1612  mesg = rb_vsprintf(fmt, args);
1613  va_end(args);
1614 
1616 }
1617 
1618 static VALUE
1619 make_errno_exc(const char *mesg)
1620 {
1621  int n = errno;
1622 
1623  errno = 0;
1624  if (n == 0) {
1625  rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
1626  }
1627  return rb_syserr_new(n, mesg);
1628 }
1629 
1630 static VALUE
1632 {
1633  int n = errno;
1634 
1635  errno = 0;
1636  if (!mesg) mesg = Qnil;
1637  if (n == 0) {
1638  const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
1639  rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
1640  }
1641  return rb_syserr_new_str(n, mesg);
1642 }
1643 
1644 VALUE
1645 rb_syserr_new(int n, const char *mesg)
1646 {
1647  VALUE arg;
1648  arg = mesg ? rb_str_new2(mesg) : Qnil;
1649  return rb_syserr_new_str(n, arg);
1650 }
1651 
1652 VALUE
1654 {
1655  return rb_class_new_instance(1, &arg, get_syserr(n));
1656 }
1657 
1658 void
1659 rb_syserr_fail(int e, const char *mesg)
1660 {
1661  rb_exc_raise(rb_syserr_new(e, mesg));
1662 }
1663 
1664 void
1666 {
1667  rb_exc_raise(rb_syserr_new_str(e, mesg));
1668 }
1669 
1670 void
1671 rb_sys_fail(const char *mesg)
1672 {
1674 }
1675 
1676 void
1678 {
1680 }
1681 
1682 void
1683 rb_mod_sys_fail(VALUE mod, const char *mesg)
1684 {
1685  VALUE exc = make_errno_exc(mesg);
1686  rb_extend_object(exc, mod);
1687  rb_exc_raise(exc);
1688 }
1689 
1690 void
1692 {
1693  VALUE exc = make_errno_exc_str(mesg);
1694  rb_extend_object(exc, mod);
1695  rb_exc_raise(exc);
1696 }
1697 
1698 void
1699 rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
1700 {
1701  VALUE exc = rb_syserr_new(e, mesg);
1702  rb_extend_object(exc, mod);
1703  rb_exc_raise(exc);
1704 }
1705 
1706 void
1708 {
1709  VALUE exc = rb_syserr_new_str(e, mesg);
1710  rb_extend_object(exc, mod);
1711  rb_exc_raise(exc);
1712 }
1713 
1714 void
1715 rb_sys_warning(const char *fmt, ...)
1716 {
1717  char buf[BUFSIZ];
1718  va_list args;
1719  int errno_save;
1720 
1721  errno_save = errno;
1722 
1723  if (!RTEST(ruby_verbose)) return;
1724 
1725  snprintf(buf, BUFSIZ, "warning: %s", fmt);
1726  snprintf(buf+strlen(buf), BUFSIZ-strlen(buf), ": %s", strerror(errno_save));
1727 
1728  va_start(args, fmt);
1729  warn_print(buf, args);
1730  va_end(args);
1731  errno = errno_save;
1732 }
1733 
1734 void
1735 rb_load_fail(const char *path)
1736 {
1737  rb_loaderror("%s -- %s", strerror(errno), path);
1738 }
1739 
1740 void
1741 rb_error_frozen(const char *what)
1742 {
1743  rb_raise(rb_eRuntimeError, "can't modify frozen %s", what);
1744 }
1745 
1746 #undef rb_check_frozen
1747 void
1749 {
1751 }
1752 
1753 void
1755 {
1756  rb_eNOERROR = set_syserr(0, "NOERROR");
1757 #define defined_error(name, num) set_syserr((num), (name));
1758 #define undefined_error(name) set_syserr(0, (name));
1759 #include "known_errors.inc"
1760 #undef defined_error
1761 #undef undefined_error
1762 }
1763 
1764 static void
1765 err_append(const char *s, rb_encoding *enc)
1766 {
1767  rb_thread_t *th = GET_THREAD();
1768  VALUE err = th->errinfo;
1769 
1770  if (th->mild_compile_error) {
1771  if (!RTEST(err)) {
1773  rb_enc_str_new(s, strlen(s), enc));
1774  th->errinfo = err;
1775  }
1776  else {
1777  VALUE str = rb_obj_as_string(err);
1778 
1779  rb_str_cat2(str, "\n");
1780  rb_str_cat2(str, s);
1781  th->errinfo = rb_exc_new3(rb_eSyntaxError, str);
1782  }
1783  }
1784  else {
1785  if (!RTEST(err)) {
1786  err = rb_exc_new2(rb_eSyntaxError, "compile error");
1787  th->errinfo = err;
1788  }
1789  rb_write_error(s);
1790  rb_write_error("\n");
1791  }
1792 }
1793