Skip to content

Commit

Permalink
Merge 'v1.6.1' into 'master' (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
Darksonn committed Jul 13, 2024
2 parents 9965a04 + fd13c7d commit f8c7b57
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 1.6.1 (July 13, 2024)

This release fixes a bug where `Bytes::is_unique` returns incorrect values when
the `Bytes` originates from a shared `BytesMut`. (#718)

# 1.6.0 (March 22, 2024)

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "bytes"
# When releasing to crates.io:
# - Update CHANGELOG.md.
# - Create "v1.x.y" git tag.
version = "1.6.0"
version = "1.6.1"
edition = "2018"
rust-version = "1.39"
license = "MIT"
Expand Down
8 changes: 7 additions & 1 deletion src/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1780,7 +1780,7 @@ static SHARED_VTABLE: Vtable = Vtable {
clone: shared_v_clone,
to_vec: shared_v_to_vec,
to_mut: shared_v_to_mut,
is_unique: crate::bytes::shared_is_unique,
is_unique: shared_v_is_unique,
drop: shared_v_drop,
};

Expand Down Expand Up @@ -1843,6 +1843,12 @@ unsafe fn shared_v_to_mut(data: &AtomicPtr<()>, ptr: *const u8, len: usize) -> B
}
}

unsafe fn shared_v_is_unique(data: &AtomicPtr<()>) -> bool {
let shared = data.load(Ordering::Acquire);
let ref_count = (*shared.cast::<Shared>()).ref_count.load(Ordering::Relaxed);
ref_count == 1
}

unsafe fn shared_v_drop(data: &mut AtomicPtr<()>, _ptr: *const u8, _len: usize) {
data.with_mut(|shared| {
release_shared(*shared as *mut Shared);
Expand Down
9 changes: 9 additions & 0 deletions tests/test_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,15 @@ fn shared_is_unique() {
assert!(c.is_unique());
}

#[test]
fn mut_shared_is_unique() {
let mut b = BytesMut::from(LONG);
let c = b.split().freeze();
assert!(!c.is_unique());
drop(b);
assert!(c.is_unique());
}

#[test]
fn test_bytesmut_from_bytes_static() {
let bs = b"1b23exfcz3r";
Expand Down

0 comments on commit f8c7b57

Please sign in to comment.