Skip to content

Commit d4b14f9

Browse files
dm4claude
andcommitted
feat(sys): upgrade to WasmEdge 0.17.0 and add macOS arm64 static support
Bumps `WASMEDGE_RELEASE_VERSION` from 0.16.1 to 0.17.0 and refreshes all `REMOTE_ARCHIVES` SHA256 hashes against the 0.17.0 release. Adds a new `macos/aarch64/static` entry consuming `WasmEdge-0.17.0-darwin_arm64_static.tar.gz` (workflow that produces it is WasmEdge/WasmEdge#4948). ## WasmEdge 0.17.0 C API changes Two breaking C ABI changes between 0.16.1 and 0.17.0 propagate through this SDK: - `WasmEdge_Limit` (value struct passed by value) was replaced with the opaque `WasmEdge_LimitContext *` (heap-allocated, constructed via `WasmEdge_LimitCreate` / `WasmEdge_LimitCreateWithMax`, queried via `WasmEdge_LimitGet{Min,Max}` / `LimitHasMax` / `LimitIsShared`, released via `WasmEdge_LimitDelete`). The `From<WasmEdge_Limit>` impls in `types.rs` are replaced with `WasmEdgeLimit::to_context()` / `from_context()` helpers. Call sites in `MemoryType::create` and `TableType::create` explicitly delete the limit context after the borrowing C API consumes it. - `Size`/`Offset`/`Page`/`Idx` arguments on several memory and table APIs widened from `uint32_t` to `uint64_t` (in preparation for the memory64 proposal). Call sites across `config.rs`, `instance/memory.rs`, and `instance/table.rs` updated with `.into()` casts. Return-type widenings on `WasmEdge_ConfigureGetMaxMemoryPage` and `WasmEdge_MemoryInstanceGetPageSize` are downcast via `as u32` since this SDK still exposes `u32` to downstream consumers. Two `Config` default-state tests are updated to match new WasmEdge 0.17.0 defaults: `memory64` and `interpreter_mode` are now both enabled by default. ## macOS arm64 static linking `crates/wasmedge-sys/build.rs` static-link branch becomes platform-conditional: - macOS: links `c++`, `z`, `ncurses`, and `xar` from the system. `libSystem` already provides `rt`/`dl`/`pthread`/`m`, and `stdc++` is `c++` on Apple toolchain. zlib (`z`), ncurses, and libxar are needed by LLVM (statically linked into `libwasmedge.a` via the `WASMEDGE_LINK_LLVM_STATIC=ON` macOS workflow). All four are available at `/usr/lib/` on every macOS install. - Linux: retains the existing `rt, dl, pthread, m, stdc++` set. The `libfmt.a` and `libzstd.a` exists-checks both gain a skip-on-macOS branch instead of falling back to dynamic `-lfmt` / `-lzstd`. The macOS static archive merges fmt+spdlog symbols into `libwasmedge.a` and doesn't ship `.a` files separately. Brew installs the dylibs to `/opt/homebrew/lib` which the system linker doesn't search by default, so the dynamic fallback breaks clean macOS builds. Skipping is correct since the symbols are already in `libwasmedge.a`. Adds a `build_macos` job to `.github/workflows/rust-static-lib.yml` exercising `cargo test --features bundled,aot,ffi` (and the async variant) on `macos-14`. ## Local verification (macOS 26 Tahoe, Xcode 26.5) - `cargo build --release -p wasmedge-sys --features bundled,aot,ffi` successfully downloads the published `darwin_arm64_static.tar.gz`, verifies SHA256, extracts, generates bindgen, and links. - `cargo test --release --workspace --exclude async-wasi --features bundled,aot,ffi -- --test-threads=1 --skip test_vmbuilder`: 78 passed, 0 failed, 12 ignored. - Downstream cloud_ai_gateway tested against this SDK via `[patch]` override; 804 unit tests green and the release binary contains no `libwasmedge.dylib` reference per `otool -L`. Signed-off-by: dm4 <dm4@secondstate.io> Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent e7a74ab commit d4b14f9

10 files changed

Lines changed: 168 additions & 72 deletions

File tree

.github/workflows/rust-static-lib.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,31 @@ jobs:
6161
- name: Test Rust SDK with async feature
6262
run: |
6363
cargo test --workspace --features bundled,aot,async,ffi -- --nocapture --test-threads=1 --skip test_vmbuilder
64+
65+
# macOS arm64 mirrors build_ubuntu but excludes the `async` feature:
66+
# async-wasi uses Linux-only socket APIs (SO_BINDTODEVICE-family —
67+
# `bind_device`, `device`, `is_listener`) that don't compile on macOS.
68+
# When async-wasi grows macOS support, re-add the "Test Rust SDK with
69+
# async feature" step below.
70+
build_macos:
71+
name: macOS arm64
72+
runs-on: macos-14
73+
steps:
74+
- name: Checkout WasmEdge Rust SDK
75+
uses: actions/checkout@v3
76+
with:
77+
fetch-depth: 0
78+
79+
- name: Install Rust-stable
80+
uses: dtolnay/rust-toolchain@stable
81+
82+
- name: Build test WASM modules
83+
working-directory: examples/wasmedge-sys
84+
run: |
85+
rustup target add wasm32-wasip1
86+
rustc async_hello.rs --target=wasm32-wasip1 -o async_hello.wasm
87+
rustc hello.rs --target=wasm32-wasip1 -o hello.wasm
88+
89+
- name: Test Rust SDK
90+
run: |
91+
cargo test --workspace --exclude async-wasi --features bundled,aot,ffi -- --nocapture --test-threads=1 --skip test_vmbuilder

crates/async-wasi/src/snapshots/common/vfs/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,10 @@ pub trait WasiDir: WasiNode {
395395
let mut bufused = 0;
396396
let mut next = cursor as u64;
397397

398+
// `next` is not a plain loop counter — it's the dirent offset stored
399+
// inside each emitted ReaddirEntity, so the clippy suggestion to use
400+
// `enumerate()`+ `cursor as u64..` would change observable semantics.
401+
#[allow(clippy::explicit_counter_loop)]
398402
for (name, inode, filetype) in self.get_readdir(next)? {
399403
next += 1;
400404
let entity = ReaddirEntity {

crates/wasmedge-sys/build.rs

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use build_standalone::*;
99

1010
use crate::build_paths::AsPath;
1111

12-
const WASMEDGE_RELEASE_VERSION: &str = "0.16.1";
12+
const WASMEDGE_RELEASE_VERSION: &str = "0.17.0";
1313
const REMOTE_ARCHIVES: phf::Map<&'static str, (&'static str, &'static str)> = phf_map! {
1414
// The key is: {os}/{arch}[/{libc}][/static]
1515
// * The libc abi is only added on linux.
@@ -18,14 +18,15 @@ const REMOTE_ARCHIVES: phf::Map<&'static str, (&'static str, &'static str)> = ph
1818
// The value is a tuple containing the sha256sum of the archive, and the platform slug as it appears in the archive name:
1919
// * The archive name is WasmEdge-{version}-{slug}.tar.gz
2020

21-
"macos/aarch64" => ("a63f78cd4eb5889777a78772f8c464b535af68ef1b3e6b875afbf35e66767008", "darwin_arm64"),
22-
"macos/x86_64" => ("df343e262fe46f95af5739c85617f6e9270760725ac04ff25e2c46b2fb11d41e", "darwin_x86_64"),
23-
"linux/aarch64/gnu" => ("2d51e6b41322eddf17ebd69f0351d14dce4cf9acedfb34340e8ab3b13cc6f2a4", "manylinux_2_28_aarch64"),
24-
"linux/x86_64/gnu" => ("43756d546b580fa8cd874190ab1abc868de80a00c80551ae4d1d359d5f9628bc", "manylinux_2_28_x86_64"),
25-
"linux/aarch64/gnu/static" => ("20d59a97a422d1e23705a4cb89e5c195cf1488fe3225b1ce1d5ba3a295ec0a25", "debian11_aarch64_static"),
26-
"linux/x86_64/gnu/static" => ("49c77f8502d6c67e294f0ce8e6ed03fa5f6c47a34528ea4b979a86516e4473c3", "debian11_x86_64_static"),
27-
"linux/aarch64/musl/static" => ("b15c9c8cd5cb6c8aa388d108504af3df98a20f501339c5c003a47b69c732c5e3", "alpine3.23_aarch64_static"),
28-
"linux/x86_64/musl/static" => ("5afb2f0c678db2ba53264be0e73733ad6e03137bd49f0716820741bc44eb1fe2", "alpine3.23_x86_64_static"),
21+
"macos/aarch64" => ("ae97ff792ac1bf7bcf703b20926b9bac168e5b6260930d13a156dc19e68a67c5", "darwin_arm64"),
22+
"macos/aarch64/static" => ("57c22c699c1bc7b10c6da78e3b14b74d578a392c8019250e58d00da61857b203", "darwin_arm64_static"),
23+
"macos/x86_64" => ("5742f7d19bbdb983f4df57114b085f908bae06f705ea3e167f802a66bd9e0342", "darwin_x86_64"),
24+
"linux/aarch64/gnu" => ("6d3aa5a43fd0998b11812e99b46e90a282f3caaacc9cfef14b67f3438b63e804", "manylinux_2_28_aarch64"),
25+
"linux/x86_64/gnu" => ("5d8165559c553eacc9b87db1799c2204e056db8609bedbf61eb29f8a21a42993", "manylinux_2_28_x86_64"),
26+
"linux/aarch64/gnu/static" => ("93c28c7caf84860ad9acb36c823a820d0abc062af432749c5eab4395e5158beb", "debian11_aarch64_static"),
27+
"linux/x86_64/gnu/static" => ("7603ce19b745984c73057887219e5635cb08f857a1fc4625ba30347dbc6effe1", "debian11_x86_64_static"),
28+
"linux/aarch64/musl/static" => ("415b8660fb11cb25f7c8a5d67a88a1ad9802eb832ca3dd65d363fc47b01faa35", "alpine3.23_aarch64_static"),
29+
"linux/x86_64/musl/static" => ("4e285eb9e94f147e8d11b53209a3b7377265ab9dd784c8ac8be7682ea3531e44", "alpine3.23_x86_64_static"),
2930
};
3031

3132
lazy_static! {
@@ -98,19 +99,58 @@ fn main() {
9899
// Tell cargo to tell rustc to link our `wasmedge` library statically.
99100
println!("cargo:rustc-link-lib=static=wasmedge");
100101

101-
// Check if libfmt.a exists in the lib_dir, otherwise link dynamically
102+
// fmt: macOS static archive merges fmt into libwasmedge.a and does not
103+
// ship libfmt.a separately. macOS developer hosts typically lack
104+
// libfmt.dylib on the linker's default search path (brew installs to
105+
// /opt/homebrew/lib which clang doesn't search by default), so the
106+
// dynamic fallback breaks clean macOS builds. Skip the explicit fmt
107+
// link on macOS — the symbols are already in libwasmedge.a.
102108
let fmt_static = std::path::Path::new(&lib_dir).join("libfmt.a");
103109
if fmt_static.exists() {
104110
debug!("found static libfmt at {fmt_static:?}");
105111
println!("cargo:rustc-link-lib=static=fmt");
106-
} else {
112+
} else if !cfg!(target_os = "macos") {
107113
debug!("static libfmt not found, linking dynamically");
108114
println!("cargo:rustc-link-lib=dylib=fmt");
115+
} else {
116+
debug!(
117+
"static libfmt not found on macOS; skipping (assumed merged into libwasmedge.a)"
118+
);
109119
}
110120

111-
for dep in ["rt", "dl", "pthread", "m", "zstd", "stdc++"] {
121+
// Platform-conditional system deps for the static-link path.
122+
// macOS: libSystem already provides rt/dl/pthread/m; libstdc++ is
123+
// libc++. When the archive was built with
124+
// WASMEDGE_LINK_LLVM_STATIC=ON (default for the darwin_arm64
125+
// static workflow), LLVM's compression code pulls in zlib
126+
// (libz), terminfo support pulls in ncurses, and archive
127+
// parsing pulls in libxar — all available as /usr/lib system
128+
// libraries on every macOS install.
129+
// Linux: needs the full set.
130+
let deps: &[&str] = if cfg!(target_os = "macos") {
131+
&["c++", "z", "ncurses", "xar"]
132+
} else {
133+
&["rt", "dl", "pthread", "m", "stdc++"]
134+
};
135+
for dep in deps {
112136
link_lib(dep);
113137
}
138+
139+
// zstd: mirror the libfmt.a fallback pattern. macOS static archive
140+
// won't ship libzstd.a; fall back to skipping rather than dynamic-linking
141+
// a library the host may not have.
142+
let zstd_static = std::path::Path::new(&lib_dir).join("libzstd.a");
143+
if zstd_static.exists() {
144+
debug!("found static libzstd at {zstd_static:?}");
145+
println!("cargo:rustc-link-lib=static=zstd");
146+
} else if !cfg!(target_os = "macos") {
147+
debug!("static libzstd not found, linking dynamically");
148+
println!("cargo:rustc-link-lib=dylib=zstd");
149+
} else {
150+
debug!(
151+
"static libzstd not found on macOS; skipping (assumed merged into libwasmedge.a)"
152+
);
153+
}
114154
} else {
115155
println!("cargo:rustc-env=LD_LIBRARY_PATH={lib_dir}");
116156
println!("cargo:rustc-link-search={lib_dir}");

crates/wasmedge-sys/src/ast_module.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl ImportType<'_> {
181181
)))),
182182
false => {
183183
let limit = unsafe { ffi::WasmEdge_MemoryTypeGetLimit(ctx_mem_ty) };
184-
let limit: WasmEdgeLimit = limit.into();
184+
let limit = WasmEdgeLimit::from_context(limit);
185185

186186
Ok(ExternalInstanceType::Memory(MemoryType::new(
187187
limit.min(),
@@ -206,7 +206,7 @@ impl ImportType<'_> {
206206

207207
// get the limit
208208
let limit = unsafe { ffi::WasmEdge_TableTypeGetLimit(ctx_tab_ty) };
209-
let limit: WasmEdgeLimit = limit.into();
209+
let limit = WasmEdgeLimit::from_context(limit);
210210

211211
Ok(ExternalInstanceType::Table(TableType::new(
212212
elem_ty,
@@ -321,7 +321,7 @@ impl ExportType<'_> {
321321

322322
// get the limit
323323
let limit = unsafe { ffi::WasmEdge_TableTypeGetLimit(ctx_tab_ty) };
324-
let limit: WasmEdgeLimit = limit.into();
324+
let limit = WasmEdgeLimit::from_context(limit);
325325

326326
Ok(ExternalInstanceType::Table(TableType::new(
327327
elem_ty,
@@ -341,7 +341,7 @@ impl ExportType<'_> {
341341
)))),
342342
false => {
343343
let limit = unsafe { ffi::WasmEdge_MemoryTypeGetLimit(ctx_mem_ty) };
344-
let limit: WasmEdgeLimit = limit.into();
344+
let limit = WasmEdgeLimit::from_context(limit);
345345

346346
Ok(ExternalInstanceType::Memory(MemoryType::new(
347347
limit.min(),

crates/wasmedge-sys/src/config.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ impl Config {
154154
///
155155
/// * `count` - The page count (64KB per page).
156156
pub fn set_max_memory_pages(&mut self, count: u32) {
157-
unsafe { ffi::WasmEdge_ConfigureSetMaxMemoryPage(self.inner.0, count) }
157+
unsafe { ffi::WasmEdge_ConfigureSetMaxMemoryPage(self.inner.0, count.into()) }
158158
}
159159

160160
/// Returns the number of the memory pages available.
161161
pub fn get_max_memory_pages(&self) -> u32 {
162-
unsafe { ffi::WasmEdge_ConfigureGetMaxMemoryPage(self.inner.0) }
162+
unsafe { ffi::WasmEdge_ConfigureGetMaxMemoryPage(self.inner.0) as u32 }
163163
}
164164

165165
/// Enables or disables the ImportExportMutGlobals option. By default, the option is enabled.
@@ -770,7 +770,8 @@ mod tests {
770770
assert!(config.exception_handling_enabled());
771771
// Note: function_references is enabled by default in WasmEdge 0.16.1+
772772
assert!(config.function_references_enabled());
773-
assert!(!config.memory64_enabled());
773+
// Note: memory64 is enabled by default in WasmEdge 0.17.0+
774+
assert!(config.memory64_enabled());
774775
assert!(config.multi_value_enabled());
775776
assert!(config.mutable_globals_enabled());
776777
assert!(config.non_trap_conversions_enabled());
@@ -801,7 +802,8 @@ mod tests {
801802
config.get_aot_compiler_output_format(),
802803
CompilerOutputFormat::Wasm,
803804
);
804-
assert!(!config.interpreter_mode_enabled());
805+
// Note: interpreter_mode is enabled by default in WasmEdge 0.17.0+
806+
assert!(config.interpreter_mode_enabled());
805807
#[cfg(feature = "aot")]
806808
assert!(!config.interruptible_enabled());
807809

@@ -913,7 +915,8 @@ mod tests {
913915
assert!(config.exception_handling_enabled());
914916
// Note: function_references is enabled by default in WasmEdge 0.16.1+
915917
assert!(config.function_references_enabled());
916-
assert!(!config.memory64_enabled());
918+
// Note: memory64 is enabled by default in WasmEdge 0.17.0+
919+
assert!(config.memory64_enabled());
917920
assert!(config.reference_types_enabled());
918921
assert!(config.simd_enabled());
919922
// Note: tail_call is enabled by default in WasmEdge 0.16.1+
@@ -1004,7 +1007,8 @@ mod tests {
10041007
assert!(config.exception_handling_enabled());
10051008
// Note: function_references is enabled by default in WasmEdge 0.16.1+
10061009
assert!(config.function_references_enabled());
1007-
assert!(!config.memory64_enabled());
1010+
// Note: memory64 is enabled by default in WasmEdge 0.17.0+
1011+
assert!(config.memory64_enabled());
10081012
assert!(config.reference_types_enabled());
10091013
assert!(config.simd_enabled());
10101014
// Note: tail_call is enabled by default in WasmEdge 0.16.1+

crates/wasmedge-sys/src/instance/memory.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ impl Memory {
7373
check(ffi::WasmEdge_MemoryInstanceGetData(
7474
self.inner.0,
7575
data.as_mut_ptr(),
76-
offset,
77-
len,
76+
offset.into(),
77+
len.into(),
7878
))?;
7979
data.set_len(len as usize);
8080
}
@@ -100,8 +100,8 @@ impl Memory {
100100
check(ffi::WasmEdge_MemoryInstanceSetData(
101101
self.inner.0,
102102
data.as_ref().as_ptr(),
103-
offset,
104-
data.as_ref().len() as u32,
103+
offset.into(),
104+
data.as_ref().len() as u64,
105105
))
106106
}
107107
}
@@ -124,7 +124,9 @@ impl Memory {
124124
/// The lifetime of the returned pointer must not exceed that of the object itself.
125125
///
126126
pub unsafe fn data_pointer(&self, offset: u32, len: u32) -> WasmEdgeResult<*const u8> {
127-
let ptr = unsafe { ffi::WasmEdge_MemoryInstanceGetPointerConst(self.inner.0, offset, len) };
127+
let ptr = unsafe {
128+
ffi::WasmEdge_MemoryInstanceGetPointerConst(self.inner.0, offset.into(), len.into())
129+
};
128130
match ptr.is_null() {
129131
true => Err(Box::new(WasmEdgeError::Mem(MemError::ConstPtr))),
130132
false => Ok(ptr),
@@ -148,7 +150,9 @@ impl Memory {
148150
/// The lifetime of the returned pointer must not exceed that of the object itself.
149151
///
150152
pub unsafe fn data_pointer_mut(&mut self, offset: u32, len: u32) -> WasmEdgeResult<*mut u8> {
151-
let ptr = unsafe { ffi::WasmEdge_MemoryInstanceGetPointer(self.inner.0, offset, len) };
153+
let ptr = unsafe {
154+
ffi::WasmEdge_MemoryInstanceGetPointer(self.inner.0, offset.into(), len.into())
155+
};
152156
match ptr.is_null() {
153157
true => Err(Box::new(WasmEdgeError::Mem(MemError::MutPtr))),
154158
false => Ok(ptr),
@@ -157,7 +161,7 @@ impl Memory {
157161

158162
/// Returns the size, in WebAssembly pages (64 KiB of each page), of this wasm memory.
159163
pub fn size(&self) -> u32 {
160-
unsafe { ffi::WasmEdge_MemoryInstanceGetPageSize(self.inner.0) }
164+
unsafe { ffi::WasmEdge_MemoryInstanceGetPageSize(self.inner.0) as u32 }
161165
}
162166

163167
/// Grows this WebAssembly memory by `count` pages.
@@ -171,7 +175,12 @@ impl Memory {
171175
/// If fail to grow the page count, then an error is returned.
172176
///
173177
pub fn grow(&mut self, count: u32) -> WasmEdgeResult<()> {
174-
unsafe { check(ffi::WasmEdge_MemoryInstanceGrowPage(self.inner.0, count)) }
178+
unsafe {
179+
check(ffi::WasmEdge_MemoryInstanceGrowPage(
180+
self.inner.0,
181+
count.into(),
182+
))
183+
}
175184
}
176185

177186
/// # Safety
@@ -264,8 +273,11 @@ impl MemType {
264273
if shared && max.is_none() {
265274
return Err(Box::new(WasmEdgeError::Mem(MemError::CreateSharedType)));
266275
}
267-
let ctx =
268-
unsafe { ffi::WasmEdge_MemoryTypeCreate(WasmEdgeLimit::new(min, max, shared).into()) };
276+
// WasmEdge_MemoryTypeCreate borrows the limit (declared `const` in
277+
// the 0.17.0 C API), so the caller owns and must delete the context.
278+
let limit_ctx = WasmEdgeLimit::new(min, max, shared).to_context();
279+
let ctx = unsafe { ffi::WasmEdge_MemoryTypeCreate(limit_ctx) };
280+
unsafe { ffi::WasmEdge_LimitDelete(limit_ctx) };
269281
match ctx.is_null() {
270282
true => Err(Box::new(WasmEdgeError::MemTypeCreate)),
271283
false => Ok(Self {
@@ -277,21 +289,21 @@ impl MemType {
277289
/// Returns the initial size of a [Memory].
278290
pub(crate) fn min(&self) -> u32 {
279291
let limit = unsafe { ffi::WasmEdge_MemoryTypeGetLimit(self.inner.0) };
280-
let limit: WasmEdgeLimit = limit.into();
292+
let limit = WasmEdgeLimit::from_context(limit);
281293
limit.min()
282294
}
283295

284296
/// Returns the maximum size of a [Memory] allowed to grow.
285297
pub(crate) fn max(&self) -> Option<u32> {
286298
let limit = unsafe { ffi::WasmEdge_MemoryTypeGetLimit(self.inner.0) };
287-
let limit: WasmEdgeLimit = limit.into();
299+
let limit = WasmEdgeLimit::from_context(limit);
288300
limit.max()
289301
}
290302

291303
/// Returns whether the memory is shared or not.
292304
pub(crate) fn shared(&self) -> bool {
293305
let limit = unsafe { ffi::WasmEdge_MemoryTypeGetLimit(self.inner.0) };
294-
let limit: WasmEdgeLimit = limit.into();
306+
let limit = WasmEdgeLimit::from_context(limit);
295307
limit.shared()
296308
}
297309
}

crates/wasmedge-sys/src/instance/table.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl Table {
7979
check(ffi::WasmEdge_TableInstanceGetData(
8080
self.inner.0,
8181
&mut data as *mut _,
82-
idx,
82+
idx.into(),
8383
))?;
8484
data
8585
};
@@ -102,7 +102,7 @@ impl Table {
102102
check(ffi::WasmEdge_TableInstanceSetData(
103103
self.inner.0,
104104
data.as_raw(),
105-
idx,
105+
idx.into(),
106106
))
107107
}
108108
}
@@ -125,7 +125,7 @@ impl Table {
125125
///
126126
/// If fail to increase the size of the [Table], then an error is returned.
127127
pub fn grow(&mut self, size: u32) -> WasmEdgeResult<()> {
128-
unsafe { check(ffi::WasmEdge_TableInstanceGrow(self.inner.0, size)) }
128+
unsafe { check(ffi::WasmEdge_TableInstanceGrow(self.inner.0, size.into())) }
129129
}
130130

131131
/// # Safety
@@ -190,9 +190,11 @@ impl TableType {
190190
///
191191
pub(crate) fn create(elem_ty: RefType, min: u32, max: Option<u32>) -> WasmEdgeResult<Self> {
192192
let ty: ValType = elem_ty.into();
193-
let ctx = unsafe {
194-
ffi::WasmEdge_TableTypeCreate(ty.into(), WasmEdgeLimit::new(min, max, false).into())
195-
};
193+
// WasmEdge_TableTypeCreate borrows the limit (declared `const` in
194+
// the 0.17.0 C API), so the caller owns and must delete the context.
195+
let limit_ctx = WasmEdgeLimit::new(min, max, false).to_context();
196+
let ctx = unsafe { ffi::WasmEdge_TableTypeCreate(ty.into(), limit_ctx) };
197+
unsafe { ffi::WasmEdge_LimitDelete(limit_ctx) };
196198
if ctx.is_null() {
197199
Err(Box::new(WasmEdgeError::TableTypeCreate))
198200
} else {
@@ -212,14 +214,14 @@ impl TableType {
212214
/// Returns the initial size of the [Table].
213215
pub(crate) fn min(&self) -> u32 {
214216
let limit = unsafe { ffi::WasmEdge_TableTypeGetLimit(self.inner.0) };
215-
let limit: WasmEdgeLimit = limit.into();
217+
let limit = WasmEdgeLimit::from_context(limit);
216218
limit.min()
217219
}
218220

219221
/// Returns the maximum size of the [Table].
220222
pub(crate) fn max(&self) -> Option<u32> {
221223
let limit = unsafe { ffi::WasmEdge_TableTypeGetLimit(self.inner.0) };
222-
let limit: WasmEdgeLimit = limit.into();
224+
let limit = WasmEdgeLimit::from_context(limit);
223225
limit.max()
224226
}
225227
}

0 commit comments

Comments
 (0)