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

allow calling unsafe function and ffi function safely:) #41

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Neutron3529
Copy link

2 macros are provided to ensure unsafe rust program will be called safely.

One of them is ffi, which allow calling ffi in safe rust:

// create safe printf function
ffi!{
    extern "C" fn printf(fmt: *const i8)->i32
}
fn main(){
    printf(c"Calling FFI in a safe way:)\n".as_ptr())
}

Another is a safe macro, which converts the unsafe function into the safe version. But sadly, you have to provide the signature about the old unsafe function (to ensure some safetyness..)

use r#unsafe::r#unsafe;
safe!{
    fn r#unsafe()->i32 := very_safe
}
fn main(){
    // then you can use `very_safe()` to call `r#unsafe::r#unsafe` safely:)
}

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.

None yet

1 participant