Document that init and cleanup are not guaranteed to run

This commit is contained in:
Christiaan Dirkx
2021-04-18 07:19:39 +02:00
parent 8aeea227da
commit e1b1081d2f
6 changed files with 13 additions and 2 deletions
+2
View File
@@ -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();
}
+2
View File
@@ -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.
+2
View File
@@ -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> {
+2
View File
@@ -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();
}
+3 -2
View File
@@ -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();