Ruby
2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
|
Go to the documentation of this file.
6 #define write_warn(str, x) \
7 (NIL_P(str) ? warn_print(x) : (void)rb_str_cat_cstr(str, x))
8 #define write_warn2(str, x, l) \
9 (NIL_P(str) ? warn_print2(x, l) : (void)rb_str_cat(str, x, l))
10 #ifdef HAVE_BUILTIN___BUILTIN_CONSTANT_P
11 #define warn_print(x) RB_GNUC_EXTENSION_BLOCK( \
12 (__builtin_constant_p(x)) ? \
13 rb_write_error2((x), (long)strlen(x)) : \
17 #define warn_print(x) rb_write_error(x)
20 #define warn_print2(x,l) rb_write_error2((x),(l))
22 #define write_warn_str(str,x) NIL_P(str) ? rb_write_error_str(x) : (void)rb_str_concat((str), (x))
23 #define warn_print_str(x) rb_write_error_str(x)
25 static VALUE error_pos_str(
void);
30 VALUE pos = error_pos_str();
42 if (!
NIL_P(sourcefile)) {
44 if (sourceline == 0) {
49 sourcefile, sourceline,
86 const char *beg =
ptr;
87 const long olen =
len;
89 unsigned char c = *
ptr;
91 case '\n':
case '\t':
continue;
106 else if (c ==
'\\') {
123 #define CSI_BEGIN "\033["
133 const char *einfo =
"";
171 const char *tail = 0;
176 if ((tail =
memchr(einfo,
'\n', elen)) != 0) {
177 write_warnq(
str, emesg, einfo, tail - einfo);
181 write_warnq(
str, emesg, einfo, elen);
195 if (tail && einfo+elen > tail) {
197 write_warnq(
str, emesg, tail, einfo+elen-tail);
201 elen -= tail - einfo;
204 tail =
memchr(einfo,
'\n', elen);
205 if (!tail || tail > einfo) {
207 write_warnq(
str, emesg, einfo, tail ? tail-einfo : elen);
214 elen -= tail - einfo;
216 do ++tail;
while (tail < einfo+elen && *tail ==
'\n');
217 write_warnq(
str, emesg, einfo, tail-einfo);
218 elen -= tail - einfo;
237 const int threshold = 1000000000;
239 ((
len - 1) / threshold) :
241 (
len < threshold ? 0 : 9) + 1);
243 #define TRACE_MAX (TRACE_HEAD+TRACE_TAIL+5)
247 for (
i = 1;
i <
len;
i++) {
266 shown_cause_p(
VALUE cause,
VALUE *shown_causes)
268 VALUE shown = *shown_causes;
282 !shown_cause_p(cause, shown_causes)) {
287 show_cause(cause,
str, highlight, reverse, shown_causes);
288 print_backtrace(eclass, errat,
str,
TRUE);
289 print_errinfo(eclass, errat, emesg,
str, highlight!=0);
292 print_errinfo(eclass, errat, emesg,
str, highlight!=0);
293 print_backtrace(eclass, errat,
str,
FALSE);
294 show_cause(cause,
str, highlight, reverse, shown_causes);
302 volatile VALUE eclass;
303 VALUE shown_causes = 0;
314 if (
NIL_P(reverse)) reverse = tty;
315 if (
NIL_P(highlight)) highlight = tty;
318 static const char traceback[] =
"Traceback "
319 "(most recent call last):\n";
321 char buff[
sizeof(traceback)+
sizeof(bold)+
sizeof(reset)-2], *p = buff;
322 const char *msg = traceback;
323 long len =
sizeof(traceback) - 1;
325 #define APPEND(s, l) (memcpy(p, s, l), p += (l))
326 APPEND(bold,
sizeof(bold)-1);
327 APPEND(traceback, bold_part);
328 APPEND(reset,
sizeof(reset)-1);
329 APPEND(traceback + bold_part,
sizeof(traceback)-bold_part-1);
331 len = p - (msg = buff);
334 show_cause(errinfo,
str, highlight, reverse, &shown_causes);
335 print_backtrace(eclass, errat,
str,
TRUE);
336 print_errinfo(eclass, errat, emesg,
str, highlight!=0);
339 print_errinfo(eclass, errat, emesg,
str, highlight!=0);
340 print_backtrace(eclass, errat,
str,
FALSE);
341 show_cause(errinfo,
str, highlight, reverse, &shown_causes);
372 #define undef_mesg_for(v, k) rb_fstring_lit("undefined"v" method `%1$s' for "k" `%2$s'")
373 #define undef_mesg(v) ( \
375 undef_mesg_for(v, "module") : \
376 undef_mesg_for(v, "class"))
400 #define inaccessible_mesg_for(v, k) rb_fstring_lit("method `%1$s' for "k" `%2$s' is "v)
401 #define inaccessible_mesg(v) ( \
403 inaccessible_mesg_for(v, "module") : \
404 inaccessible_mesg_for(v, "class"))
428 #define unknown_longjmp_status(status) \
429 rb_bug("Unknown longjmp status %d", status)
461 warn_print(
"retry outside of rescue clause\n");
471 status = sysexit_status(errinfo);
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
void rb_ec_error_print(rb_execution_context_t *volatile ec, volatile VALUE errinfo)
VALUE rb_obj_hide(VALUE obj)
Make the object invisible from Ruby code.
#define rb_ec_raised_clear(ec)
VALUE rb_ident_hash_new(void)
void rb_print_undef(VALUE klass, ID id, rb_method_visibility_t visi)
VALUE rb_attr_get(VALUE, ID)
#define RB_TYPE_P(obj, type)
void rb_error_write(VALUE errinfo, VALUE emesg, VALUE errat, VALUE str, VALUE highlight, VALUE reverse)
int rb_stderr_tty_p(void)
void rb_write_error2(const char *, long)
size_t strlen(const char *)
MJIT_FUNC_EXPORTED VALUE rb_hash_has_key(VALUE hash, VALUE key)
VALUE rb_ivar_get(VALUE, ID)
VALUE rb_backtrace_to_str_ary(VALUE obj)
#define write_warn2(str, x, l)
VALUE rb_obj_is_instance_of(VALUE, VALUE)
Determines if obj is an instance of c.
VALUE rb_get_message(VALUE exc)
void rb_print_inaccessible(VALUE klass, ID id, rb_method_visibility_t visi)
int rb_ec_set_raised(rb_execution_context_t *ec)
#define RARRAY_AREF(a, i)
#define rb_ec_raised_set(ec, f)
ID rb_frame_callee(void)
The name of the current method.
#define unknown_longjmp_status(status)
unsigned char buf[MIME_BUF_SIZE]
int rb_backtrace_p(VALUE obj)
RUBY_EXTERN void rb_write_error_str(VALUE mesg)
VALUE rb_sprintf(const char *format,...)
#define inaccessible_mesg(v)
void rb_print_undef_str(VALUE klass, VALUE name)
char str[HTML_ESCAPE_MAX_LEN+1]
const char * ruby_escaped_char(int c)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
#define rb_name_err_raise_str(mesg, recv, name)
#define write_warn_str(str, x)
VALUE rb_str_catf(VALUE str, const char *format,...)
VALUE rb_get_backtrace(VALUE exc)
int rb_ec_reset_raised(rb_execution_context_t *ec)
VALUE rb_class_name(VALUE)
#define rb_strlen_lit(str)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
MJIT_FUNC_EXPORTED VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
#define write_warn(str, x)
VALUE rb_source_location(int *pline)