This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch eo-api-finalize
in repository ego.
View the commit online.
commit f3a305505eed14d8dff01f71af383aaf41c8e36d
Author: Cedric Bail <[email protected]>
AuthorDate: Thu Nov 26 01:22:26 2026 -0600
efl: a part whose widget is invalidated has nothing left to release
When a widget is invalidated the binding hands Go's reference on each
part it still holds back to EFL, while the part has its parent, so that
the part ends cleanly. Its record did not say so: until the widget was
deleted the wrapper still looked alive, and an Unref in between -- from
a handler of the part's own invalidate, or a collection -- released a
reference Go no longer had. EFL answered with "Too many unrefs".
The record is now marked when the reference is handed back. From then
on the wrapper refers to nothing, as the README says of an object that
died under its wrapper, and releasing it releases nothing.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
efl/dispatch_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
efl/object.go | 33 ++++++++++++++++++++-------------
2 files changed, 69 insertions(+), 13 deletions(-)
diff --git a/efl/dispatch_test.go b/efl/dispatch_test.go
index 6836b2b6..30534a50 100644
--- a/efl/dispatch_test.go
+++ b/efl/dispatch_test.go
@@ -153,3 +153,52 @@ func TestDelHandlerClosesTheOtherHandle(t *testing.T) {
}
})
}
+
+// Once its widget is invalidated, Go's reference on a part is back with EFL,
+// and releasing the wrapper in the moments before the part is deleted -- from
+// a handler of the part's own -- releases nothing more. It used to drop the
+// reference the part's parent holds.
+func TestUnrefOfAPartAfterItsWidgetIsInvalidated(t *testing.T) {
+ var mainWindow *ui.Win
+ var part *efl.Object
+ var partRaw unsafe.Pointer
+ var invalidated, deleted, refsBefore, refsAfter, wrapperGone atomic.Int32
+
+ efl.Sync(func() {
+ mainWindow = efl.Must(ui.NewWin(nil, win.WithWinName("hook-part-unref")))
+ panes := efl.Must(ui.NewPanes(mainWindow))
+ part = efl.Part(panes, "first")
+ if part == nil {
+ t.Error("a Panes has a first part")
+ return
+ }
+ partRaw = eort.Eo(part)
+ eort.RegisterCallback(partRaw, efl.EFLEventInvalidateDesc(), func(unsafe.Pointer) {
+ invalidated.Add(1)
+ refsBefore.Store(int32(efl.EoRefCount(partRaw)))
+ if part.IsNil() {
+ wrapperGone.Store(1)
+ }
+ part.Unref()
+ refsAfter.Store(int32(efl.EoRefCount(partRaw)))
+ })
+ eort.RegisterCallback(partRaw, efl.EFLEventDelDesc(), func(unsafe.Pointer) { deleted.Add(1) })
+ mainWindow.Del()
+ })
+
+ deadline := time.Now().Add(5 * time.Second)
+ for efl.SyncWithReturn(func() bool { return deleted.Load() == 0 }) && time.Now().Before(deadline) {
+ time.Sleep(5 * time.Millisecond)
+ }
+
+ if invalidated.Load() != 1 || deleted.Load() != 1 {
+ t.Fatalf("the part was invalidated %d time(s) and deleted %d, want once each", invalidated.Load(), deleted.Load())
+ }
+ if wrapperGone.Load() != 1 {
+ t.Error("the wrapper still refers to a part whose reference was handed back")
+ }
+ if refsBefore.Load() != refsAfter.Load() {
+ t.Errorf("Unref took the part's references from %d to %d", refsBefore.Load(), refsAfter.Load())
+ }
+ efl.Sync(func() { mainWindow.Unref() })
+}
diff --git a/efl/object.go b/efl/object.go
index a03b77a9..77647d7f 100644
--- a/efl/object.go
+++ b/efl/object.go
@@ -158,15 +158,20 @@ type tracked struct {
count int // wrappers that share the reference
watchers int // parts that end with it
dead atomic.Bool
- owner atomic.Pointer[tracked]
- parts map[*tracked]struct{} // the parts it owns, for its invalidation
- handlers []*handler // the Go closures called for its events
+ // handedBack is set on a part when its widget's invalidation gave Go's
+ // reference on it back to EFL. The part lives on until it is deleted, but
+ // Go has nothing left to release, and the wrapper refers to nothing.
+ handedBack atomic.Bool
+ owner atomic.Pointer[tracked]
+ parts map[*tracked]struct{} // the parts it owns, for its invalidation
+ handlers []*handler // the Go closures called for its events
}
-// gone reports whether the object died, or its owner did.
+// gone reports whether the object died, or Go's reference on it was handed
+// back, or its owner died.
func (t *tracked) gone() bool {
owner := t.owner.Load()
- return t.dead.Load() || (owner != nil && owner.gone())
+ return t.dead.Load() || t.handedBack.Load() || (owner != nil && owner.gone())
}
// trackedObjs, handlers and partOwners are only touched on the loop thread,
@@ -312,7 +317,7 @@ func watchObject(ptr unsafe.Pointer) *tracked {
// has no hook left to keep.
func untrackObject(rec *tracked) (last bool) {
assertLoop()
- if rec.dead.Load() || rec.count <= 0 {
+ if rec.dead.Load() || rec.handedBack.Load() || rec.count <= 0 {
return false
}
rec.count--
@@ -328,11 +333,12 @@ func untrackObject(rec *tracked) (last bool) {
// event.
//
// Invalidated, an object is on its way out. Each part still held gets Go's
-// reference handed back now, while it has its parent: it then ends cleanly,
-// and its own hook says so. Every closure but its OnDel ones is released;
-// those go when it is deleted, having run. Releasing them is what lets a
-// closure that captured its own wrapper -- the usual way to write a handler --
-// stop keeping that wrapper alive.
+// reference handed back now, while it has its parent, and its record says so:
+// its wrappers refer to nothing from then on, and releasing them releases
+// nothing. It ends cleanly, and its own hook says so. Every closure but its
+// OnDel ones is released; those go when it is deleted, having run. Releasing
+// them is what lets a closure that captured its own wrapper -- the usual way
+// to write a handler -- stop keeping that wrapper alive.
//
// Deleted, the record dies and goes, with all that it kept.
//
@@ -351,7 +357,8 @@ func egoHookCallback(data unsafe.Pointer, event *C.Efl_Event) {
unhook = unwatch(rec)
} else {
for part := range rec.parts {
- if part.count > 0 && !part.dead.Load() {
+ if part.count > 0 && !part.dead.Load() && !part.handedBack.Load() {
+ part.handedBack.Store(true)
parts = append(parts, part.ptr)
}
}
@@ -386,7 +393,7 @@ func cleanupTrackedObjects() {
}
var left []held
for ptr, rec := range trackedObjs {
- if rec.count == 0 {
+ if rec.count == 0 || rec.handedBack.Load() {
continue
}
left = append(left, held{ptr, rec.handlers})
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.