Skip to content

Commit 1c56e99

Browse files
committed
std: don't return sentinel slices from cross_target functions
1 parent edb47c9 commit 1c56e99

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

lib/std/target.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,15 +967,15 @@ pub const Target = struct {
967967

968968
pub const stack_align = 16;
969969

970-
pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 {
970+
pub fn zigTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
971971
return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator);
972972
}
973973

974-
pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![:0]u8 {
975-
return std.fmt.allocPrint0(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
974+
pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {
975+
return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
976976
}
977977

978-
pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 {
978+
pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
979979
return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
980980
}
981981

lib/std/zig/cross_target.zig

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -495,16 +495,18 @@ pub const CrossTarget = struct {
495495
return self.isNativeCpu() and self.isNativeOs() and self.abi == null;
496496
}
497497

498-
pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![:0]u8 {
498+
pub fn zigTriple(self: CrossTarget, allocator: *mem.Allocator) error{OutOfMemory}![]u8 {
499499
if (self.isNative()) {
500-
return mem.dupeZ(allocator, u8, "native");
500+
return mem.dupe(allocator, u8, "native");
501501
}
502502

503503
const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
504504
const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";
505505

506-
var result = try std.Buffer.allocPrint(allocator, "{}-{}", .{ arch_name, os_name });
507-
defer result.deinit();
506+
var result = std.ArrayList(u8).init(allocator);
507+
errdefer result.deinit();
508+
509+
try result.outStream().print("{}-{}", .{ arch_name, os_name });
508510

509511
// The zig target syntax does not allow specifying a max os version with no min, so
510512
// if either are present, we need the min.
@@ -532,13 +534,13 @@ pub const CrossTarget = struct {
532534
return result.toOwnedSlice();
533535
}
534536

535-
pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {
537+
pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
536538
// TODO is there anything else worthy of the description that is not
537539
// already captured in the triple?
538540
return self.zigTriple(allocator);
539541
}
540542

541-
pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {
543+
pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
542544
return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
543545
}
544546

@@ -549,7 +551,7 @@ pub const CrossTarget = struct {
549551
pub const VcpkgLinkage = std.builtin.LinkMode;
550552

551553
/// Returned slice must be freed by the caller.
552-
pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![:0]u8 {
554+
pub fn vcpkgTriplet(self: CrossTarget, allocator: *mem.Allocator, linkage: VcpkgLinkage) ![]u8 {
553555
const arch = switch (self.getCpuArch()) {
554556
.i386 => "x86",
555557
.x86_64 => "x64",
@@ -580,7 +582,7 @@ pub const CrossTarget = struct {
580582
.Dynamic => "",
581583
};
582584

583-
return std.fmt.allocPrint0(allocator, "{}-{}{}", .{ arch, os, static_suffix });
585+
return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix });
584586
}
585587

586588
pub const Executor = union(enum) {

0 commit comments

Comments
 (0)