mirror of https://github.com/status-im/evmc.git
go: add LoadAndConfigure method
This commit is contained in:
parent
fb0cbd7bf8
commit
c5f3bfd5c2
|
@ -7,13 +7,17 @@ and this project adheres to [Semantic Versioning].
|
||||||
|
|
||||||
## [6.3.1] - unreleased
|
## [6.3.1] - unreleased
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added `LoadAndConfigure` method to the Go API.
|
||||||
|
[[#404](https://github.com/ethereum/evmc/pull/404)]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- In C++ API the `get_balance()` method now returns expected `evmc::uint256be`
|
- In C++ API the `get_balance()` method now returns expected `evmc::uint256be`
|
||||||
instead of `evmc_uint256be`.
|
instead of `evmc_uint256be`.
|
||||||
[[#403](https://github.com/ethereum/evmc/pull/403)]
|
[[#403](https://github.com/ethereum/evmc/pull/403)]
|
||||||
|
|
||||||
|
|
||||||
## [6.3.0] - 2019-08-12
|
## [6.3.0] - 2019-08-12
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -168,6 +168,26 @@ func Load(filename string) (instance *Instance, err error) {
|
||||||
return instance, err
|
return instance, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func LoadAndConfigure(config string) (instance *Instance, err error) {
|
||||||
|
cconfig := C.CString(config)
|
||||||
|
var loaderErr C.enum_evmc_loader_error_code
|
||||||
|
handle := C.evmc_load_and_configure(cconfig, &loaderErr)
|
||||||
|
C.free(unsafe.Pointer(cconfig))
|
||||||
|
|
||||||
|
if loaderErr == C.EVMC_LOADER_SUCCESS {
|
||||||
|
instance = &Instance{handle}
|
||||||
|
} else {
|
||||||
|
errMsg := C.evmc_last_error_msg()
|
||||||
|
if errMsg != nil {
|
||||||
|
err = fmt.Errorf("EVMC loading error: %s", C.GoString(errMsg))
|
||||||
|
} else {
|
||||||
|
err = fmt.Errorf("EVMC loading error %d", int(loaderErr))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance, err
|
||||||
|
}
|
||||||
|
|
||||||
func (instance *Instance) Destroy() {
|
func (instance *Instance) Destroy() {
|
||||||
C.evmc_destroy(instance.handle)
|
C.evmc_destroy(instance.handle)
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,20 @@ func TestLoad(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLoadConfigure(t *testing.T) {
|
||||||
|
i, err := LoadAndConfigure(modulePath)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
defer i.Destroy()
|
||||||
|
if i.Name() != "example_vm" {
|
||||||
|
t.Fatalf("name is %s", i.Name())
|
||||||
|
}
|
||||||
|
if i.Version()[0] < '0' || i.Version()[0] > '9' {
|
||||||
|
t.Fatalf("version number is weird: %s", i.Version())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestExecute(t *testing.T) {
|
func TestExecute(t *testing.T) {
|
||||||
vm, _ := Load(modulePath)
|
vm, _ := Load(modulePath)
|
||||||
defer vm.Destroy()
|
defer vm.Destroy()
|
||||||
|
|
Loading…
Reference in New Issue