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 0ab9b6cb2a8865b91090cadce53e7575253cb6e2
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 20:39:47 2026 -0600

    elementary: exact_model: forget all sizes when a slot cannot be stored
    
    The shift wrote the slots back through the compression that gives the
    old list when it fails, so the sizes of a slot were lost while the total
    still counted them. It now fails like a block of the list does: every
    size is forgotten, the totals go to zero, and the Average_Model starts
    again. A hook, for the tests only, makes the next store fail, as that
    cannot be had otherwise.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/elementary/efl_ui_average_model.c |  12 ++-
 src/lib/elementary/efl_ui_exact_model.c   |  66 ++++++++++---
 src/tests/elementary/efl_ui_model.c       | 156 +++++++++++++++++++++++++++++-
 3 files changed, 220 insertions(+), 14 deletions(-)

diff --git a/src/lib/elementary/efl_ui_average_model.c b/src/lib/elementary/efl_ui_average_model.c
index b0410568f3..8a188980b5 100644
--- a/src/lib/elementary/efl_ui_average_model.c
+++ b/src/lib/elementary/efl_ui_average_model.c
@@ -99,7 +99,7 @@ _efl_ui_average_model_prepare(Eo *obj, Efl_Ui_Average_Model_Data *root,
    Efl_Ui_Average_Model_Update *update;
    Eina_Value *previous;
    Eina_Future *f;
-   unsigned int now;
+   unsigned int now, forgotten;
 
    // What the Exact_Model refuses is not one that will be averaged
    if (!eina_value_uint_convert(value, &now) || (now & EFL_UI_EXACT_MODEL_MEASURED) ||
@@ -112,6 +112,7 @@ _efl_ui_average_model_prepare(Eo *obj, Efl_Ui_Average_Model_Data *root,
    update = calloc(1, sizeof (Efl_Ui_Average_Model_Update));
    if (!update) return efl_loop_future_rejected(obj, ENOMEM);
 
+   forgotten = _efl_ui_exact_model_forgotten_get(efl_parent_get(obj));
    previous = efl_model_property_get(obj, property);
    if (eina_value_type_get(previous) == EINA_VALUE_TYPE_ERROR)
      {
@@ -143,6 +144,15 @@ _efl_ui_average_model_prepare(Eo *obj, Efl_Ui_Average_Model_Data *root,
 
    // We have to make the change after we fetch the old value, otherwise, well, no old value left
    f = efl_model_property_set(efl_super(obj, EFL_UI_AVERAGE_MODEL_CLASS), property, value);
+   // Making room for the size, to read it or to write it, can give up all of them
+   // (a block that cannot be stored): what was told before is not kept, and this row is
+   // the first that is, so that it is added to nothing.
+   if (_efl_ui_exact_model_forgotten_get(efl_parent_get(obj)) != forgotten)
+     {
+        _efl_ui_average_model_forgotten_check(efl_parent_get(obj), root);
+        update->previous = 0;
+        update->seen = seen;
+     }
 
    root->pending = eina_list_append(root->pending, update);
    return efl_future_then(obj, f,
diff --git a/src/lib/elementary/efl_ui_exact_model.c b/src/lib/elementary/efl_ui_exact_model.c
index 7f0a02fe28..c4b0a7792a 100644
--- a/src/lib/elementary/efl_ui_exact_model.c
+++ b/src/lib/elementary/efl_ui_exact_model.c
@@ -103,6 +103,20 @@ _efl_ui_exact_model_zero_unref(void)
    _zero_block = NULL;
 }
 
+// For the tests: what the compression gives when it cannot is not otherwise to be had.
+// While EFL_UI_EXACT_MODEL_STORE_FAIL is set (to anything), the stores fail, but only
+// when EFL_RUN_IN_TREE is set as well (the marker of a run from the build tree, which
+// an installed program has no reason to have): it is not a switch for a release. It is read
+// where a block is stored (which is once per shift of the rows, or for a slot that is given
+// up, and not per size, and next to a compression that costs far more than the lookup), and
+// not once, so that a test can set it around the one call that has to fail.
+static Eina_Bool
+_efl_ui_exact_model_store_failed(void)
+{
+   return getenv("EFL_RUN_IN_TREE") && getenv("EFL_UI_EXACT_MODEL_STORE_FAIL");
+}
+
+// The list as it is when it could not be stored: the old list.
 static Eina_List *
 _efl_ui_exact_model_slot_compress(unsigned int list_index, Eina_List *compressed, unsigned int *buffer)
 {
@@ -111,6 +125,8 @@ _efl_ui_exact_model_slot_compress(unsigned int list_index, Eina_List *compressed
    Eina_Binbuf *tbuf;
    Eina_List *l = NULL;
 
+   if (_efl_ui_exact_model_store_failed()) return compressed;
+
    z = _zero_block;
    l = eina_list_nth_list(compressed, list_index);
 
@@ -235,32 +251,41 @@ _efl_ui_exact_model_buffer_expand(unsigned int list_index, unsigned int *buffer,
    return buffer;
 }
 
+static Eina_Bool _efl_ui_exact_model_block_store(Eina_List **compressed, Eina_List *l,
+                                                 unsigned int block, unsigned int *buffer);
+static void _efl_ui_exact_model_forget(Efl_Ui_Exact_Model_Data *root);
+
 // Writes the slot back under the block it holds (not the one that evicts it),
-// when it was written to, and leaves it holding nothing.
-static void
+// when it was written to, and leaves it holding nothing. False if it could not
+// be stored: what the slot held is then lost, and the sizes are all forgotten.
+static Eina_Bool
 _efl_ui_exact_model_slot_commit(Efl_Ui_Exact_Model_Data *root, unsigned char found)
 {
    unsigned int block = root->slot[found].start_offset;
+   Eina_Bool ok = EINA_TRUE;
 
-   if (!root->slot[found].defined) return;
+   if (!root->slot[found].defined) return EINA_TRUE;
 
    // (a slot that was only read has nothing to commit)
    if (root->slot[found].width &&
        root->slot[found].decompressed.width &&
        root->slot[found].dirty.width)
-     root->compressed.width =
-       _efl_ui_exact_model_slot_compress(block, root->compressed.width,
-                                         root->slot[found].width);
-   if (root->slot[found].height &&
+     ok = _efl_ui_exact_model_block_store(&root->compressed.width,
+                                          eina_list_nth_list(root->compressed.width, block),
+                                          block, root->slot[found].width);
+   if (ok &&
+       root->slot[found].height &&
        root->slot[found].decompressed.height &&
        root->slot[found].dirty.height)
-     root->compressed.height =
-       _efl_ui_exact_model_slot_compress(block, root->compressed.height,
-                                         root->slot[found].height);
+     ok = _efl_ui_exact_model_block_store(&root->compressed.height,
+                                          eina_list_nth_list(root->compressed.height, block),
+                                          block, root->slot[found].height);
    root->slot[found].decompressed.width = EINA_FALSE;
    root->slot[found].decompressed.height = EINA_FALSE;
    root->slot[found].dirty.width = EINA_FALSE;
    root->slot[found].dirty.height = EINA_FALSE;
+   if (!ok) _efl_ui_exact_model_forget(root);
+   return ok;
 }
 
 static unsigned char
@@ -299,6 +324,7 @@ _efl_ui_exact_model_slot_find(Efl_Ui_Exact_Model_Data *root, unsigned int index,
                found = lookup;
           }
 
+        // (a failed commit forgets everything, which leaves this slot empty too)
         _efl_ui_exact_model_slot_commit(root, found);
 
         root->slot[found].defined = EINA_TRUE;
@@ -350,6 +376,7 @@ _efl_ui_exact_model_block_store(Eina_List **compressed, Eina_List *l,
         return eina_list_count(*compressed) > count;
      }
 
+   if (_efl_ui_exact_model_store_failed()) return EINA_FALSE;
    tbuf = eina_binbuf_manage_new((unsigned char *) buffer,
                                  EFL_UI_EXACT_MODEL_CONTENT_LENGTH, EINA_TRUE);
    if (!tbuf) return EINA_FALSE;
@@ -520,6 +547,8 @@ _efl_ui_exact_model_width_max(Eina_List *compressed)
 static void
 _efl_ui_exact_model_forget(Efl_Ui_Exact_Model_Data *root)
 {
+   unsigned char i;
+
    ERR("Could not store the sizes of the rows while moving them: they are all forgotten.");
    _efl_ui_exact_model_compressed_free(root->compressed.width);
    _efl_ui_exact_model_compressed_free(root->compressed.height);
@@ -528,6 +557,16 @@ _efl_ui_exact_model_forget(Efl_Ui_Exact_Model_Data *root)
    root->total_size.width = 0;
    root->total_size.height = 0;
    root->forgotten++;
+   // What the slots hold is not what the rows were told any more either
+   for (i = 0; i < EINA_C_ARRAY_LENGTH(root->slot); i++)
+     {
+        root->slot[i].defined = EINA_FALSE;
+        root->slot[i].usage = 0;
+        root->slot[i].decompressed.width = EINA_FALSE;
+        root->slot[i].decompressed.height = EINA_FALSE;
+        root->slot[i].dirty.width = EINA_FALSE;
+        root->slot[i].dirty.height = EINA_FALSE;
+     }
 }
 
 // The sizes follow their rows when one comes or goes. The sizes are kept by
@@ -540,7 +579,12 @@ _efl_ui_exact_model_shift(Efl_Ui_Exact_Model_Data *root, unsigned int index, Ein
    // What is kept expanded in the slots has to be in the list to be moved
    for (i = 0; i < EINA_C_ARRAY_LENGTH(root->slot); i++)
      {
-        _efl_ui_exact_model_slot_commit(root, i);
+        // (a slot that could not be written is lost, and so is everything else)
+        if (!_efl_ui_exact_model_slot_commit(root, i))
+          {
+             root->removed.measured = EINA_FALSE;
+             return;
+          }
         root->slot[i].defined = EINA_FALSE;
         root->slot[i].usage = 0;
      }
diff --git a/src/tests/elementary/efl_ui_model.c b/src/tests/elementary/efl_ui_model.c
index 100bd731bb..2b3bcc3e25 100644
--- a/src/tests/elementary/efl_ui_model.c
+++ b/src/tests/elementary/efl_ui_model.c
@@ -659,7 +659,7 @@ EFL_START_TEST(efl_ui_average_model_remove)
    ck_assert(!!model);
    eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
    eina_future_then(efl_model_children_slice_get(base_model, 0, 4), _many_rows_then, base_rows, NULL);
-   for (loops = 0; (loops < 50) && (many->count < 4 || base_rows->count < 4); loops++)
+   for (loops = 0; (loops < 50) && ((many->count < 4) || (base_rows->count < 4)); loops++)
      {
         ecore_main_loop_iterate();
      }
@@ -772,7 +772,7 @@ EFL_START_TEST(efl_ui_average_model_remove_pending)
    ck_assert(!!model);
    eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
    eina_future_then(efl_model_children_slice_get(base_model, 0, 4), _many_rows_then, base_rows, NULL);
-   for (loops = 0; (loops < 50) && (many->count < 4 || base_rows->count < 4); loops++)
+   for (loops = 0; (loops < 50) && ((many->count < 4) || (base_rows->count < 4)); loops++)
      {
         ecore_main_loop_iterate();
      }
@@ -1094,6 +1094,99 @@ EFL_START_TEST(efl_ui_exact_model_remove_widest)
 }
 EFL_END_TEST
 
+// What cannot be stored when the sizes move is lost, and no row is then
+// said to have a size that is not its own: every size is forgotten, and the
+// totals with them.
+EFL_START_TEST(efl_ui_exact_model_shift_store_fails)
+{
+   Shift_Rows *sr = _shift_new(1100);
+   Eo *r;
+
+   _shift_height(sr, 5, 10);
+   _shift_height(sr, 1030, 20);
+   _uint_set(sr->cur[5], "self.width", 7);
+   ck_assert_uint_eq(_property_uint_expected(sr->model, "total.width"), 7);
+
+   setenv("EFL_UI_EXACT_MODEL_STORE_FAIL", "1", 1);
+   _shift_remove(sr, 3);
+   unsetenv("EFL_UI_EXACT_MODEL_STORE_FAIL");
+   memset(sr->exp, 0, sr->n * sizeof (unsigned int));
+   _shift_check(sr);
+   ck_assert_uint_eq(_property_uint_expected(sr->model, "total.width"), 0);
+
+   // The model goes on from what it has: what is told now is kept
+   r = sr->cur[1030];
+   _shift_height(sr, 1030, 33);
+   _shift_check(sr);
+   ck_assert_uint_eq(efl_composite_model_index_get(r), 1030);
+   _shift_remove(sr, 3);
+   _shift_check(sr);
+   _shift_free(sr);
+}
+EFL_END_TEST
+
+// The average over what was told is over nothing when the sizes were forgotten.
+EFL_START_TEST(efl_ui_average_model_forgotten)
+{
+   Efl_Model *base_model, *model;
+   Many_Rows *many = calloc(1, sizeof (Many_Rows));
+   Many_Rows *base_rows = calloc(1, sizeof (Many_Rows));
+   unsigned int i, loops;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < 4; i++)
+     {
+        efl_model_child_add(base_model);
+     }
+   model = efl_add_ref(EFL_UI_AVERAGE_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   ck_assert(!!model);
+   eina_future_then(efl_model_children_slice_get(model, 0, 4), _many_rows_then, many, NULL);
+   eina_future_then(efl_model_children_slice_get(base_model, 0, 4), _many_rows_then, base_rows, NULL);
+   for (loops = 0; (loops < 50) && ((many->count < 4) || (base_rows->count < 4)); loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(many->count, 4);
+
+   for (i = 0; i < 3; i++)
+     {
+        _uint_set(many->rows[i], "self.height", 10 * (i + 1));
+     }
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   // 60 over 3 seen rows, for 4 rows
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 80);
+
+   // The last row leaves, and the sizes cannot be moved
+   setenv("EFL_UI_EXACT_MODEL_STORE_FAIL", "1", 1);
+   efl_model_child_del(base_model, base_rows->rows[3]);
+   unsetenv("EFL_UI_EXACT_MODEL_STORE_FAIL");
+   ck_assert_int_eq(_property_error_expected(many->rows[0], "self.height"), EAGAIN);
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 0);
+
+   // What is told after is what the average is over
+   _uint_set(many->rows[0], "self.height", 50);
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 150);
+
+   for (i = 0; i < 4; i++)
+     {
+        efl_unref(many->rows[i]);
+        efl_unref(base_rows->rows[i]);
+     }
+   free(many);
+   free(base_rows);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 // Blocks that are all measured: what falls out of the last block as the rows
 // move is a size too, and has a block of its own.
 EFL_START_TEST(efl_ui_exact_model_shift_overflow)
@@ -1173,6 +1266,62 @@ EFL_START_TEST(efl_ui_exact_model_destroyed)
 }
 EFL_END_TEST
 
+// A row is told its height when its block has no slot, and the slot that is
+// given up cannot be stored: every size is forgotten, and the row is the one
+// that is measured after that. The average is over that row alone.
+EFL_START_TEST(efl_ui_average_model_forgotten_in_set)
+{
+   Efl_Model *base_model, *model;
+   Many_Rows *many = calloc(1, sizeof (Many_Rows));
+   unsigned int i, loops;
+
+   base_model = efl_add_ref(EFL_GENERIC_MODEL_CLASS, efl_main_loop_get());
+   for (i = 0; i < MANY_ROWS; i++)
+     {
+        efl_model_child_add(base_model);
+     }
+   model = efl_add_ref(EFL_UI_AVERAGE_MODEL_CLASS, efl_main_loop_get(),
+                       efl_ui_view_model_set(efl_added, base_model));
+   ck_assert(!!model);
+   eina_future_then(efl_model_children_slice_get(model, 0, MANY_ROWS), _many_rows_then, many, NULL);
+   for (loops = 0; (loops < 50) && many->count < MANY_ROWS; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(many->count, MANY_ROWS);
+
+   // The three slots hold a block each, written to
+   for (i = 0; i < 3; i++)
+     {
+        _uint_set(many->rows[i * 1024], "self.height", 10 * (i + 1));
+     }
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 20 * MANY_ROWS);
+
+   setenv("EFL_UI_EXACT_MODEL_STORE_FAIL", "1", 1);
+   _uint_set(many->rows[3072], "self.height", 40);
+   unsetenv("EFL_UI_EXACT_MODEL_STORE_FAIL");
+   for (loops = 0; loops < 8; loops++)
+     {
+        ecore_main_loop_iterate();
+     }
+   ck_assert_int_eq(_property_error_expected(many->rows[0], "self.height"), EAGAIN);
+   ck_assert_uint_eq(_property_uint_expected(many->rows[3072], "self.height"), 40);
+   ck_assert_uint_eq(_property_uint_expected(model, "total.height"), 40 * MANY_ROWS);
+
+   for (i = 0; i < MANY_ROWS; i++)
+     {
+        efl_unref(many->rows[i]);
+     }
+   free(many);
+   efl_unref(model);
+   efl_unref(base_model);
+}
+EFL_END_TEST
+
 void
 efl_ui_model(TCase *tc)
 {
@@ -1192,6 +1341,9 @@ efl_ui_model(TCase *tc)
    tcase_add_test(tc, efl_ui_exact_model_removed_row_write);
    tcase_add_test(tc, efl_ui_exact_model_shift_unmeasured);
    tcase_add_test(tc, efl_ui_exact_model_shift_overflow);
+   tcase_add_test(tc, efl_ui_exact_model_shift_store_fails);
+   tcase_add_test(tc, efl_ui_average_model_forgotten);
    tcase_add_test(tc, efl_ui_exact_model_remove_widest);
    tcase_add_test(tc, efl_ui_exact_model_destroyed);
+   tcase_add_test(tc, efl_ui_average_model_forgotten_in_set);
 }

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

Reply via email to