Skip to content
Newer
Older
100644 198 lines (176 sloc) 3.85 KB
9595725 update copyrights to 2011
Laurent Sansonetti authored Jan 15, 2011
1 /*
2 * This file is covered by the Ruby license. See COPYING for more details.
3 *
4 * Copyright (C) 2007-2011, Apple Inc. All rights reserved.
5 * Copyright (C) 1993-2007 Yukihiro Matsumoto
6 * Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
7 * Copyright (C) 2000 Information-technology Promotion Agency, Japan
8 */
9
9c1d230 committing experimental branch content
Laurent Sansonetti authored Mar 11, 2009
10 /*
11 * included by eval.c
12 */
13
14 #if 0
15 static void
16 warn_printf(const char *fmt, ...)
17 {
18 char buf[BUFSIZ];
19 va_list args;
20
21 va_init_list(args, fmt);
22 vsnprintf(buf, BUFSIZ, fmt, args);
23 va_end(args);
24 rb_write_error(buf);
25 }
26 #endif
27
28 #define warn_print(x) rb_write_error(x)
29 #define warn_print2(x,l) rb_write_error2(x,l)
30
31 VALUE rb_check_backtrace(VALUE);
32
33 static VALUE
34 get_backtrace(VALUE info)
35 {
36 if (NIL_P(info)) {
37 return Qnil;
38 }
39 info = rb_funcall(info, rb_intern("backtrace"), 0);
40 if (NIL_P(info)) {
41 return Qnil;
42 }
43 return rb_check_backtrace(info);
44 }
45
46 VALUE
47 rb_get_backtrace(VALUE info)
48 {
49 return get_backtrace(info);
50 }
51
52 static void
53 set_backtrace(VALUE info, VALUE bt)
54 {
55 rb_funcall(info, rb_intern("set_backtrace"), 1, bt);
56 }
57
58 static void
59 error_print(void)
60 {
61 #if 0
62 VALUE errat = Qnil; /* OK */
63 VALUE errinfo = GET_THREAD()->errinfo;
64 volatile VALUE eclass, e;
65 const char *einfo;
66 long elen;
67
68 if (NIL_P(errinfo))
69 return;
70
71 PUSH_TAG();
72 if (EXEC_TAG() == 0) {
73 errat = get_backtrace(errinfo);
74 }
75 else {
76 errat = Qnil;
77 }
78 if (EXEC_TAG())
79 goto error;
80 if (NIL_P(errat)) {
81 const char *file = rb_sourcefile();
82 int line = rb_sourceline();
83 if (file)
84 warn_printf("%s:%d", file, line);
85 else
86 warn_printf("%d", line);
87 }
88 else if (RARRAY_LEN(errat) == 0) {
89 error_pos();
90 }
91 else {
92 VALUE mesg = RARRAY_AT(errat, 0);
93
94 if (NIL_P(mesg))
95 error_pos();
96 else {
97 warn_print2(RSTRING_PTR(mesg), RSTRING_LEN(mesg));
98 }
99 }
100
101 eclass = CLASS_OF(errinfo);
102 if (EXEC_TAG() == 0) {
103 e = rb_funcall(errinfo, rb_intern("message"), 0, 0);
104 StringValue(e);
105 einfo = RSTRING_PTR(e);
106 elen = RSTRING_LEN(e);
107 }
108 else {
109 einfo = "";
110 elen = 0;
111 }
112 if (EXEC_TAG())
113 goto error;
114 if (eclass == rb_eRuntimeError && elen == 0) {
115 warn_print(": unhandled exception\n");
116 }
117 else {
118 VALUE epath;
119
120 epath = rb_class_name(eclass);
121 if (elen == 0) {
122 warn_print(": ");
123 warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
124 warn_print("\n");
125 }
126 else {
127 char *tail = 0;
128 long len = elen;
129
130 if (RSTRING_PTR(epath)[0] == '#')
131 epath = 0;
132 if ((tail = memchr(einfo, '\n', elen)) != 0) {
133 len = tail - einfo;
134 tail++; /* skip newline */
135 }
136 warn_print(": ");
137 warn_print2(einfo, len);
138 if (epath) {
139 warn_print(" (");
140 warn_print2(RSTRING_PTR(epath), RSTRING_LEN(epath));
141 warn_print(")\n");
142 }
143 if (tail) {
144 warn_print2(tail, elen - len - 1);
145 if (einfo[elen-1] != '\n') warn_print2("\n", 1);
146 }
147 }
148 }
149
150 if (!NIL_P(errat)) {
151 long i;
152 long len = RARRAY_LEN(errat);
153 int skip = eclass == rb_eSysStackError;
154
155 #define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
156 #define TRACE_HEAD 8
157 #define TRACE_TAIL 5
158
159 for (i = 1; i < len; i++) {
160 VALUE v = RARRAY_AT(errat, i);
161 if (TYPE(v) == T_STRING) {
162 warn_printf("\tfrom %s\n", RSTRING_PTR(v));
163 }
164 if (skip && i == TRACE_HEAD && len > TRACE_MAX) {
165 warn_printf("\t ... %ld levels...\n",
166 len - TRACE_HEAD - TRACE_TAIL);
167 i = len - TRACE_TAIL;
168 }
169 }
170 }
171 error:
172 POP_TAG();
173 #endif
174 }
175
176 void
177 ruby_error_print(void)
178 {
179 error_print();
180 }
181
182 void
183 rb_print_undef(VALUE klass, ID id, int scope)
184 {
185 const char *v;
186
187 switch (scope) {
188 default:
189 case NOEX_PUBLIC: v = ""; break;
190 case NOEX_PRIVATE: v = " private"; break;
191 case NOEX_PROTECTED: v = " protected"; break;
192 }
193 rb_name_error(id, "undefined%s method `%s' for %s `%s'", v,
194 rb_id2name(id),
195 (TYPE(klass) == T_MODULE) ? "module" : "class",
196 rb_class2name(klass));
197 }
Something went wrong with that request. Please try again.