Avoid alloc in wrapped func when returning error

main
copygirl 6 months 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 // If function returns an ErrorUnion, convert it to
// its payload, or return a trap if an error occurred. // its payload, or return a trap if an error occurred.
const func_results = if (@typeInfo(@TypeOf(func_results_maybe_error)) == .ErrorUnion) const func_results = if (@typeInfo(@TypeOf(func_results_maybe_error)) == .ErrorUnion)
func_results_maybe_error catch |err| { func_results_maybe_error catch |err|
const fmt = "Error '{s}' occurred in host code"; return Trap.init(@errorName(err))
const msg = std.fmt.allocPrintZ(c_alloc, fmt, .{@errorName(err)});
return Trap.init(msg catch "Error occurred in host code");
}
else else
func_results_maybe_error; func_results_maybe_error;

Loading…
Cancel
Save