Skip to content

Change main from extern "C" to "Rust", and rename to origin_main #39

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

Merged
merged 5 commits into from
Sep 10, 2023

Conversation

sunfishcode
Copy link
Owner

Origin's main function isn't called from FFI, so use extern "Rust" instead of extern "C", and rename it to origin_main to avoid confusion and collision with other main functions.

Also, use *mut for the pointers, since the memory is mutable and users may want to mutate it, and use usize for argc to avoid exposing c_int in the public API.

This includes the patch from #34.

@sunfishcode sunfishcode force-pushed the sunfishcode/extern-rust-take2 branch from 40a4b23 to 3daa7dc Compare September 9, 2023 22:42
morr0ne and others added 5 commits September 9, 2023 17:50
This function is called from Rust code, so it doesn't need to be
`extern "C"`.
This isn't the C ABI `main` function, so give it a different name.

Also, make it an `unsafe fn`, and add the `envp` arguments so that we don't
rely on the ABI to ignore extra arguments.
This memory is mutable, and users may want to mutate it, so use `*mut`.
Change `argc` to `usize` because a common use case is to pass it to
`slice::from_raw_parts`.

Change the return value to `i32`. This matches the type used by
`std::process::exit`.
@sunfishcode sunfishcode force-pushed the sunfishcode/extern-rust-take2 branch from 3daa7dc to 16bcfaf Compare September 10, 2023 00:51
@sunfishcode
Copy link
Owner Author

This isn't the last word on this toppic, but this PR is an improvement over the previous code, so I'm going to merge it for now, and we can continue to discuss alternative approaches.

@sunfishcode sunfishcode merged commit 4fa8ab1 into main Sep 10, 2023
@sunfishcode sunfishcode deleted the sunfishcode/extern-rust-take2 branch September 10, 2023 18:46
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.

2 participants