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

git pushed a commit to branch tymux-10-quiet-head
in repository terminology.

View the commit online.

commit b22825a37c3c67f97b78c156490df7ca6f227ecb
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 03:28:46 2026 -0600

    backlog_store: do not extend an entry past a failed append
    
    When a row could not be stored (no page for it, or no room to count
    its hyperlinks), the next row was still asked to continue the newest
    entry. That entry is the one before the lost row, so the line came out
    with a hole in it: the caller's join, or the wrapped bit of the entry
    before, still said "continue".
    
    A failed append now makes the next row start a new entry, whatever join
    it asked for. Any successful append or pop clears it: after a pop the
    caller picks which entry to continue. The tests make the store fail
    with backlog_store_test_fail_next_page() and
    backlog_store_test_fail_next_refs(), under BINARY_TYTEST only. termpty
    drops the row without touching its ring or beacon, which a new test
    pins.
    
    tybench cycles, one process per corpus, median of 3, before -> after:
    scroll 2866M -> 2890M (+0.8%), fill +0.6%, hyperlink -1.5%, long-lines
    -0.1%, plain-ascii -0.4% at scrollback 50; scroll +1.0%, fill +1.3%,
    hyperlink +1.0% at 2000. tybenchd -i 5 1000000: 20.0 -> 20.0 MB/s.
---
 src/bin/backlog_store.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++--
 src/bin/backlog_store.h |   7 ++
 src/bin/termpty.c       |  88 +++++++++++++++++++++++
 src/bin/tytest.c        |   2 +
 src/bin/unit_tests.h    |   2 +
 5 files changed, 279 insertions(+), 4 deletions(-)

diff --git a/src/bin/backlog_store.c b/src/bin/backlog_store.c
index a66266fe..38423868 100644
--- a/src/bin/backlog_store.c
+++ b/src/bin/backlog_store.c
@@ -170,6 +170,7 @@ struct tag_BacklogStore
    uint32_t            first_id;
    BacklogStoreGeometry geo;
    uint32_t            head_cells;
+   Eina_Bool           last_append_failed; /* the row after it starts an entry */
    uint64_t            total_entries;
    Eina_List          *jobs;
    Eina_List          *rebuilds;
@@ -480,6 +481,22 @@ _page_compressed_set(BacklogStorePage *page, Eina_Binbuf *blob)
    return EINA_TRUE;
 }
 
+#if defined(BINARY_TYTEST)
+static Eina_Bool _test_fail_page, _test_fail_refs;
+
+void
+backlog_store_test_fail_next_page(void)
+{
+   _test_fail_page = EINA_TRUE;
+}
+
+void
+backlog_store_test_fail_next_refs(void)
+{
+   _test_fail_refs = EINA_TRUE;
+}
+#endif
+
 /* The index of id in refs, or where it would go. */
 static uint32_t
 _refs_find(const BacklogStoreRefs *refs, uint16_t id)
@@ -508,6 +525,13 @@ _refs_add(BacklogStoreRefs *refs, uint16_t id, uint32_t count)
         refs->refs[idx].count += count;
         return EINA_TRUE;
      }
