Skip to content

Commit c575d98

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

9 files changed

Lines changed: 40 additions & 24 deletions

File tree

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,15 @@ class Config {
303303
wasmtime_config_wasm_tail_call_set(ptr.get(), enable);
304304
}
305305

306-
#ifdef WASMTIME_FEATURE_GC
306+
#ifdef WASMTIME_FEATURE_GC
307307
/// \brief Configures whether the WebAssembly reference types proposal is
308308
/// enabled
309309
///
310310
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_reference_types
311311
void wasm_reference_types(bool enable) {
312312
wasmtime_config_wasm_reference_types_set(ptr.get(), enable);
313313
}
314-
#endif // WASMTIME_FEATURE_GC
314+
#endif // WASMTIME_FEATURE_GC
315315

316316
/// \brief Configures whether the WebAssembly simd proposal is enabled
317317
///
@@ -363,13 +363,13 @@ class Config {
363363
wasmtime_config_wasm_memory64_set(ptr.get(), enable);
364364
}
365365

366-
#ifdef WASMTIME_FEATURE_GC
366+
#ifdef WASMTIME_FEATURE_GC
367367
/// \brief Configures whether the WebAssembly Garbage Collection proposal will
368368
/// be enabled
369369
///
370370
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_gc
371371
void wasm_gc(bool enable) { wasmtime_config_wasm_gc_set(ptr.get(), enable); }
372-
#endif // WASMTIME_FEATURE_GC
372+
#endif // WASMTIME_FEATURE_GC
373373

374374
/// \brief Configures whether the WebAssembly function references proposal
375375
/// will be enabled
@@ -387,15 +387,15 @@ class Config {
387387
wasmtime_config_wasm_wide_arithmetic_set(ptr.get(), enable);
388388
}
389389

390-
#ifdef WASMTIME_FEATURE_GC
390+
#ifdef WASMTIME_FEATURE_GC
391391
/// \brief Configures whether the WebAssembly exceptions proposal will be
392392
/// enabled
393393
///
394394
/// https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.wasm_exceptions
395395
void wasm_exceptions(bool enable) {
396396
wasmtime_config_wasm_exceptions_set(ptr.get(), enable);
397397
}
398-
#endif // WASMTIME_FEATURE_GC
398+
#endif // WASMTIME_FEATURE_GC
399399

