mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Use PyStrRef to extract String.
This commit is contained in:
@@ -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())),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user