fix unstable tests

This commit is contained in:
Nikolay Kim 2017-08-03 11:37:24 -07:00
parent 85eced19dd
commit 5537ece078
4 changed files with 23 additions and 23 deletions

View File

@ -299,7 +299,7 @@ mod test {
let cnt; let cnt;
{ {
let _pool = unsafe{::GILPool::new()}; let _pool = ::GILPool::new();
let dict = PyDict::new(py); let dict = PyDict::new(py);
let none = py.None(); let none = py.None();
cnt = none.get_refcnt(); cnt = none.get_refcnt();

View File

@ -71,6 +71,7 @@ impl<'p> Drop for PyIterator<'p> {
mod tests { mod tests {
use instance::AsPyRef; use instance::AsPyRef;
use python::Python; use python::Python;
use pythonrun::GILPool;
use conversion::{PyTryFrom, ToPyObject}; use conversion::{PyTryFrom, ToPyObject};
use objects::{PyObjectRef, PyList}; use objects::{PyObjectRef, PyList};
use objectprotocol::ObjectProtocol; use objectprotocol::ObjectProtocol;
@ -111,12 +112,14 @@ mod tests {
#[test] #[test]
fn iter_item_refcnt() { fn iter_item_refcnt() {
let gil_guard = Python::acquire_gil();
let py = gil_guard.python();
let obj; let obj;
let none; let none;
let count; let count;
{ {
let gil_guard = Python::acquire_gil(); let _pool = GILPool::new();
let py = gil_guard.python();
let l = PyList::empty(py); let l = PyList::empty(py);
none = py.None(); none = py.None();
l.append(10).unwrap(); l.append(10).unwrap();
@ -126,8 +129,7 @@ mod tests {
} }
{ {
let gil_guard = Python::acquire_gil(); let _pool = GILPool::new();
let py = gil_guard.python();
let inst = PyObjectRef::try_from(obj.as_ref(py)).unwrap(); let inst = PyObjectRef::try_from(obj.as_ref(py)).unwrap();
let mut it = inst.iter().unwrap(); let mut it = inst.iter().unwrap();

View File

@ -240,10 +240,12 @@ mod test {
#[test] #[test]
fn test_set_item_refcnt() { fn test_set_item_refcnt() {
let gil = Python::acquire_gil();
let py = gil.python();
let cnt; let cnt;
{ {
let gil = Python::acquire_gil(); let _pool = ::GILPool::new();
let py = gil.python();
let v = vec![2]; let v = vec![2];
let ob = v.to_object(py); let ob = v.to_object(py);
let list = PyList::try_from(ob.as_ref(py)).unwrap(); let list = PyList::try_from(ob.as_ref(py)).unwrap();
@ -251,11 +253,8 @@ mod test {
cnt = none.get_refcnt(); cnt = none.get_refcnt();
list.set_item(0, none).unwrap(); list.set_item(0, none).unwrap();
} }
{
let gil = Python::acquire_gil(); assert_eq!(cnt, py.None().get_refcnt());
let py = gil.python();
assert_eq!(cnt, py.None().get_refcnt());
}
} }
#[test] #[test]
@ -276,20 +275,19 @@ mod test {
#[test] #[test]
fn test_insert_refcnt() { fn test_insert_refcnt() {
let gil = Python::acquire_gil();
let py = gil.python();
let cnt; let cnt;
{ {
let gil = Python::acquire_gil(); let _pool = ::GILPool::new();
let py = gil.python();
let list = PyList::empty(py); let list = PyList::empty(py);
let none = py.None(); let none = py.None();
cnt = none.get_refcnt(); cnt = none.get_refcnt();
list.insert(0, none).unwrap(); list.insert(0, none).unwrap();
} }
{
let gil = Python::acquire_gil(); assert_eq!(cnt, py.None().get_refcnt());
let py = gil.python();
assert_eq!(cnt, py.None().get_refcnt());
}
} }
#[test] #[test]

View File

@ -180,16 +180,16 @@ pub struct GILPool {
impl GILPool { impl GILPool {
#[inline] #[inline]
pub unsafe fn new() -> GILPool { pub fn new() -> GILPool {
let p: &'static mut ReleasePool = &mut *POOL; let p: &'static mut ReleasePool = unsafe { &mut *POOL };
GILPool {owned: p.owned.len(), GILPool {owned: p.owned.len(),
borrowed: p.borrowed.len(), borrowed: p.borrowed.len(),
pointers: true, pointers: true,
no_send: marker::PhantomData} no_send: marker::PhantomData}
} }
#[inline] #[inline]
pub unsafe fn new_no_pointers() -> GILPool { pub fn new_no_pointers() -> GILPool {
let p: &'static mut ReleasePool = &mut *POOL; let p: &'static mut ReleasePool = unsafe { &mut *POOL };
GILPool {owned: p.owned.len(), GILPool {owned: p.owned.len(),
borrowed: p.borrowed.len(), borrowed: p.borrowed.len(),
pointers: false, pointers: false,