diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-23 17:10:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-23 17:10:58 -0300 |
| commit | 0073d05329335dbb0eb85f5c3044e42805d144e5 (patch) | |
| tree | 744edfc317719b2018b1c3a8657c223aec058d47 /src/ninep/addr.zig | |
| parent | a8b457a306a4442975210bcac3f04b56513c61c3 (diff) | |
| download | pardes-0073d05329335dbb0eb85f5c3044e42805d144e5.tar.gz pardes-0073d05329335dbb0eb85f5c3044e42805d144e5.zip | |
Callstack lists every caller and pages a tree too big for one query; memory bounds and resident-size fixes
Callstack walks while the server answers, counts on the message row past a
second, puts test callers last at each level, and ends a tree past one
query's memory (memory.limits.arena.lsp_query, a 256 MiB region taken and
given back per query) in a row whose Callstack shows the next page. Grep
reads whole files. New hard limits: undo text per file, image decode
pixels, the LSP snapshot of other open files, one paste. Safe builds no
longer fill worst-case buffers with 0xAA (memory.unfilled), big regions are
kept off transparent huge pages, and malloc_trim runs after big results.
Also: Look's git show pages into a +Diff, and dropped marks in File.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/ninep/addr.zig')
| -rw-r--r-- | src/ninep/addr.zig | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/ninep/addr.zig b/src/ninep/addr.zig index 86d2d49e..7753c94d 100644 --- a/src/ninep/addr.zig +++ b/src/ninep/addr.zig @@ -239,21 +239,15 @@ pub const Addr = struct { k = @intFromBool(a.text[p] == '\n'); p += 1; } - while (k < n) { - if (p >= nc) { + if (k < n) { + p = nthLineAfter(a.text, p, n - k) orelse { a.err = e_range; return null; - } - if (a.text[p] == '\n') k += 1; - p += 1; + }; } p1 = p; } - while (p < nc) { - const ch = a.text[p]; - p += 1; - if (ch == '\n') break; - } + p = if (std.mem.indexOfScalarPos(u8, a.text, p, '\n')) |nl| nl + 1 else nc; return .{ .q0 = clip(p1), .q1 = clip(p) }; } @@ -678,3 +672,31 @@ test "a line just past the last newline is an empty one there, as sam's lineaddr try testing.expectEqual(Status.ok, th.wr(p, Node.of(th.serialOf(p), .ctl), "Edit 1i/header/\n").reply.status); try testing.expectEqualStrings("header", p.panes[0].?.file.?.content); } + +/// Just past the `count`-th newline at or after `from`; null if the text has +/// fewer. Counted a block at a time (modal.lineStartOffset), where a byte at +/// a time made `echo 7000 > addr` walk every byte above line 7000. +fn nthLineAfter(text: []const u8, from: usize, count: usize) ?usize { + return from + (modal.lineStartExact(text[from..], count) orelse return null); +} + +test "nthLineAfter finds what a byte at a time finds" { + var prng: std.Random.DefaultPrng = .init(0x51ab); + const random = prng.random(); + var buf: [200]u8 = undefined; + for (0..3000) |_| { + const len = random.uintLessThan(usize, buf.len); + for (buf[0..len]) |*b| b.* = if (random.uintLessThan(u8, 3) == 0) '\n' else 'x'; + const text = buf[0..len]; + const from = random.uintLessThan(usize, len + 1); + const count = 1 + random.uintLessThan(usize, 40); + var p = from; + var k: usize = 0; + const want: ?usize = while (k < count) { + if (p >= text.len) break null; + if (text[p] == '\n') k += 1; + p += 1; + } else p; + try std.testing.expectEqual(want, nthLineAfter(text, from, count)); + } +} |
