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 e3b2c3375f09dd218396f0aac5872733edff8bf8
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 6 01:02:04 2026 -0600

    elementary: rebinding a layout part replaces its binding
    
    A widget replaces the binding of a key when it is bound again, but a
    layout part only skipped an exact duplicate, so rebinding a part from
    title to name kept it following both. Drop the other properties bound
    to the part before adding the new one, and document on
    Efl.Ui.Property_Bind.property_bind that binding a key again replaces
    its previous binding.
    
    The hash of a layout's bindings holds one reference to each property
    and did not release them: they leaked when a binding was replaced and
    when the layout was deleted.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 data/elementary/objects/test.edc                 | 23 +++++++
 src/lib/efl/interfaces/efl_ui_property_bind.eo   |  5 +-
 src/lib/elementary/efl_ui_layout.c               | 82 ++++++++++++++++++++++--
 src/tests/elementary/efl_ui_test_property_bind.c | 78 ++++++++++++++++++++++
 4 files changed, 183 insertions(+), 5 deletions(-)

diff --git a/data/elementary/objects/test.edc b/data/elementary/objects/test.edc
index cef0249d98..46c3edbdbb 100644
--- a/data/elementary/objects/test.edc
+++ b/data/elementary/objects/test.edc
@@ -833,6 +833,29 @@ collections {
          }
       }
    }
