fix unstable tests
This commit is contained in:
parent
85eced19dd
commit
5537ece078
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue