]> git.lizzy.rs Git - rust.git/commitdiff
Document that `init` and `cleanup` are not guaranteed to run
authorChristiaan Dirkx <christiaan@dirkx.email>
Sun, 18 Apr 2021 05:19:39 +0000 (07:19 +0200)
committerChristiaan Dirkx <christiaan@dirkx.email>
Thu, 22 Apr 2021 16:00:18 +0000 (18:00 +0200)
library/std/src/sys/hermit/mod.rs
library/std/src/sys/sgx/mod.rs
library/std/src/sys/unix/mod.rs
library/std/src/sys/unsupported/common.rs
library/std/src/sys/windows/mod.rs
library/std/src/sys_common/rt.rs

index 77c068e1a974431809ee48569d583b6cdd510f07..a70d1db7ca67240e2bce771b67cfd8a1cada39df 100644 (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();
 }
index 25250d060d04bb893a3fbc2aec84acafb1a5820e..059d6cb5ba13122994c69ee86439d1be1fe1181a 100644 (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.
index 8ae0c1120ff2b9245a3707033d9992ec3a8a15bc..a0ee69c2f72ddf871b6fef8320c7097437dacf21 100644 (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();
index c60c2a9b8e850ad7e32602247d7a7aff79365e90..6e72a7c632ed0b4755d3f56034a75c0296e9f31d 100644 (file)
@@ -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> {
index 21fec2aa01bf55d9b2927d18007b1b250a13553a..ddb6ac5f55c0d9684f5bc00a65a07d0072bef437 100644 (file)
 }
 
 // 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();
 }
index 5906b4e3e0e47a078181264453484fea1a1e98c3..c0c4a63cde9903964dab7f5677131900aa51676c 100644 (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();