Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
error.c
Go to the documentation of this file.
1/**********************************************************************
2
3 error.c -
4
5 $Author$
6 created at: Mon Aug 9 16:11:34 JST 1993
7
8 Copyright (C) 1993-2007 Yukihiro Matsumoto
9
10**********************************************************************/
11
13
14#include <errno.h>
15#include <stdarg.h>
16#include <stdio.h>
17
18#ifdef HAVE_STDLIB_H
19# include <stdlib.h>
20#endif
21
22#ifdef HAVE_UNISTD_H
23# include <unistd.h>
24#endif
25
26#if defined __APPLE__
27# include <AvailabilityMacros.h>
28#endif
29
30#include "internal.h"
31#include "internal/error.h"
32#include "internal/eval.h"
33#include "internal/io.h"
34#include "internal/load.h"
35#include "internal/object.h"
36#include "internal/symbol.h"
37#include "internal/thread.h"
38#include "internal/variable.h"
39#include "ruby/encoding.h"
40#include "ruby/st.h"
41#include "ruby_assert.h"
42#include "vm_core.h"
43
44#include "builtin.h"
45
51#ifndef EXIT_SUCCESS
52#define EXIT_SUCCESS 0
53#endif
54
55#ifndef WIFEXITED
56#define WIFEXITED(status) 1
57#endif
58
59#ifndef WEXITSTATUS
60#define WEXITSTATUS(status) (status)
61#endif
62
67
72static VALUE rb_mWarning;
73static VALUE rb_cWarningBuffer;
74
75static ID id_warn;
76static ID id_category;
77static ID id_deprecated;
78static ID id_experimental;
79static VALUE sym_category;
80static VALUE warning_categories;
81static VALUE warning_category_t_map;
82
83extern const char ruby_description[];
84
85static const char *
86rb_strerrno(int err)
87{
88#define defined_error(name, num) if (err == (num)) return (name);
89#define undefined_error(name)
90#include "known_errors.inc"
91#undef defined_error
92#undef undefined_error
93 return NULL;
94}
95
96static int
97err_position_0(char *buf, long len, const char *file, int line)
98{
99 if (!file) {
100 return 0;
101 }
102 else if (line == 0) {
103 return snprintf(buf, len, "%s: ", file);
104 }
105 else {
106 return snprintf(buf, len, "%s:%d: ", file, line);
107 }
108}
109
110static VALUE
111err_vcatf(VALUE str, const char *pre, const char *file, int line,
112 const char *fmt, va_list args)
113{
114 if (file) {
116 if (line) rb_str_catf(str, ":%d", line);
117 rb_str_cat2(str, ": ");
118 }
119 if (pre) rb_str_cat2(str, pre);
120 rb_str_vcatf(str, fmt, args);
121 return str;
122}
123
124VALUE
125rb_syntax_error_append(VALUE exc, VALUE file, int line, int column,
126 rb_encoding *enc, const char *fmt, va_list args)
127{
128 const char *fn = NIL_P(file) ? NULL : RSTRING_PTR(file);
129 if (!exc) {
130 VALUE mesg = rb_enc_str_new(0, 0, enc);
131 err_vcatf(mesg, NULL, fn, line, fmt, args);
132 rb_str_cat2(mesg, "\n");
133 rb_write_error_str(mesg);
134 }
135 else {
136 VALUE mesg;
137 if (NIL_P(exc)) {
138 mesg = rb_enc_str_new(0, 0, enc);
139 exc = rb_class_new_instance(1, &mesg, rb_eSyntaxError);
140 }
141 else {
142 mesg = rb_attr_get(exc, idMesg);
143 if (RSTRING_LEN(mesg) > 0 && *(RSTRING_END(mesg)-1) != '\n')
144 rb_str_cat_cstr(mesg, "\n");
145 }
146 err_vcatf(mesg, NULL, fn, line, fmt, args);
147 }
148
149 return exc;
150}
151
152static unsigned int warning_disabled_categories = (
154 0);
155
156static unsigned int
157rb_warning_category_mask(VALUE category)
158{
159 return 1U << rb_warning_category_from_name(category);
160}
161
164{
165 VALUE cat_value;
166 Check_Type(category, T_SYMBOL);
167 cat_value = rb_hash_aref(warning_categories, category);
168 if (cat_value == Qnil) {
169 rb_raise(rb_eArgError, "unknown category: %"PRIsVALUE, category);
170 }
171 return NUM2INT(cat_value);
172}
173
174void
175rb_warning_category_update(unsigned int mask, unsigned int bits)
176{
177 warning_disabled_categories &= ~mask;
178 warning_disabled_categories |= mask & ~bits;
179}
180
183{
184 return !(warning_disabled_categories & (1U << category));
185}
186
187/*
188 * call-seq:
189 * Warning[category] -> true or false
190 *
191 * Returns the flag to show the warning messages for +category+.
192 * Supported categories are:
193 *
194 * +:deprecated+ :: deprecation warnings
195 * * assignment of non-nil value to <code>$,</code> and <code>$;</code>
196 * * keyword arguments
197 * * proc/lambda without block
198 * etc.
199 *
200 * +:experimental+ :: experimental features
201 * * Pattern matching
202 */
203
204static VALUE
205rb_warning_s_aref(VALUE mod, VALUE category)
206{
209 return Qtrue;
210 return Qfalse;
211}
212
213/*
214 * call-seq:
215 * Warning[category] = flag -> flag
216 *
217 * Sets the warning flags for +category+.
218 * See Warning.[] for the categories.
219 */
220
221static VALUE
222rb_warning_s_aset(VALUE mod, VALUE category, VALUE flag)
223{
224 unsigned int mask = rb_warning_category_mask(category);
225 unsigned int disabled = warning_disabled_categories;
226 if (!RTEST(flag))
227 disabled |= mask;
228 else
229 disabled &= ~mask;
230 warning_disabled_categories = disabled;
231 return flag;
232}
233
234/*
235 * call-seq:
236 * warn(msg, category: nil) -> nil
237 *
238 * Writes warning message +msg+ to $stderr. This method is called by
239 * Ruby for all emitted warnings. A +category+ may be included with
240 * the warning.
241 *
242 * See the documentation of the Warning module for how to customize this.
243 */
244
245static VALUE
246rb_warning_s_warn(int argc, VALUE *argv, VALUE mod)
247{
248 VALUE str;
249 VALUE opt;
250 VALUE category = Qnil;
251
252 rb_scan_args(argc, argv, "1:", &str, &opt);
253 if (!NIL_P(opt)) rb_get_kwargs(opt, &id_category, 0, 1, &category);
254
255 Check_Type(str, T_STRING);
257 if (!NIL_P(category)) {
259 if (!rb_warning_category_enabled_p(cat)) return Qnil;
260 }
262 return Qnil;
263}
264
265/*
266 * Document-module: Warning
267 *
268 * The Warning module contains a single method named #warn, and the
269 * module extends itself, making Warning.warn available.
270 * Warning.warn is called for all warnings issued by Ruby.
271 * By default, warnings are printed to $stderr.
272 *
273 * Changing the behavior of Warning.warn is useful to customize how warnings are
274 * handled by Ruby, for instance by filtering some warnings, and/or outputting
275 * warnings somewhere other than $stderr.
276 *
277 * If you want to change the behavior of Warning.warn you should use
278 * +Warning.extend(MyNewModuleWithWarnMethod)+ and you can use `super`
279 * to get the default behavior of printing the warning to $stderr.
280 *
281 * Example:
282 * module MyWarningFilter
283 * def warn(message, category: nil, **kwargs)
284 * if /some warning I want to ignore/.matches?(message)
285 * # ignore
286 * else
287 * super
288 * end
289 * end
290 * end
291 * Warning.extend MyWarningFilter
292 *
293 * You should never redefine Warning#warn (the instance method), as that will
294 * then no longer provide a way to use the default behavior.
295 *
296 * The +warning+ gem provides convenient ways to customize Warning.warn.
297 */
298
299static VALUE
300rb_warning_warn(VALUE mod, VALUE str)
301{
302 return rb_funcallv(mod, id_warn, 1, &str);
303}
304
305
306static int
307rb_warning_warn_arity(void)
308{
309 const rb_method_entry_t *me = rb_method_entry(rb_singleton_class(rb_mWarning), id_warn);
310 return me ? rb_method_entry_arity(me) : 1;
311}
312
313static VALUE
314rb_warn_category(VALUE str, VALUE category)
315{
316 if (category != Qnil) {
317 category = rb_to_symbol_type(category);
318 if (!RTEST(rb_hash_aref(warning_categories, category))) {
319 rb_raise(rb_eArgError, "invalid warning category used: %s", rb_id2name(SYM2ID(category)));
320 }
321 }
322
323 if (rb_warning_warn_arity() == 1) {
324 return rb_warning_warn(rb_mWarning, str);
325 }
326 else {
327 VALUE args[2];
328 args[0] = str;
329 args[1] = rb_hash_new();
330 rb_hash_aset(args[1], sym_category, category);
331 return rb_funcallv_kw(rb_mWarning, id_warn, 2, args, RB_PASS_KEYWORDS);
332 }
333}
334
335static void
336rb_write_warning_str(VALUE str)
337{
338 rb_warning_warn(rb_mWarning, str);
339}
340
341static VALUE
342warn_vsprintf(rb_encoding *enc, const char *file, int line, const char *fmt, va_list args)
343{
344 VALUE str = rb_enc_str_new(0, 0, enc);
345
346 err_vcatf(str, "warning: ", file, line, fmt, args);
347 return rb_str_cat2(str, "\n");
348}
349
350void
351rb_compile_warn(const char *file, int line, const char *fmt, ...)
352{
353 VALUE str;
354 va_list args;
355
356 if (NIL_P(ruby_verbose)) return;
357
358 va_start(args, fmt);
359 str = warn_vsprintf(NULL, file, line, fmt, args);
360 va_end(args);
361 rb_write_warning_str(str);
362}
363
364/* rb_compile_warning() reports only in verbose mode */
365void
366rb_compile_warning(const char *file, int line, const char *fmt, ...)
367{
368 VALUE str;
369 va_list args;
370
371 if (!RTEST(ruby_verbose)) return;
372
373 va_start(args, fmt);
374 str = warn_vsprintf(NULL, file, line, fmt, args);
375 va_end(args);
376 rb_write_warning_str(str);
377}
378
379void
380rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt, ...)
381{
382 VALUE str;
383 va_list args;
384
385 if (NIL_P(ruby_verbose)) return;
386
387 va_start(args, fmt);
388 str = warn_vsprintf(NULL, file, line, fmt, args);
389 va_end(args);
390 rb_warn_category(str, rb_hash_fetch(warning_category_t_map, INT2NUM(category)));
391}
392
393static VALUE
394warning_string(rb_encoding *enc, const char *fmt, va_list args)
395{
396 int line;
397 const char *file = rb_source_location_cstr(&line);
398 return warn_vsprintf(enc, file, line, fmt, args);
399}
400
401#define with_warning_string(mesg, enc, fmt) \
402 VALUE mesg; \
403 va_list args; va_start(args, fmt); \
404 mesg = warning_string(enc, fmt, args); \
405 va_end(args);
406
407void
408rb_warn(const char *fmt, ...)
409{
410 if (!NIL_P(ruby_verbose)) {
411 with_warning_string(mesg, 0, fmt) {
412 rb_write_warning_str(mesg);
413 }
414 }
415}
416
417void
418rb_category_warn(rb_warning_category_t category, const char *fmt, ...)
419{
420 if (!NIL_P(ruby_verbose)) {
421 with_warning_string(mesg, 0, fmt) {
422 rb_warn_category(mesg, rb_hash_fetch(warning_category_t_map, INT2NUM(category)));
423 }
424 }
425}
426
427void
428rb_enc_warn(rb_encoding *enc, const char *fmt, ...)
429{
430 if (!NIL_P(ruby_verbose)) {
431 with_warning_string(mesg, enc, fmt) {
432 rb_write_warning_str(mesg);
433 }
434 }
435}
436
437/* rb_warning() reports only in verbose mode */
438void
439rb_warning(const char *fmt, ...)
440{
441 if (RTEST(ruby_verbose)) {
442 with_warning_string(mesg, 0, fmt) {
443 rb_write_warning_str(mesg);
444 }
445 }
446}
447
448/* rb_category_warning() reports only in verbose mode */
449void
450rb_category_warning(rb_warning_category_t category, const char *fmt, ...)
451{
452 if (RTEST(ruby_verbose)) {
453 with_warning_string(mesg, 0, fmt) {
454 rb_warn_category(mesg, rb_hash_fetch(warning_category_t_map, INT2NUM(category)));
455 }
456 }
457}
458
459VALUE
460rb_warning_string(const char *fmt, ...)
461{
462 with_warning_string(mesg, 0, fmt) {
463 }
464 return mesg;
465}
466
467#if 0
468void
469rb_enc_warning(rb_encoding *enc, const char *fmt, ...)
470{
471 if (RTEST(ruby_verbose)) {
472 with_warning_string(mesg, enc, fmt) {
473 rb_write_warning_str(mesg);
474 }
475 }
476}
477#endif
478
479void
480rb_warn_deprecated(const char *fmt, const char *suggest, ...)
481{
482 if (NIL_P(ruby_verbose)) return;
484 va_list args;
485 va_start(args, suggest);
486 VALUE mesg = warning_string(0, fmt, args);
487 va_end(args);
488 rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1);
489 rb_str_cat_cstr(mesg, " is deprecated");
490 if (suggest) rb_str_catf(mesg, "; use %s instead", suggest);
491 rb_str_cat_cstr(mesg, "\n");
492 rb_warn_category(mesg, ID2SYM(id_deprecated));
493}
494
495void
496rb_warn_deprecated_to_remove(const char *fmt, const char *removal, ...)
497{
498 if (NIL_P(ruby_verbose)) return;
500 va_list args;
501 va_start(args, removal);
502 VALUE mesg = warning_string(0, fmt, args);
503 va_end(args);
504 rb_str_set_len(mesg, RSTRING_LEN(mesg) - 1);
505 rb_str_catf(mesg, " is deprecated and will be removed in Ruby %s\n", removal);
506 rb_warn_category(mesg, ID2SYM(id_deprecated));
507}
508
509static inline int
510end_with_asciichar(VALUE str, int c)
511{
512 return RB_TYPE_P(str, T_STRING) &&
514}
515
516/* :nodoc: */
517static VALUE
518warning_write(int argc, VALUE *argv, VALUE buf)
519{
520 while (argc-- > 0) {
522 }
523 return buf;
524}
525
526VALUE rb_ec_backtrace_location_ary(const rb_execution_context_t *ec, long lev, long n, bool skip_internal);
527
528static VALUE
529rb_warn_m(rb_execution_context_t *ec, VALUE exc, VALUE msgs, VALUE uplevel, VALUE category)
530{
531 VALUE location = Qnil;
532 int argc = RARRAY_LENINT(msgs);
533 const VALUE *argv = RARRAY_CONST_PTR(msgs);
534
535 if (!NIL_P(ruby_verbose) && argc > 0) {
536 VALUE str = argv[0];
537 if (!NIL_P(uplevel)) {
538 long lev = NUM2LONG(uplevel);
539 if (lev < 0) {
540 rb_raise(rb_eArgError, "negative level (%ld)", lev);
541 }
542 location = rb_ec_backtrace_location_ary(ec, lev + 1, 1, TRUE);
543 if (!NIL_P(location)) {
544 location = rb_ary_entry(location, 0);
545 }
546 }
547 if (argc > 1 || !NIL_P(uplevel) || !end_with_asciichar(str, '\n')) {
548 VALUE path;
549 if (NIL_P(uplevel)) {
550 str = rb_str_tmp_new(0);
551 }
552 else if (NIL_P(location) ||
553 NIL_P(path = rb_funcall(location, rb_intern("path"), 0))) {
554 str = rb_str_new_cstr("warning: ");
555 }
556 else {
557 str = rb_sprintf("%s:%ld: warning: ",
558 rb_string_value_ptr(&path),
559 NUM2LONG(rb_funcall(location, rb_intern("lineno"), 0)));
560 }
561 RBASIC_SET_CLASS(str, rb_cWarningBuffer);
563 RBASIC_SET_CLASS(str, rb_cString);
564 }
565
566 if (exc == rb_mWarning) {
569 }
570 else {
571 rb_warn_category(str, category);
572 }
573 }
574 return Qnil;
575}
576
577#define MAX_BUG_REPORTERS 0x100
578
579static struct bug_reporters {
580 void (*func)(FILE *out, void *data);
581 void *data;
582} bug_reporters[MAX_BUG_REPORTERS];
583
584static int bug_reporters_size;
585
586int
587rb_bug_reporter_add(void (*func)(FILE *, void *), void *data)
588{
589 struct bug_reporters *reporter;
590 if (bug_reporters_size >= MAX_BUG_REPORTERS) {
591 return 0; /* failed to register */
592 }
593 reporter = &bug_reporters[bug_reporters_size++];
594 reporter->func = func;
595 reporter->data = data;
596
597 return 1;
598}
599
600/* SIGSEGV handler might have a very small stack. Thus we need to use it carefully. */
601#define REPORT_BUG_BUFSIZ 256
602static FILE *
603bug_report_file(const char *file, int line)
604{
606 FILE *out = stderr;
607 int len = err_position_0(buf, sizeof(buf), file, line);
608
609 if ((ssize_t)fwrite(buf, 1, len, out) == (ssize_t)len ||
610 (ssize_t)fwrite(buf, 1, len, (out = stdout)) == (ssize_t)len) {
611 return out;
612 }
613
614 return NULL;
615}
616
617FUNC_MINIMIZED(static void bug_important_message(FILE *out, const char *const msg, size_t len));
618
619static void
620bug_important_message(FILE *out, const char *const msg, size_t len)
621{
622 const char *const endmsg = msg + len;
623 const char *p = msg;
624
625 if (!len) return;
626 if (isatty(fileno(out))) {
627 static const char red[] = "\033[;31;1;7m";
628 static const char green[] = "\033[;32;7m";
629 static const char reset[] = "\033[m";
630 const char *e = strchr(p, '\n');
631 const int w = (int)(e - p);
632 do {
633 int i = (int)(e - p);
634 fputs(*p == ' ' ? green : red, out);
635 fwrite(p, 1, e - p, out);
636 for (; i < w; ++i) fputc(' ', out);
637 fputs(reset, out);
638 fputc('\n', out);
639 } while ((p = e + 1) < endmsg && (e = strchr(p, '\n')) != 0 && e > p + 1);
640 }
641 fwrite(p, 1, endmsg - p, out);
642}
643
644static void
645preface_dump(FILE *out)
646{
647#if defined __APPLE__
648 static const char msg[] = ""
649 "-- Crash Report log information "
650 "--------------------------------------------\n"
651 " See Crash Report log file under the one of following:\n"
652# if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
653 " * ~/Library/Logs/CrashReporter\n"
654 " * /Library/Logs/CrashReporter\n"
655# endif
656 " * ~/Library/Logs/DiagnosticReports\n"
657 " * /Library/Logs/DiagnosticReports\n"
658 " for more details.\n"
659 "Don't forget to include the above Crash Report log file in bug reports.\n"
660 "\n";
661 const size_t msglen = sizeof(msg) - 1;
662#else
663 const char *msg = NULL;
664 const size_t msglen = 0;
665#endif
666 bug_important_message(out, msg, msglen);
667}
668
669static void
670postscript_dump(FILE *out)
671{
672#if defined __APPLE__
673 static const char msg[] = ""
674 "[IMPORTANT]"
675 /*" ------------------------------------------------"*/
676 "\n""Don't forget to include the Crash Report log file under\n"
677# if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_6
678 "CrashReporter or "
679# endif
680 "DiagnosticReports directory in bug reports.\n"
681 /*"------------------------------------------------------------\n"*/
682 "\n";
683 const size_t msglen = sizeof(msg) - 1;
684#else
685 const char *msg = NULL;
686 const size_t msglen = 0;
687#endif
688 bug_important_message(out, msg, msglen);
689}
690
691static void
692bug_report_begin_valist(FILE *out, const char *fmt, va_list args)
693{
695
696 fputs("[BUG] ", out);
697 vsnprintf(buf, sizeof(buf), fmt, args);
698 fputs(buf, out);
699 snprintf(buf, sizeof(buf), "\n%s\n\n", ruby_description);
700 fputs(buf, out);
701 preface_dump(out);
702}
703
704#define bug_report_begin(out, fmt) do { \
705 va_list args; \
706 va_start(args, fmt); \
707 bug_report_begin_valist(out, fmt, args); \
708 va_end(args); \
709} while (0)
710
711static void
712bug_report_end(FILE *out)
713{
714 /* call additional bug reporters */
715 {
716 int i;
717 for (i=0; i<bug_reporters_size; i++) {
718 struct bug_reporters *reporter = &bug_reporters[i];
719 (*reporter->func)(out, reporter->data);
720 }
721 }
722 postscript_dump(out);
723}
724
725#define report_bug(file, line, fmt, ctx) do { \
726 FILE *out = bug_report_file(file, line); \
727 if (out) { \
728 bug_report_begin(out, fmt); \
729 rb_vm_bugreport(ctx); \
730 bug_report_end(out); \
731 } \
732} while (0) \
733
734#define report_bug_valist(file, line, fmt, ctx, args) do { \
735 FILE *out = bug_report_file(file, line); \
736 if (out) { \
737 bug_report_begin_valist(out, fmt, args); \
738 rb_vm_bugreport(ctx); \
739 bug_report_end(out); \
740 } \
741} while (0) \
742
743NORETURN(static void die(void));
744static void
745die(void)
746{
747#if defined(_WIN32) && defined(RUBY_MSVCRT_VERSION) && RUBY_MSVCRT_VERSION >= 80
748 _set_abort_behavior( 0, _CALL_REPORTFAULT);
749#endif
750
751 abort();
752}
753
754void
755rb_bug_without_die(const char *fmt, va_list args)
756{
757 const char *file = NULL;
758 int line = 0;
759
760 if (GET_EC()) {
762 }
763
764 report_bug_valist(file, line, fmt, NULL, args);
765}
766
767void
768rb_bug(const char *fmt, ...)
769{
770 va_list args;
771 va_start(args, fmt);
772 rb_bug_without_die(fmt, args);
773 va_end(args);
774 die();
775}
776
777void
778rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *ctx, const char *fmt, ...)
779{
780 const char *file = NULL;
781 int line = 0;
782
783 if (GET_EC()) {
785 }
786
787 report_bug(file, line, fmt, ctx);
788
789 if (default_sighandler) default_sighandler(sig);
790
791 die();
792}
793
794
795void
796rb_bug_errno(const char *mesg, int errno_arg)
797{
798 if (errno_arg == 0)
799 rb_bug("%s: errno == 0 (NOERROR)", mesg);
800 else {
801 const char *errno_str = rb_strerrno(errno_arg);
802 if (errno_str)
803 rb_bug("%s: %s (%s)", mesg, strerror(errno_arg), errno_str);
804 else
805 rb_bug("%s: %s (%d)", mesg, strerror(errno_arg), errno_arg);
806 }
807}
808
809/*
810 * this is safe to call inside signal handler and timer thread
811 * (which isn't a Ruby Thread object)
812 */
813#define write_or_abort(fd, str, len) (write((fd), (str), (len)) < 0 ? abort() : (void)0)
814#define WRITE_CONST(fd,str) write_or_abort((fd),(str),sizeof(str) - 1)
815
816void
817rb_async_bug_errno(const char *mesg, int errno_arg)
818{
819 WRITE_CONST(2, "[ASYNC BUG] ");
820 write_or_abort(2, mesg, strlen(mesg));
821 WRITE_CONST(2, "\n");
822
823 if (errno_arg == 0) {
824 WRITE_CONST(2, "errno == 0 (NOERROR)\n");
825 }
826 else {
827 const char *errno_str = rb_strerrno(errno_arg);
828
829 if (!errno_str)
830 errno_str = "undefined errno";
831 write_or_abort(2, errno_str, strlen(errno_str));
832 }
833 WRITE_CONST(2, "\n\n");
835 abort();
836}
837
838void
839rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
840{
841 report_bug_valist(RSTRING_PTR(file), line, fmt, NULL, args);
842}
843
845rb_assert_failure(const char *file, int line, const char *name, const char *expr)
846{
847 FILE *out = stderr;
848 fprintf(out, "Assertion Failed: %s:%d:", file, line);
849 if (name) fprintf(out, "%s:", name);
850 fprintf(out, "%s\n%s\n\n", expr, ruby_description);
851 preface_dump(out);
853 bug_report_end(out);
854 die();
855}
856
857static const char builtin_types[][10] = {
858 "", /* 0x00, */
859 "Object",
860 "Class",
861 "Module",
862 "Float",
863 "String",
864 "Regexp",
865 "Array",
866 "Hash",
867 "Struct",
868 "Integer",
869 "File",
870 "Data", /* internal use: wrapped C pointers */
871 "MatchData", /* data of $~ */
872 "Complex",
873 "Rational",
874 "", /* 0x10 */
875 "nil",
876 "true",
877 "false",
878 "Symbol", /* :symbol */
879 "Integer",
880 "undef", /* internal use: #undef; should not happen */
881 "", /* 0x17 */
882 "", /* 0x18 */
883 "", /* 0x19 */
884 "Memo", /* internal use: general memo */
885 "Node", /* internal use: syntax tree node */
886 "iClass", /* internal use: mixed-in module holder */
887};
888
889const char *
891{
892 const char *name;
893 if ((unsigned int)t >= numberof(builtin_types)) return 0;
894 name = builtin_types[t];
895 if (*name) return name;
896 return 0;
897}
898
899static VALUE
900displaying_class_of(VALUE x)
901{
902 switch (x) {
903 case Qfalse: return rb_fstring_cstr("false");
904 case Qnil: return rb_fstring_cstr("nil");
905 case Qtrue: return rb_fstring_cstr("true");
906 default: return rb_obj_class(x);
907 }
908}
909
910static const char *
911builtin_class_name(VALUE x)
912{
913 const char *etype;
914
915 if (NIL_P(x)) {
916 etype = "nil";
917 }
918 else if (FIXNUM_P(x)) {
919 etype = "Integer";
920 }
921 else if (SYMBOL_P(x)) {
922 etype = "Symbol";
923 }
924 else if (RB_TYPE_P(x, T_TRUE)) {
925 etype = "true";
926 }
927 else if (RB_TYPE_P(x, T_FALSE)) {
928 etype = "false";
929 }
930 else {
931 etype = NULL;
932 }
933 return etype;
934}
935
936const char *
938{
939 const char *etype = builtin_class_name(x);
940
941 if (!etype) {
942 etype = rb_obj_classname(x);
943 }
944 return etype;
945}
946
947NORETURN(static void unexpected_type(VALUE, int, int));
948#define UNDEF_LEAKED "undef leaked to the Ruby space"
949
950static void
951unexpected_type(VALUE x, int xt, int t)
952{
953 const char *tname = rb_builtin_type_name(t);
954 VALUE mesg, exc = rb_eFatal;
955
956 if (tname) {
957 mesg = rb_sprintf("wrong argument type %"PRIsVALUE" (expected %s)",
958 displaying_class_of(x), tname);
959 exc = rb_eTypeError;
960 }
961 else if (xt > T_MASK && xt <= 0x3f) {
962 mesg = rb_sprintf("unknown type 0x%x (0x%x given, probably comes"
963 " from extension library for ruby 1.8)", t, xt);
964 }
965 else {
966 mesg = rb_sprintf("unknown type 0x%x (0x%x given)", t, xt);
967 }
968 rb_exc_raise(rb_exc_new_str(exc, mesg));
969}
970
971void
973{
974 int xt;
975
976 if (x == Qundef) {
978 }
979
980 xt = TYPE(x);
981 if (xt != t || (xt == T_DATA && RTYPEDDATA_P(x))) {
982 unexpected_type(x, xt, t);
983 }
984}
985
986void
988{
989 if (x == Qundef) {
991 }
992
993 unexpected_type(x, TYPE(x), t);
994}
995
996int
998{
999 while (child) {
1000 if (child == parent) return 1;
1001 child = child->parent;
1002 }
1003 return 0;
1004}
1005
1006int
1008{
1009 if (!RB_TYPE_P(obj, T_DATA) ||
1010 !RTYPEDDATA_P(obj) || !rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
1011 return 0;
1012 }
1013 return 1;
1014}
1015
1016#undef rb_typeddata_is_instance_of
1017int
1019{
1020 return rb_typeddata_is_instance_of_inline(obj, data_type);
1021}
1022
1023void *
1025{
1026 VALUE actual;
1027
1028 if (!RB_TYPE_P(obj, T_DATA)) {
1029 actual = displaying_class_of(obj);
1030 }
1031 else if (!RTYPEDDATA_P(obj)) {
1032 actual = displaying_class_of(obj);
1033 }
1034 else if (!rb_typeddata_inherited_p(RTYPEDDATA_TYPE(obj), data_type)) {
1035 const char *name = RTYPEDDATA_TYPE(obj)->wrap_struct_name;
1036 actual = rb_str_new_cstr(name); /* or rb_fstring_cstr? not sure... */
1037 }
1038 else {
1039 return DATA_PTR(obj);
1040 }
1041
1042 const char *expected = data_type->wrap_struct_name;
1043 rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)",
1044 actual, expected);
1046}
1047
1048/* exception classes */
1071
1075
1078static VALUE rb_eNOERROR;
1079
1081#define id_cause ruby_static_id_cause
1082static ID id_message, id_backtrace;
1083static ID id_key, id_args, id_Errno, id_errno, id_i_path;
1084static ID id_receiver, id_recv, id_iseq, id_local_variables;
1085static ID id_private_call_p, id_top, id_bottom;
1086#define id_bt idBt
1087#define id_bt_locations idBt_locations
1088#define id_mesg idMesg
1089#define id_name idName
1090
1091#undef rb_exc_new_cstr
1092
1093VALUE
1094rb_exc_new(VALUE etype, const char *ptr, long len)
1095{
1096 VALUE mesg = rb_str_new(ptr, len);
1097 return rb_class_new_instance(1, &mesg, etype);
1098}
1099
1100VALUE
1101rb_exc_new_cstr(VALUE etype, const char *s)
1102{
1103 return rb_exc_new(etype, s, strlen(s));
1104}
1105
1106VALUE
1108{
1110 return rb_class_new_instance(1, &str, etype);
1111}
1112
1113static VALUE
1114exc_init(VALUE exc, VALUE mesg)
1115{
1116 rb_ivar_set(exc, id_mesg, mesg);
1117 rb_ivar_set(exc, id_bt, Qnil);
1118
1119 return exc;
1120}
1121
1122/*
1123 * call-seq:
1124 * Exception.new(msg = nil) -> exception
1125 * Exception.exception(msg = nil) -> exception
1126 *
1127 * Construct a new Exception object, optionally passing in
1128 * a message.
1129 */
1130
1131static VALUE
1132exc_initialize(int argc, VALUE *argv, VALUE exc)
1133{
1134 VALUE arg;
1135
1136 arg = (!rb_check_arity(argc, 0, 1) ? Qnil : argv[0]);
1137 return exc_init(exc, arg);
1138}
1139
1140/*
1141 * Document-method: exception
1142 *
1143 * call-seq:
1144 * exc.exception([string]) -> an_exception or exc
1145 *
1146 * With no argument, or if the argument is the same as the receiver,
1147 * return the receiver. Otherwise, create a new
1148 * exception object of the same class as the receiver, but with a
1149 * message equal to <code>string.to_str</code>.
1150 *
1151 */
1152
1153static VALUE
1154exc_exception(int argc, VALUE *argv, VALUE self)
1155{
1156 VALUE exc;
1157
1158 argc = rb_check_arity(argc, 0, 1);
1159 if (argc == 0) return self;
1160 if (argc == 1 && self == argv[0]) return self;
1161 exc = rb_obj_clone(self);
1162 rb_ivar_set(exc, id_mesg, argv[0]);
1163 return exc;
1164}
1165
1166/*
1167 * call-seq:
1168 * exception.to_s -> string
1169 *
1170 * Returns exception's message (or the name of the exception if
1171 * no message is set).
1172 */
1173
1174static VALUE
1175exc_to_s(VALUE exc)
1176{
1177 VALUE mesg = rb_attr_get(exc, idMesg);
1178
1179 if (NIL_P(mesg)) return rb_class_name(CLASS_OF(exc));
1180 return rb_String(mesg);
1181}
1182
1183/* FIXME: Include eval_error.c */
1184void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse);
1185
1186VALUE
1188{
1189 VALUE e = rb_check_funcall(exc, id_message, 0, 0);
1190 if (e == Qundef) return Qnil;
1191 if (!RB_TYPE_P(e, T_STRING)) e = rb_check_string_type(e);
1192 return e;
1193}
1194
1195/*
1196 * call-seq:
1197 * Exception.to_tty? -> true or false
1198 *
1199 * Returns +true+ if exception messages will be sent to a tty.
1200 */
1201static VALUE
1202exc_s_to_tty_p(VALUE self)
1203{
1204 return rb_stderr_tty_p() ? Qtrue : Qfalse;
1205}
1206
1207/*
1208 * call-seq:
1209 * exception.full_message(highlight: bool, order: [:top or :bottom]) -> string
1210 *
1211 * Returns formatted string of _exception_.
1212 * The returned string is formatted using the same format that Ruby uses
1213 * when printing an uncaught exceptions to stderr.
1214 *
1215 * If _highlight_ is +true+ the default error handler will send the
1216 * messages to a tty.
1217 *
1218 * _order_ must be either of +:top+ or +:bottom+, and places the error
1219 * message and the innermost backtrace come at the top or the bottom.
1220 *
1221 * The default values of these options depend on <code>$stderr</code>
1222 * and its +tty?+ at the timing of a call.
1223 */
1224
1225static VALUE
1226exc_full_message(int argc, VALUE *argv, VALUE exc)
1227{
1228 VALUE opt, str, emesg, errat;
1229 enum {kw_highlight, kw_order, kw_max_};
1230 static ID kw[kw_max_];
1231 VALUE args[kw_max_] = {Qnil, Qnil};
1232
1233 rb_scan_args(argc, argv, "0:", &opt);
1234 if (!NIL_P(opt)) {
1235 if (!kw[0]) {
1236#define INIT_KW(n) kw[kw_##n] = rb_intern_const(#n)
1237 INIT_KW(highlight);
1238 INIT_KW(order);
1239#undef INIT_KW
1240 }
1241 rb_get_kwargs(opt, kw, 0, kw_max_, args);
1242 switch (args[kw_highlight]) {
1243 default:
1244 rb_raise(rb_eArgError, "expected true or false as "
1245 "highlight: %+"PRIsVALUE, args[kw_highlight]);
1246 case Qundef: args[kw_highlight] = Qnil; break;
1247 case Qtrue: case Qfalse: case Qnil: break;
1248 }
1249 if (args[kw_order] == Qundef) {
1250 args[kw_order] = Qnil;
1251 }
1252 else {
1253 ID id = rb_check_id(&args[kw_order]);
1254 if (id == id_bottom) args[kw_order] = Qtrue;
1255 else if (id == id_top) args[kw_order] = Qfalse;
1256 else {
1257 rb_raise(rb_eArgError, "expected :top or :bottom as "
1258 "order: %+"PRIsVALUE, args[kw_order]);
1259 }
1260 }
1261 }
1262 str = rb_str_new2("");
1263 errat = rb_get_backtrace(exc);
1264 emesg = rb_get_message(exc);
1265
1266 rb_error_write(exc, emesg, errat, str, args[kw_highlight], args[kw_order]);
1267 return str;
1268}
1269
1270/*
1271 * call-seq:
1272 * exception.message -> string
1273 *
1274 * Returns the result of invoking <code>exception.to_s</code>.
1275 * Normally this returns the exception's message or name.
1276 */
1277
1278static VALUE
1279exc_message(VALUE exc)
1280{
1281 return rb_funcallv(exc, idTo_s, 0, 0);
1282}
1283
1284/*
1285 * call-seq:
1286 * exception.inspect -> string
1287 *
1288 * Return this exception's class name and message.
1289 */
1290
1291static VALUE
1292exc_inspect(VALUE exc)
1293{
1294 VALUE str, klass;
1295
1296 klass = CLASS_OF(exc);
1297 exc = rb_obj_as_string(exc);
1298 if (RSTRING_LEN(exc) == 0) {
1299 return rb_class_name(klass);
1300 }
1301
1302 str = rb_str_buf_new2("#<");
1303 klass = rb_class_name(klass);
1304 rb_str_buf_append(str, klass);
1305 rb_str_buf_cat(str, ": ", 2);
1306 rb_str_buf_append(str, exc);
1307 rb_str_buf_cat(str, ">", 1);
1308
1309 return str;
1310}
1311
1312/*
1313 * call-seq:
1314 * exception.backtrace -> array or nil
1315 *
1316 * Returns any backtrace associated with the exception. The backtrace
1317 * is an array of strings, each containing either ``filename:lineNo: in
1318 * `method''' or ``filename:lineNo.''
1319 *
1320 * def a
1321 * raise "boom"
1322 * end
1323 *
1324 * def b
1325 * a()
1326 * end
1327 *
1328 * begin
1329 * b()
1330 * rescue => detail
1331 * print detail.backtrace.join("\n")
1332 * end
1333 *
1334 * <em>produces:</em>
1335 *
1336 * prog.rb:2:in `a'
1337 * prog.rb:6:in `b'
1338 * prog.rb:10
1339 *
1340 * In the case no backtrace has been set, +nil+ is returned
1341 *
1342 * ex = StandardError.new
1343 * ex.backtrace
1344 * #=> nil
1345*/
1346
1347static VALUE
1348exc_backtrace(VALUE exc)
1349{
1350 VALUE obj;
1351
1352 obj = rb_attr_get(exc, id_bt);
1353
1354 if (rb_backtrace_p(obj)) {
1355 obj = rb_backtrace_to_str_ary(obj);
1356 /* rb_ivar_set(exc, id_bt, obj); */
1357 }
1358
1359 return obj;
1360}
1361
1362static VALUE rb_check_backtrace(VALUE);
1363
1364VALUE
1366{
1367 ID mid = id_backtrace;
1368 VALUE info;
1369 if (rb_method_basic_definition_p(CLASS_OF(exc), id_backtrace)) {
1370 VALUE klass = rb_eException;
1371 rb_execution_context_t *ec = GET_EC();
1372 if (NIL_P(exc))
1373 return Qnil;
1374 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_CALL, exc, mid, mid, klass, Qundef);
1375 info = exc_backtrace(exc);
1376 EXEC_EVENT_HOOK(ec, RUBY_EVENT_C_RETURN, exc, mid, mid, klass, info);
1377 }
1378 else {
1379 info = rb_funcallv(exc, mid, 0, 0);
1380 }
1381 if (NIL_P(info)) return Qnil;
1382 return rb_check_backtrace(info);
1383}
1384
1385/*
1386 * call-seq:
1387 * exception.backtrace_locations -> array or nil
1388 *
1389 * Returns any backtrace associated with the exception. This method is
1390 * similar to Exception#backtrace, but the backtrace is an array of
1391 * Thread::Backtrace::Location.
1392 *
1393 * This method is not affected by Exception#set_backtrace().
1394 */
1395static VALUE
1396exc_backtrace_locations(VALUE exc)
1397{
1398 VALUE obj;
1399
1400 obj = rb_attr_get(exc, id_bt_locations);
1401 if (!NIL_P(obj)) {
1403 }
1404 return obj;
1405}
1406
1407static VALUE
1408rb_check_backtrace(VALUE bt)
1409{
1410 long i;
1411 static const char err[] = "backtrace must be Array of String";
1412
1413 if (!NIL_P(bt)) {
1414 if (RB_TYPE_P(bt, T_STRING)) return rb_ary_new3(1, bt);
1415 if (rb_backtrace_p(bt)) return bt;
1416 if (!RB_TYPE_P(bt, T_ARRAY)) {
1418 }
1419 for (i=0;i<RARRAY_LEN(bt);i++) {
1420 VALUE e = RARRAY_AREF(bt, i);
1421 if (!RB_TYPE_P(e, T_STRING)) {
1423 }
1424 }
1425 }
1426 return bt;
1427}
1428
1429/*
1430 * call-seq:
1431 * exc.set_backtrace(backtrace) -> array
1432 *
1433 * Sets the backtrace information associated with +exc+. The +backtrace+ must
1434 * be an array of String objects or a single String in the format described
1435 * in Exception#backtrace.
1436 *
1437 */
1438
1439static VALUE
1440exc_set_backtrace(VALUE exc, VALUE bt)
1441{
1442 return rb_ivar_set(exc, id_bt, rb_check_backtrace(bt));
1443}
1444
1447{
1448 return exc_set_backtrace(exc, bt);
1449}
1450
1451/*
1452 * call-seq:
1453 * exception.cause -> an_exception or nil
1454 *
1455 * Returns the previous exception ($!) at the time this exception was raised.
1456 * This is useful for wrapping exceptions and retaining the original exception
1457 * information.
1458 */
1459
1460static VALUE
1461exc_cause(VALUE exc)
1462{
1463 return rb_attr_get(exc, id_cause);
1464}
1465
1466static VALUE
1467try_convert_to_exception(VALUE obj)
1468{
1469 return rb_check_funcall(obj, idException, 0, 0);
1470}
1471
1472/*
1473 * call-seq:
1474 * exc == obj -> true or false
1475 *
1476 * Equality---If <i>obj</i> is not an Exception, returns
1477 * <code>false</code>. Otherwise, returns <code>true</code> if <i>exc</i> and
1478 * <i>obj</i> share same class, messages, and backtrace.
1479 */
1480
1481static VALUE
1482exc_equal(VALUE exc, VALUE obj)
1483{
1484 VALUE mesg, backtrace;
1485
1486 if (exc == obj) return Qtrue;
1487
1488 if (rb_obj_class(exc) != rb_obj_class(obj)) {
1489 int state;
1490
1491 obj = rb_protect(try_convert_to_exception, obj, &state);
1492 if (state || obj == Qundef) {
1494 return Qfalse;
1495 }
1496 if (rb_obj_class(exc) != rb_obj_class(obj)) return Qfalse;
1497 mesg = rb_check_funcall(obj, id_message, 0, 0);
1498 if (mesg == Qundef) return Qfalse;
1499 backtrace = rb_check_funcall(obj, id_backtrace, 0, 0);
1500 if (backtrace == Qundef) return Qfalse;
1501 }
1502 else {
1503 mesg = rb_attr_get(obj, id_mesg);
1504 backtrace = exc_backtrace(obj);
1505 }
1506
1507 if (!rb_equal(rb_attr_get(exc, id_mesg), mesg))
1508 return Qfalse;
1509 if (!rb_equal(exc_backtrace(exc), backtrace))
1510 return Qfalse;
1511 return Qtrue;
1512}
1513
1514/*
1515 * call-seq:
1516 * SystemExit.new -> system_exit
1517 * SystemExit.new(status) -> system_exit
1518 * SystemExit.new(status, msg) -> system_exit
1519 * SystemExit.new(msg) -> system_exit
1520 *
1521 * Create a new +SystemExit+ exception with the given status and message.
1522 * Status is true, false, or an integer.
1523 * If status is not given, true is used.
1524 */
1525
1526static VALUE
1527exit_initialize(int argc, VALUE *argv, VALUE exc)
1528{
1529 VALUE status;
1530 if (argc > 0) {
1531 status = *argv;
1532
1533 switch (status) {
1534 case Qtrue:
1535 status = INT2FIX(EXIT_SUCCESS);
1536 ++argv;
1537 --argc;
1538 break;
1539 case Qfalse:
1540 status = INT2FIX(EXIT_FAILURE);
1541 ++argv;
1542 --argc;
1543 break;
1544 default:
1545 status = rb_check_to_int(status);
1546 if (NIL_P(status)) {
1547 status = INT2FIX(EXIT_SUCCESS);
1548 }
1549 else {
1550#if EXIT_SUCCESS != 0
1551 if (status == INT2FIX(0))
1552 status = INT2FIX(EXIT_SUCCESS);
1553#endif
1554 ++argv;
1555 --argc;
1556 }
1557 break;
1558 }
1559 }
1560 else {
1561 status = INT2FIX(EXIT_SUCCESS);
1562 }
1564 rb_ivar_set(exc, id_status, status);
1565 return exc;
1566}
1567
1568
1569/*
1570 * call-seq:
1571 * system_exit.status -> integer
1572 *
1573 * Return the status value associated with this system exit.
1574 */
1575
1576static VALUE
1577exit_status(VALUE exc)
1578{
1579 return rb_attr_get(exc, id_status);
1580}
1581
1582
1583/*
1584 * call-seq:
1585 * system_exit.success? -> true or false
1586 *
1587 * Returns +true+ if exiting successful, +false+ if not.
1588 */
1589
1590static VALUE
1591exit_success_p(VALUE exc)
1592{
1593 VALUE status_val = rb_attr_get(exc, id_status);
1594 int status;
1595
1596 if (NIL_P(status_val))
1597 return Qtrue;
1598 status = NUM2INT(status_val);
1599 if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
1600 return Qtrue;
1601
1602 return Qfalse;
1603}
1604
1605static VALUE
1606err_init_recv(VALUE exc, VALUE recv)
1607{
1608 if (recv != Qundef) rb_ivar_set(exc, id_recv, recv);
1609 return exc;
1610}
1611
1612/*
1613 * call-seq:
1614 * FrozenError.new(msg=nil, receiver: nil) -> frozen_error
1615 *
1616 * Construct a new FrozenError exception. If given the <i>receiver</i>
1617 * parameter may subsequently be examined using the FrozenError#receiver
1618 * method.
1619 *
1620 * a = [].freeze
1621 * raise FrozenError.new("can't modify frozen array", receiver: a)
1622 */
1623
1624static VALUE
1625frozen_err_initialize(int argc, VALUE *argv, VALUE self)
1626{
1627 ID keywords[1];
1628 VALUE values[numberof(keywords)], options;
1629
1630 argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1631 keywords[0] = id_receiver;
1632 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1634 err_init_recv(self, values[0]);
1635 return self;
1636}
1637
1638/*
1639 * Document-method: FrozenError#receiver
1640 * call-seq:
1641 * frozen_error.receiver -> object
1642 *
1643 * Return the receiver associated with this FrozenError exception.
1644 */
1645
1646#define frozen_err_receiver name_err_receiver
1647
1648void
1649rb_name_error(ID id, const char *fmt, ...)
1650{
1651 VALUE exc, argv[2];
1652 va_list args;
1653
1654 va_start(args, fmt);
1655 argv[0] = rb_vsprintf(fmt, args);
1656 va_end(args);
1657
1658 argv[1] = ID2SYM(id);
1660 rb_exc_raise(exc);
1661}
1662
1663void
1664rb_name_error_str(VALUE str, const char *fmt, ...)
1665{
1666 VALUE exc, argv[2];
1667 va_list args;
1668
1669 va_start(args, fmt);
1670 argv[0] = rb_vsprintf(fmt, args);
1671 va_end(args);
1672
1673 argv[1] = str;
1675 rb_exc_raise(exc);
1676}
1677
1678static VALUE
1679name_err_init_attr(VALUE exc, VALUE recv, VALUE method)
1680{
1681 const rb_execution_context_t *ec = GET_EC();
1683 cfp = rb_vm_get_ruby_level_next_cfp(ec, cfp);
1684 rb_ivar_set(exc, id_name, method);
1685 err_init_recv(exc, recv);
1686 if (cfp) rb_ivar_set(exc, id_iseq, rb_iseqw_new(cfp->iseq));
1687 return exc;
1688}
1689
1690/*
1691 * call-seq:
1692 * NameError.new(msg=nil, name=nil, receiver: nil) -> name_error
1693 *
1694 * Construct a new NameError exception. If given the <i>name</i>
1695 * parameter may subsequently be examined using the NameError#name
1696 * method. <i>receiver</i> parameter allows to pass object in
1697 * context of which the error happened. Example:
1698 *
1699 * [1, 2, 3].method(:rject) # NameError with name "rject" and receiver: Array
1700 * [1, 2, 3].singleton_method(:rject) # NameError with name "rject" and receiver: [1, 2, 3]
1701 */
1702
1703static VALUE
1704name_err_initialize(int argc, VALUE *argv, VALUE self)
1705{
1706 ID keywords[1];
1707 VALUE values[numberof(keywords)], name, options;
1708
1709 argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1710 keywords[0] = id_receiver;
1711 rb_get_kwargs(options, keywords, 0, numberof(values), values);
1712 name = (argc > 1) ? argv[--argc] : Qnil;
1714 name_err_init_attr(self, values[0], name);
1715 return self;
1716}
1717
1718static VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method);
1719
1720static VALUE
1721name_err_init(VALUE exc, VALUE mesg, VALUE recv, VALUE method)
1722{
1723 exc_init(exc, rb_name_err_mesg_new(mesg, recv, method));
1724 return name_err_init_attr(exc, recv, method);
1725}
1726
1727VALUE
1729{
1731 return name_err_init(exc, mesg, recv, method);
1732}
1733
1734/*
1735 * call-seq:
1736 * name_error.name -> string or nil
1737 *
1738 * Return the name associated with this NameError exception.
1739 */
1740
1741static VALUE
1742name_err_name(VALUE self)
1743{
1744 return rb_attr_get(self, id_name);
1745}
1746
1747/*
1748 * call-seq:
1749 * name_error.local_variables -> array
1750 *
1751 * Return a list of the local variable names defined where this
1752 * NameError exception was raised.
1753 *
1754 * Internal use only.
1755 */
1756
1757static VALUE
1758name_err_local_variables(VALUE self)
1759{
1760 VALUE vars = rb_attr_get(self, id_local_variables);
1761
1762 if (NIL_P(vars)) {
1763 VALUE iseqw = rb_attr_get(self, id_iseq);
1764 if (!NIL_P(iseqw)) vars = rb_iseqw_local_variables(iseqw);
1765 if (NIL_P(vars)) vars = rb_ary_new();
1766 rb_ivar_set(self, id_local_variables, vars);
1767 }
1768 return vars;
1769}
1770
1771static VALUE
1772nometh_err_init_attr(VALUE exc, VALUE args, int priv)
1773{
1774 rb_ivar_set(exc, id_args, args);
1775 rb_ivar_set(exc, id_private_call_p, priv ? Qtrue : Qfalse);
1776 return exc;
1777}
1778
1779/*
1780 * call-seq:
1781 * NoMethodError.new(msg=nil, name=nil, args=nil, private=false, receiver: nil) -> no_method_error
1782 *
1783 * Construct a NoMethodError exception for a method of the given name
1784 * called with the given arguments. The name may be accessed using
1785 * the <code>#name</code> method on the resulting object, and the
1786 * arguments using the <code>#args</code> method.
1787 *
1788 * If <i>private</i> argument were passed, it designates method was
1789 * attempted to call in private context, and can be accessed with
1790 * <code>#private_call?</code> method.
1791 *
1792 * <i>receiver</i> argument stores an object whose method was called.
1793 */
1794
1795static VALUE
1796nometh_err_initialize(int argc, VALUE *argv, VALUE self)
1797{
1798 int priv;
1799 VALUE args, options;
1800 argc = rb_scan_args(argc, argv, "*:", NULL, &options);
1801 priv = (argc > 3) && (--argc, RTEST(argv[argc]));
1802 args = (argc > 2) ? argv[--argc] : Qnil;
1803 if (!NIL_P(options)) argv[argc++] = options;
1805 return nometh_err_init_attr(self, args, priv);
1806}
1807
1808VALUE
1809rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
1810{
1812 name_err_init(exc, mesg, recv, method);
1813 return nometh_err_init_attr(exc, args, priv);
1814}
1815
1816/* :nodoc: */
1817enum {
1823
1824static void
1825name_err_mesg_mark(void *p)
1826{
1827 VALUE *ptr = p;
1829}
1830
1831#define name_err_mesg_free RUBY_TYPED_DEFAULT_FREE
1832
1833static size_t
1834name_err_mesg_memsize(const void *p)
1835{
1836 return NAME_ERR_MESG_COUNT * sizeof(VALUE);
1837}
1838
1839static const rb_data_type_t name_err_mesg_data_type = {
1840 "name_err_mesg",
1841 {
1842 name_err_mesg_mark,
1844 name_err_mesg_memsize,
1845 },
1847};
1848
1849/* :nodoc: */
1850static VALUE
1851rb_name_err_mesg_init(VALUE klass, VALUE mesg, VALUE recv, VALUE method)
1852{
1853 VALUE result = TypedData_Wrap_Struct(klass, &name_err_mesg_data_type, 0);
1855
1856 ptr[NAME_ERR_MESG__MESG] = mesg;
1857 ptr[NAME_ERR_MESG__RECV] = recv;
1858 ptr[NAME_ERR_MESG__NAME] = method;
1859 RTYPEDDATA_DATA(result) = ptr;
1860 return result;
1861}
1862
1863/* :nodoc: */
1864static VALUE
1865rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
1866{
1867 return rb_name_err_mesg_init(rb_cNameErrorMesg, mesg, recv, method);
1868}
1869
1870/* :nodoc: */
1871static VALUE
1872name_err_mesg_alloc(VALUE klass)
1873{
1874 return rb_name_err_mesg_init(klass, Qnil, Qnil, Qnil);
1875}
1876
1877/* :nodoc: */
1878static VALUE
1879name_err_mesg_init_copy(VALUE obj1, VALUE obj2)
1880{
1881 VALUE *ptr1, *ptr2;
1882
1883 if (obj1 == obj2) return obj1;
1884 rb_obj_init_copy(obj1, obj2);
1885
1886 TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1887 TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1888 MEMCPY(ptr1, ptr2, VALUE, NAME_ERR_MESG_COUNT);
1889 return obj1;
1890}
1891
1892/* :nodoc: */
1893static VALUE
1894name_err_mesg_equal(VALUE obj1, VALUE obj2)
1895{
1896 VALUE *ptr1, *ptr2;
1897 int i;
1898
1899 if (obj1 == obj2) return Qtrue;
1900 if (rb_obj_class(obj2) != rb_cNameErrorMesg)
1901 return Qfalse;
1902
1903 TypedData_Get_Struct(obj1, VALUE, &name_err_mesg_data_type, ptr1);
1904 TypedData_Get_Struct(obj2, VALUE, &name_err_mesg_data_type, ptr2);
1905 for (i=0; i<NAME_ERR_MESG_COUNT; i++) {
1906 if (!rb_equal(ptr1[i], ptr2[i]))
1907 return Qfalse;
1908 }
1909 return Qtrue;
1910}
1911
1912/* :nodoc: */
1913static VALUE
1914name_err_mesg_receiver_name(VALUE obj)
1915{
1916 if (RB_SPECIAL_CONST_P(obj)) return Qundef;
1917 if (RB_BUILTIN_TYPE(obj) == T_MODULE || RB_BUILTIN_TYPE(obj) == T_CLASS) {
1918 return rb_check_funcall(obj, rb_intern("name"), 0, 0);
1919 }
1920 return Qundef;
1921}
1922
1923/* :nodoc: */
1924static VALUE
1925name_err_mesg_to_str(VALUE obj)
1926{
1927 VALUE *ptr, mesg;
1928 TypedData_Get_Struct(obj, VALUE, &name_err_mesg_data_type, ptr);
1929
1930 mesg = ptr[NAME_ERR_MESG__MESG];
1931 if (NIL_P(mesg)) return Qnil;
1932 else {
1933 struct RString s_str, d_str;
1934 VALUE c, s, d = 0, args[4];
1935 int state = 0, singleton = 0;
1936 rb_encoding *usascii = rb_usascii_encoding();
1937
1938#define FAKE_CSTR(v, str) rb_setup_fake_str((v), (str), rb_strlen_lit(str), usascii)
1939 obj = ptr[NAME_ERR_MESG__RECV];
1940 switch (obj) {
1941 case Qnil:
1942 d = FAKE_CSTR(&d_str, "nil");
1943 break;
1944 case Qtrue:
1945 d = FAKE_CSTR(&d_str, "true");
1946 break;
1947 case Qfalse:
1948 d = FAKE_CSTR(&d_str, "false");
1949 break;
1950 default:
1951 d = rb_protect(name_err_mesg_receiver_name, obj, &state);
1952 if (state || d == Qundef || d == Qnil)
1953 d = rb_protect(rb_inspect, obj, &state);
1954 if (state) {
1956 }
1957 d = rb_check_string_type(d);
1958 if (NIL_P(d)) {
1959 d = rb_any_to_s(obj);
1960 }
1961 singleton = (RSTRING_LEN(d) > 0 && RSTRING_PTR(d)[0] == '#');
1962 break;
1963 }
1964 if (!singleton) {
1965 s = FAKE_CSTR(&s_str, ":");
1966 c = rb_class_name(CLASS_OF(obj));
1967 }
1968 else {
1969 c = s = FAKE_CSTR(&s_str, "");
1970 }
1972 args[1] = d;
1973 args[2] = s;
1974 args[3] = c;
1975 mesg = rb_str_format(4, args, mesg);
1976 }
1977 return mesg;
1978}
1979
1980/* :nodoc: */
1981static VALUE
1982name_err_mesg_dump(VALUE obj, VALUE limit)
1983{
1984 return name_err_mesg_to_str(obj);
1985}
1986
1987/* :nodoc: */
1988static VALUE
1989name_err_mesg_load(VALUE klass, VALUE str)
1990{
1991 return str;
1992}
1993
1994/*
1995 * call-seq:
1996 * name_error.receiver -> object
1997 *
1998 * Return the receiver associated with this NameError exception.
1999 */
2000
2001static VALUE
2002name_err_receiver(VALUE self)
2003{
2004 VALUE *ptr, recv, mesg;
2005
2006 recv = rb_ivar_lookup(self, id_recv, Qundef);
2007 if (recv != Qundef) return recv;
2008
2009 mesg = rb_attr_get(self, id_mesg);
2010 if (!rb_typeddata_is_kind_of(mesg, &name_err_mesg_data_type)) {
2011 rb_raise(rb_eArgError, "no receiver is available");
2012 }
2013 ptr = DATA_PTR(mesg);
2014 return ptr[NAME_ERR_MESG__RECV];
2015}
2016
2017/*
2018 * call-seq:
2019 * no_method_error.args -> obj
2020 *
2021 * Return the arguments passed in as the third parameter to
2022 * the constructor.
2023 */
2024
2025static VALUE
2026nometh_err_args(VALUE self)
2027{
2028 return rb_attr_get(self, id_args);
2029}
2030
2031/*
2032 * call-seq:
2033 * no_method_error.private_call? -> true or false
2034 *
2035 * Return true if the caused method was called as private.
2036 */
2037
2038static VALUE
2039nometh_err_private_call_p(VALUE self)
2040{
2041 return rb_attr_get(self, id_private_call_p);
2042}
2043
2044void
2045rb_invalid_str(const char *str, const char *type)
2046{
2047 VALUE s = rb_str_new2(str);
2048
2049 rb_raise(rb_eArgError, "invalid value for %s: %+"PRIsVALUE, type, s);
2050}
2051
2052/*
2053 * call-seq:
2054 * key_error.receiver -> object
2055 *
2056 * Return the receiver associated with this KeyError exception.
2057 */
2058
2059static VALUE
2060key_err_receiver(VALUE self)
2061{
2062 VALUE recv;
2063
2064 recv = rb_ivar_lookup(self, id_receiver, Qundef);
2065 if (recv != Qundef) return recv;
2066 rb_raise(rb_eArgError, "no receiver is available");
2067}
2068
2069/*
2070 * call-seq:
2071 * key_error.key -> object
2072 *
2073 * Return the key caused this KeyError exception.
2074 */
2075
2076static VALUE
2077key_err_key(VALUE self)
2078{
2079 VALUE key;
2080
2081 key = rb_ivar_lookup(self, id_key, Qundef);
2082 if (key != Qundef) return key;
2083 rb_raise(rb_eArgError, "no key is available");
2084}
2085
2086VALUE
2088{
2090 rb_ivar_set(exc, id_mesg, mesg);
2091 rb_ivar_set(exc, id_bt, Qnil);
2092 rb_ivar_set(exc, id_key, key);
2093 rb_ivar_set(exc, id_receiver, recv);
2094 return exc;
2095}
2096
2097/*
2098 * call-seq:
2099 * KeyError.new(message=nil, receiver: nil, key: nil) -> key_error
2100 *
2101 * Construct a new +KeyError+ exception with the given message,
2102 * receiver and key.
2103 */
2104
2105static VALUE
2106key_err_initialize(int argc, VALUE *argv, VALUE self)
2107{
2108 VALUE options;
2109
2110 rb_call_super(rb_scan_args(argc, argv, "01:", NULL, &options), argv);
2111
2112 if (!NIL_P(options)) {
2113 ID keywords[2];
2114 VALUE values[numberof(keywords)];
2115 int i;
2116 keywords[0] = id_receiver;
2117 keywords[1] = id_key;
2118 rb_get_kwargs(options, keywords, 0, numberof(values), values);
2119 for (i = 0; i < numberof(values); ++i) {
2120 if (values[i] != Qundef) {
2121 rb_ivar_set(self, keywords[i], values[i]);
2122 }
2123 }
2124 }
2125
2126 return self;
2127}
2128
2129/*
2130 * call-seq:
2131 * SyntaxError.new([msg]) -> syntax_error
2132 *
2133 * Construct a SyntaxError exception.
2134 */
2135
2136static VALUE
2137syntax_error_initialize(int argc, VALUE *argv, VALUE self)
2138{
2139 VALUE mesg;
2140 if (argc == 0) {
2141 mesg = rb_fstring_lit("compile error");
2142 argc = 1;
2143 argv = &mesg;
2144 }
2145 return rb_call_super(argc, argv);
2146}
2147
2148/*
2149 * Document-module: Errno
2150 *
2151 * Ruby exception objects are subclasses of Exception. However,
2152 * operating systems typically report errors using plain
2153 * integers. Module Errno is created dynamically to map these
2154 * operating system errors to Ruby classes, with each error number
2155 * generating its own subclass of SystemCallError. As the subclass
2156 * is created in module Errno, its name will start
2157 * <code>Errno::</code>.
2158 *
2159 * The names of the <code>Errno::</code> classes depend on the
2160 * environment in which Ruby runs. On a typical Unix or Windows
2161 * platform, there are Errno classes such as Errno::EACCES,
2162 * Errno::EAGAIN, Errno::EINTR, and so on.
2163 *
2164 * The integer operating system error number corresponding to a
2165 * particular error is available as the class constant
2166 * <code>Errno::</code><em>error</em><code>::Errno</code>.
2167 *
2168 * Errno::EACCES::Errno #=> 13
2169 * Errno::EAGAIN::Errno #=> 11
2170 * Errno::EINTR::Errno #=> 4
2171 *
2172 * The full list of operating system errors on your particular platform
2173 * are available as the constants of Errno.
2174 *
2175 * Errno.constants #=> :E2BIG, :EACCES, :EADDRINUSE, :EADDRNOTAVAIL, ...
2176 */
2177
2178static st_table *syserr_tbl;
2179
2180static VALUE
2181set_syserr(int n, const char *name)
2182{
2184
2185 if (!st_lookup(syserr_tbl, n, &error)) {
2187
2188 /* capture nonblock errnos for WaitReadable/WaitWritable subclasses */
2189 switch (n) {
2190 case EAGAIN:
2191 rb_eEAGAIN = error;
2192
2193#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
2194 break;
2195 case EWOULDBLOCK:
2196#endif
2197
2199 break;
2200 case EINPROGRESS:
2202 break;
2203 }
2204
2205 rb_define_const(error, "Errno", INT2NUM(n));
2206 st_add_direct(syserr_tbl, n, error);
2207 }
2208 else {
2210 }
2211 return error;
2212}
2213
2214static VALUE
2215get_syserr(int n)
2216{
2218
2219 if (!st_lookup(syserr_tbl, n, &error)) {
2220 char name[8]; /* some Windows' errno have 5 digits. */
2221
2222 snprintf(name, sizeof(name), "E%03d", n);
2223 error = set_syserr(n, name);
2224 }
2225 return error;
2226}
2227
2228/*
2229 * call-seq:
2230 * SystemCallError.new(msg, errno) -> system_call_error_subclass
2231 *
2232 * If _errno_ corresponds to a known system error code, constructs the
2233 * appropriate Errno class for that error, otherwise constructs a
2234 * generic SystemCallError object. The error number is subsequently
2235 * available via the #errno method.
2236 */
2237
2238static VALUE
2239syserr_initialize(int argc, VALUE *argv, VALUE self)
2240{
2241#if !defined(_WIN32)
2242 char *strerror();
2243#endif
2244 const char *err;
2245 VALUE mesg, error, func, errmsg;
2246 VALUE klass = rb_obj_class(self);
2247
2248 if (klass == rb_eSystemCallError) {
2249 st_data_t data = (st_data_t)klass;
2250 rb_scan_args(argc, argv, "12", &mesg, &error, &func);
2251 if (argc == 1 && FIXNUM_P(mesg)) {
2252 error = mesg; mesg = Qnil;
2253 }
2254 if (!NIL_P(error) && st_lookup(syserr_tbl, NUM2LONG(error), &data)) {
2255 klass = (VALUE)data;
2256 /* change class */
2257 if (!RB_TYPE_P(self, T_OBJECT)) { /* insurance to avoid type crash */
2258 rb_raise(rb_eTypeError, "invalid instance type");
2259 }
2260 RBASIC_SET_CLASS(self, klass);
2261 }
2262 }
2263 else {
2264 rb_scan_args(argc, argv, "02", &mesg, &func);
2265 error = rb_const_get(klass, id_Errno);
2266 }
2267 if (!NIL_P(error)) err = strerror(NUM2INT(error));
2268 else err = "unknown error";
2269
2271 if (!NIL_P(mesg)) {
2272 VALUE str = StringValue(mesg);
2273
2274 if (!NIL_P(func)) rb_str_catf(errmsg, " @ %"PRIsVALUE, func);
2275 rb_str_catf(errmsg, " - %"PRIsVALUE, str);
2276 }
2277 mesg = errmsg;
2278
2279 rb_call_super(1, &mesg);
2280 rb_ivar_set(self, id_errno, error);
2281 return self;
2282}
2283
2284/*
2285 * call-seq:
2286 * system_call_error.errno -> integer
2287 *
2288 * Return this SystemCallError's error number.
2289 */
2290
2291static VALUE
2292syserr_errno(VALUE self)
2293{
2294 return rb_attr_get(self, id_errno);
2295}
2296
2297/*
2298 * call-seq:
2299 * system_call_error === other -> true or false
2300 *
2301 * Return +true+ if the receiver is a generic +SystemCallError+, or
2302 * if the error numbers +self+ and _other_ are the same.
2303 */
2304
2305static VALUE
2306syserr_eqq(VALUE self, VALUE exc)
2307{
2308 VALUE num, e;
2309
2311 if (!rb_respond_to(exc, id_errno)) return Qfalse;
2312 }
2313 else if (self == rb_eSystemCallError) return Qtrue;
2314
2315 num = rb_attr_get(exc, id_errno);
2316 if (NIL_P(num)) {
2317 num = rb_funcallv(exc, id_errno, 0, 0);
2318 }
2319 e = rb_const_get(self, id_Errno);
2320 if (FIXNUM_P(num) ? num == e : rb_equal(num, e))
2321 return Qtrue;
2322 return Qfalse;
2323}
2324
2325
2326/*
2327 * Document-class: StandardError
2328 *
2329 * The most standard error types are subclasses of StandardError. A
2330 * rescue clause without an explicit Exception class will rescue all
2331 * StandardErrors (and only those).
2332 *
2333 * def foo
2334 * raise "Oups"
2335 * end
2336 * foo rescue "Hello" #=> "Hello"
2337 *
2338 * On the other hand:
2339 *
2340 * require 'does/not/exist' rescue "Hi"
2341 *
2342 * <em>raises the exception:</em>
2343 *
2344 * LoadError: no such file to load -- does/not/exist
2345 *
2346 */
2347
2348/*
2349 * Document-class: SystemExit
2350 *
2351 * Raised by +exit+ to initiate the termination of the script.
2352 */
2353
2354/*
2355 * Document-class: SignalException
2356 *
2357 * Raised when a signal is received.
2358 *
2359 * begin
2360 * Process.kill('HUP',Process.pid)
2361 * sleep # wait for receiver to handle signal sent by Process.kill
2362 * rescue SignalException => e
2363 * puts "received Exception #{e}"
2364 * end
2365 *
2366 * <em>produces:</em>
2367 *
2368 * received Exception SIGHUP
2369 */
2370
2371/*
2372 * Document-class: Interrupt
2373 *
2374 * Raised when the interrupt signal is received, typically because the
2375 * user has pressed Control-C (on most posix platforms). As such, it is a
2376 * subclass of +SignalException+.
2377 *
2378 * begin
2379 * puts "Press ctrl-C when you get bored"
2380 * loop {}
2381 * rescue Interrupt => e
2382 * puts "Note: You will typically use Signal.trap instead."
2383 * end
2384 *
2385 * <em>produces:</em>
2386 *
2387 * Press ctrl-C when you get bored
2388 *
2389 * <em>then waits until it is interrupted with Control-C and then prints:</em>
2390 *
2391 * Note: You will typically use Signal.trap instead.
2392 */
2393
2394/*
2395 * Document-class: TypeError
2396 *
2397 * Raised when encountering an object that is not of the expected type.
2398 *
2399 * [1, 2, 3].first("two")
2400 *
2401 * <em>raises the exception:</em>
2402 *
2403 * TypeError: no implicit conversion of String into Integer
2404 *
2405 */
2406
2407/*
2408 * Document-class: ArgumentError
2409 *
2410 * Raised when the arguments are wrong and there isn't a more specific
2411 * Exception class.
2412 *
2413 * Ex: passing the wrong number of arguments
2414 *
2415 * [1, 2, 3].first(4, 5)
2416 *
2417 * <em>raises the exception:</em>
2418 *
2419 * ArgumentError: wrong number of arguments (given 2, expected 1)
2420 *
2421 * Ex: passing an argument that is not acceptable:
2422 *
2423 * [1, 2, 3].first(-4)
2424 *
2425 * <em>raises the exception:</em>
2426 *
2427 * ArgumentError: negative array size
2428 */
2429
2430/*
2431 * Document-class: IndexError
2432 *
2433 * Raised when the given index is invalid.
2434 *
2435 * a = [:foo, :bar]
2436 * a.fetch(0) #=> :foo
2437 * a[4] #=> nil
2438 * a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2
2439 *
2440 */
2441
2442/*
2443 * Document-class: KeyError
2444 *
2445 * Raised when the specified key is not found. It is a subclass of
2446 * IndexError.
2447 *
2448 * h = {"foo" => :bar}
2449 * h.fetch("foo") #=> :bar
2450 * h.fetch("baz") #=> KeyError: key not found: "baz"
2451 *
2452 */
2453
2454/*
2455 * Document-class: RangeError
2456 *
2457 * Raised when a given numerical value is out of range.
2458 *
2459 * [1, 2, 3].drop(1 << 100)
2460 *
2461 * <em>raises the exception:</em>
2462 *
2463 * RangeError: bignum too big to convert into `long'
2464 */
2465
2466/*
2467 * Document-class: ScriptError
2468 *
2469 * ScriptError is the superclass for errors raised when a script
2470 * can not be executed because of a +LoadError+,
2471 * +NotImplementedError+ or a +SyntaxError+. Note these type of
2472 * +ScriptErrors+ are not +StandardError+ and will not be
2473 * rescued unless it is specified explicitly (or its ancestor
2474 * +Exception+).
2475 */
2476
2477/*
2478 * Document-class: SyntaxError
2479 *
2480 * Raised when encountering Ruby code with an invalid syntax.
2481 *
2482 * eval("1+1=2")
2483 *
2484 * <em>raises the exception:</em>
2485 *
2486 * SyntaxError: (eval):1: syntax error, unexpected '=', expecting $end
2487 */
2488
2489/*
2490 * Document-class: LoadError
2491 *
2492 * Raised when a file required (a Ruby script, extension library, ...)
2493 * fails to load.
2494 *
2495 * require 'this/file/does/not/exist'
2496 *
2497 * <em>raises the exception:</em>
2498 *
2499 * LoadError: no such file to load -- this/file/does/not/exist
2500 */
2501
2502/*
2503 * Document-class: NotImplementedError
2504 *
2505 * Raised when a feature is not implemented on the current platform. For
2506 * example, methods depending on the +fsync+ or +fork+ system calls may
2507 * raise this exception if the underlying operating system or Ruby
2508 * runtime does not support them.
2509 *
2510 * Note that if +fork+ raises a +NotImplementedError+, then
2511 * <code>respond_to?(:fork)</code> returns +false+.
2512 */
2513
2514/*
2515 * Document-class: NameError
2516 *
2517 * Raised when a given name is invalid or undefined.
2518 *
2519 * puts foo
2520 *
2521 * <em>raises the exception:</em>
2522 *
2523 * NameError: undefined local variable or method `foo' for main:Object
2524 *
2525 * Since constant names must start with a capital:
2526 *
2527 * Integer.const_set :answer, 42
2528 *
2529 * <em>raises the exception:</em>
2530 *
2531 * NameError: wrong constant name answer
2532 */
2533
2534/*
2535 * Document-class: NoMethodError
2536 *
2537 * Raised when a method is called on a receiver which doesn't have it
2538 * defined and also fails to respond with +method_missing+.
2539 *
2540 * "hello".to_ary
2541 *
2542 * <em>raises the exception:</em>
2543 *
2544 * NoMethodError: undefined method `to_ary' for "hello":String
2545 */
2546
2547/*
2548 * Document-class: FrozenError
2549 *
2550 * Raised when there is an attempt to modify a frozen object.
2551 *
2552 * [1, 2, 3].freeze << 4
2553 *
2554 * <em>raises the exception:</em>
2555 *
2556 * FrozenError: can't modify frozen Array
2557 */
2558
2559/*
2560 * Document-class: RuntimeError
2561 *
2562 * A generic error class raised when an invalid operation is attempted.
2563 * Kernel#raise will raise a RuntimeError if no Exception class is
2564 * specified.
2565 *
2566 * raise "ouch"
2567 *
2568 * <em>raises the exception:</em>
2569 *
2570 * RuntimeError: ouch
2571 */
2572
2573/*
2574 * Document-class: SecurityError
2575 *
2576 * No longer used by internal code.
2577 */
2578
2579/*
2580 * Document-class: NoMemoryError
2581 *
2582 * Raised when memory allocation fails.
2583 */
2584
2585/*
2586 * Document-class: SystemCallError
2587 *
2588 * SystemCallError is the base class for all low-level
2589 * platform-dependent errors.
2590 *
2591 * The errors available on the current platform are subclasses of
2592 * SystemCallError and are defined in the Errno module.
2593 *
2594 * File.open("does/not/exist")
2595 *
2596 * <em>raises the exception:</em>
2597 *
2598 * Errno::ENOENT: No such file or directory - does/not/exist
2599 */
2600
2601/*
2602 * Document-class: EncodingError
2603 *
2604 * EncodingError is the base class for encoding errors.
2605 */
2606
2607/*
2608 * Document-class: Encoding::CompatibilityError
2609 *
2610 * Raised by Encoding and String methods when the source encoding is
2611 * incompatible with the target encoding.
2612 */
2613
2614/*
2615 * Document-class: fatal
2616 *
2617 * fatal is an Exception that is raised when Ruby has encountered a fatal
2618 * error and must exit.
2619 */
2620
2621/*
2622 * Document-class: NameError::message
2623 * :nodoc:
2624 */
2625
2626/*
2627 * Document-class: Exception
2628 *
2629 * \Class Exception and its subclasses are used to communicate between
2630 * Kernel#raise and +rescue+ statements in <code>begin ... end</code> blocks.
2631 *
2632 * An Exception object carries information about an exception:
2633 * - Its type (the exception's class).
2634 * - An optional descriptive message.
2635 * - Optional backtrace information.
2636 *
2637 * Some built-in subclasses of Exception have additional methods: e.g., NameError#name.
2638 *
2639 * == Defaults
2640 *
2641 * Two Ruby statements have default exception classes:
2642 * - +raise+: defaults to RuntimeError.
2643 * - +rescue+: defaults to StandardError.
2644 *
2645 * == Global Variables
2646 *
2647 * When an exception has been raised but not yet handled (in +rescue+,
2648 * +ensure+, +at_exit+ and +END+ blocks), two global variables are set:
2649 * - <code>$!</code> contains the current exception.
2650 * - <code>$@</code> contains its backtrace.
2651 *
2652 * == Custom Exceptions
2653 *
2654 * To provide additional or alternate information,
2655 * a program may create custom exception classes
2656 * that derive from the built-in exception classes.
2657 *
2658 * A good practice is for a library to create a single "generic" exception class
2659 * (typically a subclass of StandardError or RuntimeError)
2660 * and have its other exception classes derive from that class.
2661 * This allows the user to rescue the generic exception, thus catching all exceptions
2662 * the library may raise even if future versions of the library add new
2663 * exception subclasses.
2664 *
2665 * For example:
2666 *
2667 * class MyLibrary
2668 * class Error < ::StandardError
2669 * end
2670 *
2671 * class WidgetError < Error
2672 * end
2673 *
2674 * class FrobError < Error
2675 * end
2676 *
2677 * end
2678 *
2679 * To handle both MyLibrary::WidgetError and MyLibrary::FrobError the library
2680 * user can rescue MyLibrary::Error.
2681 *
2682 * == Built-In Exception Classes
2683 *
2684 * The built-in subclasses of Exception are:
2685 *
2686 * * NoMemoryError
2687 * * ScriptError
2688 * * LoadError
2689 * * NotImplementedError
2690 * * SyntaxError
2691 * * SecurityError
2692 * * SignalException
2693 * * Interrupt
2694 * * StandardError
2695 * * ArgumentError
2696 * * UncaughtThrowError
2697 * * EncodingError
2698 * * FiberError
2699 * * IOError
2700 * * EOFError
2701 * * IndexError
2702 * * KeyError
2703 * * StopIteration
2704 * * ClosedQueueError
2705 * * LocalJumpError
2706 * * NameError
2707 * * NoMethodError
2708 * * RangeError
2709 * * FloatDomainError
2710 * * RegexpError
2711 * * RuntimeError
2712 * * FrozenError
2713 * * SystemCallError
2714 * * Errno::*
2715 * * ThreadError
2716 * * TypeError
2717 * * ZeroDivisionError
2718 * * SystemExit
2719 * * SystemStackError
2720 * * fatal
2721 */
2722
2723static VALUE
2724exception_alloc(VALUE klass)
2725{
2726 return rb_class_allocate_instance(klass);
2727}
2728
2729static VALUE
2730exception_dumper(VALUE exc)
2731{
2732 // TODO: Currently, the instance variables "bt" and "bt_locations"
2733 // refers to the same object (Array of String). But "bt_locations"
2734 // should have an Array of Thread::Backtrace::Locations.
2735
2736 return exc;
2737}
2738
2739static int
2740ivar_copy_i(st_data_t key, st_data_t val, st_data_t exc)
2741{
2742 rb_ivar_set((VALUE) exc, (ID) key, (VALUE) val);
2743 return ST_CONTINUE;
2744}
2745
2746static VALUE
2747exception_loader(VALUE exc, VALUE obj)
2748{
2749 // The loader function of rb_marshal_define_compat seems to be called for two events:
2750 // one is for fixup (r_fixup_compat), the other is for TYPE_USERDEF.
2751 // In the former case, the first argument is an instance of Exception (because
2752 // we pass rb_eException to rb_marshal_define_compat). In the latter case, the first
2753 // argument is a class object (see TYPE_USERDEF case in r_object0).
2754 // We want to copy all instance variables (but "bt_locations") from obj to exc.
2755 // But we do not want to do so in the second case, so the following branch is for that.
2756 if (RB_TYPE_P(exc, T_CLASS)) return obj; // maybe called from Marshal's TYPE_USERDEF
2757
2758 rb_ivar_foreach(obj, ivar_copy_i, exc);
2759
2760 if (rb_attr_get(exc, id_bt) == rb_attr_get(exc, id_bt_locations)) {
2762 }
2763
2764 return exc;
2765}
2766
2767void
2769{
2771 rb_define_alloc_func(rb_eException, exception_alloc);
2772 rb_marshal_define_compat(rb_eException, rb_eException, exception_dumper, exception_loader);
2774 rb_define_singleton_method(rb_eException, "to_tty?", exc_s_to_tty_p, 0);
2775 rb_define_method(rb_eException, "exception", exc_exception, -1);
2776 rb_define_method(rb_eException, "initialize", exc_initialize, -1);
2777 rb_define_method(rb_eException, "==", exc_equal, 1);
2778 rb_define_method(rb_eException, "to_s", exc_to_s, 0);
2779 rb_define_method(rb_eException, "message", exc_message, 0);
2780 rb_define_method(rb_eException, "full_message", exc_full_message, -1);
2781 rb_define_method(rb_eException, "inspect", exc_inspect, 0);
2782 rb_define_method(rb_eException, "backtrace", exc_backtrace, 0);
2783 rb_define_method(rb_eException, "backtrace_locations", exc_backtrace_locations, 0);
2784 rb_define_method(rb_eException, "set_backtrace", exc_set_backtrace, 1);
2785 rb_define_method(rb_eException, "cause", exc_cause, 0);
2786
2788 rb_define_method(rb_eSystemExit, "initialize", exit_initialize, -1);
2789 rb_define_method(rb_eSystemExit, "status", exit_status, 0);
2790 rb_define_method(rb_eSystemExit, "success?", exit_success_p, 0);
2791
2793 rb_eSignal = rb_define_class("SignalException", rb_eException);
2795
2801 rb_define_method(rb_eKeyError, "initialize", key_err_initialize, -1);
2802 rb_define_method(rb_eKeyError, "receiver", key_err_receiver, 0);
2803 rb_define_method(rb_eKeyError, "key", key_err_key, 0);
2805
2808 rb_define_method(rb_eSyntaxError, "initialize", syntax_error_initialize, -1);
2809
2811 /* the path failed to load */
2812 rb_attr(rb_eLoadError, rb_intern_const("path"), 1, 0, Qfalse);
2813
2814 rb_eNotImpError = rb_define_class("NotImplementedError", rb_eScriptError);
2815
2817 rb_define_method(rb_eNameError, "initialize", name_err_initialize, -1);
2818 rb_define_method(rb_eNameError, "name", name_err_name, 0);
2819 rb_define_method(rb_eNameError, "receiver", name_err_receiver, 0);
2820 rb_define_method(rb_eNameError, "local_variables", name_err_local_variables, 0);
2822 rb_define_alloc_func(rb_cNameErrorMesg, name_err_mesg_alloc);
2823 rb_define_method(rb_cNameErrorMesg, "initialize_copy", name_err_mesg_init_copy, 1);
2824 rb_define_method(rb_cNameErrorMesg, "==", name_err_mesg_equal, 1);
2825 rb_define_method(rb_cNameErrorMesg, "to_str", name_err_mesg_to_str, 0);
2826 rb_define_method(rb_cNameErrorMesg, "_dump", name_err_mesg_dump, 1);
2827 rb_define_singleton_method(rb_cNameErrorMesg, "_load", name_err_mesg_load, 1);
2829 rb_define_method(rb_eNoMethodError, "initialize", nometh_err_initialize, -1);
2830 rb_define_method(rb_eNoMethodError, "args", nometh_err_args, 0);
2831 rb_define_method(rb_eNoMethodError, "private_call?", nometh_err_private_call_p, 0);
2832
2835 rb_define_method(rb_eFrozenError, "initialize", frozen_err_initialize, -1);
2838 rb_eNoMemError = rb_define_class("NoMemoryError", rb_eException);
2842
2843 syserr_tbl = st_init_numtable();
2845 rb_define_method(rb_eSystemCallError, "initialize", syserr_initialize, -1);
2846 rb_define_method(rb_eSystemCallError, "errno", syserr_errno, 0);
2847 rb_define_singleton_method(rb_eSystemCallError, "===", syserr_eqq, 1);
2848
2849 rb_mErrno = rb_define_module("Errno");
2850
2851 rb_mWarning = rb_define_module("Warning");
2852 rb_define_singleton_method(rb_mWarning, "[]", rb_warning_s_aref, 1);
2853 rb_define_singleton_method(rb_mWarning, "[]=", rb_warning_s_aset, 2);
2854 rb_define_method(rb_mWarning, "warn", rb_warning_s_warn, -1);
2855 rb_extend_object(rb_mWarning, rb_mWarning);
2856
2857 /* :nodoc: */
2858 rb_cWarningBuffer = rb_define_class_under(rb_mWarning, "buffer", rb_cString);
2859 rb_define_method(rb_cWarningBuffer, "write", warning_write, -1);
2860
2861 id_cause = rb_intern_const("cause");
2862 id_message = rb_intern_const("message");
2863 id_backtrace = rb_intern_const("backtrace");
2864 id_key = rb_intern_const("key");
2865 id_args = rb_intern_const("args");
2866 id_receiver = rb_intern_const("receiver");
2867 id_private_call_p = rb_intern_const("private_call?");
2868 id_local_variables = rb_intern_const("local_variables");
2869 id_Errno = rb_intern_const("Errno");
2870 id_errno = rb_intern_const("errno");
2871 id_i_path = rb_intern_const("@path");
2872 id_warn = rb_intern_const("warn");
2873 id_category = rb_intern_const("category");
2874 id_deprecated = rb_intern_const("deprecated");
2875 id_experimental = rb_intern_const("experimental");
2876 id_top = rb_intern_const("top");
2877 id_bottom = rb_intern_const("bottom");
2878 id_iseq = rb_make_internal_id();
2879 id_recv = rb_make_internal_id();
2880
2881 sym_category = ID2SYM(id_category);
2882
2883 warning_categories = rb_ident_hash_new();
2884 rb_gc_register_mark_object(warning_categories);
2885 rb_hash_aset(warning_categories, ID2SYM(id_deprecated), INT2NUM(RB_WARN_CATEGORY_DEPRECATED));
2886 rb_hash_aset(warning_categories, ID2SYM(id_experimental), INT2NUM(RB_WARN_CATEGORY_EXPERIMENTAL));
2887 rb_obj_freeze(warning_categories);
2888
2889 warning_category_t_map = rb_ident_hash_new();
2890 rb_gc_register_mark_object(warning_category_t_map);
2891 rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_NONE), Qnil);
2892 rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_DEPRECATED), ID2SYM(id_deprecated));
2893 rb_hash_aset(warning_category_t_map, INT2NUM(RB_WARN_CATEGORY_EXPERIMENTAL), ID2SYM(id_experimental));
2894 rb_obj_freeze(warning_category_t_map);
2895}
2896
2897void
2898rb_enc_raise(rb_encoding *enc, VALUE exc, const char *fmt, ...)
2899{
2900 va_list args;
2901 VALUE mesg;
2902
2903 va_start(args, fmt);
2904 mesg = rb_enc_vsprintf(enc, fmt, args);
2905 va_end(args);
2906
2907 rb_exc_raise(rb_exc_new3(exc, mesg));
2908}
2909
2910void
2911rb_vraise(VALUE exc, const char *fmt, va_list ap)
2912{
2913 rb_exc_raise(rb_exc_new3(exc, rb_vsprintf(fmt, ap)));
2914}
2915
2916void
2917rb_raise(VALUE exc, const char *fmt, ...)
2918{
2919 va_list args;
2920 va_start(args, fmt);
2921 rb_vraise(exc, fmt, args);
2922 va_end(args);
2923}
2924
2925NORETURN(static void raise_loaderror(VALUE path, VALUE mesg));
2926
2927static void
2928raise_loaderror(VALUE path, VALUE mesg)
2929{
2931 rb_ivar_set(err, id_i_path, path);
2933}
2934
2935void
2936rb_loaderror(const char *fmt, ...)
2937{
2938 va_list args;
2939 VALUE mesg;
2940
2941 va_start(args, fmt);
2942 mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2943 va_end(args);
2944 raise_loaderror(Qnil, mesg);
2945}
2946
2947void
2948rb_loaderror_with_path(VALUE path, const char *fmt, ...)
2949{
2950 va_list args;
2951 VALUE mesg;
2952
2953 va_start(args, fmt);
2954 mesg = rb_enc_vsprintf(rb_locale_encoding(), fmt, args);
2955 va_end(args);
2956 raise_loaderror(path, mesg);
2957}
2958
2959void
2961{
2963 "%"PRIsVALUE"() function is unimplemented on this machine",
2965}
2966
2967void
2968rb_fatal(const char *fmt, ...)
2969{
2970 va_list args;
2971 VALUE mesg;
2972
2973 if (! ruby_thread_has_gvl_p()) {
2974 /* The thread has no GVL. Object allocation impossible (cant run GC),
2975 * thus no message can be printed out. */
2976 fprintf(stderr, "[FATAL] rb_fatal() outside of GVL\n");
2978 die();
2979 }
2980
2981 va_start(args, fmt);
2982 mesg = rb_vsprintf(fmt, args);
2983 va_end(args);
2984
2986}
2987
2988static VALUE
2989make_errno_exc(const char *mesg)
2990{
2991 int n = errno;
2992
2993 errno = 0;
2994 if (n == 0) {
2995 rb_bug("rb_sys_fail(%s) - errno == 0", mesg ? mesg : "");
2996 }
2997 return rb_syserr_new(n, mesg);
2998}
2999
3000static VALUE
3001make_errno_exc_str(VALUE mesg)
3002{
3003 int n = errno;
3004
3005 errno = 0;
3006 if (!mesg) mesg = Qnil;
3007 if (n == 0) {
3008 const char *s = !NIL_P(mesg) ? RSTRING_PTR(mesg) : "";
3009 rb_bug("rb_sys_fail_str(%s) - errno == 0", s);
3010 }
3011 return rb_syserr_new_str(n, mesg);
3012}
3013
3014VALUE
3015rb_syserr_new(int n, const char *mesg)
3016{
3017 VALUE arg;
3018 arg = mesg ? rb_str_new2(mesg) : Qnil;
3019 return rb_syserr_new_str(n, arg);
3020}
3021
3022VALUE
3024{
3025 return rb_class_new_instance(1, &arg, get_syserr(n));
3026}
3027
3028void
3029rb_syserr_fail(int e, const char *mesg)
3030{
3031 rb_exc_raise(rb_syserr_new(e, mesg));
3032}
3033
3034void
3036{
3038}
3039
3040void
3041rb_sys_fail(const char *mesg)
3042{
3043 rb_exc_raise(make_errno_exc(mesg));
3044}
3045
3046void
3048{
3049 rb_exc_raise(make_errno_exc_str(mesg));
3050}
3051
3052#ifdef RUBY_FUNCTION_NAME_STRING
3053void
3054rb_sys_fail_path_in(const char *func_name, VALUE path)
3055{
3056 int n = errno;
3057
3058 errno = 0;
3059 rb_syserr_fail_path_in(func_name, n, path);
3060}
3061
3062void
3063rb_syserr_fail_path_in(const char *func_name, int n, VALUE path)
3064{
3065 rb_exc_raise(rb_syserr_new_path_in(func_name, n, path));
3066}
3067
3068VALUE
3069rb_syserr_new_path_in(const char *func_name, int n, VALUE path)
3070{
3071 VALUE args[2];
3072
3073 if (!path) path = Qnil;
3074 if (n == 0) {
3075 const char *s = !NIL_P(path) ? RSTRING_PTR(path) : "";
3076 if (!func_name) func_name = "(null)";
3077 rb_bug("rb_sys_fail_path_in(%s, %s) - errno == 0",
3078 func_name, s);
3079 }
3080 args[0] = path;
3081 args[1] = rb_str_new_cstr(func_name);
3082 return rb_class_new_instance(2, args, get_syserr(n));
3083}
3084#endif
3085
3086void
3087rb_mod_sys_fail(VALUE mod, const char *mesg)
3088{
3089 VALUE exc = make_errno_exc(mesg);
3090 rb_extend_object(exc, mod);
3091 rb_exc_raise(exc);
3092}
3093
3094void
3096{
3097 VALUE exc = make_errno_exc_str(mesg);
3098 rb_extend_object(exc, mod);
3099 rb_exc_raise(exc);
3100}
3101
3102void
3103rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
3104{
3105 VALUE exc = rb_syserr_new(e, mesg);
3106 rb_extend_object(exc, mod);
3107 rb_exc_raise(exc);
3108}
3109
3110void
3112{
3113 VALUE exc = rb_syserr_new_str(e, mesg);
3114 rb_extend_object(exc, mod);
3115 rb_exc_raise(exc);
3116}
3117
3118static void
3119syserr_warning(VALUE mesg, int err)
3120{
3121 rb_str_set_len(mesg, RSTRING_LEN(mesg)-1);
3122 rb_str_catf(mesg, ": %s\n", strerror(err));
3123 rb_write_warning_str(mesg);
3124}
3125
3126#if 0
3127void
3128rb_sys_warn(const char *fmt, ...)
3129{
3130 if (!NIL_P(ruby_verbose)) {
3131 int errno_save = errno;
3132 with_warning_string(mesg, 0, fmt) {
3133 syserr_warning(mesg, errno_save);
3134 }
3135 errno = errno_save;
3136 }
3137}
3138
3139void
3140rb_syserr_warn(int err, const char *fmt, ...)
3141{
3142 if (!NIL_P(ruby_verbose)) {
3143 with_warning_string(mesg, 0, fmt) {
3144 syserr_warning(mesg, err);
3145 }
3146 }
3147}
3148
3149void
3150rb_sys_enc_warn(rb_encoding *enc, const char *fmt, ...)
3151{
3152 if (!NIL_P(ruby_verbose)) {
3153 int errno_save = errno;
3154 with_warning_string(mesg, enc, fmt) {
3155 syserr_warning(mesg, errno_save);
3156 }
3157 errno = errno_save;
3158 }
3159}
3160
3161void
3162rb_syserr_enc_warn(int err, rb_encoding *enc, const char *fmt, ...)
3163{
3164 if (!NIL_P(ruby_verbose)) {
3165 with_warning_string(mesg, enc, fmt) {
3166 syserr_warning(mesg, err);
3167 }
3168 }
3169}
3170#endif
3171
3172void
3173rb_sys_warning(const char *fmt, ...)
3174{
3175 if (RTEST(ruby_verbose)) {
3176 int errno_save = errno;
3177 with_warning_string(mesg, 0, fmt) {
3178 syserr_warning(mesg, errno_save);
3179 }
3180 errno = errno_save;
3181 }
3182}
3183
3184#if 0
3185void
3186rb_syserr_warning(int err, const char *fmt, ...)
3187{
3188 if (RTEST(ruby_verbose)) {
3189 with_warning_string(mesg, 0, fmt) {
3190 syserr_warning(mesg, err);
3191 }
3192 }
3193}
3194#endif
3195
3196void
3197rb_sys_enc_warning(rb_encoding *enc, const char *fmt, ...)
3198{
3199 if (RTEST(ruby_verbose)) {
3200 int errno_save = errno;
3201 with_warning_string(mesg, enc, fmt) {
3202 syserr_warning(mesg, errno_save);
3203 }
3204 errno = errno_save;
3205 }
3206}
3207
3208void
3209rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt, ...)
3210{
3211 if (RTEST(ruby_verbose)) {
3212 with_warning_string(mesg, enc, fmt) {
3213 syserr_warning(mesg, err);
3214 }
3215 }
3216}
3217
3218void
3219rb_load_fail(VALUE path, const char *err)
3220{
3222 rb_str_cat2(mesg, " -- ");
3223 rb_str_append(mesg, path); /* should be ASCII compatible */
3224 raise_loaderror(path, mesg);
3225}
3226
3227void
3228rb_error_frozen(const char *what)
3229{
3230 rb_raise(rb_eFrozenError, "can't modify frozen %s", what);
3231}
3232
3233void
3234rb_frozen_error_raise(VALUE frozen_obj, const char *fmt, ...)
3235{
3236 va_list args;
3237 VALUE exc, mesg;
3238
3239 va_start(args, fmt);
3240 mesg = rb_vsprintf(fmt, args);
3241 va_end(args);
3242 exc = rb_exc_new3(rb_eFrozenError, mesg);
3243 rb_ivar_set(exc, id_recv, frozen_obj);
3244 rb_exc_raise(exc);
3245}
3246
3247static VALUE
3248inspect_frozen_obj(VALUE obj, VALUE mesg, int recur)
3249{
3250 if (recur) {
3251 rb_str_cat_cstr(mesg, " ...");
3252 }
3253 else {
3254 rb_str_append(mesg, rb_inspect(obj));
3255 }
3256 return mesg;
3257}
3258
3259void
3261{
3262 VALUE debug_info;
3263 const ID created_info = id_debug_created_info;
3264 VALUE mesg = rb_sprintf("can't modify frozen %"PRIsVALUE": ",
3265 CLASS_OF(frozen_obj));
3267
3268 rb_ivar_set(exc, id_recv, frozen_obj);
3269 rb_exec_recursive(inspect_frozen_obj, frozen_obj, mesg);
3270
3271 if (!NIL_P(debug_info = rb_attr_get(frozen_obj, created_info))) {
3272 VALUE path = rb_ary_entry(debug_info, 0);
3273 VALUE line = rb_ary_entry(debug_info, 1);
3274
3275 rb_str_catf(mesg, ", created at %"PRIsVALUE":%"PRIsVALUE, path, line);
3276 }
3277 rb_exc_raise(exc);
3278}
3279
3280#undef rb_check_frozen
3281void
3283{
3285}
3286
3287void
3289{
3290 rb_warn_deprecated_to_remove("rb_error_untrusted", "3.2");
3291}
3292
3293#undef rb_check_trusted
3294void
3296{
3297 rb_warn_deprecated_to_remove("rb_check_trusted", "3.2");
3298}
3299
3300void
3302{
3303 if (!FL_ABLE(obj)) return;
3305 if (!FL_ABLE(orig)) return;
3306}
3307
3308void
3310{
3311 rb_eNOERROR = set_syserr(0, "NOERROR");
3312#define defined_error(name, num) set_syserr((num), (name));
3313#define undefined_error(name) set_syserr(0, (name));
3314#include "known_errors.inc"
3315#undef defined_error
3316#undef undefined_error
3317}
3318
3319#include "warning.rbinc"
3320
VALUE rb_ary_new(void)
Definition: array.c:749
VALUE rb_ary_entry(VALUE ary, long offset)
Definition: array.c:1672
#define NORETURN(x)
Definition: attributes.h:152
#define FUNC_MINIMIZED(x)
Definition: attributes.h:126
#define UNREACHABLE_RETURN
Definition: assume.h:31
#define rb_category_warn(category,...)
Definition: bigdecimal.h:163
int bits(struct state *s, int need)
Definition: blast.c:72
int ruby_thread_has_gvl_p(void)
Definition: thread.c:1935
#define rb_define_method(klass, mid, func, arity)
Defines klass#mid.
Definition: cxxanyargs.hpp:653
#define rb_define_singleton_method(klass, mid, func, arity)
Defines klass.mid.
Definition: cxxanyargs.hpp:668
#define mod(x, y)
Definition: date_strftime.c:28
#define recur(fmt)
enum @11::@13::@14 mask
struct RIMemo * ptr
Definition: debug.c:88
char * strchr(char *, char)
#define MJIT_FUNC_EXPORTED
Definition: dllexport.h:55
VALUE rb_cEncoding
Definition: encoding.c:57
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1583
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1549
big_t * num
Definition: enough.c:232
string_t out
Definition: enough.c:230
#define FAKE_CSTR(v, str)
#define INIT_KW(n)
uint8_t len
Definition: escape.c:17
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
#define numberof(array)
Definition: etc.c:649
#define EXIT_FAILURE
Definition: eval_intern.h:32
#define RUBY_EVENT_C_CALL
Definition: event.h:35
#define RUBY_EVENT_C_RETURN
Definition: event.h:36
#define RSTRING_LEN(string)
Definition: fbuffer.h:22
#define RSTRING_PTR(string)
Definition: fbuffer.h:19
#define PRIsVALUE
Definition: function.c:10
VALUE rb_class_allocate_instance(VALUE klass)
Definition: gc.c:2482
void rb_gc_mark_locations(const VALUE *start, const VALUE *end)
Definition: gc.c:5580
void rb_gc_register_mark_object(VALUE obj)
Inform the garbage collector that object is a live Ruby object that should not be moved.
Definition: gc.c:8022
#define CLASS_OF
Definition: globals.h:153
VALUE rb_cString
Definition: string.c:80
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
Definition: eval.c:1730
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:748
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1924
VALUE rb_define_class_under(VALUE outer, const char *name, VALUE super)
Defines a class under the namespace of outer.
Definition: class.c:797
VALUE rb_define_module(const char *name)
Definition: class.c:871
ID rb_frame_this_func(void)
The original name of the current method.
Definition: eval.c:1216
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:2296
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Definition: class.c:2085
#define FL_ABLE
Definition: fl_type.h:121
void rb_notimplement(void)
Definition: error.c:2960
int rb_bug_reporter_add(void(*func)(FILE *, void *), void *data)
Definition: error.c:587
VALUE rb_syntax_error_append(VALUE exc, VALUE file, int line, int column, rb_encoding *enc, const char *fmt, va_list args)
Definition: error.c:125
#define id_bt
Definition: error.c:1086
void rb_syserr_fail(int e, const char *mesg)
Definition: error.c:3029
VALUE rb_get_backtrace(VALUE exc)
Definition: error.c:1365
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2917
void rb_warn_deprecated_to_remove(const char *fmt, const char *removal,...)
Definition: error.c:496
int rb_typeddata_inherited_p(const rb_data_type_t *child, const rb_data_type_t *parent)
Definition: error.c:997
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:1446
void rb_mod_sys_fail_str(VALUE mod, VALUE mesg)
Definition: error.c:3095
void rb_enc_warn(rb_encoding *enc, const char *fmt,...)
Definition: error.c:428
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:351
void rb_sys_enc_warning(rb_encoding *enc, const char *fmt,...)
Definition: error.c:3197
void rb_category_compile_warn(rb_warning_category_t category, const char *file, int line, const char *fmt,...)
Definition: error.c:380
void rb_warning_category_update(unsigned int mask, unsigned int bits)
Definition: error.c:175
VALUE rb_eNotImpError
Definition: error.c:1067
void rb_mod_sys_fail(VALUE mod, const char *mesg)
Definition: error.c:3087
VALUE rb_eScriptError
Definition: error.c:1072
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:712
void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
Definition: eval_error.c:314
#define report_bug_valist(file, line, fmt, ctx, args)
Definition: error.c:734
int rb_typeddata_is_kind_of(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:1007
VALUE rb_eKeyError
Definition: error.c:1060
void rb_bug(const char *fmt,...)
Definition: error.c:768
#define id_mesg
Definition: error.c:1088
VALUE rb_cNameErrorMesg
Definition: error.c:1069
#define with_warning_string(mesg, enc, fmt)
Definition: error.c:401
VALUE rb_eSystemExit
Definition: error.c:1050
void rb_name_error(ID id, const char *fmt,...)
Definition: error.c:1649
#define MAX_BUG_REPORTERS
Definition: error.c:577
void rb_syserr_enc_warning(int err, rb_encoding *enc, const char *fmt,...)
Definition: error.c:3209
#define UNDEF_LEAKED
Definition: error.c:948
void rb_sys_warning(const char *fmt,...)
Definition: error.c:3173
#define id_name
Definition: error.c:1089
VALUE rb_nomethod_err_new(VALUE mesg, VALUE recv, VALUE method, VALUE args, int priv)
Definition: error.c:1809
VALUE rb_syserr_new(int n, const char *mesg)
Definition: error.c:3015
void rb_check_copyable(VALUE obj, VALUE orig)
Definition: error.c:3301
VALUE rb_eStandardError
Definition: error.c:1054
VALUE rb_mErrno
Definition: error.c:1077
VALUE rb_syserr_new_str(int n, VALUE arg)
Definition: error.c:3023
void rb_error_frozen(const char *what)
Definition: error.c:3228
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
Definition: eval.c:1925
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:3035
VALUE rb_ident_hash_new(void)
Definition: hash.c:4443
const char * rb_builtin_type_name(int t)
Definition: error.c:890
VALUE rb_warning_string(const char *fmt,...)
Definition: error.c:460
VALUE rb_eFrozenError
Definition: error.c:1056
void rb_sys_fail_str(VALUE mesg)
Definition: error.c:3047
VALUE rb_eNoMemError
Definition: error.c:1068
VALUE rb_eRangeError
Definition: error.c:1061
void Init_Exception(void)
Definition: error.c:2768
void rb_error_untrusted(VALUE obj)
Definition: error.c:3288
VALUE rb_eLoadError
Definition: error.c:1074
VALUE rb_eTypeError
Definition: error.c:1057
VALUE rb_iseqw_local_variables(VALUE iseqval)
Definition: iseq.c:3385
VALUE rb_eNoMatchingPatternError
Definition: error.c:1070
void rb_name_error_str(VALUE str, const char *fmt,...)
Definition: error.c:1664
void rb_fatal(const char *fmt,...)
Definition: error.c:2968
#define EXIT_SUCCESS
Definition: error.c:52
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Definition: error.c:3234
VALUE rb_eEncCompatError
Definition: error.c:1064
void rb_vraise(VALUE exc, const char *fmt, va_list ap)
Definition: error.c:2911
#define WEXITSTATUS(status)
Definition: error.c:60
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
Definition: eval.c:1105
void rb_load_fail(VALUE path, const char *err)
Definition: error.c:3219
void rb_unexpected_type(VALUE x, int t)
Definition: error.c:987
VALUE rb_eFatal
Definition: error.c:1053
#define report_bug(file, line, fmt, ctx)
Definition: error.c:725
void rb_invalid_str(const char *str, const char *type)
Definition: error.c:2045
VALUE rb_eInterrupt
Definition: error.c:1051
VALUE rb_eNameError
Definition: error.c:1062
const char * rb_builtin_class_name(VALUE x)
Definition: error.c:937
void Init_syserr(void)
Definition: error.c:3309
VALUE rb_eNoMethodError
Definition: error.c:1065
void rb_category_warning(rb_warning_category_t category, const char *fmt,...)
Definition: error.c:450
void rb_warn_deprecated(const char *fmt, const char *suggest,...)
Definition: error.c:480
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
Definition: eval.c:728
void rb_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:796
VALUE rb_ec_backtrace_location_ary(const rb_execution_context_t *ec, long lev, long n, bool skip_internal)
Definition: vm_backtrace.c:898
void rb_bug_without_die(const char *fmt, va_list args)
Definition: error.c:755
VALUE rb_eRuntimeError
Definition: error.c:1055
VALUE rb_name_err_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1728
#define id_bt_locations
Definition: error.c:1087
void * rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
Definition: error.c:1024
void rb_bug_for_fatal_signal(ruby_sighandler_t default_sighandler, int sig, const void *ctx, const char *fmt,...)
Definition: error.c:778
void rb_warn(const char *fmt,...)
Definition: error.c:408
#define WIFEXITED(status)
Definition: error.c:56
rb_warning_category_t rb_warning_category_from_name(VALUE category)
Definition: error.c:163
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:1094
void rb_error_frozen_object(VALUE frozen_obj)
Definition: error.c:3260
VALUE rb_exc_new_str(VALUE etype, VALUE str)
Definition: error.c:1107
VALUE rb_eArgError
Definition: error.c:1058
void rb_assert_failure(const char *file, int line, const char *name, const char *expr)
Definition: error.c:845
void rb_compile_warning(const char *file, int line, const char *fmt,...)
Definition: error.c:366
void rb_mod_syserr_fail(VALUE mod, int e, const char *mesg)
Definition: error.c:3103
void rb_loaderror(const char *fmt,...)
Definition: error.c:2936
VALUE rb_eException
Definition: error.c:1049
VALUE rb_iseqw_new(const rb_iseq_t *)
Definition: iseq.c:1217
VALUE rb_eIndexError
Definition: error.c:1059
VALUE rb_get_message(VALUE exc)
Definition: error.c:1187
void rb_loaderror_with_path(VALUE path, const char *fmt,...)
Definition: error.c:2948
VALUE rb_eEAGAIN
Definition: error.c:69
long rb_backtrace_length_limit
Definition: error.c:68
void rb_report_bug_valist(VALUE file, int line, const char *fmt, va_list args)
Definition: error.c:839
VALUE rb_eEINPROGRESS
Definition: error.c:71
void rb_async_bug_errno(const char *mesg, int errno_arg)
Definition: error.c:817
VALUE rb_eSyntaxError
Definition: error.c:1073
VALUE rb_eEncodingError
Definition: error.c:1063
#define REPORT_BUG_BUFSIZ
Definition: error.c:601
#define write_or_abort(fd, str, len)
Definition: error.c:813
VALUE rb_eSecurityError
Definition: error.c:1066
bool rb_warning_category_enabled_p(rb_warning_category_t category)
Definition: error.c:182
int rb_str_end_with_asciichar(VALUE str, int c)
Definition: io.c:7833
#define id_cause
Definition: error.c:1081
const char ruby_description[]
Definition: version.c:43
void rb_sys_fail(const char *mesg)
Definition: error.c:3041
#define frozen_err_receiver
Definition: error.c:1646
void rb_mod_syserr_fail_str(VALUE mod, int e, VALUE mesg)
Definition: error.c:3111
ID ruby_static_id_cause
Definition: error.c:1080
#define name_err_mesg_free
Definition: error.c:1831
VALUE rb_eEWOULDBLOCK
Definition: error.c:70
void rb_check_type(VALUE x, int t)
Definition: error.c:972
VALUE rb_eSystemCallError
Definition: error.c:1076
#define WRITE_CONST(fd, str)
Definition: error.c:814
void rb_warning(const char *fmt,...)
Definition: error.c:439
VALUE rb_eSignal
Definition: error.c:1052
VALUE rb_key_err_new(VALUE mesg, VALUE recv, VALUE key)
Definition: error.c:2087
@ NAME_ERR_MESG__MESG
Definition: error.c:1818
@ NAME_ERR_MESG_COUNT
Definition: error.c:1821
@ NAME_ERR_MESG__RECV
Definition: error.c:1819
@ NAME_ERR_MESG__NAME
Definition: error.c:1820
VALUE rb_check_to_int(VALUE)
Tries to convert val into Integer.
Definition: object.c:3066
VALUE rb_cObject
Object class.
Definition: object.c:49
VALUE rb_any_to_s(VALUE)
Default implementation of #to_s.
Definition: object.c:561
VALUE rb_obj_alloc(VALUE)
Allocates an instance of klass.
Definition: object.c:1900
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Allocates and initializes an instance of klass.
Definition: object.c:1953
VALUE rb_obj_init_copy(VALUE, VALUE)
Default implementation of #initialize_copy.
Definition: object.c:516
VALUE rb_obj_class(VALUE)
Definition: object.c:245
VALUE rb_inspect(VALUE)
Convenient wrapper of Object::inspect.
Definition: object.c:585
VALUE rb_equal(VALUE, VALUE)
This function is an optimized version of calling #==.
Definition: object.c:157
VALUE rb_obj_clone(VALUE)
Almost same as Object::clone.
Definition: object.c:457
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:724
VALUE rb_obj_freeze(VALUE)
Make the object unmodifiable.
Definition: object.c:1101
VALUE rb_String(VALUE)
Equivalent to Kernel#String in Ruby.
Definition: object.c:3673
VALUE rb_hash_fetch(VALUE hash, VALUE key)
Definition: hash.c:2138
VALUE rb_hash_aref(VALUE hash, VALUE key)
Definition: hash.c:2046
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:2901
VALUE rb_hash_new(void)
Definition: hash.c:1538
@ id_debug_created_info
Definition: id.h:129
VALUE rb_enc_str_new_cstr(const char *, rb_encoding *)
Definition: string.c:897
VALUE rb_enc_vsprintf(rb_encoding *, const char *, va_list)
Definition: sprintf.c:1151
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:857
Thin wrapper to ruby/config.h.
rb_warning_category_t
Definition: error.h:32
@ RB_WARN_CATEGORY_DEPRECATED
Definition: error.h:34
@ RB_WARN_CATEGORY_EXPERIMENTAL
Definition: error.h:35
@ RB_WARN_CATEGORY_NONE
Definition: error.h:33
#define ruby_verbose
Definition: error.h:68
VALUE rb_call_super_kw(int, const VALUE *, int)
Definition: vm_eval.c:290
VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE *, int)
Definition: vm_eval.c:1030
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:1077
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:298
Defines RBIMPL_HAS_BUILTIN.
#define rb_ary_new3
Definition: array.h:73
#define rb_check_frozen
Definition: error.h:72
#define rb_check_frozen_internal(obj)
Definition: error.h:58
#define rb_exc_new3
Definition: error.h:31
#define rb_check_trusted
Definition: error.h:32
#define rb_check_arity
Definition: error.h:34
VALUE rb_io_puts(int, const VALUE *, VALUE)
Definition: io.c:7895
#define rb_str_new2
Definition: string.h:276
void rb_must_asciicompat(VALUE)
Definition: string.c:2314
#define rb_str_cat2
Definition: string.h:285
#define rb_str_buf_new2
Definition: string.h:281
#define rb_str_new(str, len)
Definition: string.h:213
#define rb_str_buf_cat
Definition: string.h:283
#define rb_exc_new_cstr(exc, str)
Definition: string.h:271
void rb_str_set_len(VALUE, long)
Definition: string.c:2842
VALUE rb_check_string_type(VALUE)
Definition: string.c:2462
#define rb_str_buf_new_cstr(str)
Definition: string.h:261
VALUE rb_str_tmp_new(long)
Definition: string.c:1427
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:3118
VALUE rb_str_buf_append(VALUE, VALUE)
Definition: string.c:3103
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1529
#define rb_str_cat_cstr(buf, str)
Definition: string.h:266
#define rb_str_new_cstr(str)
Definition: string.h:219
VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int), VALUE, VALUE)
Definition: thread.c:5360
VALUE rb_class_name(VALUE)
Definition: variable.c:293
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:2624
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1242
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1493
void rb_attr(VALUE, ID, int, int, int)
Definition: vm_method.c:1508
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:619
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:2561
void rb_define_alloc_func(VALUE, rb_alloc_func_t)
#define ID2SYM
Definition: symbol.h:44
const char * rb_id2name(ID)
Definition: symbol.c:944
#define SYM2ID
Definition: symbol.h:45
ID rb_intern(const char *)
Definition: symbol.c:785
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:1069
void rb_define_const(VALUE, const char *, VALUE)
Definition: variable.c:3150
char * strerror(int)
Definition: strerror.c:11
#define NUM2INT
Definition: int.h:44
#define INT2NUM
Definition: int.h:43
#define rb_typeddata_is_instance_of
Definition: error.h:71
#define id_status
Definition: eval.h:17
Internal header for IO.
int rb_stderr_tty_p(void)
Definition: io.c:8105
Internal header for require.
Internal header for Object.
#define rb_fstring_lit(str)
Definition: string.h:78
VALUE rb_to_symbol_type(VALUE obj)
Definition: symbol.c:1211
ID rb_make_internal_id(void)
Definition: symbol.c:953
Internal header for Thread.
VALUE rb_ivar_lookup(VALUE obj, ID id, VALUE undef)
Definition: variable.c:1192
void rb_print_backtrace(void)
Definition: vm_dump.c:753
VALUE rb_backtrace_to_str_ary(VALUE obj)
Definition: vm_backtrace.c:809
int rb_backtrace_p(VALUE obj)
Definition: vm_backtrace.c:471
VALUE rb_backtrace_to_location_ary(VALUE obj)
Definition: vm_backtrace.c:864
const char * rb_source_location_cstr(int *pline)
Definition: vm.c:1616
#define rb_fstring_cstr(...)
Definition: internal.h:71
#define rb_funcallv(...)
Definition: internal.h:77
#define rb_method_basic_definition_p(...)
Definition: internal.h:78
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
voidpf void * buf
Definition: ioapi.h:138
#define INT2FIX
Definition: long.h:48
#define NUM2LONG
Definition: long.h:51
void rb_marshal_define_compat(VALUE newclass, VALUE oldclass, VALUE(*dumper)(VALUE), VALUE(*loader)(VALUE, VALUE))
Definition: marshal.c:146
#define T_MASK
Definition: md5.c:131
#define MEMCPY(p1, p2, type, n)
Definition: memory.h:129
#define ALLOC_N
Definition: memory.h:133
const rb_method_entry_t * rb_method_entry(VALUE klass, ID id)
Definition: vm_method.c:1023
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:2684
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition: cxxanyargs.hpp:56
void rb_ivar_foreach(VALUE q, int_type *w, VALUE e)
Iteration over each instance variable of the object.
Definition: cxxanyargs.hpp:496
const char * name
Definition: nkf.c:208
#define TRUE
Definition: nkf.h:175
#define rb_enc_raise
Definition: parser.c:21
#define RARRAY_CONST_PTR(s)
Definition: psych_emitter.c:4
#define RARRAY_AREF(a, i)
Definition: psych_emitter.c:7
#define RARRAY_LEN
Definition: rarray.h:52
#define DATA_PTR(obj)
Definition: rdata.h:56
#define NULL
Definition: regenc.h:69
#define StringValue(v)
Definition: rstring.h:50
char * rb_string_value_ptr(volatile VALUE *)
Definition: string.c:2334
#define RTYPEDDATA_DATA(v)
Definition: rtypeddata.h:47
#define TypedData_Get_Struct(obj, type, data_type, sval)
Definition: rtypeddata.h:130
#define TypedData_Wrap_Struct(klass, data_type, sval)
Definition: rtypeddata.h:101
@ RUBY_TYPED_FREE_IMMEDIATELY
Definition: rtypeddata.h:62
const char * rb_obj_classname(VALUE)
Definition: variable.c:308
int argc
Definition: ruby.c:240
char ** argv
Definition: ruby.c:241
#define EWOULDBLOCK
Definition: rubysocket.h:164
#define RB_PASS_KEYWORDS
Definition: scan_args.h:47
#define RB_PASS_CALLED_KEYWORDS
Definition: scan_args.h:48
#define Qundef
#define Qtrue
#define RTEST
#define Qnil
#define Qfalse
#define NIL_P
#define FIXNUM_P
VALUE rb_vsprintf(const char *, va_list)
Definition: sprintf.c:1197
VALUE rb_str_vcatf(VALUE, const char *, va_list)
Definition: sprintf.c:1216
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:214
VALUE rb_str_catf(VALUE, const char *,...)
Definition: sprintf.c:1243
VALUE rb_sprintf(const char *,...)
Definition: sprintf.c:1203
@ ST_CONTINUE
Definition: st.h:99
unsigned long st_data_t
Definition: st.h:22
#define st_init_numtable
Definition: st.h:106
#define st_lookup
Definition: st.h:128
#define st_add_direct
Definition: st.h:154
Defines old _.
size_t strlen(const char *)
Definition: gzappend.c:170
const rb_iseq_t * iseq
Definition: vm_core.h:772
const rb_data_type_t * parent
Definition: rtypeddata.h:80
const char * wrap_struct_name
Definition: rtypeddata.h:71
rb_control_frame_t * cfp
Definition: vm_core.h:858
Definition: method.h:54
Definition: st.h:79
Definition: blast.c:41
#define vsnprintf
Definition: subst.h:15
#define snprintf
Definition: subst.h:14
#define t
Definition: symbol.c:253
void error(const char *msg)
Definition: untgz.c:593
unsigned long VALUE
Definition: value.h:38
unsigned long ID
Definition: value.h:39
#define TYPE(_)
Definition: value_type.h:105
#define T_STRING
Definition: value_type.h:77
#define T_DATA
Definition: value_type.h:59
#define T_MODULE
Definition: value_type.h:69
#define T_TRUE
Definition: value_type.h:80
#define T_FALSE
Definition: value_type.h:60
#define T_ARRAY
Definition: value_type.h:55
#define T_OBJECT
Definition: value_type.h:74
#define T_SYMBOL
Definition: value_type.h:79
#define T_CLASS
Definition: value_type.h:57
#define SYMBOL_P
Definition: value_type.h:87
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
Definition: vm.c:589
#define rb_id2str(id)
Definition: vm_backtrace.c:30
void(* ruby_sighandler_t)(int)
Definition: vm_core.h:1650
void rb_vm_bugreport(const void *)
Definition: vm_dump.c:962
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:2001
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1392
#define fileno(p)
Definition: vsnprintf.c:219
int err
Definition: win32.c:142
#define EINPROGRESS
Definition: win32.h:471
void rb_write_error_str(VALUE mesg)
Definition: io.c:8083