fix error from instancel fixed bool

This commit is contained in:
Nikolay Kim 2017-06-30 08:51:45 +06:00
parent 6b093af3d9
commit 3028dcf58f
3 changed files with 7 additions and 5 deletions

View file

@ -189,7 +189,7 @@ impl PyErr {
ptype: if ptype.is_null() {
py.get_type::<exc::SystemError>().into()
} else {
PyType::from_type_ptr(py, ptype as *mut ffi::PyTypeObject).into()
Py::from_owned_ptr(ptype)
},
pvalue: PyObject::from_owned_ptr_or_opt(py, pvalue),
ptraceback: PyObject::from_owned_ptr_or_opt(py, ptraceback)
@ -219,7 +219,7 @@ impl PyErr {
if unsafe { ffi::PyExceptionInstance_Check(ptr) } != 0 {
PyErr {
ptype: unsafe { PyType::from_type_ptr(py, ptr as *mut ffi::PyTypeObject).into() },
ptype: unsafe { Py::from_borrowed_ptr( ffi::PyExceptionInstance_Class(ptr)) },
pvalue: Some(obj),
ptraceback: None
}

View file

@ -16,7 +16,7 @@ impl PyBool {
#[inline]
pub fn new<'p>(py: Python<'p>, val: bool) -> &'p PyBool {
unsafe {
py.cast_from_ptr(if val { ffi::Py_True() } else { ffi::Py_False() })
py.cast_from_borrowed_ptr(if val { ffi::Py_True() } else { ffi::Py_False() })
}
}

View file

@ -138,13 +138,15 @@ impl Drop for Pool {
}
}
pub unsafe fn register_owned<'p>(_py: Python<'p>, obj: *mut ffi::PyObject) -> &'p PyObjectRef {
pub unsafe fn register_owned<'p>(_py: Python<'p>, obj: *mut ffi::PyObject) -> &'p PyObjectRef
{
let pool: &'static mut Vec<*mut ffi::PyObject> = mem::transmute(OWNED);
pool.push(obj);
mem::transmute(&pool[pool.len()-1])
}
pub unsafe fn register_borrowed<'p>(_py: Python<'p>, obj: *mut ffi::PyObject) -> &'p PyObjectRef {
pub unsafe fn register_borrowed<'p>(_py: Python<'p>, obj: *mut ffi::PyObject) -> &'p PyObjectRef
{
let pool: &'static mut Vec<*mut ffi::PyObject> = mem::transmute(BORROWED);
pool.push(obj);
mem::transmute(&pool[pool.len()-1])