From 5537ece0787a0f21eede186899316234948ec0ce Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Thu, 3 Aug 2017 11:37:24 -0700 Subject: [PATCH] fix unstable tests --- src/objects/dict.rs | 2 +- src/objects/iterator.rs | 10 ++++++---- src/objects/list.rs | 26 ++++++++++++-------------- src/pythonrun.rs | 8 ++++---- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/objects/dict.rs b/src/objects/dict.rs index 7affde90..32d93e02 100644 --- a/src/objects/dict.rs +++ b/src/objects/dict.rs @@ -299,7 +299,7 @@ mod test { let cnt; { - let _pool = unsafe{::GILPool::new()}; + let _pool = ::GILPool::new(); let dict = PyDict::new(py); let none = py.None(); cnt = none.get_refcnt(); diff --git a/src/objects/iterator.rs b/src/objects/iterator.rs index 9af334f1..a80319a5 100644 --- a/src/objects/iterator.rs +++ b/src/objects/iterator.rs @@ -71,6 +71,7 @@ impl<'p> Drop for PyIterator<'p> { mod tests { use instance::AsPyRef; use python::Python; + use pythonrun::GILPool; use conversion::{PyTryFrom, ToPyObject}; use objects::{PyObjectRef, PyList}; use objectprotocol::ObjectProtocol; @@ -111,12 +112,14 @@ mod tests { #[test] fn iter_item_refcnt() { + let gil_guard = Python::acquire_gil(); + let py = gil_guard.python(); + let obj; let none; let count; { - let gil_guard = Python::acquire_gil(); - let py = gil_guard.python(); + let _pool = GILPool::new(); let l = PyList::empty(py); none = py.None(); l.append(10).unwrap(); @@ -126,8 +129,7 @@ mod tests { } { - let gil_guard = Python::acquire_gil(); - let py = gil_guard.python(); + let _pool = GILPool::new(); let inst = PyObjectRef::try_from(obj.as_ref(py)).unwrap(); let mut it = inst.iter().unwrap(); diff --git a/src/objects/list.rs b/src/objects/list.rs index ee767789..e9234c49 100644 --- a/src/objects/list.rs +++ b/src/objects/list.rs @@ -240,10 +240,12 @@ mod test { #[test] fn test_set_item_refcnt() { + let gil = Python::acquire_gil(); + let py = gil.python(); + let cnt; { - let gil = Python::acquire_gil(); - let py = gil.python(); + let _pool = ::GILPool::new(); let v = vec![2]; let ob = v.to_object(py); let list = PyList::try_from(ob.as_ref(py)).unwrap(); @@ -251,11 +253,8 @@ mod test { cnt = none.get_refcnt(); list.set_item(0, none).unwrap(); } - { - let gil = Python::acquire_gil(); - let py = gil.python(); - assert_eq!(cnt, py.None().get_refcnt()); - } + + assert_eq!(cnt, py.None().get_refcnt()); } #[test] @@ -276,20 +275,19 @@ mod test { #[test] fn test_insert_refcnt() { + let gil = Python::acquire_gil(); + let py = gil.python(); + let cnt; { - let gil = Python::acquire_gil(); - let py = gil.python(); + let _pool = ::GILPool::new(); let list = PyList::empty(py); let none = py.None(); cnt = none.get_refcnt(); list.insert(0, none).unwrap(); } - { - let gil = Python::acquire_gil(); - let py = gil.python(); - assert_eq!(cnt, py.None().get_refcnt()); - } + + assert_eq!(cnt, py.None().get_refcnt()); } #[test] diff --git a/src/pythonrun.rs b/src/pythonrun.rs index 909330b2..70dc88ab 100644 --- a/src/pythonrun.rs +++ b/src/pythonrun.rs @@ -180,16 +180,16 @@ pub struct GILPool { impl GILPool { #[inline] - pub unsafe fn new() -> GILPool { - let p: &'static mut ReleasePool = &mut *POOL; + pub fn new() -> GILPool { + let p: &'static mut ReleasePool = unsafe { &mut *POOL }; GILPool {owned: p.owned.len(), borrowed: p.borrowed.len(), pointers: true, no_send: marker::PhantomData} } #[inline] - pub unsafe fn new_no_pointers() -> GILPool { - let p: &'static mut ReleasePool = &mut *POOL; + pub fn new_no_pointers() -> GILPool { + let p: &'static mut ReleasePool = unsafe { &mut *POOL }; GILPool {owned: p.owned.len(), borrowed: p.borrowed.len(), pointers: false,