Skip to content

Commit b34556f

Browse files
authored
C++ API: Make wasmtime::Store::gc return a Result (#12439)
* C++ API: Make `Store::gc()` return a `Result` * Handle GC errors in C++ example programs * clang format
1 parent c4a38d6 commit b34556f

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

crates/c-api/include/wasmtime/store.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ public:
233233

234234
/// Runs a garbage collection pass in the referenced store to collect loose
235235
/// GC-managed objects, if any are available.
236-
void gc() { context().gc(); }
236+
Result<std::monostate> gc() { return context().gc(); }
237237

238238
private:
239239
template <typename F>

examples/anyref.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ int main() {
9595
}
9696

9797
std::cout << "GCing within the store...\n";
98-
store.context().gc();
98+
if (!store.context().gc()) {
99+
std::cerr << "> Error while collecting garbage\n";
100+
return 1;
101+
}
99102

100103
std::cout << "Done.\n";
101104
return 0;

examples/externref.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,10 @@ int main() {
5050
<< "\n";
5151

5252
std::cout << "Running a gc..\n";
53-
store.context().gc();
53+
if (!store.context().gc()) {
54+
std::cerr << "> Error while collecting garbage\n";
55+
return 1;
56+
}
57+
58+
return 0;
5459
}

0 commit comments

Comments
 (0)