This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efl.

View the commit online.

commit 93c54553916dc651cea08e14f5feaf34c32068dc
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 8 15:12:00 2026 -0600

    elementary: a spotlight takes a manager it holds only by its parent
    
    The spotlight_manager and indicator setters deleted the old object and
    assigned the new one before checking, with EINA_SAFETY_ON_FALSE_RETURN
    (efl_ownable_get()), that there was a ref to pass on. A manager made
    with efl_add(CLASS, container) has only its parent's ref: the check
    logged an ERR and returned with the manager assigned but not bound, and
    without the POS_UPDATE callback. Do as the collections do: work out
    whether a ref came with the object first, refuse a wrong class before
    touching anything, unref only a ref that was given, and keep the object
    that is set again. The indicator setter gets the same shape.
    
    The tests set a manager and an indicator from efl_add(CLASS, container),
    efl_new and efl_add_ref, and check they end bound and held.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_spotlight_container.c | 44 ++++++++++---
 src/tests/elementary/efl_ui_test_spotlight.c    | 86 +++++++++++++++++++++++++
 2 files changed, 120 insertions(+), 10 deletions(-)

diff --git a/src/lib/elementary/efl_ui_spotlight_container.c b/src/lib/elementary/efl_ui_spotlight_container.c
index a825cb6bbf..03cb9cfd92 100644
--- a/src/lib/elementary/efl_ui_spotlight_container.c
+++ b/src/lib/elementary/efl_ui_spotlight_container.c
@@ -654,17 +654,24 @@ _pos_updated(void *data, const Efl_Event *event)
 EOLIAN static void
 _efl_ui_spotlight_container_spotlight_manager_set(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Efl_Ui_Spotlight_Manager *transition)
 {
+   Eina_Bool ref_given = EINA_FALSE;
+
+   // everything is checked before the container is touched: a refused manager
+   // leaves the one that is there in place
    if (transition)
-     EINA_SAFETY_ON_FALSE_RETURN(efl_isa(transition, EFL_UI_SPOTLIGHT_MANAGER_CLASS));
+     {
+        EINA_SAFETY_ON_FALSE_RETURN(efl_isa(transition, EFL_UI_SPOTLIGHT_MANAGER_CLASS));
+        // The ownership is passed to us, with a ref that is not the parent's. A
+        // manager that has only its parent's (efl_add(CLASS, obj)) brings none:
+        // it has nothing to let go of, and unreffing it would be one ref too many.
+        ref_given = (efl_ref_count(transition) - (efl_parent_get(transition) ? 1 : 0)) > 0;
+     }
 
    // the manager that is there, set again, stays: ending it would end the one
    // that is being set. The ref it came with is let go of, as for any manager.
    if (transition && (transition == pd->transition))
      {
-        int extra_refs = efl_ref_count(transition) - (efl_parent_get(transition) ? 1 : 0);
-
-        if (extra_refs > 0)
-          efl_unref(transition);
+        if (ref_given) efl_unref(transition);
         return;
      }
 
@@ -678,15 +685,17 @@ _efl_ui_spotlight_container_spotlight_manager_set(Eo *obj, Efl_Ui_Spotlight_Cont
      }
 
    if (!transition)
-     transition = efl_new(EFL_UI_SPOTLIGHT_PLAIN_MANAGER_CLASS);
+     {
+        transition = efl_new(EFL_UI_SPOTLIGHT_PLAIN_MANAGER_CLASS);
+        ref_given = EINA_TRUE;
+     }
    pd->transition = transition;
 
    if (pd->transition)
      {
-        EINA_SAFETY_ON_FALSE_RETURN(efl_ownable_get(pd->transition));
         efl_parent_set(pd->transition, obj);
         //the api indicates that the caller passes ownership to this function, so we need to unref here
-        efl_unref(pd->transition);
+        if (ref_given) efl_unref(pd->transition);
         //disable animation when not finalized yet, this help reducing the overhead of scheduling a animation that will not be displayed
         _animated_transition_manager_eval(obj, pd);
         efl_ui_spotlight_manager_animated_transition_set(pd->transition, efl_finalized_get(obj));
@@ -709,6 +718,22 @@ _efl_ui_spotlight_container_spotlight_manager_get(const Eo *obj EINA_UNUSED, Efl
 EOLIAN static void
 _efl_ui_spotlight_container_indicator_set(Eo *obj, Efl_Ui_Spotlight_Container_Data *pd, Efl_Ui_Spotlight_Indicator *indicator)
 {
+   Eina_Bool ref_given = EINA_FALSE;
+
+   // checked before the container is touched, as for the manager
+   if (indicator)
+     {
+        EINA_SAFETY_ON_FALSE_RETURN(efl_isa(indicator, EFL_UI_SPOTLIGHT_INDICATOR_CLASS));
+        ref_given = (efl_ref_count(indicator) - (efl_parent_get(indicator) ? 1 : 0)) > 0;
+     }
+
+   // the indicator that is there, set again, stays
+   if (indicator && (indicator == pd->indicator))
+     {
+        if (ref_given) efl_unref(indicator);
+        return;
+     }
+
    if (pd->indicator)
      {
         efl_del(pd->indicator);
@@ -716,10 +741,9 @@ _efl_ui_spotlight_container_indicator_set(Eo *obj, Efl_Ui_Spotlight_Container_Da
    pd->indicator = indicator;
    if (pd->indicator)
      {
-        EINA_SAFETY_ON_FALSE_RETURN(efl_ownable_get(pd->indicator));
         efl_parent_set(pd->indicator, obj);
         //the api indicates that the caller passes ownership to this function, so we need to unref here
-        efl_unref(pd->indicator);
+        if (ref_given) efl_unref(pd->indicator);
         efl_ui_spotlight_indicator_bind(pd->indicator, obj);
         if (!EINA_DBL_EQ(pd->position, -1))
           efl_ui_spotlight_indicator_position_update(pd->indicator, pd->position);
diff --git a/src/tests/elementary/efl_ui_test_spotlight.c b/src/tests/elementary/efl_ui_test_spotlight.c
index 0d9b9962bf..2c437241aa 100644
--- a/src/tests/elementary/efl_ui_test_spotlight.c
+++ b/src/tests/elementary/efl_ui_test_spotlight.c
@@ -770,6 +770,90 @@ spotlight_teardown()
    memset(&indicator_calls, 0, sizeof(indicator_calls));
 }
 
+// The manager and the indicator may be handed over in three ways: with a ref
+// of their own (efl_new, efl_add_ref), or with only their parent's
+// (efl_add(CLASS, container)). Each ends bound, held by the container and ended
+// with it, without an error logged (the fixture fails on one).
+static Eo *
+_tracked_manager(int how, Eo *c)
+{
+   Eo *m;
+
+   memset(&transition_calls, 0, sizeof(transition_calls));
+   if (how == 0)
+     m = efl_add(efl_ui_spotlight_manager_realized_class_get(), c,
+                 efl_object_override(efl_added, &transition_tracker));
+   else if (how == 1)
+     m = efl_new(efl_ui_spotlight_manager_realized_class_get(),
+                 efl_object_override(efl_added, &transition_tracker));
+   else
+     m = efl_add_ref(efl_ui_spotlight_manager_realized_class_get(), NULL,
+                     efl_object_override(efl_added, &transition_tracker));
+   return m;
+}
+
+EFL_START_TEST (efl_ui_spotlight_manager_ownership)
+{
+   int how;
+
+   for (how = 0; how < 3; how++)
+     {
+        Eina_Bool gone = EINA_FALSE;
+        Eo *c = efl_add(EFL_UI_SPOTLIGHT_CONTAINER_CLASS, win);
+        Eo *m = _tracked_manager(how, c);
+
+        efl_event_callback_add(m, EFL_EVENT_DEL, _manager_del, &gone);
+        efl_ui_spotlight_manager_set(c, m);
+
+        ck_assert(!gone);
+        ck_assert_ptr_eq(efl_ui_spotlight_manager_get(c), m);
+        ck_assert_ptr_eq(efl_parent_get(m), c);
+        ck_assert_int_eq(efl_ref_count(m), 1);
+        ck_assert_int_eq(transition_calls.spotlight.called, 1);
+        ck_assert_ptr_eq(transition_calls.spotlight.spotlight, c);
+        ck_assert_int_eq(efl_event_callback_count(m, EFL_UI_SPOTLIGHT_MANAGER_EVENT_POS_UPDATE), 1);
+
+        efl_del(c);
+        ck_assert(gone);
+     }
+}
+EFL_END_TEST
+
+EFL_START_TEST (efl_ui_spotlight_indicator_ownership)
+{
+   int how;
+
+   for (how = 0; how < 3; how++)
+     {
+        Eina_Bool gone = EINA_FALSE;
+        Eo *c = efl_add(EFL_UI_SPOTLIGHT_CONTAINER_CLASS, win);
+        Eo *i;
+
+        memset(&indicator_calls, 0, sizeof(indicator_calls));
+        if (how == 0)
+          i = efl_add(efl_ui_spotlight_indicator_realized_class_get(), c,
+                      efl_object_override(efl_added, &indicator_tracker));
+        else if (how == 1)
+          i = _create_indicator();
+        else
+          i = efl_add_ref(efl_ui_spotlight_indicator_realized_class_get(), NULL,
+                          efl_object_override(efl_added, &indicator_tracker));
+        efl_event_callback_add(i, EFL_EVENT_DEL, _manager_del, &gone);
+        efl_ui_spotlight_indicator_set(c, i);
+
+        ck_assert(!gone);
+        ck_assert_ptr_eq(efl_ui_spotlight_indicator_get(c), i);
+        ck_assert_ptr_eq(efl_parent_get(i), c);
+        ck_assert_int_eq(efl_ref_count(i), 1);
+        ck_assert_int_eq(indicator_calls.spotlight.called, 1);
+        ck_assert_ptr_eq(indicator_calls.spotlight.spotlight, c);
+
+        efl_del(c);
+        ck_assert(gone);
+     }
+}
+EFL_END_TEST
+
 void efl_ui_test_spotlight(TCase *tc)
 {
    tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
@@ -791,4 +875,6 @@ void efl_ui_test_spotlight(TCase *tc)
    tcase_add_test(tc, efl_ui_spotlight_manager_unset);
    tcase_add_test(tc, efl_ui_spotlight_manager_twice);
    tcase_add_test(tc, efl_ui_spotlight_min_max_sizing);
+   tcase_add_test(tc, efl_ui_spotlight_manager_ownership);
+   tcase_add_test(tc, efl_ui_spotlight_indicator_ownership);
 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to