Skip to content

Commit 364ddeb

Browse files
committed
Fix compilation on Windows
1 parent 53c653f commit 364ddeb

File tree

1 file changed

+31
-17
lines changed

1 file changed

+31
-17
lines changed

vm/src/stdlib/os.rs

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ use std::time::{Duration, SystemTime};
66
use std::{env, fs};
77

88
use bitflags::bitflags;
9+
#[cfg(unix)]
910
use nix::errno::Errno;
11+
#[cfg(unix)]
1012
use nix::unistd::{self, Gid, Pid, Uid};
1113
use num_traits::cast::ToPrimitive;
1214

@@ -176,6 +178,7 @@ fn convert_io_error(vm: &VirtualMachine, err: io::Error) -> PyObjectRef {
176178
os_error
177179
}
178180

181+
#[cfg(unix)]
179182
fn convert_nix_error(vm: &VirtualMachine, err: nix::Error) -> PyObjectRef {
180183
let nix_error = match err {
181184
nix::Error::InvalidPath => {
@@ -204,6 +207,7 @@ fn convert_nix_error(vm: &VirtualMachine, err: nix::Error) -> PyObjectRef {
204207
nix_error
205208
}
206209

210+
#[cfg(unix)]
207211
fn convert_nix_errno(vm: &VirtualMachine, errno: Errno) -> PyClassRef {
208212
match errno {
209213
Errno::EPERM => vm.ctx.exceptions.permission_error.clone(),
@@ -1000,23 +1004,33 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
10001004
"supports_follow_symlinks" => supports_follow_symlinks.into_object(),
10011005
});
10021006

1003-
if cfg!(unix) {
1004-
extend_module!(vm, module, {
1005-
"getppid" => ctx.new_rustfunc(os_getppid),
1006-
"getgid" => ctx.new_rustfunc(os_getgid),
1007-
"getegid" => ctx.new_rustfunc(os_getegid),
1008-
"getpgid" => ctx.new_rustfunc(os_getpgid),
1009-
"getsid" => ctx.new_rustfunc(os_getsid),
1010-
"getuid" => ctx.new_rustfunc(os_getuid),
1011-
"geteuid" => ctx.new_rustfunc(os_geteuid),
1012-
"setgid" => ctx.new_rustfunc(os_setgid),
1013-
"setegid" => ctx.new_rustfunc(os_setegid),
1014-
"setpgid" => ctx.new_rustfunc(os_setpgid),
1015-
"setsid" => ctx.new_rustfunc(os_setsid),
1016-
"setuid" => ctx.new_rustfunc(os_setuid),
1017-
"seteuid" => ctx.new_rustfunc(os_seteuid),
1018-
});
1019-
}
1007+
extend_module_platform_specific(&vm, module)
1008+
}
1009+
1010+
#[cfg(unix)]
1011+
fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) -> PyObjectRef {
1012+
let ctx = &vm.ctx;
1013+
1014+
extend_module!(vm, module, {
1015+
"getppid" => ctx.new_rustfunc(os_getppid),
1016+
"getgid" => ctx.new_rustfunc(os_getgid),
1017+
"getegid" => ctx.new_rustfunc(os_getegid),
1018+
"getpgid" => ctx.new_rustfunc(os_getpgid),
1019+
"getsid" => ctx.new_rustfunc(os_getsid),
1020+
"getuid" => ctx.new_rustfunc(os_getuid),
1021+
"geteuid" => ctx.new_rustfunc(os_geteuid),
1022+
"setgid" => ctx.new_rustfunc(os_setgid),
1023+
"setegid" => ctx.new_rustfunc(os_setegid),
1024+
"setpgid" => ctx.new_rustfunc(os_setpgid),
1025+
"setsid" => ctx.new_rustfunc(os_setsid),
1026+
"setuid" => ctx.new_rustfunc(os_setuid),
1027+
"seteuid" => ctx.new_rustfunc(os_seteuid),
1028+
});
1029+
1030+
module
1031+
}
10201032

1033+
#[cfg(not(unix))]
1034+
fn extend_module_platform_specific(_vm: &VirtualMachine, module: PyObjectRef) -> PyObjectRef {
10211035
module
10221036
}

0 commit comments

Comments
 (0)