400400
/// \brief Configures whether the WebAssembly custom-page-sizes proposal will
401401
/// be enabled

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ template <> struct WasmType<std::optional<ExternRef>> {
103103
p->externref = 0;
104104
}
105105
}
106-
106+
107107
static std::optional<ExternRef> load(Store::Context cx,
108-
wasmtime_val_raw_t *p) {
108+
wasmtime_val_raw_t *p) {
109109
if (p->externref == 0) {
110110
return std::nullopt;
111111
}

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

Lines changed: 5 additions & 6 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,6 @@ typedef struct wasmtime_anyref {
5657
void *__private3;
5758
} wasmtime_anyref_t;
5859

59-
#ifdef WASMTIME_FEATURE_GC
6060
/// \brief Helper function to initialize the `ref` provided to a null anyref
6161
/// value.
6262
static inline void wasmtime_anyref_set_null(wasmtime_anyref_t *ref) {
@@ -72,7 +72,6 @@ static inline bool wasmtime_anyref_is_null(const wasmtime_anyref_t *ref) {
7272
return ref->store_id == 0;
7373
}
7474

75-
7675
/**
7776
* \brief Creates a new reference pointing to the same data that `anyref`
7877
* points to (depending on the configured collector this might increase a
@@ -203,7 +202,6 @@ WASM_API_EXTERN bool wasmtime_anyref_i31_get_s(wasmtime_context_t *context,
203202
* `wasmtime_externref_set_null`. Null can be tested for with the
204203
* `wasmtime_externref_is_null` function.
205204
*/
206-
#endif // WASMTIME_FEATURE_GC
207205

208206
typedef struct wasmtime_externref {
209207
/// Internal metadata tracking within the store, embedders should not
@@ -217,7 +215,6 @@ typedef struct wasmtime_externref {
217215
void *__private3;
218216
} wasmtime_externref_t;
219217

220-
#ifdef WASMTIME_FEATURE_GC
221218
/// \brief Helper function to initialize the `ref` provided to a null externref
222219
/// value.
223220
static inline void wasmtime_externref_set_null(wasmtime_externref_t *ref) {
@@ -318,7 +315,6 @@ WASM_API_EXTERN void wasmtime_externref_from_raw(wasmtime_context_t *context,
318315
*/
319316
WASM_API_EXTERN uint32_t wasmtime_externref_to_raw(
320317
wasmtime_context_t *context, const wasmtime_externref_t *ref);
321-
#endif // WASMTIME_FEATURE_GC
322318

323319
/**
324320
* \typedef wasmtime_exnref_t
@@ -399,11 +395,12 @@ typedef uint8_t wasmtime_valkind_t;
399395
/// exnref
400396
#define WASMTIME_EXNREF 8
401397

398+
#endif // WASMTIME_FEATURE_GC
399+
402400
/// \brief A 128-bit value representing the WebAssembly `v128` type. Bytes are
403401
/// stored in little-endian order.
404402
typedef uint8_t wasmtime_v128[16];
405403

406-
407404
/**
408405
* \typedef wasmtime_valunion_t
409406
* \brief Convenience alias for #wasmtime_valunion
@@ -423,6 +420,7 @@ typedef union wasmtime_valunion {
423420
float32_t f32;
424421
/// Field used if #wasmtime_val_t::kind is #WASMTIME_F64
425422
float64_t f64;
423+
#ifdef WASMTIME_FEATURE_GC
426424
/// Field used if #wasmtime_val_t::kind is #WASMTIME_ANYREF
427425
wasmtime_anyref_t anyref;
428426
/// Field used if #wasmtime_val_t::kind is #WASMTIME_EXTERNREF
@@ -434,6 +432,7 @@ typedef union wasmtime_valunion {
434432
/// Use `wasmtime_funcref_is_null` to test whether this is a null function
435433
/// reference.
436434
wasmtime_func_t funcref;
435+
#endif // WASMTIME_FEATURE_GC
437436
/// Field used if #wasmtime_val_t::kind is #WASMTIME_V128
438437
wasmtime_v128 v128;
439438
} wasmtime_valunion_t;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ public:
108108

109109
class EqRef;
110110

111-
112111
#ifdef WASMTIME_FEATURE_GC
113112
/**
114113
* \brief Representation of a WebAssembly `anyref` value.

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: 10 additions & 5 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};
@@ -46,7 +44,10 @@ impl Drop for wasm_val_t {
4644

4745
impl Clone for wasm_val_t {
4846
fn clone(&self) -> Self {
49-
#[allow(unused_mut)]
47+
#[allow(
48+
unused_mut,
49+
reason = "needed for conditional mutation under cfg(feature = \"gc\")"
50+
)]
5051
let mut ret = wasm_val_t {
5152
kind: self.kind,
5253
of: self.of,
@@ -166,6 +167,7 @@ pub union wasmtime_val_union {
166167
pub anyref: ManuallyDrop<wasmtime_anyref_t>,
167168
#[cfg(feature = "gc")]
168169
pub externref: ManuallyDrop<wasmtime_externref_t>,
170+
#[cfg(feature = "gc")]
169171
pub exnref: ManuallyDrop<wasmtime_exnref_t>,
170172
#[cfg(feature = "gc")]
171173
pub funcref: wasmtime_func_t,
@@ -311,6 +313,7 @@ impl wasmtime_val_t {
311313
funcref: func.into(),
312314
},
313315
},
316+
#[cfg(feature = "gc")]
314317
Val::ExnRef(e) => wasmtime_val_t {
315318
kind: crate::WASMTIME_EXNREF,
316319
of: wasmtime_val_union {
@@ -374,6 +377,7 @@ impl wasmtime_val_t {
374377
}
375378
#[cfg(feature = "gc")]
376379
crate::WASMTIME_FUNCREF => Val::FuncRef(self.of.funcref.as_wasmtime()),
380+
#[cfg(feature = "gc")]
377381
crate::WASMTIME_EXNREF => {
378382
Val::ExnRef(self.of.exnref.as_wasmtime().map(|e| e.to_rooted(cx)))
379383
}
@@ -401,6 +405,7 @@ pub unsafe extern "C" fn wasmtime_val_clone(
401405
crate::WASMTIME_EXTERNREF => wasmtime_val_union {
402406
externref: ManuallyDrop::new(src.of.externref.as_wasmtime().into()),
403407
},
408+
#[cfg(feature = "gc")]
404409
crate::WASMTIME_EXNREF => wasmtime_val_union {
405410
exnref: ManuallyDrop::new(src.of.exnref.as_wasmtime().into()),
406411
},

0 commit comments

Comments
 (0)