Skip to content

Commit

Permalink
Bump to 7.0.0 (bytecodealliance#136)
Browse files Browse the repository at this point in the history
Also add a binding for `wasmtime_store_limiter`
  • Loading branch information
alexcrichton authored Mar 20, 2023
1 parent e655f68 commit 4a52ebb
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 37 deletions.
2 changes: 1 addition & 1 deletion ci/download-wasmtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import urllib.request
import zipfile

WASMTIME_VERSION = "v6.0.0"
WASMTIME_VERSION = "v7.0.0"


def main(platform, arch):
Expand Down
57 changes: 23 additions & 34 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ heck = { version = "0.4", features = ["unicode"] }
wit-component = "0.6"
wit-parser = "0.6"
indexmap = "1.0"
wasmtime-environ = { version = "6.0.0", features = ['component-model'] }
wasmtime-environ = { version = "7.0.0", features = ['component-model'] }
wit-bindgen = { workspace = true, features = ['default'] }

[features]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
with open("README.md", "r") as fh:
long_description = fh.read()

version = "6.0.0"
version = "7.0.0"

# Give unique version numbers to all commits so our publication-on-each commit
# works on main
Expand Down
24 changes: 24 additions & 0 deletions tests/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,27 @@ def test_fuel(self):
assert(store.consume_fuel(1) == 1)
with self.assertRaises(WasmtimeError):
store.consume_fuel(2)

def test_limits(self):
store = Store()
Memory(store, MemoryType(Limits(1, None)))

store = Store()
store.set_limits(memory_size=0)
with self.assertRaises(WasmtimeError):
Memory(store, MemoryType(Limits(1, None)))
store.set_limits(memory_size=100000)
Memory(store, MemoryType(Limits(1, None)))

store = Store()
store.set_limits(table_elements=1)
Table(store, TableType(ValType.funcref(), Limits(1, None)), None)
with self.assertRaises(WasmtimeError):
Table(store, TableType(ValType.funcref(), Limits(2, None)), None)

store = Store()
store.set_limits(memory_size=200000)
mem = Memory(store, MemoryType(Limits(1, None)))
mem.grow(store, 1)
with self.assertRaises(WasmtimeError):
mem.grow(store, 100)
12 changes: 12 additions & 0 deletions wasmtime/_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1959,6 +1959,12 @@ def wasi_config_inherit_stderr(config: Any) -> None:
def wasi_config_preopen_dir(config: Any, path: Any, guest_path: Any) -> bool:
return _wasi_config_preopen_dir(config, path, guest_path) # type: ignore

_wasi_config_preopen_socket = dll.wasi_config_preopen_socket
_wasi_config_preopen_socket.restype = c_bool
_wasi_config_preopen_socket.argtypes = [POINTER(wasi_config_t), c_uint32, POINTER(c_char)]
def wasi_config_preopen_socket(config: Any, fd_num: Any, host_port: Any) -> bool:
return _wasi_config_preopen_socket(config, fd_num, host_port) # type: ignore

class wasmtime_error(Structure):
pass

Expand Down Expand Up @@ -2207,6 +2213,12 @@ def wasmtime_store_new(engine: Any, data: Any, finalizer: Any) -> ctypes._Pointe
def wasmtime_store_context(store: Any) -> ctypes._Pointer:
return _wasmtime_store_context(store) # type: ignore

_wasmtime_store_limiter = dll.wasmtime_store_limiter
_wasmtime_store_limiter.restype = None
_wasmtime_store_limiter.argtypes = [POINTER(wasmtime_store_t), c_int64, c_int64, c_int64, c_int64, c_int64]
def wasmtime_store_limiter(store: Any, memory_size: Any, table_elements: Any, instances: Any, tables: Any, memories: Any) -> None:
return _wasmtime_store_limiter(store, memory_size, table_elements, instances, tables, memories) # type: ignore

_wasmtime_store_delete = dll.wasmtime_store_delete
_wasmtime_store_delete.restype = None
_wasmtime_store_delete.argtypes = [POINTER(wasmtime_store_t)]
Expand Down
33 changes: 33 additions & 0 deletions wasmtime/_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,39 @@ def set_epoch_deadline(self, ticks_after_current: int) -> None:
"""
ffi.wasmtime_context_set_epoch_deadline(self._context, ticks_after_current)

def set_limits(self,
memory_size: int = -1,
table_elements: int = -1,
instances: int = -1,
tables: int = -1,
memories: int = -1) -> None:
"""
Configures the limits of various items within this store.
* `memory_size` - the maximum size, in bytes, that linear memory is
allowed to consume within this store. Setting this to a lower value
will cause instantiation to fail if a module needs more memory.
Additionally the `memory.grow` instruction will return -1 once this
threshold is reached.
* `table_elements` - the maximum number of elements that can be stored
within tables in this store. Currently each table element takes 8
bytes.
* `instances` - the maximum number of WebAssembly instances that can
be created.
* `tables` - the maximum number of WebAssembly tables that can
be created.
* `memories` - the maximum number of WebAssembly linear memories that
can be created.
If any limit is negative then the limit will not be set as a part of
this invocation and it will be ignored.
"""
ffi.wasmtime_store_limiter(self._ptr, memory_size, table_elements, instances, tables, memories)

def __del__(self) -> None:
if hasattr(self, '_ptr'):
ffi.wasmtime_store_delete(self._ptr)
Expand Down

0 comments on commit 4a52ebb

Please sign in to comment.