You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, there is no safe way to manipulate fields containing a custom non-opaque struct or opaque type inside non-opaque structs using code generated by C# / .NET backend.
I think support for this can be achieved by duplicating fields inside the managed classes (as opposed to holding the raw struct), except we swap the other raw structs and pointers by an appropriate managed object (this is similar to the C++ backend approach).
Since non-opaque structs have Copy semantic (by Diplomat's design), this is trivial to get this working for fields containing other non-opaque structs (everything is copied at FFI boundary).
Support for references to opaque types is a bit more tricky though.
Emphasis on Boxes. We can't copy an owning pointer that way without risking use-after-free bugs (if two managed opaque types are using the same underlying pointer Drop will run twice for the same value).
We can however support references on opaque types. This should be addressed in dotnet backend too.
Also, a distinction between owning managed classes and borrowing managed classes have to exist.
That is, for:
If Bar<'f> contains &'f Foo, the actual Foo (pointed by both owning C# Foo and borrowing C# Foo) must not be dropped when borrowing C# Foo is destructed.
The text was updated successfully, but these errors were encountered:
Currently, there is no safe way to manipulate fields containing a custom non-opaque struct or opaque type inside non-opaque structs using code generated by C# / .NET backend.
I think support for this can be achieved by duplicating fields inside the managed classes (as opposed to holding the raw struct), except we swap the other raw structs and pointers by an appropriate managed object (this is similar to the C++ backend approach).
Since non-opaque structs have
Copy
semantic (by Diplomat's design), this is trivial to get this working for fields containing other non-opaque structs (everything is copied at FFI boundary).Support for references to opaque types is a bit more tricky though.
First, as mentioned by @Manishearth in #130 (comment):
Emphasis on
Boxes
. We can't copy an owning pointer that way without risking use-after-free bugs (if two managed opaque types are using the same underlying pointer Drop will run twice for the same value).We can however support references on opaque types. This should be addressed in dotnet backend too.
Also, a distinction between owning managed classes and borrowing managed classes have to exist.
That is, for:
If
Bar<'f>
contains&'f Foo
, the actualFoo
(pointed by both owning C#Foo
and borrowing C#Foo
) must not be dropped when borrowing C#Foo
is destructed.The text was updated successfully, but these errors were encountered: