Skip to content

Commit f8c7b57

Browse files
committed
Merge 'v1.6.1' into 'master' (#721)
2 parents 9965a04 + fd13c7d commit f8c7b57

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 1.6.1 (July 13, 2024)
2+
3+
This release fixes a bug where `Bytes::is_unique` returns incorrect values when
4+
the `Bytes` originates from a shared `BytesMut`. (#718)
5+
16
# 1.6.0 (March 22, 2024)
27

38
### Added

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ name = "bytes"
44
# When releasing to crates.io:
55
# - Update CHANGELOG.md.
66
# - Create "v1.x.y" git tag.
7-
version = "1.6.0"
7+
version = "1.6.1"
88
edition = "2018"
99
rust-version = "1.39"
1010
license = "MIT"

src/bytes_mut.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ static SHARED_VTABLE: Vtable = Vtable {
17801780
clone: shared_v_clone,
17811781
to_vec: shared_v_to_vec,
17821782
to_mut: shared_v_to_mut,
1783-
is_unique: crate::bytes::shared_is_unique,
1783+
is_unique: shared_v_is_unique,
17841784
drop: shared_v_drop,
17851785
};
17861786

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

1846+
unsafe fn shared_v_is_unique(data: &AtomicPtr<()>) -> bool {
1847+
let shared = data.load(Ordering::Acquire);
1848+
let ref_count = (*shared.cast::<Shared>()).ref_count.load(Ordering::Relaxed);
1849+
ref_count == 1
1850+
}
1851+
18461852
unsafe fn shared_v_drop(data: &mut AtomicPtr<()>, _ptr: *const u8, _len: usize) {
18471853
data.with_mut(|shared| {
18481854
release_shared(*shared as *mut Shared);

tests/test_bytes.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,15 @@ fn shared_is_unique() {
11731173
assert!(c.is_unique());
11741174
}
11751175

1176+
#[test]
1177+
fn mut_shared_is_unique() {
1178+
let mut b = BytesMut::from(LONG);
1179+
let c = b.split().freeze();
1180+
assert!(!c.is_unique());
1181+
drop(b);
1182+
assert!(c.is_unique());
1183+
}
1184+
11761185
#[test]
11771186
fn test_bytesmut_from_bytes_static() {
11781187
let bs = b"1b23exfcz3r";

0 commit comments

Comments
 (0)