+#if defined(BINARY_TYTEST)
+   if (_test_fail_refs)
+     {
+        _test_fail_refs = EINA_FALSE;
+        return EINA_FALSE;
+     }
+#endif
    if (refs->count == refs->alloc)
      {
         uint32_t alloc = refs->alloc ? refs->alloc * 2 : 4;
@@ -725,6 +749,13 @@ _page_add(BacklogStore *bs)
      }
    else
      {
+#if defined(BINARY_TYTEST)
+        if (_test_fail_page)
+          {
+             _test_fail_page = EINA_FALSE;
+             return NULL;
+          }
+#endif
         page = _page_new(bs, page_id);
         if (!page)
           return NULL;
@@ -882,7 +913,9 @@ backlog_store_free(BacklogStore *bs)
 
 /* Clients follow the head through its atomics without a lock: the cells
  * are written before the width that covers them is published, and a new
- * entry's offset and width before num_entries counts it. */
+ * entry's offset and width before num_entries counts it. A row that fails
+ * is lost, so the one after it cannot continue the entry before it: it
+ * starts a new one. */
 Eina_Bool
 backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
                      BacklogStoreJoin join, Eina_Bool refs,
@@ -896,6 +929,8 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
    EINA_SAFETY_ON_NULL_RETURN_VAL(bs, EINA_FALSE);
    EINA_SAFETY_ON_TRUE_RETURN_VAL(w < 0 || (w > 0 && !cells), EINA_FALSE);
    first_id = bs->first_id;
+   if (bs->last_append_failed)
+     join = BACKLOG_STORE_NEW;
 
    if (bs->count)
      {
@@ -919,7 +954,7 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
         if (add > 0)
           {
              if (refs && !_page_refs_add(head_page, cells, add))
-               return EINA_FALSE;
+               goto failed;
              memcpy(_page_cells(head, bs->geo.header_size) + bs->head_cells,
                     cells, add * sizeof(Termcell));
              atomic_store_explicit(&_page_entry_w(bs, head)[n - 1],
@@ -935,14 +970,14 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
           {
              head = _page_add(bs);
              if (!head)
-               return EINA_FALSE;
+               goto failed;
              head_page = &bs->pages[bs->count - 1];
              n = 0;
              added = EINA_TRUE;
           }
         add = MIN((size_t)w, TERMSRV_BACKLOG_ENTRY_MAX_CELLS);
         if (refs && !_page_refs_add(head_page, cells, add))
-          return EINA_FALSE;
+          goto failed;
         if (add > 0)
           memcpy(_page_cells(head, bs->geo.header_size) + bs->head_cells,
                  cells, add * sizeof(Termcell));
@@ -976,7 +1011,12 @@ backlog_store_append(BacklogStore *bs, const Termcell *cells, ssize_t w,
         saved->added = add;
         saved->pages_changed = added || (first_id != bs->first_id);
      }
+   bs->last_append_failed = EINA_FALSE;
    return EINA_TRUE;
+
+failed:
+   bs->last_append_failed = EINA_TRUE;
+   return EINA_FALSE;
 }
 
 void
@@ -1791,6 +1831,7 @@ backlog_store_pop(BacklogStore *bs)
    head->widths[n] = 0;
    head->entries = n;
    bs->total_entries--;
+   bs->last_append_failed = EINA_FALSE;
    return EINA_TRUE;
 }
 
@@ -4469,4 +4510,139 @@ tytest_backlog_store_termpty(void)
    ecore_shutdown();
    return 0;
 }
+
+/* Test: a row the store could not take ends the entry it would have
+ * continued: the next row starts a new one, however it was asked to join,
+ * and the rows after it join again. */
+static void
+_test_append_fail(BacklogStoreBacking backing)
+{
+   Termcell row[TEST_ROW_W], *cells;
+   BacklogStore *bs;
+   uint32_t w, page_id = 0;
+   int mode;
+
+   for (mode = BACKLOG_STORE_EXTEND; mode <= BACKLOG_STORE_EXTEND_WRAPPED;
+        mode++)
+     {
+        bs = _test_store_new(backing, 4 * _TEST_ENTRIES);
+        _test_pages_fill(bs, 0, _TEST_ENTRIES);
+        assert(backlog_store_count(bs) == 1);
+
+        /* the page is full: the next entry needs a page, which fails */
+        _test_row_fill(row, TEST_ROW_W, 'A');
+        backlog_store_test_fail_next_page();
+        assert(!backlog_store_append(bs, row, TEST_ROW_W, BACKLOG_STORE_NEW,
+                                     EINA_TRUE, NULL));
+        assert(backlog_store_count(bs) == 1);
+
+        /* the entry before it wraps onto the row that was lost, not onto
+         * this one */
+        cells = backlog_store_newest_get(bs, &w, &page_id);
+        cells[w - 1].att.autowrapped = 1;
+        row[2].att.autowrapped = 1;
+        assert(backlog_store_append(bs, row, 3, mode, EINA_TRUE, NULL));
+        assert(backlog_store_count(bs) == 2);
+        assert(bs->pages[0].widths[_TEST_ENTRIES - 1] == TEST_ROW_W);
+        cells = backlog_store_newest_get(bs, &w, &page_id);
+        assert(w == 3 && page_id == 1 && cells[0].codepoint == 'A');
+        assert(bs->total_entries == _TEST_ENTRIES + 1);
+
+        /* only that one row: the next joins as asked */
+        assert(backlog_store_append(bs, row, 2, mode, EINA_TRUE, NULL));
+        cells = backlog_store_newest_get(bs, &w, &page_id);
+        assert(w == 5 && bs->total_entries == _TEST_ENTRIES + 1);
+        backlog_store_free(bs);
+     }
+
+   /* a pop forgets it: the entry that is the newest then is the one the
+    * caller chose to continue */
+   bs = _test_store_new(backing, 4 * _TEST_ENTRIES);
+   _test_pages_fill(bs, 0, _TEST_ENTRIES);
+   _test_row_fill(row, TEST_ROW_W, 'A');
+   backlog_store_test_fail_next_page();
+   assert(!backlog_store_append(bs, row, TEST_ROW_W, BACKLOG_STORE_NEW,
+                                EINA_TRUE, NULL));
+   assert(backlog_store_pop(bs));
+   assert(backlog_store_append(bs, row, 3, BACKLOG_STORE_EXTEND, EINA_TRUE,
+                               NULL));
+   cells = backlog_store_newest_get(bs, &w, &page_id);
+   assert(w == TEST_ROW_W + 3 && bs->total_entries == _TEST_ENTRIES - 1);
+   backlog_store_free(bs);
+
+   /* a pop that finds nothing to take changes nothing */
+   bs = _test_store_new(backing, 4 * _TEST_ENTRIES);
+   backlog_store_test_fail_next_page();
+   assert(!backlog_store_append(bs, row, TEST_ROW_W, BACKLOG_STORE_NEW,
+                                EINA_TRUE, NULL));
+   assert(!backlog_store_pop(bs));
+   assert(backlog_store_append(bs, row, 2, BACKLOG_STORE_NEW, EINA_TRUE,
+                               NULL));
+   assert(backlog_store_append(bs, row, 2, BACKLOG_STORE_EXTEND, EINA_TRUE,
+                               NULL));
+   assert(bs->total_entries == 1);
+   backlog_store_free(bs);
+}
+
+static void
+_test_append_links_row(Termcell *row, uint16_t first, uint16_t second)
+{
+   memset(row, 0, 4 * sizeof(*row));
+   row[0].codepoint = 'a';
+   row[0].att.link_id = 3;
+   row[1].codepoint = 'b';
+   row[1].att.link_id = first;
+   row[2].codepoint = 'c';
+   row[2].att.link_id = second;
+   row[3].codepoint = 'd';
+}
+
+/* Test: a row whose links the store could not count is lost whole, along
+ * with the links it had counted, and ends the entry it would have
+ * continued. */
+static void
+_test_append_fail_links(BacklogStoreBacking backing)
+{
+   Test_Links links = { { 0 }, 0, 0 };
+   BacklogStore *bs = _test_links_store_new(backing, 4 * _TEST_ENTRIES,
+                                            &links);
+   Termcell row[4];
+   uint32_t w, page_id;
+
+   _test_append_links_row(row, 5, 5);
+   assert(backlog_store_append(bs, row, 4, BACKLOG_STORE_NEW, EINA_TRUE,
+                               NULL));
+
+   /* in the entry that grows: 3 is counted, then 7 fails */
+   _test_append_links_row(row, 7, 7);
+   backlog_store_test_fail_next_refs();
+   assert(!backlog_store_append(bs, row, 4, BACKLOG_STORE_EXTEND, EINA_TRUE,
+                                NULL));
+   assert(backlog_store_append(bs, row, 4, BACKLOG_STORE_EXTEND, EINA_TRUE,
+                               NULL));
+   assert(backlog_store_newest_get(bs, &w, &page_id) && w == 4);
+   assert(bs->total_entries == 2);
+
+   /* in a new one */
+   _test_append_links_row(row, 9, 9);
+   backlog_store_test_fail_next_refs();
+   assert(!backlog_store_append(bs, row, 4, BACKLOG_STORE_NEW, EINA_TRUE,
+                                NULL));
+   assert(backlog_store_append(bs, row, 4, BACKLOG_STORE_EXTEND, EINA_TRUE,
+                               NULL));
+   assert(backlog_store_newest_get(bs, &w, &page_id) && w == 4);
+   assert(bs->total_entries == 3);
+
+   backlog_store_free(bs);
+   assert(links.total[3] == 3 && links.total[5] == 2 &&
+          links.total[7] == 2 && links.total[9] == 2);
+}
+
+int
+tytest_backlog_store_append_fail(void)
+{
+   _test_backings_run(_test_append_fail);
+   _test_backings_run(_test_append_fail_links);
+   return 0;
+}
 #endif
diff --git a/src/bin/backlog_store.h b/src/bin/backlog_store.h
index db23e493..c53e4d77 100644
--- a/src/bin/backlog_store.h
+++ b/src/bin/backlog_store.h
@@ -71,6 +71,13 @@ Eina_Bool backlog_store_append(BacklogStore *bs, const Termcell *cells,
                                ssize_t w, BacklogStoreJoin join,
                                Eina_Bool refs, BacklogStoreSaved *saved);
 
+#if defined(BINARY_TYTEST)
+/* Make the next page creation, or the next link or block id new to its
+ * page, fail, once. */
+void backlog_store_test_fail_next_page(void);
+void backlog_store_test_fail_next_refs(void);
+#endif
+
 /* The geometry the store keeps its pages in. */
 const BacklogStoreGeometry *backlog_store_geometry(const BacklogStore *bs);
 
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index d5a22c77..6f31fb0a 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -5427,6 +5427,94 @@ tytest_backlog_long_wrap(void)
    return 0;
 }
 
