Skip to content

Commit 6456114

Browse files
authored
mpk: fix example CLI argument (#10777)
The `--memory-size` argument caused failures when running the `mpk.rs` example. This was due to some `clap`-related conversions that no longer worked as when this was written: ``` thread 'main' panicked at examples/mpk.rs:69:18: Mismatch between definition and access of `memory_size`. Could not downcast to usize, need to downcast to u64 ``` This change explicitly uses `u64` for the CLI argument, fixing the failure.
1 parent a66afef commit 6456114

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

examples/mpk.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ struct Args {
6666
/// The maximum number of bytes for each WebAssembly linear memory in the
6767
/// pool.
6868
#[arg(long, default_value = "128MiB", value_parser = parse_byte_size)]
69-
memory_size: usize,
69+
memory_size: u64,
7070

7171
/// The maximum number of bytes a memory is considered static; see
7272
/// `Config::memory_reservation` for more details and the default
@@ -185,8 +185,10 @@ impl ExponentialSearch {
185185
fn build_engine(args: &Args, num_memories: u32, enable_mpk: MpkEnabled) -> Result<usize> {
186186
// Configure the memory pool.
187187
let mut pool = PoolingAllocationConfig::default();
188-
pool.max_memory_size(args.memory_size);
189-
pool.total_memories(num_memories)
188+
let max_memory_size =
189+
usize::try_from(args.memory_size).expect("memory size should fit in `usize`");
190+
pool.max_memory_size(max_memory_size)
191+
.total_memories(num_memories)
190192
.memory_protection_keys(enable_mpk);
191193

192194
// Configure the engine itself.

0 commit comments

Comments
 (0)