authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 21:12:01-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-24 21:21:05-05:00
log15d415e10b81a66fa3b887fb2a0c20bbcd614d94
tree10a61530b2b3d335cb8239d269b42569b8e932d8
parent34b1ebefaab2e8f5c322bc96388bb4fefec31027
signaturelock-open Commit is signed but in an unrecognized format.

make std.mem.toSlice use null terminated pointers

and fix the fallout

17 files changed, 76 insertions(+), 75 deletions(-)

lib/std/buffer.zig+2-7
......@@ -72,11 +72,11 @@ pub const Buffer = struct {
7272 self.list.deinit();
7373 }
7474
75 pub fn toSlice(self: Buffer) []u8 {
75 pub fn toSlice(self: Buffer) [:0]u8 {
7676 return self.list.toSlice()[0..self.len()];
7777 }
7878
79 pub fn toSliceConst(self: Buffer) []const u8 {
79 pub fn toSliceConst(self: Buffer) [:0]const u8 {
8080 return self.list.toSliceConst()[0..self.len()];
8181 }
8282
......@@ -131,11 +131,6 @@ pub const Buffer = struct {
131131 try self.resize(m.len);
132132 mem.copy(u8, self.list.toSlice(), m);
133133 }
134
135 /// For passing to C functions.
136 pub fn ptr(self: Buffer) [*]u8 {
137 return self.list.items.ptr;
138 }
139134};
140135
141136test "simple Buffer" {
lib/std/c.zig+1-1
......@@ -110,7 +110,7 @@ pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int;
110110pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int;
111111pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int;
112112pub extern "c" fn rmdir(path: [*]const u8) c_int;
113pub extern "c" fn getenv(name: [*]const u8) ?[*]u8;
113pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8;
114114pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
115115pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
116116pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
lib/std/fs.zig+1-1
......@@ -533,7 +533,7 @@ pub const Dir = struct {
533533 const next_index = self.index + linux_entry.reclen();
534534 self.index = next_index;
535535
536 const name = mem.toSlice(u8, @ptrCast([*]u8, &linux_entry.d_name));
536 const name = mem.toSlice(u8, @ptrCast([*:0]u8, &linux_entry.d_name));
537537
538538 // skip . and .. entries
539539 if (mem.eql(u8, name, ".") or mem.eql(u8, name, "..")) {
lib/std/mem.zig+3-3
......@@ -356,17 +356,17 @@ pub fn eql(comptime T: type, a: []const T, b: []const T) bool {
356356 return true;
357357}
358358
359pub fn len(comptime T: type, ptr: [*]const T) usize {
359pub fn len(comptime T: type, ptr: [*:0]const T) usize {
360360 var count: usize = 0;
361361 while (ptr[count] != 0) : (count += 1) {}
362362 return count;
363363}
364364
365pub fn toSliceConst(comptime T: type, ptr: [*]const T) []const T {
365pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T {
366366 return ptr[0..len(T, ptr)];
367367}
368368
369pub fn toSlice(comptime T: type, ptr: [*]T) []T {
369pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T {
370370 return ptr[0..len(T, ptr)];
371371}
372372
lib/std/net.zig+2-2
......@@ -360,7 +360,7 @@ pub const Address = extern union {
360360 unreachable;
361361 }
362362
363 const path_len = std.mem.len(u8, &self.un.path);
363 const path_len = std.mem.len(u8, @ptrCast([*:0]const u8, &self.un.path));
364364 return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len);
365365 },
366366 else => unreachable,
......@@ -1271,7 +1271,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8)
12711271 var tmp: [256]u8 = undefined;
12721272 // Returns len of compressed name. strlen to get canon name.
12731273 _ = try os.dn_expand(packet, data, &tmp);
1274 const canon_name = mem.toSliceConst(u8, &tmp);
1274 const canon_name = mem.toSliceConst(u8, @ptrCast([*:0]const u8, &tmp));
12751275 if (isValidHostName(canon_name)) {
12761276 try ctx.canon.replaceContents(canon_name);
12771277 }
lib/std/os.zig+16-15
......@@ -66,12 +66,12 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) {
6666pub usingnamespace @import("os/bits.zig");
6767
6868/// See also `getenv`. Populated by startup code before main().
69pub var environ: [][*]u8 = undefined;
69pub var environ: [][*:0]u8 = undefined;
7070
7171/// Populated by startup code before main().
7272/// Not available on Windows. See `std.process.args`
7373/// for obtaining the process arguments.
74pub var argv: [][*]u8 = undefined;
74pub var argv: [][*:0]u8 = undefined;
7575
7676/// To obtain errno, call this function with the return value of the
7777/// system function call. For some systems this will obtain the value directly
......@@ -784,7 +784,7 @@ pub fn execveC(path: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]co
784784/// matching the syscall API on all targets. This removes the need for an allocator.
785785/// This function also uses the PATH environment variable to get the full path to the executable.
786786/// If `file` is an absolute path, this is the same as `execveC`.
787pub fn execvpeC(file: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) ExecveError {
787pub fn execvpeC(file: [*:0]const u8, child_argv: [*]const ?[*:0]const u8, envp: [*]const ?[*:0]const u8) ExecveError {
788788 const file_slice = mem.toSliceConst(u8, file);
789789 if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveC(file, child_argv, envp);
790790
......@@ -820,8 +820,8 @@ pub fn execvpe(
820820 argv_slice: []const []const u8,
821821 env_map: *const std.BufMap,
822822) (ExecveError || error{OutOfMemory}) {
823 const argv_buf = try allocator.alloc(?[*]u8, argv_slice.len + 1);
824 mem.set(?[*]u8, argv_buf, null);
823 const argv_buf = try allocator.alloc(?[*:0]u8, argv_slice.len + 1);
824 mem.set(?[*:0]u8, argv_buf, null);
825825 defer {
826826 for (argv_buf) |arg| {
827827 const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break;
......@@ -834,7 +834,8 @@ pub fn execvpe(
834834 @memcpy(arg_buf.ptr, arg.ptr, arg.len);
835835 arg_buf[arg.len] = 0;
836836
837 argv_buf[i] = arg_buf.ptr;
837 // TODO avoid @ptrCast using slice syntax with https://github.com/ziglang/zig/issues/3731
838 argv_buf[i] = @ptrCast([*:0]u8, arg_buf.ptr);
838839 }
839840 argv_buf[argv_slice.len] = null;
840841
......@@ -844,10 +845,10 @@ pub fn execvpe(
844845 return execvpeC(argv_buf.ptr[0].?, argv_buf.ptr, envp_buf.ptr);
845846}
846847
847pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*]u8 {
848pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*:0]u8 {
848849 const envp_count = env_map.count();
849 const envp_buf = try allocator.alloc(?[*]u8, envp_count + 1);
850 mem.set(?[*]u8, envp_buf, null);
850 const envp_buf = try allocator.alloc(?[*:0]u8, envp_count + 1);
851 mem.set(?[*:0]u8, envp_buf, null);
851852 errdefer freeNullDelimitedEnvMap(allocator, envp_buf);
852853 {
853854 var it = env_map.iterator();
......@@ -859,7 +860,8 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.
859860 @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len);
860861 env_buf[env_buf.len - 1] = 0;
861862
862 envp_buf[i] = env_buf.ptr;
863 // TODO avoid @ptrCast using slice syntax with https://github.com/ziglang/zig/issues/3731
864 envp_buf[i] = @ptrCast([*:0]u8, env_buf.ptr);
863865 }
864866 assert(i == envp_count);
865867 }
......@@ -867,7 +869,7 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.
867869 return envp_buf;
868870}
869871
870pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*]u8) void {
872pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) void {
871873 for (envp_buf) |env| {
872874 const env_buf = if (env) |ptr| ptr[0 .. mem.len(u8, ptr) + 1] else break;
873875 allocator.free(env_buf);
......@@ -896,8 +898,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
896898
897899/// Get an environment variable with a null-terminated name.
898900/// See also `getenv`.
899/// TODO https://github.com/ziglang/zig/issues/265
900pub fn getenvC(key: [*]const u8) ?[]const u8 {
901pub fn getenvC(key: [*:0]const u8) ?[]const u8 {
901902 if (builtin.link_libc) {
902903 const value = system.getenv(key) orelse return null;
903904 return mem.toSliceConst(u8, value);
......@@ -922,7 +923,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 {
922923 break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len));
923924 };
924925 switch (err) {
925 0 => return mem.toSlice(u8, out_buffer.ptr),
926 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)),
926927 EFAULT => unreachable,
927928 EINVAL => unreachable,
928929 ENOENT => return error.CurrentWorkingDirectoryUnlinked,
......@@ -2865,7 +2866,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 {
28652866 var uts: utsname = undefined;
28662867 switch (errno(system.uname(&uts))) {
28672868 0 => {
2868 const hostname = mem.toSlice(u8, &uts.nodename);
2869 const hostname = mem.toSlice(u8, @ptrCast([*:0]u8, &uts.nodename));
28692870 mem.copy(u8, name_buffer, hostname);
28702871 return name_buffer[0..hostname.len];
28712872 },
lib/std/os/linux/vdso.zig+4-2
......@@ -65,7 +65,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
6565 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue;
6666 if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue;
6767 if (0 == syms[i].st_shndx) continue;
68 if (!mem.eql(u8, name, mem.toSliceConst(u8, strings + syms[i].st_name))) continue;
68 const sym_name = @ptrCast([*:0]const u8, strings + syms[i].st_name);
69 if (!mem.eql(u8, name, mem.toSliceConst(u8, sym_name))) continue;
6970 if (maybe_versym) |versym| {
7071 if (!checkver(maybe_verdef.?, versym[i], vername, strings))
7172 continue;
......@@ -87,5 +88,6 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [
8788 def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next);
8889 }
8990 const aux = @intToPtr(*elf.Verdaux, @ptrToInt(def) + def.vd_aux);
90 return mem.eql(u8, vername, mem.toSliceConst(u8, strings + aux.vda_name));
91 const vda_name = @ptrCast([*:0]const u8, strings + aux.vda_name);
92 return mem.eql(u8, vername, mem.toSliceConst(u8, vda_name));
9193}
lib/std/special/start.zig+6-6
......@@ -123,12 +123,12 @@ fn posixCallMainAndExit() noreturn {
123123 @setAlignStack(16);
124124 }
125125 const argc = starting_stack_ptr[0];
126 const argv = @ptrCast([*][*]u8, starting_stack_ptr + 1);
126 const argv = @ptrCast([*][*:0]u8, starting_stack_ptr + 1);
127127
128 const envp_optional = @ptrCast([*]?[*]u8, argv + argc + 1);
128 const envp_optional = @ptrCast([*:null]?[*:0]u8, argv + argc + 1);
129129 var envp_count: usize = 0;
130130 while (envp_optional[envp_count]) |_| : (envp_count += 1) {}
131 const envp = @ptrCast([*][*]u8, envp_optional)[0..envp_count];
131 const envp = @ptrCast([*][*:0]u8, envp_optional)[0..envp_count];
132132
133133 if (builtin.os == .linux) {
134134 // Find the beginning of the auxiliary vector
......@@ -168,7 +168,7 @@ fn posixCallMainAndExit() noreturn {
168168 std.os.exit(@inlineCall(callMainWithArgs, argc, argv, envp));
169169}
170170
171fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
171fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
172172 std.os.argv = argv[0..argc];
173173 std.os.environ = envp;
174174
......@@ -177,10 +177,10 @@ fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 {
177177 return initEventLoopAndCallMain();
178178}
179179
180extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 {
180extern fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) i32 {
181181 var env_count: usize = 0;
182182 while (c_envp[env_count] != null) : (env_count += 1) {}
183 const envp = @ptrCast([*][*]u8, c_envp)[0..env_count];
183 const envp = @ptrCast([*][*:0]u8, c_envp)[0..env_count];
184184 return @inlineCall(callMainWithArgs, @intCast(usize, c_argc), c_argv, envp);
185185}
186186
src-self-hosted/clang.zig+3-3
......@@ -708,7 +708,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum {
708708};
709709
710710pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation;
711pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*]const u8;
711pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8;
712712pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;
713713pub extern fn ZigClangSourceManager_getSpellingColumnNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint;
714714pub extern fn ZigClangSourceManager_getCharacterData(self: ?*const struct_ZigClangSourceManager, SL: struct_ZigClangSourceLocation) [*c]const u8;
......@@ -746,7 +746,7 @@ pub extern fn ZigClangQualType_isRestrictQualified(self: struct_ZigClangQualType
746746pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass;
747747pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType;
748748pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool;
749pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*]const u8;
749pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*:0]const u8;
750750pub extern fn ZigClangStmt_getBeginLoc(self: *const struct_ZigClangStmt) struct_ZigClangSourceLocation;
751751pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) ZigClangStmtClass;
752752pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool;
......@@ -904,7 +904,7 @@ pub extern fn ZigClangLoadFromCommandLine(
904904) ?*ZigClangASTUnit;
905905
906906pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind;
907pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*]const u8;
907pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*:0]const u8;
908908
909909pub const ZigClangCompoundStmt_const_body_iterator = [*c]const *struct_ZigClangStmt;
910910
src-self-hosted/compilation.zig+3-3
......@@ -490,8 +490,8 @@ pub const Compilation = struct {
490490 // LLVM creates invalid binaries on Windows sometimes.
491491 // See https://github.com/ziglang/zig/issues/508
492492 // As a workaround we do not use target native features on Windows.
493 var target_specific_cpu_args: ?[*]u8 = null;
494 var target_specific_cpu_features: ?[*]u8 = null;
493 var target_specific_cpu_args: ?[*:0]u8 = null;
494 var target_specific_cpu_features: ?[*:0]u8 = null;
495495 defer llvm.DisposeMessage(target_specific_cpu_args);
496496 defer llvm.DisposeMessage(target_specific_cpu_features);
497497 if (target == Target.Native and !target.isWindows()) {
......@@ -501,7 +501,7 @@ pub const Compilation = struct {
501501
502502 comp.target_machine = llvm.CreateTargetMachine(
503503 comp.llvm_target,
504 comp.llvm_triple.ptr(),
504 comp.llvm_triple.toSliceConst(),
505505 target_specific_cpu_args orelse "",
506506 target_specific_cpu_features orelse "",
507507 opt_level,
src-self-hosted/llvm.zig+22-22
......@@ -83,16 +83,16 @@ pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext;
8383pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext;
8484
8585pub const AddGlobal = LLVMAddGlobal;
86extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*]const u8) ?*Value;
86extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*:0]const u8) ?*Value;
8787
8888pub const ConstStringInContext = LLVMConstStringInContext;
89extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value;
89extern fn LLVMConstStringInContext(C: *Context, Str: [*:0]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value;
9090
9191pub const ConstInt = LLVMConstInt;
9292extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value;
9393
9494pub const BuildLoad = LLVMBuildLoad;
95extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*]const u8) ?*Value;
95extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*:0]const u8) ?*Value;
9696
9797pub const ConstNull = LLVMConstNull;
9898extern fn LLVMConstNull(Ty: *Type) ?*Value;
......@@ -110,24 +110,24 @@ pub const CreateEnumAttribute = LLVMCreateEnumAttribute;
110110extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute;
111111
112112pub const AddFunction = LLVMAddFunction;
113extern fn LLVMAddFunction(M: *Module, Name: [*]const u8, FunctionTy: *Type) ?*Value;
113extern fn LLVMAddFunction(M: *Module, Name: [*:0]const u8, FunctionTy: *Type) ?*Value;
114114
115115pub const CreateCompileUnit = ZigLLVMCreateCompileUnit;
116116extern fn ZigLLVMCreateCompileUnit(
117117 dibuilder: *DIBuilder,
118118 lang: c_uint,
119119 difile: *DIFile,
120 producer: [*]const u8,
120 producer: [*:0]const u8,
121121 is_optimized: bool,
122 flags: [*]const u8,
122 flags: [*:0]const u8,
123123 runtime_version: c_uint,
124 split_name: [*]const u8,
124 split_name: [*:0]const u8,
125125 dwo_id: u64,
126126 emit_debug_info: bool,
127127) ?*DICompileUnit;
128128
129129pub const CreateFile = ZigLLVMCreateFile;
130extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*]const u8, directory: [*]const u8) ?*DIFile;
130extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*:0]const u8, directory: [*:0]const u8) ?*DIFile;
131131
132132pub const ArrayType = LLVMArrayType;
133133extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type;
......@@ -145,7 +145,7 @@ pub const IntTypeInContext = LLVMIntTypeInContext;
145145extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type;
146146
147147pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext;
148extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*]const u8, C: *Context) ?*Module;
148extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*:0]const u8, C: *Context) ?*Module;
149149
150150pub const VoidTypeInContext = LLVMVoidTypeInContext;
151151extern fn LLVMVoidTypeInContext(C: *Context) ?*Type;
......@@ -157,7 +157,7 @@ pub const ContextDispose = LLVMContextDispose;
157157extern fn LLVMContextDispose(C: *Context) void;
158158
159159pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData;
160extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*]u8;
160extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*:0]u8;
161161
162162pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout;
163163extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;
......@@ -165,9 +165,9 @@ extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData;
165165pub const CreateTargetMachine = ZigLLVMCreateTargetMachine;
166166extern fn ZigLLVMCreateTargetMachine(
167167 T: *Target,
168 Triple: [*]const u8,
169 CPU: [*]const u8,
170 Features: [*]const u8,
168 Triple: [*:0]const u8,
169 CPU: [*:0]const u8,
170 Features: [*:0]const u8,
171171 Level: CodeGenOptLevel,
172172 Reloc: RelocMode,
173173 CodeModel: CodeModel,
......@@ -175,10 +175,10 @@ extern fn ZigLLVMCreateTargetMachine(
175175) ?*TargetMachine;
176176
177177pub const GetHostCPUName = LLVMGetHostCPUName;
178extern fn LLVMGetHostCPUName() ?[*]u8;
178extern fn LLVMGetHostCPUName() ?[*:0]u8;
179179
180180pub const GetNativeFeatures = ZigLLVMGetNativeFeatures;
181extern fn ZigLLVMGetNativeFeatures() ?[*]u8;
181extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8;
182182
183183pub const GetElementType = LLVMGetElementType;
184184extern fn LLVMGetElementType(Ty: *Type) *Type;
......@@ -190,16 +190,16 @@ pub const BuildStore = LLVMBuildStore;
190190extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value;
191191
192192pub const BuildAlloca = LLVMBuildAlloca;
193extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*]const u8) ?*Value;
193extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*:0]const u8) ?*Value;
194194
195195pub const ConstInBoundsGEP = LLVMConstInBoundsGEP;
196196pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value;
197197
198198pub const GetTargetFromTriple = LLVMGetTargetFromTriple;
199extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: **Target, ErrorMessage: ?*[*]u8) Bool;
199extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: ?*[*:0]u8) Bool;
200200
201201pub const VerifyModule = LLVMVerifyModule;
202extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool;
202extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*:0]u8) Bool;
203203
204204pub const GetInsertBlock = LLVMGetInsertBlock;
205205extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock;
......@@ -216,7 +216,7 @@ pub const GetParam = LLVMGetParam;
216216extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value;
217217
218218pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext;
219extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*]const u8) ?*BasicBlock;
219extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) ?*BasicBlock;
220220
221221pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd;
222222extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void;
......@@ -278,14 +278,14 @@ pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile;
278278extern fn ZigLLVMTargetMachineEmitToFile(
279279 targ_machine_ref: *TargetMachine,
280280 module_ref: *Module,
281 filename: [*]const u8,
281 filename: [*:0]const u8,
282282 output_type: EmitOutputType,
283 error_message: *[*]u8,
283 error_message: *[*:0]u8,
284284 is_debug: bool,
285285 is_small: bool,
286286) bool;
287287
288288pub const BuildCall = ZigLLVMBuildCall;
289extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?*Value;
289extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*:0]const u8) ?*Value;
290290
291291pub const PrivateLinkage = c.LLVMLinkage.LLVMPrivateLinkage;
src-self-hosted/stage1.zig+2-2
......@@ -144,7 +144,7 @@ export fn stage2_render_ast(tree: *ast.Tree, output_file: *FILE) Error {
144144
145145// TODO: just use the actual self-hosted zig fmt. Until https://github.com/ziglang/zig/issues/2377,
146146// we use a blocking implementation.
147export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {
147export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int {
148148 if (std.debug.runtime_safety) {
149149 fmtMain(argc, argv) catch unreachable;
150150 } else {
......@@ -156,7 +156,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int {
156156 return 0;
157157}
158158
159fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void {
159fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void {
160160 const allocator = std.heap.c_allocator;
161161 var args_list = std.ArrayList([]const u8).init(allocator);
162162 const argc_usize = @intCast(usize, argc);
src-self-hosted/translate_c.zig+1-1
......@@ -113,7 +113,7 @@ const Context = struct {
113113 }
114114
115115 /// Convert a null-terminated C string to a slice allocated in the arena
116 fn str(c: *Context, s: [*]const u8) ![]u8 {
116 fn str(c: *Context, s: [*:0]const u8) ![]u8 {
117117 return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s));
118118 }
119119
src-self-hosted/util.zig+3-3
......@@ -172,9 +172,9 @@ pub fn getDarwinArchString(self: Target) []const u8 {
172172
173173pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target {
174174 var result: *llvm.Target = undefined;
175 var err_msg: [*]u8 = undefined;
176 if (llvm.GetTargetFromTriple(triple.ptr(), &result, &err_msg) != 0) {
177 std.debug.warn("triple: {s} error: {s}\n", triple.ptr(), err_msg);
175 var err_msg: [*:0]u8 = undefined;
176 if (llvm.GetTargetFromTriple(triple.toSlice(), &result, &err_msg) != 0) {
177 std.debug.warn("triple: {s} error: {s}\n", triple.toSlice(), err_msg);
178178 return error.UnsupportedTarget;
179179 }
180180 return result;
src/analyze.cpp+4-2
......@@ -7792,7 +7792,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
77927792
77937793 bool done = false;
77947794 if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile ||
7795 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero)
7795 ptr_type->data.pointer.explicit_alignment != 0 || ptr_type->data.pointer.allow_zero ||
7796 ptr_type->data.pointer.sentinel != nullptr)
77967797 {
77977798 ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false,
77987799 PtrLenUnknown, 0, 0, 0, false);
......@@ -7811,7 +7812,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa
78117812 ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry;
78127813 assert(child_ptr_type->id == ZigTypeIdPointer);
78137814 if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile ||
7814 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero)
7815 child_ptr_type->data.pointer.explicit_alignment != 0 || child_ptr_type->data.pointer.allow_zero ||
7816 child_ptr_type->data.pointer.sentinel != nullptr)
78157817 {
78167818 ZigType *grand_child_type = child_ptr_type->data.pointer.child_type;
78177819 ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false,
test/stage1/behavior/cast.zig+1-1
......@@ -348,7 +348,7 @@ fn testCastPtrOfArrayToSliceAndPtr() void {
348348test "cast *[1][*]const u8 to [*]const ?[*]const u8" {
349349 const window_name = [1][*]const u8{"window name"};
350350 const x: [*]const ?[*]const u8 = &window_name;
351 expect(mem.eql(u8, std.mem.toSliceConst(u8, x[0].?), "window name"));
351 expect(mem.eql(u8, std.mem.toSliceConst(u8, @ptrCast([*:0]const u8, x[0].?)), "window name"));
352352}
353353
354354test "@intCast comptime_int" {
test/stage1/behavior/pointers.zig+2-1
......@@ -207,7 +207,8 @@ test "null terminated pointer" {
207207 var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'};
208208 var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero);
209209 var no_zero_ptr: [*]const u8 = zero_ptr;
210 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, no_zero_ptr), "hello"));
210 var zero_ptr_again = @ptrCast([*:0]const u8, no_zero_ptr);
211 expect(std.mem.eql(u8, std.mem.toSliceConst(u8, zero_ptr_again), "hello"));
211212 }
212213 };
213214 S.doTheTest();