-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[r+] Add note about libc::exit's unsafety. #21026
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4157,6 +4157,27 @@ pub mod funcs { | |
pub fn malloc(size: size_t) -> *mut c_void; | ||
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; | ||
pub fn free(p: *mut c_void); | ||
|
||
/// Exits the running program in a possibly dangerous manner. | ||
/// | ||
/// # Unsafety | ||
/// | ||
/// While this forces your program to exit, it does so in a way that has | ||
/// consequences. This will skip all unwinding code, which means that anything | ||
/// relying on unwinding for cleanup (such as flushing and closing a buffer to a | ||
/// file) may act in an unexpected way. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume panic! already has the same unsafety note? Given that panicking in destructors will skip unwinding too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsure, but that's out of the scope of this ticket. |
||
/// | ||
/// # Examples | ||
/// | ||
/// ```no_run | ||
/// extern crate libc; | ||
/// | ||
/// fn main() { | ||
/// unsafe { | ||
/// libc::exit(1); | ||
/// } | ||
/// } | ||
/// ``` | ||
pub fn exit(status: c_int) -> !; | ||
pub fn _exit(status: c_int) -> !; | ||
pub fn atexit(cb: extern fn()) -> c_int; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One last minor nit/question: Should this heading be
Warning
or something like that rather thanUnsafety
? I'm not sure how strict we want to be about the use of the term "unsafe" in documentation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given that the function is an
unsafe fn
, I choseunsafety
rather than something like "Warning".