6
$Date: 2007-05-02 06:45:48 +0900 (水, 02 5月 2007) $
6
$Date: 2007-08-25 12:29:39 +0900 (土, 25 8月 2007) $
7
7
created at: Mon Aug 9 16:11:34 JST 1993
9
Copyright (C) 1993-2003 Yukihiro Matsumoto
9
Copyright (C) 1993-2007 Yukihiro Matsumoto
11
11
**********************************************************************/
13
#include "ruby/ruby.h"
18
18
#include <stdarg.h>
26
26
extern const char ruby_version[], ruby_release_date[], ruby_platform[];
29
const char *rb_sourcefile(void);
30
int rb_sourceline(void);
33
err_position_0(char *buf, long len, const char *file, long line)
29
err_position_0(char *buf, long len, const char *file, int line)
49
45
return err_position_0(buf, len, rb_sourcefile(), rb_sourceline());
53
compile_position(char *buf, long len)
55
ruby_set_current_source();
56
return err_position_0(buf, len, ruby_sourcefile, ruby_sourceline);
60
49
err_snprintf(char *buf, long len, const char *fmt, va_list args)
71
compile_snprintf(char *buf, long len, const char *fmt, va_list args)
60
compile_snprintf(char *buf, long len, const char *file, int line, const char *fmt, va_list args)
75
n = compile_position(buf, len);
64
n = err_position_0(buf, len, file, line);
77
66
vsnprintf((char*)buf+n, len-n, fmt, args);
81
70
static void err_append(const char*);
84
rb_compile_error(const char *fmt, ...)
73
rb_compile_error(const char *file, int line, const char *fmt, ...)
89
78
va_start(args, fmt);
90
compile_snprintf(buf, BUFSIZ, fmt, args);
79
compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
109
compile_warn_print(const char *fmt, va_list args)
97
compile_warn_print(const char *file, int line, const char *fmt, va_list args)
114
compile_snprintf(buf, BUFSIZ, fmt, args);
102
compile_snprintf(buf, BUFSIZ, file, line, fmt, args);
115
103
len = strlen(buf);
116
104
buf[len++] = '\n';
117
105
rb_write_error2(buf, len);
121
rb_compile_warn(const char *fmt, ...)
109
rb_compile_warn(const char *file, int line, const char *fmt, ...)
123
111
char buf[BUFSIZ];
128
116
snprintf(buf, BUFSIZ, "warning: %s", fmt);
130
118
va_start(args, fmt);
131
compile_warn_print(buf, args);
119
compile_warn_print(file, line, buf, args);
135
123
/* rb_compile_warning() reports only in verbose mode */
137
rb_compile_warning(const char *fmt, ...)
125
rb_compile_warning(const char *file, int line, const char *fmt, ...)
139
127
char buf[BUFSIZ];
144
132
snprintf(buf, BUFSIZ, "warning: %s", fmt);
146
134
va_start(args, fmt);
147
compile_warn_print(buf, args);
135
compile_warn_print(file, line, buf, args);
200
void rb_vm_bugreport(void);
215
rb_bug(const char *fmt, ...)
203
report_bug(const char *file, int line, const char *fmt, va_list args)
217
205
char buf[BUFSIZ];
219
206
FILE *out = stderr;
220
int len = err_position(buf, BUFSIZ);
207
int len = err_position_0(buf, BUFSIZ, file, line);
222
209
if (fwrite(buf, 1, len, out) == len ||
223
210
fwrite(buf, 1, len, (out = stdout)) == len) {
225
212
fputs("[BUG] ", out);
227
213
vfprintf(out, fmt, args);
229
214
fprintf(out, "\nruby %s (%s) [%s]\n\n",
230
215
ruby_version, ruby_release_date, ruby_platform);
220
rb_bug(const char *fmt, ...)
225
report_bug(rb_sourcefile(), rb_sourceline(), fmt, args);
232
rb_compile_bug(const char *file, int line, const char *fmt, ...)
237
report_bug(file, line, fmt, args);
489
496
exc_backtrace(VALUE exc)
491
ID bt = rb_intern("bt");
493
if (!rb_ivar_defined(exc, bt)) return Qnil;
494
return rb_ivar_get(exc, bt);
500
if (!bt) bt = rb_intern("bt");
501
return rb_attr_get(exc, bt);
498
check_backtrace(VALUE bt)
505
rb_check_backtrace(VALUE bt)
501
508
static const char *err = "backtrace must be Array of String";
530
537
exc_set_backtrace(VALUE exc, VALUE bt)
532
return rb_iv_set(exc, "bt", check_backtrace(bt));
539
return rb_iv_set(exc, "bt", rb_check_backtrace(bt));
1535
1542
err_append(const char *s)
1537
1544
rb_thread_t *th = GET_THREAD();
1545
VALUE err = th->errinfo;
1538
1547
if (th->parse_in_eval) {
1539
if (NIL_P(th->errinfo)) {
1540
th->errinfo = rb_exc_new2(rb_eSyntaxError, s);
1549
err = rb_exc_new2(rb_eSyntaxError, s);
1543
VALUE str = rb_obj_as_string(GET_THREAD()->errinfo);
1553
VALUE str = rb_obj_as_string(err);
1545
1555
rb_str_cat2(str, "\n");
1546
1556
rb_str_cat2(str, s);