backtrace.c (count_backtrace_i): remove empty callback

Instead specifying NULL as function argument of each_backtrace()
count the number of callbacks.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-07-11 07:17:19 +09:00
parent 6f99806d5b
commit 2af0ff52e9
+3 -9
View File
@@ -79,19 +79,12 @@ each_backtrace(mrb_state *mrb, ptrdiff_t ciidx, each_backtrace_func func, void *
break;
}
}
func(mrb, &loc, data);
if (func) func(mrb, &loc, data);
n++;
}
return n;
}
static void
count_backtrace_i(mrb_state *mrb,
const struct backtrace_location *loc,
void *data)
{
}
static void
pack_backtrace_i(mrb_state *mrb,
const struct backtrace_location *loc,
@@ -113,7 +106,8 @@ packed_backtrace(mrb_state *mrb)
if (ciidx >= mrb->c->ciend - mrb->c->cibase)
ciidx = mrb->c->ciend - mrb->c->cibase; /* ciidx is broken... */
int len = each_backtrace(mrb, ciidx, count_backtrace_i, NULL);
/* count the number of backtraces */
int len = each_backtrace(mrb, ciidx, NULL, NULL);
backtrace = mrb_data_object_alloc(mrb, NULL, NULL, &bt_type);
if (len > 0) {
void *ptr = mrb_malloc(mrb, len * sizeof(struct backtrace_location));