Skip to content

HTTPS clone URL

Subversion checkout URL

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