(
path: OsPath,
argv: Either<PyListRef, PyTupleRef>,
vm: &VirtualMachine,
)
| 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] |
no test coverage detected