feat(core): make Buffer.IsFreed nil-safe

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 19:31:31 +00:00
parent 65d3825cad
commit f19b691112
2 changed files with 12 additions and 0 deletions

View file

@ -123,6 +123,9 @@ func (b *Buffer) Len() int {
// buffer := NewBuffer(4)
// if buffer.IsFreed() { ... }
func (b *Buffer) IsFreed() bool {
if b == nil {
return true
}
return b.freed.Load()
}

View file

@ -71,6 +71,15 @@ func TestBufferUseAfterFreePanics(t *testing.T) {
})
}
func TestBufferIsFreedIsNilSafe(t *testing.T) {
t.Parallel()
var nilBuffer *Buffer
if !nilBuffer.IsFreed() {
t.Fatal("expected nil buffer to report freed")
}
}
func TestCStringRoundTrip(t *testing.T) {
t.Parallel()