Skip to content

Commit

Permalink
Fix pre 3.1.48 versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jerbob92 committed Dec 1, 2023
1 parent c76f317 commit d2d4689
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions internal/emval.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,17 @@ func EmvalReturnValue(ctx context.Context, mod api.Module, returnType registered
return 0, fmt.Errorf("could not call toWireType on _emval_as: %w", err)
}

// Default of 0 to reset value at memory address.
rd := int32(0)

// Only create destructor ref when needed.
if destructors != nil && len(*destructors) > 0 {
rd := engine.emvalEngine.toHandle(destructors)
ok := mod.Memory().WriteUint32Le(destructorsRef, uint32(rd))
if !ok {
return 0, fmt.Errorf("could not write destructor ref to memory")
}
rd = engine.emvalEngine.toHandle(destructors)
}

ok := mod.Memory().WriteUint32Le(destructorsRef, uint32(rd))
if !ok {
return 0, fmt.Errorf("could not write destructor ref to memory")
}

return returnVal, nil
Expand Down Expand Up @@ -829,6 +834,7 @@ var EmvalNewCString = api.GoModuleFunc(func(ctx context.Context, mod api.Module,
var EmvalRunDestructors = api.GoModuleFunc(func(ctx context.Context, mod api.Module, stack []uint64) {
engine := MustGetEngineFromContext(ctx, mod).(*engine)
id := api.DecodeI32(stack[0])

destructorsVal, err := engine.emvalEngine.toValue(id)
if err != nil {
panic(fmt.Errorf("could not find handle: %w", err))
Expand Down

0 comments on commit d2d4689

Please sign in to comment.