Skip to content
Open
Show file tree
Hide file tree
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
12 changes: 12 additions & 0 deletions src/cc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ impl<T: ?Sized, O: AbstractObjectSpace> RawCc<T, O> {
pub fn strong_count(&self) -> usize {
self.ref_count()
}

/// Returns `true` if the two `Cc`s point to the same allocation
#[inline]
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.0.as_ptr() == other.0.as_ptr()
}
}

impl<T: ?Sized, O: AbstractObjectSpace> RawWeak<T, O> {
Expand Down Expand Up @@ -412,6 +418,12 @@ impl<T: ?Sized, O: AbstractObjectSpace> RawWeak<T, O> {
pub fn weak_count(&self) -> usize {
self.inner().weak_count()
}

/// Returns `true` if the two `Weak`s point to the same allocation
#[inline]
pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.0.as_ptr() == other.0.as_ptr()
}
}

impl<T: ?Sized, O: AbstractObjectSpace> RawCc<T, O> {
Expand Down
23 changes: 22 additions & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::debug;
use crate::testutil::test_small_graph;
use crate::{collect, Cc, Trace, Tracer};
use crate::{debug, Weak};
use std::cell::Cell;
use std::cell::RefCell;
use std::ops::Deref;
Expand Down Expand Up @@ -509,6 +509,27 @@ fn test_trace_impl_double_visits() {
}
}

#[test]
fn test_cc_ptr_eq() {
let a = Cc::new(1);
let b = a.clone();
let c = Cc::new(1);

assert!(Cc::ptr_eq(&a, &b));
assert!(!Cc::ptr_eq(&a, &c));
}

#[test]
fn test_weak_ptr_eq() {
let a = Cc::new(1);
let b = a.downgrade();
let a = a.downgrade();
let c = Cc::new(1).downgrade();

assert!(Weak::ptr_eq(&a, &b));
assert!(!Weak::ptr_eq(&a, &c));
}

#[cfg(not(miri))]
quickcheck::quickcheck! {
fn test_quickcheck_16_vertex_graph(edges: Vec<u8>, atomic_bits: u16, collect_bits: u16) -> bool {
Expand Down