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 6c01ec128835ddbaffb922e93a896a168a2bfe5c
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 6 00:21:15 2026 -0600
elementary: a widget stops listening when its provider goes away
The provider taking its model along did not take the properties,changed
subscription along: the widget kept a callback on a model that outlived
it, and the model called into the widget after it was freed. Drop the
subscription with the model, with the same helper the model change and
unregister paths use.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/lib/elementary/efl_ui_widget.c | 37 ++++++++++++------------
src/tests/elementary/efl_ui_test_property_bind.c | 32 ++++++++++++++++++++
2 files changed, 51 insertions(+), 18 deletions(-)
diff --git a/src/lib/elementary/efl_ui_widget.c b/src/lib/elementary/efl_ui_widget.c
index e2b1fb75ca..600e6f3e52 100644
--- a/src/lib/elementary/efl_ui_widget.c
+++ b/src/lib/elementary/efl_ui_widget.c
@@ -5995,6 +5995,19 @@ _efl_ui_widget_model_update(Eo *obj, Efl_Ui_Widget_Data *pd)
eina_iterator_free(it);
}
+// Stops listening to the model for changes, but keeps the model
+static void
+_efl_ui_widget_model_unsubscribe(Eo *obj, Efl_Ui_Widget_Data *pd)
+{
+ if (!pd->properties.registered) return;
+
+ efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
+ _efl_ui_model_property_bind_changed, obj);
+ efl_event_callback_del(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
+ _efl_ui_view_property_bind_changed, obj);
+ pd->properties.registered = EINA_FALSE;
+}
+
static void _efl_ui_widget_model_provider_model_change(void *data, const Efl_Event *event EINA_UNUSED);
static void _efl_ui_widget_model_provider_invalidate(void *data, const Efl_Event *event EINA_UNUSED);
@@ -6010,14 +6023,7 @@ _efl_ui_widget_model_provider_model_change(void *data, const Efl_Event *event)
if (!pd) return;
// The properties,changed subscription belongs to the model being replaced
- if (pd->properties.registered)
- {
- efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
- _efl_ui_model_property_bind_changed, data);
- efl_event_callback_del(data, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
- _efl_ui_view_property_bind_changed, data);
- pd->properties.registered = EINA_FALSE;
- }
+ _efl_ui_widget_model_unsubscribe(data, pd);
efl_replace(&pd->properties.model,
efl_ui_view_model_get(pd->properties.provider));
@@ -6041,6 +6047,9 @@ _efl_ui_widget_model_provider_invalidate(void *data, const Efl_Event *event EINA
ELM_WIDGET_DATA_GET(data, pd);
if (!pd) return;
+
+ // The model goes with the provider, and the subscription made to it with the model
+ _efl_ui_widget_model_unsubscribe(data, pd);
efl_event_callback_array_del(pd->properties.provider,
efl_ui_widget_model_provider_callbacks(),
data);
@@ -6089,16 +6098,8 @@ _efl_ui_widget_model_register(Eo *obj, Efl_Ui_Widget_Data *pd)
static void
_efl_ui_widget_model_unregister(Eo *obj, Efl_Ui_Widget_Data *pd)
{
- if (pd->properties.registered)
- {
- // Remove any existing handler that might exist for any reason
- efl_event_callback_del(pd->properties.model, EFL_MODEL_EVENT_PROPERTIES_CHANGED,
- _efl_ui_model_property_bind_changed, obj);
- efl_event_callback_del(obj, EFL_UI_PROPERTY_BIND_EVENT_PROPERTIES_CHANGED,
- _efl_ui_view_property_bind_changed, obj);
-
- pd->properties.registered = EINA_FALSE;
- }
+ // Remove any existing handler that might exist for any reason
+ _efl_ui_widget_model_unsubscribe(obj, pd);
// Invalidate must be called before setting a new model and even if no model is registered
if (pd->properties.provider)
_efl_ui_widget_model_provider_invalidate(obj, NULL);
diff --git a/src/tests/elementary/efl_ui_test_property_bind.c b/src/tests/elementary/efl_ui_test_property_bind.c
index 60059d5bf8..c05759c458 100644
--- a/src/tests/elementary/efl_ui_test_property_bind.c
+++ b/src/tests/elementary/efl_ui_test_property_bind.c
@@ -630,11 +630,43 @@ EFL_START_TEST(rebinding_a_key_replaces_the_binding)
}
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. */
+EFL_START_TEST(efl_ui_model_provider_dies_first)
+{
+ Eo *win = _window();
+ Eo *model = _model_new("t", eina_value_string_new("one"));
+ Eo *box, *provider, *label;
+ unsigned int before = efl_event_callback_count(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED);
+
+ box = efl_add(EFL_UI_BOX_CLASS, win);
+ provider = efl_add(EFL_MODEL_PROVIDER_CLASS, box);
+ efl_provider_register(box, EFL_MODEL_PROVIDER_CLASS, provider);
+ label = efl_add(EFL_UI_TEXTBOX_CLASS, box,
+ efl_ui_property_bind(efl_added, "text", "t"));
+ efl_pack_end(box, label);
+ efl_ui_view_model_set(provider, model);
+ ck_assert_str_eq(efl_text_get(label), "one");
+ ck_assert_int_gt(efl_event_callback_count(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED), before);
+
+ efl_del(provider);
+ ck_assert_int_eq(efl_event_callback_count(model, EFL_MODEL_EVENT_PROPERTIES_CHANGED), before);
+
+ // Nothing is called, now or after the widget is gone
+ _model_set(model, "t", eina_value_string_new("two"));
+ efl_del(label);
+ _model_set(model, "t", eina_value_string_new("three"));
+ efl_unref(model);
+}
+EFL_END_TEST
+
void
efl_ui_test_property_bind(TCase *tc)
{
tcase_add_test(tc, textbox_user_edit_reaches_the_model);
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, textbox_model_change_does_not_loop);
tcase_add_test(tc, textbox_typing_in_the_middle_keeps_the_cursor);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.