Skip to content

Commit c8cd574

Browse files
committed
Cover the refcount ceiling through inc and dec
inc_by writes its own overflow check, so a test built on it leaves inc and dec unexercised. The reported aborts came through inc, one reference at a time. Assisted-by: Claude Code:claude-opus-5
1 parent d905856 commit c8cd574

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎crates/common/src/refcount.rs‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,28 @@ mod tests {
318318
assert_eq!(rc.get(), REFERENCES + 1);
319319
}
320320

321+
/// `inc` and `dec` reach the same ceiling as `inc_by`.
322+
///
323+
/// The aborts reported against this layout came one reference at a time
324+
/// through `inc`, whose overflow check is written separately from
325+
/// `inc_by`'s, and the count has to come back down through `dec` without
326+
/// reporting the object collectable before the last reference goes.
327+
#[test]
328+
fn inc_and_dec_reach_past_a_16_bit_ceiling() {
329+
const REFERENCES: usize = 1 << 20;
330+
331+
let rc = RefCount::new(); // strong = 1
332+
for _ in 1..REFERENCES {
333+
rc.inc();
334+
}
335+
assert_eq!(rc.get(), REFERENCES);
336+
for _ in 1..REFERENCES {
337+
assert!(!rc.dec());
338+
}
339+
assert_eq!(rc.get(), 1);
340+
assert!(rc.dec());
341+
}
342+
321343
/// A fresh count holds exactly one strong reference and no stray bits.
322344
///
323345
/// `get` masks the flags away, so a spare field left in the word would not

0 commit comments

Comments
 (0)