terminal: more robust handling of max_page_size

not 100%
This commit is contained in:
Mitchell Hashimoto
2026-01-16 14:35:14 -08:00
parent 442a395850
commit df35363b15
2 changed files with 20 additions and 1 deletions

View File

@@ -414,6 +414,10 @@ fn initPages(
const pooled = layout.total_size <= std_size;
const page_alloc = pool.pages.arena.child_allocator;
// Guaranteed by comptime checks in initialCapacity but
// redundant here for safety.
assert(layout.total_size <= size.max_page_size);
var rem = rows;
while (rem > 0) {
const node = try pool.nodes.create();
@@ -2091,7 +2095,7 @@ fn resizeWithoutReflowGrowCols(
) catch |err| err: {
comptime assert(@TypeOf(err) == error{OutOfMemory});
// We verify all maxed out page layouts work.
// We verify all maxed out page layouts don't overflow,
var cap = page.capacity;
cap.cols = cols;
@@ -3017,6 +3021,14 @@ pub fn increaseCapacity(
return error.OutOfSpace;
};
@field(cap, field_name) = new;
// If our capacity exceeds the maximum page size, treat it
// as an OutOfSpace because things like page splitting will
// help.
const layout = Page.layout(cap);
if (layout.total_size > size.max_page_size) {
return error.OutOfSpace;
}
},
};
@@ -3091,6 +3103,11 @@ inline fn createPageExt(
const pooled = layout.total_size <= std_size;
const page_alloc = pool.pages.arena.child_allocator;
// It would be better to encode this into the Zig error handling
// system but that is a big undertaking and we only have a few
// centralized call sites so it is handled on its own currently.
assert(layout.total_size <= size.max_page_size);
// Our page buffer comes from our standard memory pool if it
// is within our standard size since this is what the pool
// dispenses. Otherwise, we use the heap allocator to allocate.

View File

@@ -2046,6 +2046,8 @@ test "Page.layout can take a maxed capacity" {
@field(cap, field.name) = std.math.maxInt(field.type);
}
// Note that a max capacity will exceed our max_page_size so we
// can't init a page with it, but it should layout.
_ = Page.layout(cap);
}