Skip to content

Commit

Permalink
Clean up gil tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kngwyu committed May 2, 2020
1 parent 8c6cbb6 commit 39bfb5f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/gil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ fn decrement_gil_count() {
#[cfg(test)]
mod test {
use super::{GILPool, GIL_COUNT, POOL};
use crate::{ffi, gil, AsPyPointer, PyObject, Python, ToPyObject};
use crate::{ffi, gil, AsPyPointer, IntoPyPointer, PyObject, Python, ToPyObject};
use std::ptr::NonNull;

fn get_object() -> PyObject {
// Convenience function for getting a single unique object
Expand All @@ -322,8 +323,7 @@ mod test {

{
let gil = Python::acquire_gil();
let py = gil.python();
let _ = gil::register_owned(py, obj.into_nonnull());
gil::register_owned(gil.python(), NonNull::new_unchecked(obj.into_ptr()));

assert_eq!(ffi::Py_REFCNT(obj_ptr), 2);
assert_eq!(p.owned.len(), 1);
Expand Down Expand Up @@ -352,14 +352,14 @@ mod test {
let _pool = GILPool::new();
assert_eq!(p.owned.len(), 0);

let _ = gil::register_owned(py, obj.into_nonnull());
gil::register_owned(py, NonNull::new_unchecked(obj.into_ptr()));

assert_eq!(p.owned.len(), 1);
assert_eq!(ffi::Py_REFCNT(obj_ptr), 2);
{
let _pool = GILPool::new();
let obj = get_object();
let _ = gil::register_owned(py, obj.into_nonnull());
gil::register_owned(py, NonNull::new_unchecked(obj.into_ptr()));
assert_eq!(p.owned.len(), 2);
}
assert_eq!(p.owned.len(), 1);
Expand Down
7 changes: 0 additions & 7 deletions src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ impl PyObject {
PyObject(ptr)
}

#[cfg(test)]
pub(crate) unsafe fn into_nonnull(self) -> NonNull<ffi::PyObject> {
let res = self.0;
std::mem::forget(self); // Avoid Drop
res
}

/// Creates a `PyObject` instance for the given FFI pointer.
/// This moves ownership over the pointer into the `PyObject`.
/// Undefined behavior if the pointer is NULL or invalid.
Expand Down

0 comments on commit 39bfb5f

Please sign in to comment.