Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing reference in sync calls should also be considered unsafe #6

Open
Heap-Hop opened this issue May 15, 2024 · 1 comment
Open

Comments

@Heap-Hop
Copy link

Thank you for creating this great crate!

I noticed that passing a reference in a sync call might cause a dangling pointer because the reference on the Go side might be saved, while it could have already been dropped on the Rust side.

Given that the design goal of this crate is to pursue extreme performance, this might be expected. However, I am wondering if synchronous calls should also be considered unsafe, similar to asynchronous calls.

Please have a look or try this simple example:
https://github.com/Heap-Hop/rust2go/tree/unsafe_sync

Heap-Hop@9734b24#diff-8aa8e83ff3b2189fd6397149a7b274f82daede3923191a3d0409f72a2f8bb78fR36

If I missed any mention of similar issues in the documentation, please correct me. Thanks again.

@ihciah
Copy link
Owner

ihciah commented May 15, 2024

Yes it is.

There are 2 responsibites, one is to ensure params not dropped when go executing user's function, and another one is to make sure borrowed parameters not outlive the function.

I think the first one is for rust, so not taking ownership and drop the future is not safe.
The second one is for golang side to obey. Since there's no unsafe marker in golang, users must ensure it by themself. We cannot push this responsibility to rust because golang not having unsafe marker, it is not rust side's job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants