Skip to content

create_extern_c_wrapper should probably define an unsafe function #5

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

Open
adamreichold opened this issue Nov 16, 2019 · 0 comments
Open

Comments

@adamreichold
Copy link

create_extern_c_wrapper currently defines a safe function via a C-compatible ABI and uses unsafe blocks to transform raw pointers into slices. An unsafe block is basically an assertion to the compiler, that the author is able to check the relevant preconditions for the unsafe operations to be correct. However, a raw pointer can never be verified without additional information, e.g. even if it is non-null and the alignment is valid, it could still be dangling to pointing into a completely different allocation.

This suggests that it is the responsibility of the calling (C++) code to ensure that the pointers are valid as the Rust code has no ability to check the pointers and hence justify the unsafe blocks. This would be expressed by marking the whole function unsafe which is fitting as the calling C++ is considered "unsafe" by definition.

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

1 participant