Skip to content

boost::scoped_ptr demo #524

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

Closed
wants to merge 1 commit into from
Closed

boost::scoped_ptr demo #524

wants to merge 1 commit into from

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 28, 2020

Example code in response to #251 (comment).

Note this line is using cxx::kind::Opaque:

type Kind = cxx::kind::Opaque;

because passing a boost::scoped_ptr by value across the FFI is not possible due to both of the following being true:

  1. It uses the "small class" ABI in C++ which Rust has no representation for. Any Rust data structure will always either look like "small POD" or "big classes" as far as the ABI in C++.

  2. It exposes no way to exit out of "small class" state (analogous to unique_ptr<T>::release which is what we use for making UniquePtr work by value on the language boundary).

For a different smart pointer for which one or both of these doesn't apply you'd probably use cxx::kind::Trivial because Rust's move semantics are non-problematic for anything pointer-like.

@dtolnay
Copy link
Owner Author

dtolnay commented Nov 28, 2020

#525 shows an approach where item 1 in #524 (comment) does not apply -- it just works around "small class" by adding padding, which isn't great, but is compatible with Rust.

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

Successfully merging this pull request may close these issues.

1 participant