+#if defined(BINARY_TYTEST)
+/* Test: a row the store refuses is lost without a trace in the ring or
+ * the beacon, and the rows after it are saved as before, starting a new
+ * entry. */
+int
+tytest_backlog_append_fail(void)
+{
+   Termpty ty_storage, *ty = &ty_storage;
+   Term_Link *link;
+   Termcell cells[10];
+   uint32_t entries_per_page;
+   int j, length;
+   uint32_t i;
+
+   _ty_test_init(ty, 10, 5);
+   termpty_backlog_size_set(ty, 200);
+   entries_per_page = backlog_store_geometry(ty->backlog_store)->
+      entries_per_page;
+
+   memset(cells, 0, sizeof(cells));
+   for (j = 0; j < 10; j++)
+     cells[j].codepoint = 'a';
+   for (i = 0; i < entries_per_page; i++)
+     termpty_text_save_top(ty, cells, 10);
+   assert(backlog_store_count(ty->backlog_store) == 1);
+   termpty_backlog_follow(ty);
+   length = termpty_backlog_length(ty);
+
+   /* the next row needs a page, which fails: it is lost, and the ring
+    * and the beacon do not know it */
+   cells[9].att.autowrapped = 1;
+   backlog_store_test_fail_next_page();
+   termpty_text_save_top(ty, cells, 10);
+   cells[9].att.autowrapped = 0;
+   assert(backlog_store_count(ty->backlog_store) == 1);
+   termpty_backlog_follow(ty);
+   assert(termpty_backlog_length(ty) == length);
+   assert(BACKLOG_ROW_GET(ty, 1)->w == 10);
+   assert(BACKLOG_ROW_GET(ty, 1)->cells[0].codepoint == 'a');
+
+   /* the rows after it are saved as before */
+   for (j = 0; j < 10; j++)
+     cells[j].codepoint = 'z';
+   termpty_text_save_top(ty, cells, 10);
+   termpty_backlog_follow(ty);
+   assert(termpty_backlog_length(ty) == length + 1);
+   assert(BACKLOG_ROW_GET(ty, 1)->w == 10);
+   assert(BACKLOG_ROW_GET(ty, 1)->cells[0].codepoint == 'z');
+   assert(BACKLOG_ROW_GET(ty, 2)->w == 10);
+   assert(BACKLOG_ROW_GET(ty, 2)->cells[0].codepoint == 'a');
+
+   /* a row whose link cannot be counted is lost too, and the row after it
+    * does not continue the wrapped entry before it */
+   link = term_link_new(ty);
+   assert(link && ty->hl.size);
+   for (j = 0; j < 10; j++)
+     cells[j].codepoint = 'E';
+   cells[9].att.autowrapped = 1;
+   termpty_text_save_top(ty, cells, 10);
+   for (j = 0; j < 10; j++)
+     {
+        cells[j].codepoint = 'L';
+        cells[j].att.link_id = link - ty->hl.links;
+     }
+   backlog_store_test_fail_next_refs();
+   termpty_text_save_top(ty, cells, 10);
+   for (j = 0; j < 10; j++)
+     {
+        cells[j].codepoint = 'y';
+        cells[j].att.link_id = 0;
+     }
+   cells[9].att.autowrapped = 0;
+   termpty_text_save_top(ty, cells, 10);
+   termpty_backlog_follow(ty);
+   assert(termpty_backlog_length(ty) == length + 3);
+   assert(BACKLOG_ROW_GET(ty, 1)->w == 10);
+   assert(BACKLOG_ROW_GET(ty, 1)->cells[0].codepoint == 'y');
+   assert(BACKLOG_ROW_GET(ty, 2)->w == 10);
+   assert(BACKLOG_ROW_GET(ty, 2)->cells[0].codepoint == 'E');
+
+   term_link_free(ty, link);
+   term_link_table_drop_if_empty(ty);
+   _ty_test_shutdown(ty);
+   return 0;
+}
+
+#endif
+
 /* Test: termpty_write() calls the hook when one is set, instead of
  * queuing the data for the real pty fd, and falls through to the real
  * pty write buffer once the hook is cleared. */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 40b7b4d7..53d4ea22 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -38,6 +38,7 @@ static struct {
        { "dummy", tytest_dummy },
        { "write_hook", tytest_write_hook},
        { "backlog_long_wrap", tytest_backlog_long_wrap},
+       { "backlog_append_fail", tytest_backlog_append_fail},
        { "backlog_clear_ids", tytest_backlog_clear_ids},
        { "backlog_view_head_only", tytest_backlog_view_head_only},
        { "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
@@ -183,6 +184,7 @@ static struct {
        { "backlog_store_fd_budget", tytest_backlog_store_fd_budget},
        { "backlog_store_page_fd_async", tytest_backlog_store_page_fd_async},
        { "backlog_store_sealed", tytest_backlog_store_sealed},
+       { "backlog_store_append_fail", tytest_backlog_store_append_fail},
        { "backlog_view_sync", tytest_backlog_view_sync},
        { "backlog_view_ring_full", tytest_backlog_view_ring_full},
        { "backlog_view_map_again", tytest_backlog_view_map_again},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 97fa8a04..f09f9be5 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -8,6 +8,7 @@ typedef int (*tytest_func)(void);
 int tytest_dummy(void);
 int tytest_write_hook(void);
 int tytest_backlog_long_wrap(void);
+int tytest_backlog_append_fail(void);
 int tytest_backlog_clear_ids(void);
 int tytest_backlog_view_head_only(void);
 int tytest_backlog_wide_entry_rows(void);
@@ -138,6 +139,7 @@ int tytest_backlog_store_blocks(void);
 int tytest_backlog_store_fd_budget(void);
 int tytest_backlog_store_page_fd_async(void);
 int tytest_backlog_store_sealed(void);
+int tytest_backlog_store_append_fail(void);
 int tytest_backlog_view_sync(void);
 int tytest_backlog_view_ring_full(void);
 int tytest_backlog_view_map_again(void);

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

Reply via email to