mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-29 03:04:38 +08:00
wasi: fix os.environb byte handling (#8476)
Part of: #4583 This will enable -m test for wasi preview 1 Signed-off-by: Jiwoo Ahn <ikwydls1314@gmail.com>
This commit is contained in:
1 parent
3a1caa1eb5
commit
689c8b57e7
1 file changed
+4
-3
@@ -519,13 +519,14 @@ pub fn set_errno(value: i32) {
|
||||
#[cfg(not(any(unix, windows, target_os = "wasi")))]
|
||||
pub fn set_errno(_value: i32) {}
|
||||
|
||||
#[cfg(unix)]
|
||||
// WASIp1, like Unix, provides byte-preserving OsStr conversions.
|
||||
#[cfg(any(unix, all(target_os = "wasi", not(target_env = "p2"))))]
|
||||
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
|
||||
use std::os::unix::ffi::OsStrExt;
|
||||
use self::ffi::OsStrExt;
|
||||
Ok(std::ffi::OsStr::from_bytes(b))
|
||||
}
|
||||
|
||||
#[cfg(not(unix))]
|
||||
#[cfg(not(any(unix, all(target_os = "wasi", not(target_env = "p2")))))]
|
||||
pub fn bytes_as_os_str(b: &[u8]) -> Result<&std::ffi::OsStr, Utf8Error> {
|
||||
Ok(core::str::from_utf8(b)?.as_ref())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user