Skip to content

Commit

Permalink
use report_getmessage
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed May 30, 2024
1 parent 8b7452b commit 7f23976
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
27 changes: 10 additions & 17 deletions cli/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ print_trap(const struct exec_context *ctx, const struct trap_info *trap)
/* the messages here are aimed to match assert_trap in wast */
enum trapid id = trap->trapid;
const char *msg = "unknown";
const char *trapmsg = ctx->report->msg;
const char *trapmsg = report_getmessage(ctx->report);
switch (id) {
case TRAP_DIV_BY_ZERO:
msg = "integer divide by zero";
Expand Down Expand Up @@ -454,9 +454,6 @@ print_trap(const struct exec_context *ctx, const struct trap_info *trap)
default:
break;
}
if (trapmsg == NULL) {
trapmsg = "no message";
}
nbio_printf("Error: [trap] %s (%u): %s\n", msg, id, trapmsg);

print_trace(ctx); /* XXX nbio_printf */
Expand Down Expand Up @@ -572,11 +569,10 @@ repl_load_from_buf(struct repl_state *state, const char *modname,
ctx.options = state->opts.load_options;
ret = module_create(&mod->module, mod->buf, mod->buf + mod->bufsize,
&ctx);
if (ctx.report.msg != NULL) {
xlog_error("load/validation error: %s", ctx.report.msg);
nbio_printf("load/validation error: %s\n", ctx.report.msg);
} else if (ret != 0) {
nbio_printf("load/validation error: no message\n");
if (ret != 0) {
const char *msg = report_getmessage(&ctx.report);
xlog_error("load/validation error: %s", msg);
nbio_printf("load/validation error: %s\n", msg);
}
load_context_clear(&ctx);
if (ret != 0) {
Expand Down Expand Up @@ -604,15 +600,12 @@ repl_load_from_buf(struct repl_state *state, const char *modname,
report_init(&report);
ret = instance_create_no_init(mod->module, &mod->inst, imports,
&report);
if (report.msg != NULL) {
xlog_error("instance_create: %s", report.msg);
nbio_printf("instantiation error: %s\n", report.msg);
} else if (ret != 0) {
nbio_printf("instantiation error: no message\n");
}
report_clear(&report);
if (ret != 0) {
xlog_printf("instance_create_no_init failed with %d\n", ret);
const char *msg = report_getmessage(&report);
xlog_error("instance_create_no_init failed with %d: %s", ret,
msg);
nbio_printf("instantiation error: %s\n", msg);
report_clear(&report);
goto fail;
}
ret = repl_exec_init(state, mod, trap_ok);
Expand Down
4 changes: 2 additions & 2 deletions libdyld/dyld.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ dyld_load_object_from_file(struct dyld *d, const struct name *name,
&lctx);
if (ret != 0) {
xlog_error("module_create failed with %d: %s", ret,
lctx.report.msg);
report_getmessage(&lctx.report));
load_context_clear(&lctx);
goto fail;
}
Expand Down Expand Up @@ -840,7 +840,7 @@ dyld_load_object_from_file(struct dyld *d, const struct name *name,
obj->local_import_obj, &report);
if (ret != 0) {
xlog_error("instance_create failed with %d: %s", ret,
report.msg);
report_getmessage(&report));
report_clear(&report);
goto fail;
}
Expand Down
17 changes: 6 additions & 11 deletions libwasi_threads/wasi_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,10 @@ done_thread_start_func(struct exec_context *ctx, const struct thread_arg *arg,
"%s: wasi_thread_start exited voluntarily %u",
__func__, ctx->trap.trapid);
ret = 0;
} else if (ctx->report->msg != NULL) {
} else {
xlog_trace("%s: wasi_thread_start trapped %u: %s",
__func__, ctx->trap.trapid,
ctx->report->msg);
} else {
xlog_trace("%s: wasi_thread_start trapped %u",
__func__, ctx->trap.trapid);
report_getmessage(ctx->report));
}
}
exec_context_clear(ctx);
Expand Down Expand Up @@ -431,15 +428,13 @@ wasi_thread_spawn_common(struct exec_context *ctx,
struct report report;
report_init(&report);
ret = instance_create(wasi->module, &inst, wasi->imports, &report);
if (report.msg != NULL) {
xlog_trace("%s: instance_create: %s", __func__, report.msg);
}
report_clear(&report);
if (ret != 0) {
xlog_trace("%s: instance_create failed with %d", __func__,
ret);
xlog_trace("%s: instance_create failed with %d: %s", __func__,
ret, report_getmessage(&report));
report_clear(&report);
goto fail;
}
report_clear(&report);
toywasm_mutex_lock(&wasi->cluster.lock);
ret = idalloc_alloc(&wasi->tids, &tid);
if (ret != 0) {
Expand Down

0 comments on commit 7f23976

Please sign in to comment.