Skip to content

Commit 89143a5

Browse files
committed
Fixes thrownexcpetion import which is behind gc
1 parent 0f78a86 commit 89143a5

6 files changed

Lines changed: 30 additions & 12 deletions

File tree

crates/c-api/include/wasmtime/val.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
extern "C" {
1616
#endif
1717

18+
#ifdef WASMTIME_FEATURE_GC
1819
struct wasmtime_eqref;
1920
/// Convenience alias for #wasmtime_eqref
2021
typedef struct wasmtime_eqref wasmtime_eqref_t;
@@ -56,7 +57,7 @@ typedef struct wasmtime_anyref {
5657
void *__private3;
5758
} wasmtime_anyref_t;
5859

59-
#ifdef WASMTIME_FEATURE_GC
60+
6061
/// \brief Helper function to initialize the `ref` provided to a null anyref
6162
/// value.
6263
static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
@@ -203,7 +204,6 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
203204
* `wasmtime_externref_set_null`. Null can be tested for with the
204205
* `wasmtime_externref_is_null` function.
205206
*/
206-
#endif // WASMTIME_FEATURE_GC
207207

208208
typedef struct wasmtime_externref {
209209
/// Internal metadata tracking within the store, embedders should not
@@ -217,7 +217,6 @@ typedef struct wasmtime_externref {
217217
void *__private3;
218218
} wasmtime_externref_t;
219219

220-
#ifdef WASMTIME_FEATURE_GC
221220
/// \brief Helper function to initialize the `ref` provided to a null externref
222221
/// value.
223222
static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
@@ -318,7 +317,7 @@ WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
318317
*/
319318
WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
320319
wasmtime_context_t *context, const wasmtime_externref_t *ref);
321-
#endif // WASMTIME_FEATURE_GC
320+
322321

323322
/**
324323
* \typedef wasmtime_exnref_t
@@ -399,6 +398,8 @@ typedef uint8_t wasmtime_valkind_t;
399398
/// exnref
400399
#define WASMTIME_EXNREF 8
401400

401+
#endif // WASMTIME_FEATURE_GC
402+
402403
/// \brief A 128-bit value representing the WebAssembly `v128` type. Bytes are
403404
/// stored in little-endian order.
404405
typedef uint8_t wasmtime_v128[16];
@@ -423,6 +424,7 @@ typedef union wasmtime_valunion {
423424
float32_t f32;
424425
/// Field used if #wasmtime_val_t::kind is #WASMTIME_F64
425426
float64_t f64;
427+
#ifdef WASMTIME_FEATURE_GC
426428
/// Field used if #wasmtime_val_t::kind is #WASMTIME_ANYREF
427429
wasmtime_anyref_t anyref;
428430
/// Field used if #wasmtime_val_t::kind is #WASMTIME_EXTERNREF
@@ -434,6 +436,7 @@ typedef union wasmtime_valunion {
434436
/// Use `wasmtime_funcref_is_null` to test whether this is a null function
435437
/// reference.
436438
wasmtime_func_t funcref;
439+
#endif // WASMTIME_FEATURE_GC
437440
/// Field used if #wasmtime_val_t::kind is #WASMTIME_V128
438441
wasmtime_v128 v128;
439442
} wasmtime_valunion_t;

crates/c-api/src/exn.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "gc")]
12
use crate::{
23
WasmtimeStoreContextMut, handle_result, wasm_trap_t, wasmtime_error_t, wasmtime_val_t,
34
};

crates/c-api/src/func.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ use std::mem::{self, MaybeUninit};
1010
use std::panic::{self, AssertUnwindSafe};
1111
use std::ptr;
1212
use std::str;
13-
#[cfg(feature = "gc")]
14-
use wasmtime::RootScope;
1513
use wasmtime::{
1614
AsContext, AsContextMut, Error, Extern, Func, Result, StoreContext, StoreContextMut, Trap, Val,
1715
ValRaw,
1816
};
17+
#[cfg(feature = "gc")]
18+
use wasmtime::{RootScope, ThrownException};
1919

2020
#[derive(Clone)]
2121
#[repr(transparent)]
@@ -406,8 +406,18 @@ pub unsafe extern "C" fn wasmtime_func_call_unchecked(
406406
}
407407
}
408408

409+
#[cfg(feature = "gc")]
410+
fn is_trap_like_impl(err: &Error) -> bool {
411+
err.is::<Trap>() || err.is::<ThrownException>()
412+
}
413+
414+
#[cfg(not(feature = "gc"))]
415+
fn is_trap_like_impl(err: &Error) -> bool {
416+
err.is::<Trap>()
417+
}
418+
409419
fn store_err(err: Error, trap_ret: &mut *mut wasm_trap_t) -> Option<Box<wasmtime_error_t>> {
410-
if err.is::<Trap>() || err.is::<wasmtime::ThrownException>() {
420+
if is_trap_like_impl(&err) {
411421
*trap_ret = Box::into_raw(Box::new(wasm_trap_t::new(err)));
412422
None
413423
} else {

crates/c-api/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub use wasmtime;
2020
mod config;
2121
mod engine;
2222
mod error;
23+
#[cfg(feature = "gc")]
2324
mod exn;
2425
mod r#extern;
2526
mod func;
@@ -44,6 +45,7 @@ mod vec;
4445
pub use crate::config::*;
4546
pub use crate::engine::*;
4647
pub use crate::error::*;
48+
#[cfg(feature = "gc")]
4749
pub use crate::exn::*;
4850
pub use crate::r#extern::*;
4951
pub use crate::func::*;

crates/c-api/src/ref.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::WasmtimeStoreContextMut;
44
use crate::abort;
55
use std::mem::{ManuallyDrop, MaybeUninit};
6-
use std::{num::NonZeroU64, os::raw::c_void, ptr};
6+
use std::{num::NonZeroU64, os::raw::c_void};
77
use wasmtime::{
88
AnyRef, ArrayRef, ArrayRefPre, ArrayType, EqRef, ExnRef, ExternRef, FieldType, I31, Mutability,
99
OwnedRooted, Ref, RootScope, StorageType, StructRef, StructRefPre, StructType, Val, ValType,

crates/c-api/src/val.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#[cfg(feature = "gc")]
22
use crate::r#ref::ref_to_val;
3-
use crate::{
4-
WASM_I32, from_valtype, into_valtype, wasm_valkind_t, wasmtime_exnref_t, wasmtime_valkind_t,
5-
};
3+
use crate::{WASM_I32, from_valtype, into_valtype, wasm_valkind_t, wasmtime_valkind_t};
64
#[cfg(feature = "gc")]
7-
use crate::{wasm_ref_t, wasmtime_anyref_t, wasmtime_externref_t};
5+
use crate::{wasm_ref_t, wasmtime_anyref_t, wasmtime_exnref_t, wasmtime_externref_t};
86
use std::mem::{ManuallyDrop, MaybeUninit};
97
use std::ptr;
108
use wasmtime::{AsContextMut, Func, Val, ValType};
@@ -166,6 +164,7 @@ pub union wasmtime_val_union {
166164
pub anyref: ManuallyDrop<wasmtime_anyref_t>,
167165
#[cfg(feature = "gc")]
168166
pub externref: ManuallyDrop<wasmtime_externref_t>,
167+
#[cfg(feature = "gc")]
169168
pub exnref: ManuallyDrop<wasmtime_exnref_t>,
170169
#[cfg(feature = "gc")]
171170
pub funcref: wasmtime_func_t,
@@ -311,6 +310,7 @@ impl wasmtime_val_t {
311310
funcref: func.into(),
312311
},
313312
},
313+
#[cfg(feature = "gc")]
314314
Val::ExnRef(e) => wasmtime_val_t {
315315
kind: crate::WASMTIME_EXNREF,
316316
of: wasmtime_val_union {
@@ -374,6 +374,7 @@ impl wasmtime_val_t {
374374
}
375375
#[cfg(feature = "gc")]
376376
crate::WASMTIME_FUNCREF => Val::FuncRef(self.of.funcref.as_wasmtime()),
377+
#[cfg(feature = "gc")]
377378
crate::WASMTIME_EXNREF => {
378379
Val::ExnRef(self.of.exnref.as_wasmtime().map(|e| e.to_rooted(cx)))
379380
}
@@ -401,6 +402,7 @@ pub unsafe extern "C" fn wasmtime_val_clone(
401402
crate::WASMTIME_EXTERNREF => wasmtime_val_union {
402403
externref: ManuallyDrop::new(src.of.externref.as_wasmtime().into()),
403404
},
405+
#[cfg(feature = "gc")]
404406
crate::WASMTIME_EXNREF => wasmtime_val_union {
405407
exnref: ManuallyDrop::new(src.of.exnref.as_wasmtime().into()),
406408
},

0 commit comments

Comments
 (0)