Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: relax check in pyobject_drop test #4014

Merged
merged 1 commit into from
Mar 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/gil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,11 @@ mod tests {
}

#[cfg(not(target_arch = "wasm32"))]
fn pool_dirty_with(
inc_refs: Vec<NonNull<ffi::PyObject>>,
dec_refs: Vec<NonNull<ffi::PyObject>>,
) -> bool {
*POOL.pointer_ops.lock() == (inc_refs, dec_refs)
fn pool_dec_refs_contains(obj: &PyObject) -> bool {
POOL.pointer_ops
.lock()
.1
.contains(&unsafe { NonNull::new_unchecked(obj.as_ptr()) })
}

#[test]
Expand Down Expand Up @@ -633,11 +633,13 @@ mod tests {

assert_eq!(obj.get_refcnt(py), 2);
assert!(pool_inc_refs_does_not_contain(&obj));
assert!(pool_dec_refs_does_not_contain(&obj));

// With the GIL held, reference cound will be decreased immediately.
// With the GIL held, reference count will be decreased immediately.
drop(reference);

assert_eq!(obj.get_refcnt(py), 1);
assert!(pool_inc_refs_does_not_contain(&obj));
assert!(pool_dec_refs_does_not_contain(&obj));
});
}
Expand All @@ -652,17 +654,16 @@ mod tests {

assert_eq!(obj.get_refcnt(py), 2);
assert!(pool_inc_refs_does_not_contain(&obj));
assert!(pool_dec_refs_does_not_contain(&obj));

// Drop reference in a separate thread which doesn't have the GIL.
std::thread::spawn(move || drop(reference)).join().unwrap();

// The reference count should not have changed (the GIL has always
// been held by this thread), it is remembered to release later.
assert_eq!(obj.get_refcnt(py), 2);
assert!(pool_dirty_with(
vec![],
vec![NonNull::new(obj.as_ptr()).unwrap()]
));
assert!(pool_inc_refs_does_not_contain(&obj));
assert!(pool_dec_refs_contains(&obj));
obj
});

Expand Down
Loading