mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 09:53:04 +03:00
Document that init and cleanup are not guaranteed to run
This commit is contained in:
@@ -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 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 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 @@ unsafe fn reset_sigpipe() {
|
||||
}
|
||||
|
||||
// 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 mod memchr {
|
||||
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 @@
|
||||
}
|
||||
|
||||
// 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 @@
|
||||
|
||||
// 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();
|
||||
|
||||
Reference in New Issue
Block a user