Use PyStrRef to extract String.

This commit is contained in:
jfh
2021-07-15 16:08:55 +03:00
parent c14e7b074d
commit 6cd8644de8

View File

@@ -1696,12 +1696,7 @@ mod _os {
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self> {
match obj.downcast::<int::PyInt>() {
Ok(int) => int::try_to_primitive(int.as_bigint(), vm).map(Self::Val),
Err(obj) => {
let cstring = std::ffi::CString::try_from_object(vm, obj)?;
cstring.into_string().map(Self::Name).map_err(|e| {
vm.new_os_error(format!("error while parsing string: {:?}", e))
})
}
Err(obj) => PyStrRef::try_from_object(vm, obj).map(|o| Self::Name(o.to_string())),
}
}
}