From c3d6bac9d716433ca31f7d39332b2a6a96d8187d Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 12 Nov 2025 00:35:04 +0100 Subject: call_import.c: Fix prev_ret So far, this variable was only being assigned by unwind.c, which is called only for WebAssembly functions. However, it is still mandatory to report the last returned value from imported functions, too, as prev_ret is relied upon by operators such as `drop`. --- src/routines/call_import.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/routines/call_import.c b/src/routines/call_import.c index 6a94ff0..38e0338 100644 --- a/src/routines/call_import.c +++ b/src/routines/call_import.c @@ -151,18 +151,20 @@ static enum nw_state call_done(struct nw_interp *const i) const nw_varuint32 pcnt = fn->param_count; const struct nw_interp_cfg *const icfg = &i->cfg; union nw_value *const ret = fn->ret.count ? icfg->args + pcnt : NULL; + struct nw_return r = {0}; if (ret) { size_t sz; + const enum nw_type type = fn->ret.type; - if (nwp_type_sz(fn->ret.type, &sz)) + if (nwp_type_sz(type, &sz)) { static const char *const exc = "invalid return type"; i->exception = exc; #ifdef NW_LOG - nwp_log("%s: %#x\n", exc, (unsigned)fn->ret.type); + nwp_log("%s: %#x\n", exc, (unsigned)type); #endif return NW_FATAL; } @@ -175,10 +177,14 @@ static enum nw_state call_done(struct nw_interp *const i) ci->io = io; i->next = push_return; } + + r.count = 1; + r.type = type; } else nwp_interp_resume(i); + i->fr.prev_ret = r; return NW_AGAIN; } -- cgit v1.2.3