MCPcopy Index your code
hub / github.com/RustPython/RustPython / spawnv

Function spawnv

crates/vm/src/stdlib/nt.rs:1063–1099  ·  view source on GitHub ↗
(
        mode: i32,
        path: OsPath,
        argv: Either<PyListRef, PyTupleRef>,
        vm: &VirtualMachine,
    )

Source from the content-addressed store, hash-verified

1061 #[cfg(target_env = "msvc")]
1062 #[pyfunction]
1063 fn spawnv(
1064 mode: i32,
1065 path: OsPath,
1066 argv: Either<PyListRef, PyTupleRef>,
1067 vm: &VirtualMachine,
1068 ) -> PyResult<intptr_t> {
1069 use crate::function::FsPath;
1070 use core::iter::once;
1071
1072 let path = path.to_wide_cstring(vm)?;
1073
1074 let argv = vm.extract_elements_with(argv.as_ref(), |obj| {
1075 let fspath = FsPath::try_from_path_like(obj, true, vm)?;
1076 fspath.to_wide_cstring(vm)
1077 })?;
1078
1079 let first = argv
1080 .first()
1081 .ok_or_else(|| vm.new_value_error("spawnv() arg 3 must not be empty"))?;
1082
1083 if first.is_empty() {
1084 return Err(vm.new_value_error("spawnv() arg 3 first element cannot be empty"));
1085 }
1086
1087 let argv_spawn: Vec<*const u16> = argv
1088 .iter()
1089 .map(|v| v.as_ptr())
1090 .chain(once(core::ptr::null()))
1091 .collect();
1092
1093 let result = unsafe { suppress_iph!(_wspawnv(mode, path.as_ptr(), argv_spawn.as_ptr())) };
1094 if result == -1 {
1095 Err(vm.new_last_errno_error())
1096 } else {
1097 Ok(result)
1098 }
1099 }
1100
1101 #[cfg(target_env = "msvc")]
1102 #[pyfunction]

Callers

nothing calls this directly

Calls 14

onceFunction · 0.85
extract_elements_withMethod · 0.80
ok_or_elseMethod · 0.80
collectMethod · 0.80
chainMethod · 0.80
new_last_errno_errorMethod · 0.80
ErrClass · 0.50
to_wide_cstringMethod · 0.45
as_refMethod · 0.45
firstMethod · 0.45
is_emptyMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected