Remove class info from backtrace lines.
MODIFY
include/mruby.h
include/mruby.h
@@ -155,8 +155,6 @@ struct mrb_jmpbuf;
typedef struct {
const char *filename;
int lineno;
- struct RClass *klass;
- char sep;
mrb_sym method_id;
} mrb_backtrace_entry;

MODIFY
mrbgems/mruby-kernel-ext/test/kernel.rb
mrbgems/mruby-kernel-ext/test/kernel.rb
@@ -20,13 +20,13 @@ assert('Kernel.caller, Kernel#caller') do
bar(*args)
end
end
- assert_equal "kernel.rb:#{caller_lineno}:in Object#foo", c.new.baz(0)[0][-26..-1]
- assert_equal "#bar", c.new.baz[0][-4..-1]
- assert_equal "#foo", c.new.baz(0)[0][-4..-1]
- assert_equal "#bar", c.new.baz(1)[0][-4..-1]
- assert_equal "#baz", c.new.baz(2)[0][-4..-1]
- assert_equal ["#foo", "#bar"], c.new.baz(0, 2).map { |i| i[-4..-1] }
- assert_equal ["#bar", "#baz"], c.new.baz(1..2).map { |i| i[-4..-1] }
+ assert_equal "kernel.rb:#{caller_lineno}:in foo", c.new.baz(0)[0][-19..-1]
+ assert_equal "bar", c.new.baz[0][-3..-1]
+ assert_equal "foo", c.new.baz(0)[0][-3..-1]
+ assert_equal "bar", c.new.baz(1)[0][-3..-1]
+ assert_equal "baz", c.new.baz(2)[0][-3..-1]
+ assert_equal ["foo", "bar"], c.new.baz(0, 2).map { |i| i[-3..-1] }
+ assert_equal ["bar", "baz"], c.new.baz(1..2).map { |i| i[-3..-1] }
assert_nil c.new.baz(10..20)
assert_raise(ArgumentError) { c.new.baz(-1) }
assert_raise(ArgumentError) { c.new.baz(-1, 1) }

MODIFY
src/backtrace.c
src/backtrace.c
@@ -19,8 +19,6 @@ struct backtrace_location_raw {
int lineno;
const char *filename;
mrb_sym method_id;
- char sep;
- struct RClass *klass;
};
struct backtrace_location {
@@ -28,8 +26,6 @@ struct backtrace_location {
int lineno;
const char *filename;
const char *method;
- char sep;
- const char *class_name;
};
typedef void (*each_backtrace_func)(mrb_state*, struct backtrace_location_raw*, void*);
@@ -57,13 +53,8 @@ print_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data)
fprintf(args->stream, "\t[%d] %s:%d", loc->i, loc->filename, loc->lineno);
if (loc->method) {
- if (loc->class_name) {
- fprintf(args->stream, ":in %s%c%s", loc->class_name, loc->sep, loc->method);
- }
- else {
fprintf(args->stream, ":in %s", loc->method);
}
- }
fprintf(args->stream, "\n");
}
@@ -83,12 +74,6 @@ get_backtrace_i(mrb_state *mrb, struct backtrace_location *loc, void *data)
if (loc->method) {
mrb_str_cat_lit(mrb, str, ":in ");
-
- if (loc->class_name) {
- mrb_str_cat_cstr(mrb, str, loc->class_name);
- mrb_str_cat(mrb, str, &loc->sep, 1);
- }
-
mrb_str_cat_cstr(mrb, str, loc->method);
}
@@ -132,19 +117,11 @@ each_backtrace(mrb_state *mrb, mrb_int ciidx, mrb_code *pc0, each_backtrace_func
if (loc.lineno == -1) continue;
- if (ci->target_class == ci->proc->target_class) {
- loc.sep = '.';
- }
- else {
- loc.sep = '#';
- }
-
if (!loc.filename) {
loc.filename = "(unknown)";
}
loc.method_id = ci->mid;
- loc.klass = ci->proc->target_class;
loc.i = i;
func(mrb, &loc, data);
}
@@ -165,8 +142,6 @@ output_backtrace_i(mrb_state *mrb, struct backtrace_location_raw *loc_raw, void
loc.lineno = loc_raw->lineno;
loc.filename = loc_raw->filename;
loc.method = mrb_sym2name(mrb, loc_raw->method_id);
- loc.sep = loc_raw->sep;
- loc.class_name = mrb_class_name(mrb, loc_raw->klass);
args->func(mrb, &loc, args->data);
}
@@ -244,15 +219,7 @@ print_backtrace_saved(mrb_state *mrb)
const char *method_name;
method_name = mrb_sym2name(mrb, entry->method_id);
- if (entry->klass) {
- fprintf(stream, ":in %s%c%s",
- mrb_class_name(mrb, entry->klass),
- entry->sep,
- method_name);
- }
- else {
fprintf(stream, ":in %s", method_name);
- }
mrb_gc_arena_restore(mrb, ai);
}
@@ -353,8 +320,6 @@ save_backtrace_i(mrb_state *mrb,
entry = &mrb->backtrace.entries[mrb->backtrace.n];
entry->filename = loc_raw->filename;
entry->lineno = loc_raw->lineno;
- entry->klass = loc_raw->klass;
- entry->sep = loc_raw->sep;
entry->method_id = loc_raw->method_id;
mrb->backtrace.n++;
@@ -408,12 +373,6 @@ mrb_restore_backtrace(mrb_state *mrb)
mrb_fixnum_value(entry->lineno));
if (entry->method_id != 0) {
mrb_str_cat_lit(mrb, mrb_entry, ":in ");
-
- if (entry->klass) {
- mrb_str_cat_cstr(mrb, mrb_entry, mrb_class_name(mrb, entry->klass));
- mrb_str_cat(mrb, mrb_entry, &entry->sep, 1);
- }
-
mrb_str_cat_cstr(mrb, mrb_entry, mrb_sym2name(mrb, entry->method_id));
}

MODIFY
src/gc.c
src/gc.c
@@ -872,10 +872,6 @@ root_scan_phase(mrb_state *mrb, mrb_gc *gc)
mrb_gc_mark(mrb, (struct RBasic*)mrb->exc);
/* mark backtrace */
mrb_gc_mark(mrb, (struct RBasic*)mrb->backtrace.exc);
- e = (size_t)mrb->backtrace.n;
- for (i=0; i<e; i++) {
- mrb_gc_mark(mrb, (struct RBasic*)mrb->backtrace.entries[i].klass);
- }
/* mark pre-allocated exception */
mrb_gc_mark(mrb, (struct RBasic*)mrb->nomem_err);
mrb_gc_mark(mrb, (struct RBasic*)mrb->stack_err);

MODIFY
test/t/exception.rb
test/t/exception.rb
@@ -398,7 +398,7 @@ assert('GC in rescue') do
end
rescue => exception
GC.start
- assert_equal("#{__FILE__}:#{line}:in Object.call",
+ assert_equal("#{__FILE__}:#{line}:in call",
exception.backtrace.first)
end
end
@@ -416,7 +416,7 @@ assert('Method call in rescue') do
rescue => exception
[3].each do
end
- assert_equal("#{__FILE__}:#{line}:in Object.call",
+ assert_equal("#{__FILE__}:#{line}:in call",
exception.backtrace.first)
end
end

Remove class info from backtrace lines.