feat(scope): expose scope cleanup state

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 19:25:03 +00:00
parent b5e288510f
commit 9bc20fda95
2 changed files with 27 additions and 0 deletions

View file

@ -80,3 +80,11 @@ func (s *Scope) FreeAll() {
Free(pointer)
}
}
// IsFreed reports whether FreeAll has been called.
func (s *Scope) IsFreed() bool {
if s == nil {
return true
}
return s.freed.Load()
}

View file

@ -37,3 +37,22 @@ func TestScopePanicsAfterFreeAll(t *testing.T) {
scope.CString("nope")
})
}
func TestScopeIsFreedTracksLifecycle(t *testing.T) {
t.Parallel()
scope := NewScope()
if scope.IsFreed() {
t.Fatal("expected new scope to be active")
}
scope.FreeAll()
if !scope.IsFreed() {
t.Fatal("expected scope to report freed after FreeAll")
}
var nilScope *Scope
if !nilScope.IsFreed() {
t.Fatal("expected nil scope to be treated as freed")
}
}