add PyErr to io::Error convert

This commit is contained in:
Nikolay Kim 2017-04-06 10:09:32 -07:00
parent ffe774a8cc
commit 8ccb749c1e
2 changed files with 11 additions and 1 deletions

View File

@ -394,6 +394,14 @@ impl <'p> std::convert::From<PythonObjectDowncastError<'p>> for PyErr {
}
}
/// Convert PyErr to io::Error
impl std::convert::From<PyErr> for std::io::Error {
fn from(err: PyErr) -> Self {
std::io::Error::new(
std::io::ErrorKind::Other, format!("Python exception: {:?}", err))
}
}
/// Construct PyObject from the result of a Python FFI call that returns a new reference (owned pointer).
/// Returns `Err(PyErr)` if the pointer is `null`.
/// Unsafe because the pointer might be invalid.

View File

@ -29,7 +29,9 @@ macro_rules! py_class_init_properties {
$type_object.tp_getset =
props.as_ptr() as *mut $crate::_detail::ffi::PyGetSetDef;
std::mem::forget(props);
use std::mem;
mem::forget(props);
}};
}