Skip to content

HTTPS clone URL

Subversion checkout URL

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