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 e4be5549222fae5e76b657476d4acb3452ddeb13
Author: Cedric BAIL <[email protected]>
AuthorDate: Fri Nov 20 01:11:40 2026 -0600
termpty: keep the page ids going when the scrollback is cleared
CSI 3 J and RIS free the store and make a new one, whose page ids start
again at 0. A reader that keeps pages by id, such as a client mapping
them, would take the new pages for the old ones.
The new store goes on from the id after the last page of the old one,
the head that pop parked included. A reader then sees every old page
evicted, as it would after a long output, and a late release of an old
page is an unknown id, which the store ignores.
---
src/bin/backlog.c | 22 ++++++++++++++---
src/bin/backlog_store.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/backlog_store.h | 7 ++++++
src/bin/termpty.c | 41 ++++++++++++++++++++++++++++++
src/bin/tytest.c | 2 ++
src/bin/unit_tests.h | 2 ++
6 files changed, 137 insertions(+), 3 deletions(-)
diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index a06f7fc1..0400c3f5 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -138,11 +138,19 @@ termpty_backlog_free(Termpty *ty)
_backlog_beacon_reset(ty);
}
+static void _backlog_size_set(Termpty *ty, size_t size, uint32_t first_id);
+
+/* The new store goes on from the ids of the old one: to a tymux client the
+ * old pages were evicted, and a late release of one of them is ignored. */
void
termpty_clear_backlog(Termpty *ty)
{
+ uint32_t next_id = 0;
+
+ if (ty->backlog_store)
+ next_id = backlog_store_next_id(ty->backlog_store);
termpty_backlog_free(ty);
- termpty_backlog_size_set(ty, ty->backlog_scrollback);
+ _backlog_size_set(ty, ty->backlog_scrollback, next_id);
}
ssize_t
@@ -257,8 +265,9 @@ _ring_view_new(Termpty *ty, size_t backsize)
return EINA_TRUE;
}
-void
-termpty_backlog_size_set(Termpty *ty, size_t size)
+/* A new store takes its page ids from first_id on. */
+static void
+_backlog_size_set(Termpty *ty, size_t size, uint32_t first_id)
{
const BacklogStoreGeometry *geo;
@@ -291,6 +300,7 @@ termpty_backlog_size_set(Termpty *ty, size_t size)
ERR("cannot create a backlog of %zu lines", size);
return;
}
+ backlog_store_first_id_set(ty->backlog_store, first_id);
backlog_store_link_release_cb_set(ty->backlog_store,
_store_link_release, ty);
backlog_store_block_release_cb_set(ty->backlog_store,
@@ -306,6 +316,12 @@ termpty_backlog_size_set(Termpty *ty, size_t size)
}
}
+void
+termpty_backlog_size_set(Termpty *ty, size_t size)
+{
+ _backlog_size_set(ty, size, 0);
+}
+
void
termpty_backlog_external_push(Termpty *ty, Termcell *cells, ssize_t w)
{
diff --git a/src/bin/backlog_store.c b/src/bin/backlog_store.c
index d1df44b4..327f50cc 100644
--- a/src/bin/backlog_store.c
+++ b/src/bin/backlog_store.c
@@ -904,6 +904,21 @@ backlog_store_count(const BacklogStore *bs)
return bs->count;
}
+uint32_t
+backlog_store_next_id(const BacklogStore *bs)
+{
+ EINA_SAFETY_ON_NULL_RETURN_VAL(bs, 0);
+ return bs->first_id + bs->count + bs->parked;
+}
+
+void
+backlog_store_first_id_set(BacklogStore *bs, uint32_t first_id)
+{
+ EINA_SAFETY_ON_NULL_RETURN(bs);
+ EINA_SAFETY_ON_TRUE_RETURN(bs->count || bs->parked || bs->detached);
+ bs->first_id = first_id;
+}
+
const BacklogStoreGeometry *
backlog_store_geometry(const BacklogStore *bs)
{
@@ -2962,6 +2977,57 @@ tytest_backlog_store_pop(void)
return 0;
}
+/* Test: a store that replaces another one goes on from its ids, a parked
+ * head's included, and the late releases of the old pages leave the holds
+ * on its own alone. */
+static void
+_test_next_id(BacklogStoreBacking backing)
+{
+ BacklogStore *old, *bs;
+ uint32_t next_id;
+
+ ecore_init();
+ old = backlog_store_new("test", backing, _TEST_SCROLLBACK);
+ assert(old);
+ assert(backlog_store_next_id(old) == 0);
+ _test_pages_fill(old, 0, _TEST_ENTRIES + 1);
+ backlog_store_hold(old, 0);
+ backlog_store_hold(old, 1);
+ assert(backlog_store_pop(old) && backlog_store_pop(old));
+ assert(backlog_store_count(old) == 1 && old->parked == 1);
+ next_id = backlog_store_next_id(old);
+ assert(next_id == 2);
+ backlog_store_free(old);
+
+ bs = backlog_store_new("test", backing, _TEST_SCROLLBACK);
+ assert(bs);
+ backlog_store_first_id_set(bs, next_id);
+ assert(backlog_store_first_id(bs) == next_id);
+ assert(backlog_store_count(bs) == 0);
+ _test_pages_fill(bs, 0, 1);
+ assert(backlog_store_first_id(bs) == next_id);
+ assert(backlog_store_count(bs) == 1);
+ assert(backlog_store_next_id(bs) == next_id + 1);
+ backlog_store_hold(bs, next_id);
+ backlog_store_release(bs, 0);
+ backlog_store_release(bs, 1);
+ backlog_store_release(bs, 1);
+ assert(_page_find(bs, next_id)->refs == 1);
+ assert(!backlog_store_page_exists(bs, 0));
+ assert(!backlog_store_page_exists(bs, 1));
+ backlog_store_release(bs, next_id);
+ assert(_page_find(bs, next_id)->refs == 0);
+ backlog_store_free(bs);
+ ecore_shutdown();
+}
+
+int
+tytest_backlog_store_next_id(void)
+{
+ _test_backings_run(_test_next_id);
+ return 0;
+}
+
typedef struct
{
uint32_t total[16];
diff --git a/src/bin/backlog_store.h b/src/bin/backlog_store.h
index 3282ac00..c279901f 100644
--- a/src/bin/backlog_store.h
+++ b/src/bin/backlog_store.h
@@ -132,6 +132,13 @@ void backlog_store_block_release_cb_set(BacklogStore *bs,
uint32_t backlog_store_first_id(const BacklogStore *bs);
uint32_t backlog_store_count(const BacklogStore *bs);
+/* The id after every page the store ever made, those that pop parked
+ * included: give it to backlog_store_first_id_set() of the store that
+ * replaces this one, so that an id never means two pages to a client. */
+uint32_t backlog_store_next_id(const BacklogStore *bs);
+/* The id of the first page of a store that has made none yet. */
+void backlog_store_first_id_set(BacklogStore *bs, uint32_t first_id);
+
/* The memfd of page_id, owned by the store: send it, do not close it, and
* do not use it past the next call into the store, which may close it. A
* compressed page is rebuilt into a new memfd, named "ty-export-", and a
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 7c901e65..19790369 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -5954,6 +5954,47 @@ tytest_backlog_view_local_slide(void)
return 0;
}
+/* Test: clearing the scrollback, with CSI 3 J or RIS, makes a store that
+ * goes on from the ids of the old one, so that a tymux client sees the old
+ * pages as evicted rather than taking new pages for them. */
+int
+tytest_backlog_clear_ids(void)
+{
+ Termpty ty;
+ uint32_t next_id;
+
+ _ty_test_init(&ty, 80, 24);
+ termpty_backlog_size_set(&ty, 0);
+ termpty_backlog_size_set(&ty, 64);
+ _ty_padded_feed(&ty, 1, 200, 0);
+ assert(backlog_store_first_id(ty.backlog_store) > 0);
+ next_id = backlog_store_next_id(ty.backlog_store);
+
+ _ty_feed(&ty, "\033[3J");
+ /* the view synced with the new store as it is, not with its ids */
+ assert(ty.backlog_view->store_first_id == next_id);
+ assert(termpty_backlog_length(&ty) == 0);
+ assert(backlog_store_first_id(ty.backlog_store) == next_id);
+ assert(backlog_store_count(ty.backlog_store) == 0);
+ _ty_padded_feed(&ty, 300, 330, 0);
+ assert(backlog_store_first_id(ty.backlog_store) == next_id);
+ assert(_ty_backlog_number(&ty, 1) == 330 - 23);
+ _ty_backlog_pages_check(&ty);
+ _ty_backlog_rows_check(&ty);
+
+ next_id = backlog_store_next_id(ty.backlog_store);
+ _ty_feed(&ty, "\033c");
+ assert(ty.backlog_view->store_first_id == next_id);
+ assert(termpty_backlog_length(&ty) == 0);
+ assert(backlog_store_first_id(ty.backlog_store) == next_id);
+ _ty_padded_feed(&ty, 400, 430, 0);
+ assert(backlog_store_first_id(ty.backlog_store) == next_id);
+ assert(_ty_backlog_number(&ty, 1) == 430 - 23);
+ _ty_backlog_pages_check(&ty);
+ _ty_test_shutdown(&ty);
+ return 0;
+}
+
/* Test: a window that reaches compressed pages has them rebuilt on a
* thread, rather than on the next read. */
int
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index c45eaa0b..8629239b 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -40,6 +40,7 @@ static struct {
{ "backlog_hook", tytest_backlog_hook},
{ "backlog_hook_wrap_replay", tytest_backlog_hook_wrap_replay},
{ "backlog_hook_long_wrap", tytest_backlog_hook_long_wrap},
+ { "backlog_clear_ids", tytest_backlog_clear_ids},
{ "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
{ "backlog_external", tytest_backlog_external},
{ "backlog_store_termpty", tytest_backlog_store_termpty},
@@ -177,6 +178,7 @@ static struct {
{ "backlog_store_anon", tytest_backlog_store_anon},
{ "backlog_store_held_evict", tytest_backlog_store_held_evict},
{ "backlog_store_pop", tytest_backlog_store_pop},
+ { "backlog_store_next_id", tytest_backlog_store_next_id},
{ "backlog_store_links", tytest_backlog_store_links},
{ "backlog_store_blocks", tytest_backlog_store_blocks},
{ "backlog_view_sync", tytest_backlog_view_sync},
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index c13b9e3d..38ac37aa 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -10,6 +10,7 @@ int tytest_write_hook(void);
int tytest_backlog_hook(void);
int tytest_backlog_hook_wrap_replay(void);
int tytest_backlog_hook_long_wrap(void);
+int tytest_backlog_clear_ids(void);
int tytest_backlog_wide_entry_rows(void);
int tytest_backlog_external(void);
int tytest_backlog_store_termpty(void);
@@ -132,6 +133,7 @@ int tytest_backlog_store_compress_widths(void);
int tytest_backlog_store_anon(void);
int tytest_backlog_store_held_evict(void);
int tytest_backlog_store_pop(void);
+int tytest_backlog_store_next_id(void);
int tytest_backlog_store_links(void);
int tytest_backlog_store_blocks(void);
int tytest_backlog_view_sync(void);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.