lotus/curiosrc/ffiselect/testffi.go

28 lines
672 B
Go
Raw Normal View History

package ffiselect
import (
"reflect"
"github.com/samber/lo"
"golang.org/x/xerrors"
2024-05-24 19:29:07 +00:00
"github.com/filecoin-project/lotus/curiosrc/ffiselect/ffidirect"
)
func callTest(logctx []any, fn string, rawargs ...interface{}) ([]interface{}, error) {
args := lo.Map(rawargs, func(arg any, i int) reflect.Value {
return reflect.ValueOf(arg)
})
resAry := reflect.ValueOf(ffidirect.FFI{}).MethodByName(fn).Call(args)
res := lo.Map(resAry, func(res reflect.Value, i int) any {
return res.Interface()
})
if res[len(res)-1].(ffidirect.ErrorString) != "" {
return nil, xerrors.Errorf("callTest error: %s", res[len(res)-1].(ffidirect.ErrorString))
}
return res, nil
}