Document that init
and cleanup
are not guaranteed to run
This commit is contained in:
parent
8aeea227da
commit
e1b1081d2f
6 changed files with 13 additions and 2 deletions
|
@ -96,12 +96,14 @@ pub extern "C" fn __rust_abort() {
|
|||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
let _ = net::init();
|
||||
args::init(argc, argv);
|
||||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub unsafe fn cleanup() {
|
||||
args::cleanup();
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ pub mod time;
|
|||
pub use crate::sys_common::os_str_bytes as os_str;
|
||||
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
unsafe {
|
||||
args::init(argc, argv);
|
||||
|
@ -47,6 +48,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
|||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub unsafe fn cleanup() {}
|
||||
|
||||
/// This function is used to implement functionality that simply doesn't exist.
|
||||
|
|
|
@ -45,6 +45,7 @@ pub mod time;
|
|||
pub use crate::sys_common::os_str_bytes as os_str;
|
||||
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
||||
// The standard streams might be closed on application startup. To prevent
|
||||
// std::io::{stdin, stdout,stderr} objects from using other unrelated file
|
||||
|
@ -120,6 +121,7 @@ pub unsafe fn init(argc: isize, argv: *const *const u8) {
|
|||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub unsafe fn cleanup() {
|
||||
args::cleanup();
|
||||
stack_overflow::cleanup();
|
||||
|
|
|
@ -11,9 +11,11 @@ pub use crate::sys_common::os_str_bytes as os_str;
|
|||
use crate::os::raw::c_char;
|
||||
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub unsafe fn cleanup() {}
|
||||
|
||||
pub fn unsupported<T>() -> std_io::Result<T> {
|
||||
|
|
|
@ -50,11 +50,13 @@ cfg_if::cfg_if! {
|
|||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime initialization.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
pub unsafe fn init(_argc: isize, _argv: *const *const u8) {
|
||||
stack_overflow::init();
|
||||
}
|
||||
|
||||
// SAFETY: must be called only once during runtime cleanup.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
pub unsafe fn cleanup() {
|
||||
net::cleanup();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ use crate::thread::Thread;
|
|||
|
||||
// One-time runtime initialization.
|
||||
// Runs before `main`.
|
||||
// NOTE: this is not guaranteed to run, for example when Rust code is called externally.
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
pub fn init(argc: isize, argv: *const *const u8) {
|
||||
static INIT: Once = Once::new();
|
||||
|
@ -23,8 +24,8 @@ pub fn init(argc: isize, argv: *const *const u8) {
|
|||
}
|
||||
|
||||
// One-time runtime cleanup.
|
||||
// Runs after `main` or at program exit. Note however that this is not guaranteed to run,
|
||||
// for example when the program aborts.
|
||||
// Runs after `main` or at program exit.
|
||||
// NOTE: this is not guaranteed to run, for example when the program aborts.
|
||||
#[cfg_attr(test, allow(dead_code))]
|
||||
pub fn cleanup() {
|
||||
static CLEANUP: Once = Once::new();
|
||||
|
|
Loading…
Reference in a new issue