Skip to content

Commit 67e1774

Browse files
fix(c): Prefix import module name for resource-drop with [export] (#946)
* fix(c): Prefix import module name for resource-drop with `[export]` Import module name for exported resource's drop should be prefixed with [export] * test: disable resource drop check for c-sharp generator for now
1 parent bcd136e commit 67e1774

File tree

7 files changed

+26
-2
lines changed

7 files changed

+26
-2
lines changed

crates/c/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,10 +1040,11 @@ extern void {ns}_{snake}_drop_own({own} handle);
10401040
let import_module = if self.in_import {
10411041
self.wasm_import_module.unwrap().to_string()
10421042
} else {
1043-
match self.interface {
1043+
let module = match self.interface {
10441044
Some((_, key)) => self.resolve.name_world_key(key),
10451045
None => unimplemented!("resource exports from worlds"),
1046-
}
1046+
};
1047+
format!("[export]{module}")
10471048
};
10481049

10491050
let drop_fn = format!("__wasm_import_{ns}_{snake}_drop");

tests/runtime/resources.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ fn run_test(exports: Guest, store: &mut Store<crate::Wasi<MyImports>>) -> Result
9797
ResourceAny::resource_drop(z_instance_1, &mut *store)?;
9898
ResourceAny::resource_drop(z_instance_2, &mut *store)?;
9999

100+
exports.call_consume(&mut *store, x_add)?;
101+
100102
let dropped_zs_end = z.call_num_dropped(&mut *store)?;
101103
if dropped_zs_start != 0 {
102104
assert_eq!(dropped_zs_end, dropped_zs_start + 2);

tests/runtime/resources/wasm.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ exports_own_z_t exports_add(exports_z_t* a, exports_z_t* b) {
5353
return exports_constructor_z(c);
5454
}
5555

56+
void exports_consume(exports_own_x_t x) {
57+
exports_x_drop_own(x);
58+
}
59+
5660
void exports_x_destructor(exports_x_t* x) {
5761
free(x);
5862
}

tests/runtime/resources/wasm.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ public static IExports.Z Add(IExports.Z a, IExports.Z b)
1010
{
1111
return new Z(((Z) a).val + ((Z) b).val);
1212
}
13+
14+
public static void Consume(IExports.X x)
15+
{
16+
// FIXME: c-sharp generator seems wrong here
17+
// x.Dispose();
18+
}
1319

1420
public static Result<None, string> TestImports()
1521
{

tests/runtime/resources/wasm.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ func (e ExportsImpl) Add(z ExportsZ, b ExportsZ) ExportsZ {
6060
return &MyZ{a: z.MethodZGetA() + b.MethodZGetA()}
6161
}
6262

63+
func (e ExportsImpl) Consume(x ExportsX) {
64+
DropExportsX(x)
65+
}
66+
6367
func (k *MyKebabCase) MethodKebabCaseGetA() uint32 {
6468
return k.a
6569
}

tests/runtime/resources/wasm.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ impl exports::exports::Guest for Test {
3232
let b = b.get::<ComponentZ>();
3333
Z::new(ComponentZ { val: a.val + b.val })
3434
}
35+
36+
fn consume(x: exports::exports::X) {
37+
drop(x);
38+
}
39+
3540
fn test_imports() -> Result<(), String> {
3641
use imports::*;
3742
let y = Y::new(10);

tests/runtime/resources/world.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ world resources {
2727

2828
add: func(a: borrow<z>, b: borrow<z>) -> own<z>;
2929

30+
consume: func(x: x);
31+
3032
resource kebab-case {
3133
constructor(a: u32);
3234
get-a: func() -> u32;

0 commit comments

Comments
 (0)