+   group { name: "bind_parts_layout";
+      parts {
+         part { name: "t1";
+            type: TEXT;
+            effect: NONE;
+            description { state: "default" 0.0;
+               text { text: ""; font: "Sans"; size: 10; }
+            }
+         }
+         part { name: "t2";
+            type: TEXT;
+            description { state: "default" 0.0;
+               text { text: ""; font: "Sans"; size: 10; }
+            }
+         }
+         part { name: "t3";
+            type: TEXT;
+            description { state: "default" 0.0;
+               text { text: ""; font: "Sans"; size: 10; }
+            }
+         }
+      }
+   }
    group { name: "font_overlay_layout";
       styles {
          style { name: "test_class_style";
diff --git a/src/lib/efl/interfaces/efl_ui_property_bind.eo b/src/lib/efl/interfaces/efl_ui_property_bind.eo
index d0249ae7f8..ae697839e3 100644
--- a/src/lib/efl/interfaces/efl_ui_property_bind.eo
+++ b/src/lib/efl/interfaces/efl_ui_property_bind.eo
@@ -21,7 +21,10 @@ interface Efl.Ui.Property_Bind
    methods {
       property_bind {
          [[bind property data with the given key string. when the data is ready or changed,
-           bind the data to the key action and process promised work.]]
+           bind the data to the key action and process promised work.
+
+           Binding a key again replaces its previous binding: the key follows the new
+           property only. Binding it to the same property again changes nothing.]]
          params {
             key: string; [[key string for bind model property data]]
             property: string; [[Model property name]]
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index d18ab3a746..ec86bd7ed4 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -929,6 +929,24 @@ _efl_ui_layout_base_efl_canvas_group_group_add(Eo *obj, Efl_Ui_Layout_Data *_pd
         (edje, "size,eval", "efl", _on_size_evaluate_signal, obj);
 }
 
+// Every entry of a connect hash owns one reference to its property, which
+// the hash does not release by itself.
+static void
+_efl_ui_layout_connect_hash_free(Eina_Hash *hash)
+{
+   Eina_Iterator *it;
+   Eina_Hash_Tuple *tuple;
+
+   if (!hash) return;
+   it = eina_hash_iterator_tuple_new(hash);
+   EINA_ITERATOR_FOREACH(it, tuple)
+     {
+        eina_stringshare_del(tuple->key);
+     }
+   eina_iterator_free(it);
+   eina_hash_free(hash);
+}
+
 EOLIAN static void
 _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
 {
@@ -971,9 +989,9 @@ _efl_ui_layout_base_efl_canvas_group_group_del(Eo *obj, Efl_Ui_Layout_Data *sd)
                                 _efl_model_properties_changed_cb, sd);
      }
 
-   eina_hash_free(sd->connect.properties);
+   _efl_ui_layout_connect_hash_free(sd->connect.properties);
    sd->connect.properties = NULL;
-   eina_hash_free(sd->connect.signals);
+   _efl_ui_layout_connect_hash_free(sd->connect.signals);
    sd->connect.signals = NULL;
    eina_hash_free(sd->connect.factories);
    sd->connect.factories = NULL;
@@ -2710,6 +2728,57 @@ _efl_ui_layout_connected(Eina_Hash *hash, Eina_Stringshare *property, const char
    return found;
 }
 
+// A part follows one property: drop what it was bound to before, unless it
+// is the property being bound.
+// Eina cannot delete one entry among several that share a key (removal looks
+// the node up by key, and finds another one), so the hash is rebuilt without
+// the stale entries. Every entry owns one reference to its property, which
+// the hash does not release by itself.
+static void
+_efl_ui_layout_unbind_part(Eina_Hash **hashp, Eina_Stringshare *property, const char *part)
+{
+   Eina_Hash *hash = *hashp;
+   Eina_Hash *fresh;
+   Eina_Iterator *it;
+   Eina_Hash_Tuple *tuple;
+   Eina_Bool stale = EINA_FALSE;
+
+   it = eina_hash_iterator_tuple_new(hash);
+   EINA_ITERATOR_FOREACH(it, tuple)
+     {
+        if ((tuple->key != property) && !strcmp(tuple->data, part))
+          {
+             stale = EINA_TRUE;
+             break;
+          }
+     }
+   eina_iterator_free(it);
+   if (!stale) return;
+
+   fresh = eina_hash_stringshared_new(EINA_FREE_CB(free));
+   if (!fresh) return;
+
+   it = eina_hash_iterator_tuple_new(hash);
+   EINA_ITERATOR_FOREACH(it, tuple)
+     {
+        if ((tuple->key != property) && !strcmp(tuple->data, part))
+          {
+             eina_stringshare_del(tuple->key);
+             free((void *)tuple->data);
+          }
+        else
+          {
+             eina_hash_add(fresh, tuple->key, tuple->data);
+          }
+     }
+   eina_iterator_free(it);
+
+   // The entries were moved, not copied
+   eina_hash_free_cb_set(hash, NULL);
+   eina_hash_free(hash);
+   *hashp = fresh;
+}
+
 EOLIAN static Eina_Error
 _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Data *pd, const char *key, const char *property)
 {
@@ -2717,6 +2786,7 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
    Eina_Stringshare *sprop;
    Eina_Stringshare *sk;
    Eina_Hash *hash = NULL;
+   Eina_Hash **hashp = NULL;
    char *data = ""
    Efl_Model *model;
    Eina_Error r;
@@ -2739,12 +2809,14 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
 
    if (strncmp(SIGNAL_PREFIX, key, sizeof(SIGNAL_PREFIX) - 1) == 0)
      {
-        hash = pd->connect.signals;
+        hashp = &pd->connect.signals;
+        hash = *hashp;
         data = "" + sizeof(SIGNAL_PREFIX) - 1);
      }
    else
      {
-        hash = pd->connect.properties;
+        hashp = &pd->connect.properties;
+        hash = *hashp;
         data = ""
      }
 
@@ -2760,6 +2832,8 @@ _efl_ui_layout_base_efl_ui_property_bind_property_bind(Eo *obj, Efl_Ui_Layout_Da
      }
    else
      {
+        _efl_ui_layout_unbind_part(hashp, sprop, data);
+        hash = *hashp;
         eina_hash_add(hash, sprop, data);
      }
 
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
index c05759c458..4ad561f14e 100644
--- a/src/tests/elementary/efl_ui_test_property_bind.c
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -630,6 +630,82 @@ EFL_START_TEST(rebinding_a_key_replaces_the_binding)
 }
 EFL_END_TEST
 
+// Binding a part again replaces what it was bound to: it follows the new
+// property only, and the old one has no hold on it any more.
+EFL_START_TEST(rebinding_a_layout_part_replaces_the_binding)
+{
+   Eo *win = _window();
+   Eo *model = _model_new("title", eina_value_string_new("T"));
+   Eo *ly;
+   char buf[PATH_MAX];
+
+   _model_set(model, "name", eina_value_string_new("N"));
+
+   ly = efl_add(EFL_UI_LAYOUT_CLASS, win);
+   snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
+   ck_assert(efl_file_simple_load(ly, buf, "layout"));
+
+   ck_assert_int_eq(efl_ui_property_bind(ly, "text", "title"), 0);
+   ck_assert_int_eq(efl_ui_property_bind(ly, "text", "name"), 0);
+   // The same binding again, as a factory does for a reused item
+   ck_assert_int_eq(efl_ui_property_bind(ly, "text", "name"), 0);
+   efl_ui_view_model_set(ly, model);
+   ecore_main_loop_iterate();
+   ck_assert_str_eq(efl_text_get(efl_part(ly, "text")), "N");
+
+   _model_set(model, "title", eina_value_string_new("T2"));
+   ecore_main_loop_iterate();
+   ck_assert_str_eq(efl_text_get(efl_part(ly, "text")), "N");
+
+   _model_set(model, "name", eina_value_string_new("N2"));
+   ecore_main_loop_iterate();
+   ck_assert_str_eq(efl_text_get(efl_part(ly, "text")), "N2");
+   efl_unref(model);
+}
+EFL_END_TEST
+
+// Several parts bound to one property: rebinding one of them takes only that
+// one away from the property, the others keep following it. Each part takes
+// its turn, as the order the stale entries are found in is not defined.
+EFL_START_TEST(rebinding_one_of_several_parts_keeps_the_others)
+{
+   static const char *const parts[] = { "t1", "t2", "t3" };
+   Eo *win = _window();
+   Eo *m1 = _model_new("title", eina_value_string_new("T"));
+   Eo *m2 = _model_new("title", eina_value_string_new("T2"));
+   char buf[PATH_MAX];
+   unsigned int i, j;
+
+   _model_set(m1, "name", eina_value_string_new("N"));
+   _model_set(m2, "name", eina_value_string_new("N2"));
+   snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
+
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(parts); i++)
+     {
+        Eo *ly = efl_add(EFL_UI_LAYOUT_CLASS, win);
+
+        ck_assert(efl_file_simple_load(ly, buf, "bind_parts_layout"));
+        for (j = 0; j < EINA_C_ARRAY_LENGTH(parts); j++)
+          {
+             ck_assert_int_eq(efl_ui_property_bind(ly, parts[j], "title"), 0);
+          }
+        ck_assert_int_eq(efl_ui_property_bind(ly, parts[i], "name"), 0);
+
+        // Binding a model updates every bound part from scratch
+        efl_ui_view_model_set(ly, m1);
+        ecore_main_loop_iterate();
+        efl_ui_view_model_set(ly, m2);
+        ecore_main_loop_iterate();
+        for (j = 0; j < EINA_C_ARRAY_LENGTH(parts); j++)
+          {
+             ck_assert_str_eq(efl_text_get(efl_part(ly, parts[j])), (i == j) ? "N2" : "T2");
+          }
+     }
+   efl_unref(m1);
+   efl_unref(m2);
+}
+EFL_END_TEST
+
 /* A model outlives the provider that handed it to a widget. The widget has
  * to stop listening to it with the provider, or the model calls into a widget
  * that has since been freed. */
@@ -668,6 +744,8 @@ efl_ui_test_property_bind(TCase *tc)
    tcase_add_test(tc, efl_ui_model_provider_live_edit);
    tcase_add_test(tc, efl_ui_model_provider_dies_first);
    tcase_add_test(tc, rebinding_a_key_replaces_the_binding);
+   tcase_add_test(tc, rebinding_a_layout_part_replaces_the_binding);
+   tcase_add_test(tc, rebinding_one_of_several_parts_keeps_the_others);
    tcase_add_test(tc, textbox_model_change_does_not_loop);
    tcase_add_test(tc, textbox_typing_in_the_middle_keeps_the_cursor);
    tcase_add_test(tc, textbox_typing_at_the_start_keeps_the_cursor);

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

Reply via email to