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

Function execv

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

Source from the content-addressed store, hash-verified

1177 #[cfg(target_env = "msvc")]
1178 #[pyfunction]
1179 fn execv(
1180 path: OsPath,
1181 argv: Either<PyListRef, PyTupleRef>,
1182 vm: &VirtualMachine,
1183 ) -> PyResult<()> {
1184 use core::iter::once;
1185
1186 let make_widestring =
1187 |s: &str| widestring::WideCString::from_os_str(s).map_err(|err| err.to_pyexception(vm));
1188
1189 let path = path.to_wide_cstring(vm)?;
1190
1191 let argv = vm.extract_elements_with(argv.as_ref(), |obj| {
1192 let arg = PyStrRef::try_from_object(vm, obj)?;
1193 make_widestring(arg.expect_str())
1194 })?;
1195
1196 let first = argv
1197 .first()
1198 .ok_or_else(|| vm.new_value_error("execv() arg 2 must not be empty"))?;
1199
1200 if first.is_empty() {
1201 return Err(vm.new_value_error("execv() arg 2 first element cannot be empty"));
1202 }
1203
1204 let argv_execv: Vec<*const u16> = argv
1205 .iter()
1206 .map(|v| v.as_ptr())
1207 .chain(once(core::ptr::null()))
1208 .collect();
1209
1210 if (unsafe { suppress_iph!(_wexecv(path.as_ptr(), argv_execv.as_ptr())) } == -1) {
1211 Err(vm.new_last_errno_error())
1212 } else {
1213 Ok(())
1214 }
1215 }
1216
1217 #[cfg(target_env = "msvc")]
1218 #[pyfunction]

Callers 2

execlFunction · 0.50
exec_innerFunction · 0.50

Calls 15

onceFunction · 0.85
extract_elements_withMethod · 0.80
expect_strMethod · 0.80
ok_or_elseMethod · 0.80
collectMethod · 0.80
chainMethod · 0.80
new_last_errno_errorMethod · 0.80
ErrClass · 0.50
to_pyexceptionMethod · 0.45
to_wide_cstringMethod · 0.45
as_refMethod · 0.45
firstMethod · 0.45

Tested by

no test coverage detected