-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #1208 - christianpoveda:environ-shim, r=RalfJung
Environ shim Remake of #1147. There are three main problems with this: 1. For some reason `update_environ` is not updating `environ` when `setenv` or `unsetenv` are called. Even then it works during initialization. 2. I am not deallocating the old array with the variables in `update_environ`. 3. I had to store the `environ` place into `MemoryExtra` as a field to update it. I was thinking about changing `extern_statics` to store places instead of `AllocID`s to avoid this. @RalfJung
- Loading branch information
Showing
7 changed files
with
123 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//ignore-windows: TODO env var emulation stubbed out on Windows | ||
|
||
#[cfg(target_os="linux")] | ||
fn get_environ() -> *const *const u8 { | ||
extern "C" { | ||
static mut environ: *const *const u8; | ||
} | ||
unsafe { environ } | ||
} | ||
|
||
#[cfg(target_os="macos")] | ||
fn get_environ() -> *const *const u8 { | ||
extern "C" { | ||
fn _NSGetEnviron() -> *mut *const *const u8; | ||
} | ||
unsafe { *_NSGetEnviron() } | ||
} | ||
|
||
fn main() { | ||
let pointer = get_environ(); | ||
let _x = unsafe { *pointer }; | ||
std::env::set_var("FOO", "BAR"); | ||
let _y = unsafe { *pointer }; //~ ERROR dangling pointer was dereferenced | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[] | ||
[ | ||
( | ||
"MIRI_TEST", | ||
"the answer", | ||
), | ||
] | ||
[ | ||
( | ||
"MIRI_TEST", | ||
"42", | ||
), | ||
] | ||
[] |