From 2af0ff52e9ae3fd3a44470dea92c9770f3c24516 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Tue, 11 Jul 2023 07:17:19 +0900 Subject: [PATCH] backtrace.c (count_backtrace_i): remove empty callback Instead specifying NULL as function argument of each_backtrace() count the number of callbacks. --- src/backtrace.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/backtrace.c b/src/backtrace.c index 580bea56e..816b0e6db 100644 --- a/src/backtrace.c +++ b/src/backtrace.c @@ -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));