From 2dfec13ef08e0b47f0d80d599fb8552438e9e37a Mon Sep 17 00:00:00 2001 From: MrDmitry Date: Sun, 21 Jan 2024 03:16:09 -0500 Subject: [PATCH 1/2] Fix last_index after variable substitution Iterative passes should start at the end of the previous substitution --- lib/std/Build/Step/ConfigHeader.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/Build/Step/ConfigHeader.zig b/lib/std/Build/Step/ConfigHeader.zig index 59b8f610a2..44d387f524 100644 --- a/lib/std/Build/Step/ConfigHeader.zig +++ b/lib/std/Build/Step/ConfigHeader.zig @@ -537,7 +537,7 @@ fn replace_variables( switch (value) { .boolean => |b| { const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, @intFromBool(b), endline }); - last_index = start_index + 1; + last_index = prefix_index + 1; allocator.free(content_buf); content_buf = buf; @@ -546,14 +546,14 @@ fn replace_variables( const buf = try std.fmt.allocPrint(allocator, "{s}{}{s}", .{ beginline, i, endline }); const isNegative = i < 0; const digits = (if (0 < i) std.math.log10(@abs(i)) else 0) + 1; - last_index = start_index + @intFromBool(isNegative) + digits + 1; + last_index = prefix_index + @intFromBool(isNegative) + digits; allocator.free(content_buf); content_buf = buf; }, .string, .ident => |x| { const buf = try std.fmt.allocPrint(allocator, "{s}{s}{s}", .{ beginline, x, endline }); - last_index = start_index + x.len + 1; + last_index = prefix_index + x.len; allocator.free(content_buf); content_buf = buf; @@ -561,7 +561,7 @@ fn replace_variables( else => { const buf = try std.fmt.allocPrint(allocator, "{s}{s}", .{ beginline, endline }); - last_index = start_index + 1; + last_index = prefix_index; allocator.free(content_buf); content_buf = buf; From e72f1d5ae70b78046c27d0b7fc12ee4b69380b2a Mon Sep 17 00:00:00 2001 From: MrDmitry Date: Sun, 21 Jan 2024 03:18:37 -0500 Subject: [PATCH 2/2] Extend test cases Add tests for: - packed neighboring variables - separated neighboring variables - mixed types of neighboring variables --- test/standalone/cmakedefine/config.h.cmake | 54 +++++++++++++++++++++- test/standalone/cmakedefine/expected.h | 54 +++++++++++++++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/test/standalone/cmakedefine/config.h.cmake b/test/standalone/cmakedefine/config.h.cmake index d6961653df..4f078970c7 100644 --- a/test/standalone/cmakedefine/config.h.cmake +++ b/test/standalone/cmakedefine/config.h.cmake @@ -49,12 +49,24 @@ // no substition // @noval@ +// no substition +// @noval@@noval@ + +// no substition +// @noval@.@noval@ + // 1 // @trueval@ // 0 // @falseval@ +// 10 +// @trueval@@falseval@ + +// 0.1 +// @falseval@.@trueval@ + // 0 // @zeroval@ @@ -64,21 +76,47 @@ // 10 // @tenval@ +// 01 +// @zeroval@@oneval@ + +// 0.10 +// @zeroval@.@tenval@ + // test // @stringval@ +// testtest +// @stringval@@stringval@ + +// test.test +// @stringval@.@stringval@ + +// test10 +// @noval@@stringval@@trueval@@zeroval@ // ${} substition -// removal +// no substition // ${noval} +// no substition +// ${noval}${noval} + +// no substition +// ${noval}.${noval} + // 1 // ${trueval} // 0 // ${falseval} +// 10 +// ${trueval}${falseval} + +// 0.1 +// ${falseval}.${trueval} + // 0 // ${zeroval} @@ -88,6 +126,20 @@ // 10 // ${tenval} +// 01 +// ${zeroval}${oneval} + +// 0.10 +// ${zeroval}.${tenval} + // test // ${stringval} +// testtest +// ${stringval}${stringval} + +// test.test +// ${stringval}.${stringval} + +// test10 +// ${noval}${stringval}${trueval}${zeroval} diff --git a/test/standalone/cmakedefine/expected.h b/test/standalone/cmakedefine/expected.h index d71f070678..580f0f11d8 100644 --- a/test/standalone/cmakedefine/expected.h +++ b/test/standalone/cmakedefine/expected.h @@ -49,12 +49,24 @@ // no substition // +// no substition +// + +// no substition +// . + // 1 // 1 // 0 // 0 +// 10 +// 10 + +// 0.1 +// 0.1 + // 0 // 0 @@ -64,21 +76,47 @@ // 10 // 10 +// 01 +// 01 + +// 0.10 +// 0.10 + // test // test +// testtest +// testtest + +// test.test +// test.test + +// test10 +// test10 // substition -// removal +// no substition // +// no substition +// + +// no substition +// . + // 1 // 1 // 0 // 0 +// 10 +// 10 + +// 0.1 +// 0.1 + // 0 // 0 @@ -88,6 +126,20 @@ // 10 // 10 +// 01 +// 01 + +// 0.10 +// 0.10 + // test // test +// testtest +// testtest + +// test.test +// test.test + +// test10 +// test10