diff --git a/BUILD.bazel b/BUILD.bazel
index ef3db1d..3cbce98 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -63,7 +63,7 @@ go_library(
],
"//conditions:default": [],
}),
- importpath = "github.com/bytecodealliance/wasmtime-go/v14",
+ importpath = "github.com/bytecodealliance/wasmtime-go/v15",
visibility = ["//visibility:public"],
)
diff --git a/README.md b/README.md
index 3d0f595..78172d7 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,8 @@
-
-
+
+
@@ -25,7 +25,7 @@
## Installation
```sh
-go get -u github.com/bytecodealliance/wasmtime-go/v14@v14.0.0
+go get -u github.com/bytecodealliance/wasmtime-go/v15@v15.0.0
```
Be sure to check out the [API documentation][api]!
@@ -39,7 +39,7 @@ need to arrange to build Wasmtime and use `CGO_*` env vars to compile correctly.
This project has been tested with Go 1.13 or later.
-[api]: https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v14
+[api]: https://pkg.go.dev/github.com/bytecodealliance/wasmtime-go/v15
[wasmtime]: https://github.com/bytecodealliance/wasmtime
If you are a bazel user, add following to your WORKSPACE file:
@@ -47,8 +47,8 @@ If you are a bazel user, add following to your WORKSPACE file:
```
go_repository(
name = "com_github_bytecodealliance_wasmtime_go",
- importpath = "github.com/bytecodealliance/wasmtime-go/v14",
- version = "v14.0.0",
+ importpath = "github.com/bytecodealliance/wasmtime-go/v15",
+ version = "v15.0.0",
)
```
@@ -61,7 +61,7 @@ package main
import (
"fmt"
- "github.com/bytecodealliance/wasmtime-go/v14"
+ "github.com/bytecodealliance/wasmtime-go/v15"
)
func main() {
diff --git a/ci/download-wasmtime.py b/ci/download-wasmtime.py
index cebaa2c..2e503c9 100644
--- a/ci/download-wasmtime.py
+++ b/ci/download-wasmtime.py
@@ -10,7 +10,7 @@
import glob
-version = 'v14.0.0'
+version = 'v15.0.0'
urls = [
['wasmtime-{}-x86_64-mingw-c-api.zip', 'windows-x86_64'],
['wasmtime-{}-x86_64-linux-c-api.tar.xz', 'linux-x86_64'],
@@ -61,6 +61,8 @@
os.remove(dylib)
for dylib in glob.glob("build/**/*.so"):
os.remove(dylib)
+for dylib in glob.glob("build/**/*-min.a"):
+ os.remove(dylib)
for subdir, dirs, files in os.walk("build"):
dir_name = os.path.basename(os.path.normpath(subdir))
diff --git a/example_test.go b/example_test.go
index a7eacfc..e24cb11 100644
--- a/example_test.go
+++ b/example_test.go
@@ -10,7 +10,7 @@ import (
"strings"
"time"
- "github.com/bytecodealliance/wasmtime-go/v14"
+ "github.com/bytecodealliance/wasmtime-go/v15"
)
// Example of limiting a WebAssembly function's runtime using "fuel consumption".
@@ -19,7 +19,7 @@ func ExampleConfig_fuel() {
config.SetConsumeFuel(true)
engine := wasmtime.NewEngineWithConfig(config)
store := wasmtime.NewStore(engine)
- err := store.AddFuel(10000)
+ err := store.SetFuel(10000)
if err != nil {
log.Fatal(err)
}
@@ -57,18 +57,21 @@ func ExampleConfig_fuel() {
if fibonacci == nil {
log.Fatal("Failed to find function export `fibonacci`")
}
+ fuel := uint64(10000)
for n := 0; ; n++ {
- fuelBefore, _ := store.FuelConsumed()
+ err := store.SetFuel(fuel)
+ if err != nil {
+ log.Fatal(err)
+ }
output, err := fibonacci.Call(store, n)
if err != nil {
break
}
- fuelAfter, _ := store.FuelConsumed()
- fmt.Printf("fib(%d) = %d [consumed %d fuel]\n", n, output, fuelAfter-fuelBefore)
- err = store.AddFuel(fuelAfter - fuelBefore)
+ fuelAfter, err := store.GetFuel()
if err != nil {
log.Fatal(err)
}
+ fmt.Printf("fib(%d) = %d [consumed %d fuel]\n", n, output, fuel-fuelAfter)
}
// Output:
// fib(0) = 0 [consumed 6 fuel]
diff --git a/go.mod b/go.mod
index 37cea1a..40e18e0 100644
--- a/go.mod
+++ b/go.mod
@@ -1,4 +1,4 @@
-module github.com/bytecodealliance/wasmtime-go/v14
+module github.com/bytecodealliance/wasmtime-go/v15
go 1.18
diff --git a/includebuild.go b/includebuild.go
index 0b10bae..02c3c59 100644
--- a/includebuild.go
+++ b/includebuild.go
@@ -12,11 +12,11 @@ import (
// included in vendored dependencies.
// Cf. https://github.com/golang/go/issues/26366
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/include"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/include/wasmtime"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/linux-aarch64"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/linux-x86_64"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/macos-aarch64"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/macos-x86_64"
- _ "github.com/bytecodealliance/wasmtime-go/v14/build/windows-x86_64"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/include"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/include/wasmtime"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/linux-aarch64"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/linux-x86_64"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/macos-aarch64"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/macos-x86_64"
+ _ "github.com/bytecodealliance/wasmtime-go/v15/build/windows-x86_64"
)
diff --git a/store.go b/store.go
index b19ae10..b689ca0 100644
--- a/store.go
+++ b/store.go
@@ -227,23 +227,27 @@ func goFinalizeFuncWrap(env unsafe.Pointer) {
gEngineFuncWrapSlab.deallocate(idx)
}
-// FuelConsumed returns the amount of fuel consumed by this context's store
-// execution so far.
+// GetFuel returns the amount of fuel remaining in this store.
//
-// If fuel consumption is not enabled via `Config.SetConsumeFuel` then this function
-// will return false. Otherwise true is returned and the fuel parameter is
-// filled in with fuel consumed so far.
+// If fuel consumption is not enabled via `Config.SetConsumeFuel` then
+// this function will return an error. Otherwise this will retrieve the fuel
+// remaining and return it.
//
-// Also note that fuel, if enabled, must be originally configured via `Store.AddFuel`.
-func (store *Store) FuelConsumed() (uint64, bool) {
- fuel := C.uint64_t(0)
- enable := C.wasmtime_context_fuel_consumed(store.Context(), &fuel)
+// Also note that fuel, if enabled, must be originally configured via
+// `Store.SetFuel`.
+func (store *Store) GetFuel() (uint64, error) {
+ var remaining uint64
+ c_remaining := C.uint64_t(remaining)
+ err := C.wasmtime_context_get_fuel(store.Context(), &c_remaining)
runtime.KeepAlive(store)
+ if err != nil {
+ return 0, mkError(err)
+ }
- return uint64(fuel), bool(enable)
+ return uint64(c_remaining), nil
}
-// AddFuel adds fuel to this context's store for wasm to consume while executing.
+// SetFuel sets this store's fuel to the specified value.
//
// For this method to work fuel consumption must be enabled via
// `Config.SetConsumeFuel`. By default a store starts with 0 fuel
@@ -255,8 +259,8 @@ func (store *Store) FuelConsumed() (uint64, bool) {
// wasm to trap. More usages of fuel are planned for the future.
//
// If fuel is not enabled within this store then an error is returned.
-func (store *Store) AddFuel(fuel uint64) error {
- err := C.wasmtime_context_add_fuel(store.Context(), C.uint64_t(fuel))
+func (store *Store) SetFuel(fuel uint64) error {
+ err := C.wasmtime_context_set_fuel(store.Context(), C.uint64_t(fuel))
runtime.KeepAlive(store)
if err != nil {
return mkError(err)
@@ -265,28 +269,6 @@ func (store *Store) AddFuel(fuel uint64) error {
return nil
}
-// ConsumeFuel attempts to manually consume fuel from the store.
-//
-// If fuel consumption is not enabled via `Config.SetConsumeFuel` then
-// this function will return an error. Otherwise this will attempt to consume
-// the specified amount of `fuel` from the store. If successful the remaining
-// amount of fuel is returned. If `fuel` couldn't be consumed
-// then an error is returned.
-//
-// Also note that fuel, if enabled, must be originally configured via
-// `Store.AddFuel`.
-func (store *Store) ConsumeFuel(fuel uint64) (uint64, error) {
- var remaining uint64
- c_remaining := C.uint64_t(remaining)
- err := C.wasmtime_context_consume_fuel(store.Context(), C.uint64_t(fuel), &c_remaining)
- runtime.KeepAlive(store)
- if err != nil {
- return 0, mkError(err)
- }
-
- return uint64(c_remaining), nil
-}
-
// Limiter provides limits for a store. Used by hosts to limit resource
// consumption of instances. Use negative value to keep the default value
// for the limit.
diff --git a/store_test.go b/store_test.go
index e5d56b7..3bde05a 100644
--- a/store_test.go
+++ b/store_test.go
@@ -42,8 +42,8 @@ func TestFuelConsumed(t *testing.T) {
engine := NewEngine()
store := NewStore(engine)
- fuel, enable := store.FuelConsumed()
- require.False(t, enable)
+ fuel, enable := store.GetFuel()
+ require.Error(t, enable)
require.Equal(t, fuel, uint64(0))
}
@@ -53,35 +53,15 @@ func TestAddFuel(t *testing.T) {
engine := NewEngineWithConfig(config)
store := NewStore(engine)
- fuel, enable := store.FuelConsumed()
- require.True(t, enable)
+ fuel, enable := store.GetFuel()
+ require.NoError(t, enable)
require.Equal(t, fuel, uint64(0))
const add_fuel = 3
- err := store.AddFuel(add_fuel)
+ err := store.SetFuel(add_fuel)
require.NoError(t, err)
}
-func TestConsumeFuel(t *testing.T) {
- config := NewConfig()
- config.SetConsumeFuel(true)
- engine := NewEngineWithConfig(config)
- store := NewStore(engine)
-
- fuel, enable := store.FuelConsumed()
- require.True(t, enable)
- require.Equal(t, fuel, uint64(0))
-
- const add_fuel = 3
- err := store.AddFuel(add_fuel)
- require.NoError(t, err)
-
- consume_fuel := uint64(1)
- remaining, err := store.ConsumeFuel(consume_fuel)
- require.NoError(t, err)
- require.Equal(t, (add_fuel - consume_fuel), remaining)
-}
-
func TestLimiterMemorySizeFail(t *testing.T) {
engine := NewEngine()
store := NewStore(engine)