Avoid alloc in wrapped func when returning error

main
copygirl 1 year ago
parent acb6b4b0a5
commit 4bc1ded481
  1. 7
      src/func.zig

@ -135,11 +135,8 @@ pub const Func = extern struct {
// If function returns an ErrorUnion, convert it to
// its payload, or return a trap if an error occurred.
const func_results = if (@typeInfo(@TypeOf(func_results_maybe_error)) == .ErrorUnion)
func_results_maybe_error catch |err| {
const fmt = "Error '{s}' occurred in host code";
const msg = std.fmt.allocPrintZ(c_alloc, fmt, .{@errorName(err)});
return Trap.init(msg catch "Error occurred in host code");
}
func_results_maybe_error catch |err|
return Trap.init(@errorName(err))
else
func_results_maybe_error;

Loading…
Cancel
Save