Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
cpetig committed Sep 2, 2024
2 parents 034e7c6 + c648fc7 commit 44a5a1e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions crates/csharp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1449,6 +1449,11 @@ impl InterfaceGenerator<'_> {
.map(|key| self.resolve.name_world_key(key))
.unwrap_or_else(|| "$root".into());

// As of this writing, we cannot safely drop a handle to an imported resource from a .NET finalizer
// because it may still have one or more open child resources. Once WIT has explicit syntax for
// indicating parent/child relationships, we should be able to use that information to keep track
// of child resources automatically in generated code, at which point we'll be able to drop them in
// the correct order from finalizers.
uwriteln!(
self.src,
r#"
Expand All @@ -1463,22 +1468,17 @@ impl InterfaceGenerator<'_> {
public void Dispose() {{
Dispose(true);
GC.SuppressFinalize(this);
}}
[DllImport("{module_name}", EntryPoint = "[resource-drop]{name}"), WasmImportLinkage]
private static extern void wasmImportResourceDrop(int p0);
protected virtual void Dispose(bool disposing) {{
if (Handle != 0) {{
if (disposing && Handle != 0) {{
wasmImportResourceDrop(Handle);
Handle = 0;
}}
}}
~{upper_camel}() {{
Dispose(false);
}}
"#
);
}
Expand Down

0 comments on commit 44a5a1e

Please sign in to comment.