authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2020-03-07 15:25:48+11:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-04-01 10:36:38-04:00
logbb5383cf00b3a518f9101f1503681aff510cdcbb
tree658044ebecf53c991bb95c1b977eb621201efc83
parent0ee2462a3116020013f8c55e830182df0fa369f2
signaturelock-open Commit is signed but in an unrecognized format.

std: don't return sentinel slices from cross_target functions


2 files changed, 14 insertions(+), 12 deletions(-)

lib/std/target.zig+4-4
...@@ -967,15 +967,15 @@ pub const Target = struct {...@@ -967,15 +967,15 @@ pub const Target = struct {
967967
968 pub const stack_align = 16;968 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 {
971 return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator);971 return std.zig.CrossTarget.fromTarget(self).zigTriple(allocator);
972 }972 }
973973
974 pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![:0]u8 {974 pub fn linuxTripleSimple(allocator: *mem.Allocator, cpu_arch: Cpu.Arch, os_tag: Os.Tag, abi: Abi) ![]u8 {
975 return std.fmt.allocPrint0(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });975 return std.fmt.allocPrint(allocator, "{}-{}-{}", .{ @tagName(cpu_arch), @tagName(os_tag), @tagName(abi) });
976 }976 }
977977
978 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![:0]u8 {978 pub fn linuxTriple(self: Target, allocator: *mem.Allocator) ![]u8 {
979 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);979 return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
980 }980 }
981981
lib/std/zig/cross_target.zig+10-8
...@@ -495,16 +495,18 @@ pub const CrossTarget = struct {...@@ -495,16 +495,18 @@ pub const CrossTarget = struct {
495 return self.isNativeCpu() and self.isNativeOs() and self.abi == null;495 return self.isNativeCpu() and self.isNativeOs() and self.abi == null;
496 }496 }
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 {
499 if (self.isNative()) {499 if (self.isNative()) {
500 return mem.dupeZ(allocator, u8, "native");500 return mem.dupe(allocator, u8, "native");
501 }501 }
502502
503 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";503 const arch_name = if (self.cpu_arch) |arch| @tagName(arch) else "native";
504 const os_name = if (self.os_tag) |os_tag| @tagName(os_tag) else "native";504 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 });506 var result = std.ArrayList(u8).init(allocator);
507 defer result.deinit();507 errdefer result.deinit();
508
509 try result.outStream().print("{}-{}", .{ arch_name, os_name });
508510
509 // The zig target syntax does not allow specifying a max os version with no min, so511 // The zig target syntax does not allow specifying a max os version with no min, so
510 // if either are present, we need the min.512 // if either are present, we need the min.
...@@ -532,13 +534,13 @@ pub const CrossTarget = struct {...@@ -532,13 +534,13 @@ pub const CrossTarget = struct {
532 return result.toOwnedSlice();534 return result.toOwnedSlice();
533 }535 }
534536
535 pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {537 pub fn allocDescription(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
536 // TODO is there anything else worthy of the description that is not538 // TODO is there anything else worthy of the description that is not
537 // already captured in the triple?539 // already captured in the triple?
538 return self.zigTriple(allocator);540 return self.zigTriple(allocator);
539 }541 }
540542
541 pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![:0]u8 {543 pub fn linuxTriple(self: CrossTarget, allocator: *mem.Allocator) ![]u8 {
542 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());544 return Target.linuxTripleSimple(allocator, self.getCpuArch(), self.getOsTag(), self.getAbi());
543 }545 }
544546
...@@ -549,7 +551,7 @@ pub const CrossTarget = struct {...@@ -549,7 +551,7 @@ pub const CrossTarget = struct {
549 pub const VcpkgLinkage = std.builtin.LinkMode;551 pub const VcpkgLinkage = std.builtin.LinkMode;
550552
551 /// Returned slice must be freed by the caller.553 /// 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 {
553 const arch = switch (self.getCpuArch()) {555 const arch = switch (self.getCpuArch()) {
554 .i386 => "x86",556 .i386 => "x86",
555 .x86_64 => "x64",557 .x86_64 => "x64",
...@@ -580,7 +582,7 @@ pub const CrossTarget = struct {...@@ -580,7 +582,7 @@ pub const CrossTarget = struct {
580 .Dynamic => "",582 .Dynamic => "",
581 };583 };
582584
583 return std.fmt.allocPrint0(allocator, "{}-{}{}", .{ arch, os, static_suffix });585 return std.fmt.allocPrint(allocator, "{}-{}{}", .{ arch, os, static_suffix });
584 }586 }
585587
586 pub const Executor = union(enum) {588 pub const Executor = union(enum) {