Skip to content

Commit 1c2206c

Browse files
committed
Merge branch 'main' of github.com:bytecodealliance/wit-bindgen into wasmfx-merge
2 parents 3640c4c + c648fc7 commit 1c2206c

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

crates/csharp/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,11 @@ impl InterfaceGenerator<'_> {
14441444
.map(|key| self.resolve.name_world_key(key))
14451445
.unwrap_or_else(|| "$root".into());
14461446

1447+
// As of this writing, we cannot safely drop a handle to an imported resource from a .NET finalizer
1448+
// because it may still have one or more open child resources. Once WIT has explicit syntax for
1449+
// indicating parent/child relationships, we should be able to use that information to keep track
1450+
// of child resources automatically in generated code, at which point we'll be able to drop them in
1451+
// the correct order from finalizers.
14471452
uwriteln!(
14481453
self.src,
14491454
r#"
@@ -1458,22 +1463,17 @@ impl InterfaceGenerator<'_> {
14581463
14591464
public void Dispose() {{
14601465
Dispose(true);
1461-
GC.SuppressFinalize(this);
14621466
}}
14631467
14641468
[DllImport("{module_name}", EntryPoint = "[resource-drop]{name}"), WasmImportLinkage]
14651469
private static extern void wasmImportResourceDrop(int p0);
14661470
14671471
protected virtual void Dispose(bool disposing) {{
1468-
if (Handle != 0) {{
1472+
if (disposing && Handle != 0) {{
14691473
wasmImportResourceDrop(Handle);
14701474
Handle = 0;
14711475
}}
14721476
}}
1473-
1474-
~{upper_camel}() {{
1475-
Dispose(false);
1476-
}}
14771477
"#
14781478
);
14791479
}

crates/moonbit/src/lib.rs

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,35 @@ pub extern "wasm" fn ptr2int_array(ptr : Int) -> FixedArray[Int] =
149149
pub extern "wasm" fn ptr2float_array(ptr : Int) -> FixedArray[Float] =
150150
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.const 241 i32.store8 local.get 0 i32.const 8 i32.sub)
151151
152-
pub extern "wasm" fn ptr2uint64_array(ptr : Int) -> FixedArray[UInt64] =
153-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
152+
extern "wasm" fn ptr2uint64_array_ffi(ptr : Int) -> FixedArray[UInt64] =
153+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
154+
155+
pub fn ptr2uint64_array(ptr : Int) -> FixedArray[UInt64] {
156+
set_64_header_ffi(ptr - 4)
157+
ptr2uint64_array_ffi(ptr)
158+
}
154159
155-
pub extern "wasm" fn ptr2int64_array(ptr : Int) -> FixedArray[Int64] =
156-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
160+
extern "wasm" fn ptr2int64_array_ffi(ptr : Int) -> FixedArray[Int64] =
161+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
162+
163+
pub fn ptr2int64_array(ptr : Int) -> FixedArray[Int64] {
164+
set_64_header_ffi(ptr - 4)
165+
ptr2int64_array_ffi(ptr)
166+
}
157167
158-
pub extern "wasm" fn ptr2double_array(ptr : Int) -> FixedArray[Double] =
159-
#|(func (param i32) (result i32) local.get 0 i32.const 4 i32.sub i32.load i32.const 1 i32.shr_u i32.const 241 i32.or local.get 0 i32.const 4 i32.sub i32.store local.get 0 i32.const 8 i32.sub)
168+
extern "wasm" fn ptr2double_array_ffi(ptr : Int) -> FixedArray[Double] =
169+
#|(func (param i32) (result i32) local.get 0 i32.const 8 i32.sub)
170+
171+
pub fn ptr2double_array(ptr : Int) -> FixedArray[Double] {
172+
set_64_header_ffi(ptr - 4)
173+
ptr2double_array_ffi(ptr)
174+
}
175+
176+
fn set_64_header_ffi(offset : Int) -> Unit {
177+
let len = load32(offset)
178+
store32(offset, len.lsr(1))
179+
store8(offset, 241)
180+
}
160181
161182
pub trait Any {}
162183
pub struct Cleanup {

0 commit comments

Comments
 (0)