adjust runtime page size APIs

* fix merge conflicts
* rename the declarations
* reword documentation
* extract FixedBufferAllocator to separate file
* take advantage of locals
* remove the assertion about max alignment in Allocator API, leaving it
  Allocator implementation defined
* fix non-inline function call in start logic

The GeneralPurposeAllocator implementation is totally broken because it
uses global state but I didn't address that in this commit.
This commit is contained in:
Andrew Kelley
2025-01-29 14:16:25 -08:00
parent 439667be04
commit 284de7d957
23 changed files with 723 additions and 718 deletions

View File

@@ -2,7 +2,6 @@ const builtin = @import("builtin");
const std = @import("std.zig");
const math = std.math;
const mem = std.mem;
const heap = std.heap;
const io = std.io;
const posix = std.posix;
const fs = std.fs;
@@ -1238,7 +1237,7 @@ test printLineFromFileAnyOs {
const overlap = 10;
var writer = file.writer();
try writer.writeByteNTimes('a', heap.min_page_size - overlap);
try writer.writeByteNTimes('a', std.heap.page_size_min - overlap);
try writer.writeByte('\n');
try writer.writeByteNTimes('a', overlap);
@@ -1253,10 +1252,10 @@ test printLineFromFileAnyOs {
defer allocator.free(path);
var writer = file.writer();
try writer.writeByteNTimes('a', heap.max_page_size);
try writer.writeByteNTimes('a', std.heap.page_size_max);
try printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 1, .column = 0 });
try expectEqualStrings(("a" ** heap.max_page_size) ++ "\n", output.items);
try expectEqualStrings(("a" ** std.heap.page_size_max) ++ "\n", output.items);
output.clearRetainingCapacity();
}
{
@@ -1266,18 +1265,18 @@ test printLineFromFileAnyOs {
defer allocator.free(path);
var writer = file.writer();
try writer.writeByteNTimes('a', 3 * heap.max_page_size);
try writer.writeByteNTimes('a', 3 * std.heap.page_size_max);
try expectError(error.EndOfFile, printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 2, .column = 0 }));
try printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 1, .column = 0 });
try expectEqualStrings(("a" ** (3 * heap.max_page_size)) ++ "\n", output.items);
try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "\n", output.items);
output.clearRetainingCapacity();
try writer.writeAll("a\na");
try printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 1, .column = 0 });
try expectEqualStrings(("a" ** (3 * heap.max_page_size)) ++ "a\n", output.items);
try expectEqualStrings(("a" ** (3 * std.heap.page_size_max)) ++ "a\n", output.items);
output.clearRetainingCapacity();
try printLineFromFileAnyOs(output_stream, .{ .file_name = path, .line = 2, .column = 0 });
@@ -1291,7 +1290,7 @@ test printLineFromFileAnyOs {
defer allocator.free(path);
var writer = file.writer();
const real_file_start = 3 * heap.min_page_size;
const real_file_start = 3 * std.heap.page_size_min;
try writer.writeByteNTimes('\n', real_file_start);
try writer.writeAll("abc\ndef");