From 5c133c5765f3c4e80d46c35c104edc23d883c60e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 19 May 2026 16:29:49 -0700 Subject: [PATCH] Configuration: fix deserialization of LengthPrefixedList don't assume only 1 field --- BRANCH_TODO | 3 ++- lib/std/Build/Configuration.zig | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/BRANCH_TODO b/BRANCH_TODO index 6c4920c58e8fb546acb2b3b92a216cdfbd621173..da43728d8dee952202828bc0edb58a3ccd76cac8 100644 --- a/BRANCH_TODO +++ b/BRANCH_TODO @@ -1,4 +1,4 @@ -* WriteFile step failing when making langref +* Run step getting wrong path_directory values * double check when targets get resolved (should be at configure time) * finish migrating the rest of the build steps * pass overridden pkg-dir to maker @@ -39,6 +39,7 @@ * WriteFiles: introduce Group * re-examine the use case of adding file paths to Options steps * extract the reusable Configure abstractions and reuse it for Zir etc +* add the ability to delete files to UpdateSourceFiles ## Already Filed Followup Issues * build system fmt step with check=false does not acquire a write lock on source files #35204 diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig index 5888aa8abff79acb414d20537168eff36b3a6d6c..612c3256bb4010ad2dc2458f470d85ff2bcfa86b 100644 --- a/lib/std/Build/Configuration.zig +++ b/lib/std/Build/Configuration.zig @@ -2545,8 +2545,10 @@ pub const Storage = enum { }; } - /// The field contains a u32 length followed by that many items, each - /// element bitcastable to u32. + /// The field contains a u32 length followed by that many items. Each + /// element needs well-defined memory layout but can otherwise be any + /// multiple of u32 length. The length is number of elements, not the + /// number of u32s. pub fn LengthPrefixedList(comptime ElemArg: type) type { return struct { slice: []const Elem, @@ -2759,19 +2761,21 @@ pub const Storage = enum { }, .extended => @compileError("TODO"), .length_prefixed_list => { + const n = @divExact(@sizeOf(Field.Elem), @sizeOf(u32)); const data_start = i.* + 1; - const len = buffer[data_start - 1]; - defer i.* = data_start + len; - return .{ .slice = @ptrCast(buffer[data_start..][0..len]) }; + const buf_len = buffer[data_start - 1] * n; + defer i.* = data_start + buf_len; + return .{ .slice = @ptrCast(buffer[data_start..][0..buf_len]) }; }, .flag_length_prefixed_list => { const flags = @field(container, @tagName(Field.flags)); const flag = @field(flags, @tagName(Field.flag)); if (!flag) return .{ .slice = &.{} }; + const n = @divExact(@sizeOf(Field.Elem), @sizeOf(u32)); const data_start = i.* + 1; - const len = buffer[data_start - 1]; - defer i.* = data_start + len; - return .{ .slice = @ptrCast(buffer[data_start..][0..len]) }; + const buf_len = buffer[data_start - 1] * n; + defer i.* = data_start + buf_len; + return .{ .slice = @ptrCast(buffer[data_start..][0..buf_len]) }; }, .flag_list => { const flags = @field(container, @tagName(Field.flags)); -- 2.54.0