Skip to content

native-lib: allow passing structs as arguments #4466

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

nia-e
Copy link
Contributor

@nia-e nia-e commented Jul 14, 2025

Blocked on #4456 currently to make rebasing easier when that lands. This allows passing arbitrary structs as arguments to native code; receiving a struct as a return value is not yet implemented. Also includes a couple of tests.

I figured the review queue looked a bit too empty :D

@nia-e nia-e force-pushed the native-structs branch 2 times, most recently from ca18991 to 4e6a464 Compare July 14, 2025 02:05

fn main() {
let pass_me = PassMe { value: 42, other_value: 1337 };
unsafe { pass_struct(pass_me) }; //~ ERROR: Undefined Behavior: passing a non-#[repr(C)] struct over FFI
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I think it's UB, but maybe if the user intentionally sets #[allow(improper_ctypes)] we might just want to report this as unsupported instead of UB?

@nia-e nia-e force-pushed the native-structs branch 2 times, most recently from 1faf540 to e9670f0 Compare July 16, 2025 09:42
@nia-e
Copy link
Contributor Author

nia-e commented Jul 16, 2025

Think this is ready for review. I split off a bunch of the new code this introduces into a different file to not pollute native_lib/mod.rs too much more than it already is

@rustbot ready

@rustbot rustbot added the S-waiting-on-review Status: Waiting for a review to complete label Jul 16, 2025
@nia-e nia-e force-pushed the native-structs branch 2 times, most recently from 7cd63db to 532a735 Compare July 17, 2025 10:19
@nia-e
Copy link
Contributor Author

nia-e commented Jul 17, 2025

Seems like there's some trouble here, nvm.

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: Waiting for the PR author to address review comments and removed S-waiting-on-review Status: Waiting for a review to complete labels Jul 17, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 17, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@nia-e nia-e force-pushed the native-structs branch 6 times, most recently from 809f60e to edfa595 Compare July 17, 2025 17:58
@nia-e
Copy link
Contributor Author

nia-e commented Jul 17, 2025

Should be fixed. Also bumped the libffi version since apparently there was a soundness issue that got resolved since the previous version we were on; that wasn't the cause of my test failures, but it's probably smart to include it anyways. There's a couple // TODO:s, but those are either out of scope for this first PR (unions) or things I'm just uncertain of and need advice (the other 2).

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Waiting for a review to complete and removed S-waiting-on-author Status: Waiting for the PR author to address review comments labels Jul 17, 2025
@nia-e nia-e force-pushed the native-structs branch 4 times, most recently from 802f48b to 685a17c Compare July 17, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Waiting for a review to complete
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants