Invoke constructors and destructors
Huge thanks to @xtibor for both discovering that this was still an issue, and also providing information with how to fix it
This commit is contained in:
@@ -220,6 +220,9 @@ pub extern "C" fn erand(xsubi: [c_ushort; 3]) -> c_double {
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn exit(status: c_int) {
|
||||
extern "C" {
|
||||
static __fini_array_start: extern "C" fn();
|
||||
static __fini_array_end: extern "C" fn();
|
||||
|
||||
fn _fini();
|
||||
}
|
||||
|
||||
@@ -229,6 +232,13 @@ pub unsafe extern "C" fn exit(status: c_int) {
|
||||
}
|
||||
}
|
||||
|
||||
// Look for the neighbor functions in memory until the end
|
||||
let mut f = &__fini_array_end as *const _;
|
||||
while f > &__fini_array_start {
|
||||
f = f.offset(-1);
|
||||
(*f)();
|
||||
}
|
||||
|
||||
_fini();
|
||||
|
||||
Sys::exit(status);
|
||||
|
||||
Reference in New Issue
Block a user