| author | |
| committer | |
| log | 15d415e10b81a66fa3b887fb2a0c20bbcd614d94 |
| tree | 10a61530b2b3d335cb8239d269b42569b8e932d8 |
| parent | 34b1ebefaab2e8f5c322bc96388bb4fefec31027 |
| signature |
and fix the fallout17 files changed, 76 insertions(+), 75 deletions(-)
lib/std/buffer.zig+2-7| ... | ... | @@ -72,11 +72,11 @@ pub const Buffer = struct { |
| 72 | 72 | self.list.deinit(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | pub fn toSlice(self: Buffer) []u8 { | |
| 75 | pub fn toSlice(self: Buffer) [:0]u8 { | |
| 76 | 76 | return self.list.toSlice()[0..self.len()]; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | pub fn toSliceConst(self: Buffer) []const u8 { | |
| 79 | pub fn toSliceConst(self: Buffer) [:0]const u8 { | |
| 80 | 80 | return self.list.toSliceConst()[0..self.len()]; |
| 81 | 81 | } |
| 82 | 82 | |
| ... | ... | @@ -131,11 +131,6 @@ pub const Buffer = struct { |
| 131 | 131 | try self.resize(m.len); |
| 132 | 132 | mem.copy(u8, self.list.toSlice(), m); |
| 133 | 133 | } |
| 134 | ||
| 135 | /// For passing to C functions. | |
| 136 | pub fn ptr(self: Buffer) [*]u8 { | |
| 137 | return self.list.items.ptr; | |
| 138 | } | |
| 139 | 134 | }; |
| 140 | 135 | |
| 141 | 136 | test "simple Buffer" { |
lib/std/c.zig+1-1| ... | ... | @@ -110,7 +110,7 @@ pub extern "c" fn nanosleep(rqtp: *const timespec, rmtp: ?*timespec) c_int; |
| 110 | 110 | pub extern "c" fn setreuid(ruid: c_uint, euid: c_uint) c_int; |
| 111 | 111 | pub extern "c" fn setregid(rgid: c_uint, egid: c_uint) c_int; |
| 112 | 112 | pub extern "c" fn rmdir(path: [*]const u8) c_int; |
| 113 | pub extern "c" fn getenv(name: [*]const u8) ?[*]u8; | |
| 113 | pub extern "c" fn getenv(name: [*:0]const u8) ?[*:0]u8; | |
| 114 | 114 | pub extern "c" fn sysctl(name: [*]const c_int, namelen: c_uint, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 115 | 115 | pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int; |
| 116 | 116 | pub 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 { |
| 533 | 533 | const next_index = self.index + linux_entry.reclen(); |
| 534 | 534 | self.index = next_index; |
| 535 | 535 | |
| 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)); | |
| 537 | 537 | |
| 538 | 538 | // skip . and .. entries |
| 539 | 539 | 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 { |
| 356 | 356 | return true; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | pub fn len(comptime T: type, ptr: [*]const T) usize { | |
| 359 | pub fn len(comptime T: type, ptr: [*:0]const T) usize { | |
| 360 | 360 | var count: usize = 0; |
| 361 | 361 | while (ptr[count] != 0) : (count += 1) {} |
| 362 | 362 | return count; |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | pub fn toSliceConst(comptime T: type, ptr: [*]const T) []const T { | |
| 365 | pub fn toSliceConst(comptime T: type, ptr: [*:0]const T) [:0]const T { | |
| 366 | 366 | return ptr[0..len(T, ptr)]; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | pub fn toSlice(comptime T: type, ptr: [*]T) []T { | |
| 369 | pub fn toSlice(comptime T: type, ptr: [*:0]T) [:0]T { | |
| 370 | 370 | return ptr[0..len(T, ptr)]; |
| 371 | 371 | } |
| 372 | 372 |
lib/std/net.zig+2-2| ... | ... | @@ -360,7 +360,7 @@ pub const Address = extern union { |
| 360 | 360 | unreachable; |
| 361 | 361 | } |
| 362 | 362 | |
| 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)); | |
| 364 | 364 | return @intCast(os.socklen_t, @sizeOf(os.sockaddr_un) - self.un.path.len + path_len); |
| 365 | 365 | }, |
| 366 | 366 | else => unreachable, |
| ... | ... | @@ -1271,7 +1271,7 @@ fn dnsParseCallback(ctx: dpc_ctx, rr: u8, data: []const u8, packet: []const u8) |
| 1271 | 1271 | var tmp: [256]u8 = undefined; |
| 1272 | 1272 | // Returns len of compressed name. strlen to get canon name. |
| 1273 | 1273 | _ = 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)); | |
| 1275 | 1275 | if (isValidHostName(canon_name)) { |
| 1276 | 1276 | try ctx.canon.replaceContents(canon_name); |
| 1277 | 1277 | } |
lib/std/os.zig+16-15| ... | ... | @@ -66,12 +66,12 @@ pub const system = if (builtin.link_libc) std.c else switch (builtin.os) { |
| 66 | 66 | pub usingnamespace @import("os/bits.zig"); |
| 67 | 67 | |
| 68 | 68 | /// See also `getenv`. Populated by startup code before main(). |
| 69 | pub var environ: [][*]u8 = undefined; | |
| 69 | pub var environ: [][*:0]u8 = undefined; | |
| 70 | 70 | |
| 71 | 71 | /// Populated by startup code before main(). |
| 72 | 72 | /// Not available on Windows. See `std.process.args` |
| 73 | 73 | /// for obtaining the process arguments. |
| 74 | pub var argv: [][*]u8 = undefined; | |
| 74 | pub var argv: [][*:0]u8 = undefined; | |
| 75 | 75 | |
| 76 | 76 | /// To obtain errno, call this function with the return value of the |
| 77 | 77 | /// 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 |
| 784 | 784 | /// matching the syscall API on all targets. This removes the need for an allocator. |
| 785 | 785 | /// This function also uses the PATH environment variable to get the full path to the executable. |
| 786 | 786 | /// If `file` is an absolute path, this is the same as `execveC`. |
| 787 | pub fn execvpeC(file: [*]const u8, child_argv: [*]const ?[*]const u8, envp: [*]const ?[*]const u8) ExecveError { | |
| 787 | pub fn execvpeC(file: [*:0]const u8, child_argv: [*]const ?[*:0]const u8, envp: [*]const ?[*:0]const u8) ExecveError { | |
| 788 | 788 | const file_slice = mem.toSliceConst(u8, file); |
| 789 | 789 | if (mem.indexOfScalar(u8, file_slice, '/') != null) return execveC(file, child_argv, envp); |
| 790 | 790 | |
| ... | ... | @@ -820,8 +820,8 @@ pub fn execvpe( |
| 820 | 820 | argv_slice: []const []const u8, |
| 821 | 821 | env_map: *const std.BufMap, |
| 822 | 822 | ) (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); | |
| 825 | 825 | defer { |
| 826 | 826 | for (argv_buf) |arg| { |
| 827 | 827 | const arg_buf = if (arg) |ptr| mem.toSlice(u8, ptr) else break; |
| ... | ... | @@ -834,7 +834,8 @@ pub fn execvpe( |
| 834 | 834 | @memcpy(arg_buf.ptr, arg.ptr, arg.len); |
| 835 | 835 | arg_buf[arg.len] = 0; |
| 836 | 836 | |
| 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); | |
| 838 | 839 | } |
| 839 | 840 | argv_buf[argv_slice.len] = null; |
| 840 | 841 | |
| ... | ... | @@ -844,10 +845,10 @@ pub fn execvpe( |
| 844 | 845 | return execvpeC(argv_buf.ptr[0].?, argv_buf.ptr, envp_buf.ptr); |
| 845 | 846 | } |
| 846 | 847 | |
| 847 | pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*]u8 { | |
| 848 | pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std.BufMap) ![]?[*:0]u8 { | |
| 848 | 849 | 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); | |
| 851 | 852 | errdefer freeNullDelimitedEnvMap(allocator, envp_buf); |
| 852 | 853 | { |
| 853 | 854 | var it = env_map.iterator(); |
| ... | ... | @@ -859,7 +860,8 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std. |
| 859 | 860 | @memcpy(env_buf.ptr + pair.key.len + 1, pair.value.ptr, pair.value.len); |
| 860 | 861 | env_buf[env_buf.len - 1] = 0; |
| 861 | 862 | |
| 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); | |
| 863 | 865 | } |
| 864 | 866 | assert(i == envp_count); |
| 865 | 867 | } |
| ... | ... | @@ -867,7 +869,7 @@ pub fn createNullDelimitedEnvMap(allocator: *mem.Allocator, env_map: *const std. |
| 867 | 869 | return envp_buf; |
| 868 | 870 | } |
| 869 | 871 | |
| 870 | pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*]u8) void { | |
| 872 | pub fn freeNullDelimitedEnvMap(allocator: *mem.Allocator, envp_buf: []?[*:0]u8) void { | |
| 871 | 873 | for (envp_buf) |env| { |
| 872 | 874 | const env_buf = if (env) |ptr| ptr[0 .. mem.len(u8, ptr) + 1] else break; |
| 873 | 875 | allocator.free(env_buf); |
| ... | ... | @@ -896,8 +898,7 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 896 | 898 | |
| 897 | 899 | /// Get an environment variable with a null-terminated name. |
| 898 | 900 | /// See also `getenv`. |
| 899 | /// TODO https://github.com/ziglang/zig/issues/265 | |
| 900 | pub fn getenvC(key: [*]const u8) ?[]const u8 { | |
| 901 | pub fn getenvC(key: [*:0]const u8) ?[]const u8 { | |
| 901 | 902 | if (builtin.link_libc) { |
| 902 | 903 | const value = system.getenv(key) orelse return null; |
| 903 | 904 | return mem.toSliceConst(u8, value); |
| ... | ... | @@ -922,7 +923,7 @@ pub fn getcwd(out_buffer: []u8) GetCwdError![]u8 { |
| 922 | 923 | break :blk errno(system.getcwd(out_buffer.ptr, out_buffer.len)); |
| 923 | 924 | }; |
| 924 | 925 | switch (err) { |
| 925 | 0 => return mem.toSlice(u8, out_buffer.ptr), | |
| 926 | 0 => return mem.toSlice(u8, @ptrCast([*:0]u8, out_buffer.ptr)), | |
| 926 | 927 | EFAULT => unreachable, |
| 927 | 928 | EINVAL => unreachable, |
| 928 | 929 | ENOENT => return error.CurrentWorkingDirectoryUnlinked, |
| ... | ... | @@ -2865,7 +2866,7 @@ pub fn gethostname(name_buffer: *[HOST_NAME_MAX]u8) GetHostNameError![]u8 { |
| 2865 | 2866 | var uts: utsname = undefined; |
| 2866 | 2867 | switch (errno(system.uname(&uts))) { |
| 2867 | 2868 | 0 => { |
| 2868 | const hostname = mem.toSlice(u8, &uts.nodename); | |
| 2869 | const hostname = mem.toSlice(u8, @ptrCast([*:0]u8, &uts.nodename)); | |
| 2869 | 2870 | mem.copy(u8, name_buffer, hostname); |
| 2870 | 2871 | return name_buffer[0..hostname.len]; |
| 2871 | 2872 | }, |
lib/std/os/linux/vdso.zig+4-2| ... | ... | @@ -65,7 +65,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { |
| 65 | 65 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info & 0xf) & OK_TYPES)) continue; |
| 66 | 66 | if (0 == (@as(u32, 1) << @intCast(u5, syms[i].st_info >> 4) & OK_BINDS)) continue; |
| 67 | 67 | 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; | |
| 69 | 70 | if (maybe_versym) |versym| { |
| 70 | 71 | if (!checkver(maybe_verdef.?, versym[i], vername, strings)) |
| 71 | 72 | continue; |
| ... | ... | @@ -87,5 +88,6 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [ |
| 87 | 88 | def = @intToPtr(*elf.Verdef, @ptrToInt(def) + def.vd_next); |
| 88 | 89 | } |
| 89 | 90 | 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)); | |
| 91 | 93 | } |
lib/std/special/start.zig+6-6| ... | ... | @@ -123,12 +123,12 @@ fn posixCallMainAndExit() noreturn { |
| 123 | 123 | @setAlignStack(16); |
| 124 | 124 | } |
| 125 | 125 | 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); | |
| 127 | 127 | |
| 128 | const envp_optional = @ptrCast([*]?[*]u8, argv + argc + 1); | |
| 128 | const envp_optional = @ptrCast([*:null]?[*:0]u8, argv + argc + 1); | |
| 129 | 129 | var envp_count: usize = 0; |
| 130 | 130 | 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]; | |
| 132 | 132 | |
| 133 | 133 | if (builtin.os == .linux) { |
| 134 | 134 | // Find the beginning of the auxiliary vector |
| ... | ... | @@ -168,7 +168,7 @@ fn posixCallMainAndExit() noreturn { |
| 168 | 168 | std.os.exit(@inlineCall(callMainWithArgs, argc, argv, envp)); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 { | |
| 171 | fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 { | |
| 172 | 172 | std.os.argv = argv[0..argc]; |
| 173 | 173 | std.os.environ = envp; |
| 174 | 174 | |
| ... | ... | @@ -177,10 +177,10 @@ fn callMainWithArgs(argc: usize, argv: [*][*]u8, envp: [][*]u8) u8 { |
| 177 | 177 | return initEventLoopAndCallMain(); |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | extern fn main(c_argc: i32, c_argv: [*][*]u8, c_envp: [*]?[*]u8) i32 { | |
| 180 | extern fn main(c_argc: i32, c_argv: [*][*:0]u8, c_envp: [*:null]?[*:0]u8) i32 { | |
| 181 | 181 | var env_count: usize = 0; |
| 182 | 182 | 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]; | |
| 184 | 184 | return @inlineCall(callMainWithArgs, @intCast(usize, c_argc), c_argv, envp); |
| 185 | 185 | } |
| 186 | 186 |
src-self-hosted/clang.zig+3-3| ... | ... | @@ -708,7 +708,7 @@ pub const ZigClangStringLiteral_StringKind = extern enum { |
| 708 | 708 | }; |
| 709 | 709 | |
| 710 | 710 | pub extern fn ZigClangSourceManager_getSpellingLoc(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) struct_ZigClangSourceLocation; |
| 711 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*]const u8; | |
| 711 | pub extern fn ZigClangSourceManager_getFilename(self: *const struct_ZigClangSourceManager, SpellingLoc: struct_ZigClangSourceLocation) ?[*:0]const u8; | |
| 712 | 712 | pub extern fn ZigClangSourceManager_getSpellingLineNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; |
| 713 | 713 | pub extern fn ZigClangSourceManager_getSpellingColumnNumber(self: ?*const struct_ZigClangSourceManager, Loc: struct_ZigClangSourceLocation) c_uint; |
| 714 | 714 | pub 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 |
| 746 | 746 | pub extern fn ZigClangType_getTypeClass(self: ?*const struct_ZigClangType) ZigClangTypeClass; |
| 747 | 747 | pub extern fn ZigClangType_getPointeeType(self: ?*const struct_ZigClangType) struct_ZigClangQualType; |
| 748 | 748 | pub extern fn ZigClangType_isVoidType(self: ?*const struct_ZigClangType) bool; |
| 749 | pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*]const u8; | |
| 749 | pub extern fn ZigClangType_getTypeClassName(self: *const struct_ZigClangType) [*:0]const u8; | |
| 750 | 750 | pub extern fn ZigClangStmt_getBeginLoc(self: *const struct_ZigClangStmt) struct_ZigClangSourceLocation; |
| 751 | 751 | pub extern fn ZigClangStmt_getStmtClass(self: ?*const struct_ZigClangStmt) ZigClangStmtClass; |
| 752 | 752 | pub extern fn ZigClangStmt_classof_Expr(self: ?*const struct_ZigClangStmt) bool; |
| ... | ... | @@ -904,7 +904,7 @@ pub extern fn ZigClangLoadFromCommandLine( |
| 904 | 904 | ) ?*ZigClangASTUnit; |
| 905 | 905 | |
| 906 | 906 | pub extern fn ZigClangDecl_getKind(decl: *const ZigClangDecl) ZigClangDeclKind; |
| 907 | pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*]const u8; | |
| 907 | pub extern fn ZigClangDecl_getDeclKindName(decl: *const struct_ZigClangDecl) [*:0]const u8; | |
| 908 | 908 | |
| 909 | 909 | pub const ZigClangCompoundStmt_const_body_iterator = [*c]const *struct_ZigClangStmt; |
| 910 | 910 |
src-self-hosted/compilation.zig+3-3| ... | ... | @@ -490,8 +490,8 @@ pub const Compilation = struct { |
| 490 | 490 | // LLVM creates invalid binaries on Windows sometimes. |
| 491 | 491 | // See https://github.com/ziglang/zig/issues/508 |
| 492 | 492 | // 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; | |
| 495 | 495 | defer llvm.DisposeMessage(target_specific_cpu_args); |
| 496 | 496 | defer llvm.DisposeMessage(target_specific_cpu_features); |
| 497 | 497 | if (target == Target.Native and !target.isWindows()) { |
| ... | ... | @@ -501,7 +501,7 @@ pub const Compilation = struct { |
| 501 | 501 | |
| 502 | 502 | comp.target_machine = llvm.CreateTargetMachine( |
| 503 | 503 | comp.llvm_target, |
| 504 | comp.llvm_triple.ptr(), | |
| 504 | comp.llvm_triple.toSliceConst(), | |
| 505 | 505 | target_specific_cpu_args orelse "", |
| 506 | 506 | target_specific_cpu_features orelse "", |
| 507 | 507 | opt_level, |
src-self-hosted/llvm.zig+22-22| ... | ... | @@ -83,16 +83,16 @@ pub const X86FP80TypeInContext = c.LLVMX86FP80TypeInContext; |
| 83 | 83 | pub const X86MMXTypeInContext = c.LLVMX86MMXTypeInContext; |
| 84 | 84 | |
| 85 | 85 | pub const AddGlobal = LLVMAddGlobal; |
| 86 | extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*]const u8) ?*Value; | |
| 86 | extern fn LLVMAddGlobal(M: *Module, Ty: *Type, Name: [*:0]const u8) ?*Value; | |
| 87 | 87 | |
| 88 | 88 | pub const ConstStringInContext = LLVMConstStringInContext; |
| 89 | extern fn LLVMConstStringInContext(C: *Context, Str: [*]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value; | |
| 89 | extern fn LLVMConstStringInContext(C: *Context, Str: [*:0]const u8, Length: c_uint, DontNullTerminate: Bool) ?*Value; | |
| 90 | 90 | |
| 91 | 91 | pub const ConstInt = LLVMConstInt; |
| 92 | 92 | extern fn LLVMConstInt(IntTy: *Type, N: c_ulonglong, SignExtend: Bool) ?*Value; |
| 93 | 93 | |
| 94 | 94 | pub const BuildLoad = LLVMBuildLoad; |
| 95 | extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*]const u8) ?*Value; | |
| 95 | extern fn LLVMBuildLoad(arg0: *Builder, PointerVal: *Value, Name: [*:0]const u8) ?*Value; | |
| 96 | 96 | |
| 97 | 97 | pub const ConstNull = LLVMConstNull; |
| 98 | 98 | extern fn LLVMConstNull(Ty: *Type) ?*Value; |
| ... | ... | @@ -110,24 +110,24 @@ pub const CreateEnumAttribute = LLVMCreateEnumAttribute; |
| 110 | 110 | extern fn LLVMCreateEnumAttribute(C: *Context, KindID: c_uint, Val: u64) ?*Attribute; |
| 111 | 111 | |
| 112 | 112 | pub const AddFunction = LLVMAddFunction; |
| 113 | extern fn LLVMAddFunction(M: *Module, Name: [*]const u8, FunctionTy: *Type) ?*Value; | |
| 113 | extern fn LLVMAddFunction(M: *Module, Name: [*:0]const u8, FunctionTy: *Type) ?*Value; | |
| 114 | 114 | |
| 115 | 115 | pub const CreateCompileUnit = ZigLLVMCreateCompileUnit; |
| 116 | 116 | extern fn ZigLLVMCreateCompileUnit( |
| 117 | 117 | dibuilder: *DIBuilder, |
| 118 | 118 | lang: c_uint, |
| 119 | 119 | difile: *DIFile, |
| 120 | producer: [*]const u8, | |
| 120 | producer: [*:0]const u8, | |
| 121 | 121 | is_optimized: bool, |
| 122 | flags: [*]const u8, | |
| 122 | flags: [*:0]const u8, | |
| 123 | 123 | runtime_version: c_uint, |
| 124 | split_name: [*]const u8, | |
| 124 | split_name: [*:0]const u8, | |
| 125 | 125 | dwo_id: u64, |
| 126 | 126 | emit_debug_info: bool, |
| 127 | 127 | ) ?*DICompileUnit; |
| 128 | 128 | |
| 129 | 129 | pub const CreateFile = ZigLLVMCreateFile; |
| 130 | extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*]const u8, directory: [*]const u8) ?*DIFile; | |
| 130 | extern fn ZigLLVMCreateFile(dibuilder: *DIBuilder, filename: [*:0]const u8, directory: [*:0]const u8) ?*DIFile; | |
| 131 | 131 | |
| 132 | 132 | pub const ArrayType = LLVMArrayType; |
| 133 | 133 | extern fn LLVMArrayType(ElementType: *Type, ElementCount: c_uint) ?*Type; |
| ... | ... | @@ -145,7 +145,7 @@ pub const IntTypeInContext = LLVMIntTypeInContext; |
| 145 | 145 | extern fn LLVMIntTypeInContext(C: *Context, NumBits: c_uint) ?*Type; |
| 146 | 146 | |
| 147 | 147 | pub const ModuleCreateWithNameInContext = LLVMModuleCreateWithNameInContext; |
| 148 | extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*]const u8, C: *Context) ?*Module; | |
| 148 | extern fn LLVMModuleCreateWithNameInContext(ModuleID: [*:0]const u8, C: *Context) ?*Module; | |
| 149 | 149 | |
| 150 | 150 | pub const VoidTypeInContext = LLVMVoidTypeInContext; |
| 151 | 151 | extern fn LLVMVoidTypeInContext(C: *Context) ?*Type; |
| ... | ... | @@ -157,7 +157,7 @@ pub const ContextDispose = LLVMContextDispose; |
| 157 | 157 | extern fn LLVMContextDispose(C: *Context) void; |
| 158 | 158 | |
| 159 | 159 | pub const CopyStringRepOfTargetData = LLVMCopyStringRepOfTargetData; |
| 160 | extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*]u8; | |
| 160 | extern fn LLVMCopyStringRepOfTargetData(TD: *TargetData) ?[*:0]u8; | |
| 161 | 161 | |
| 162 | 162 | pub const CreateTargetDataLayout = LLVMCreateTargetDataLayout; |
| 163 | 163 | extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData; |
| ... | ... | @@ -165,9 +165,9 @@ extern fn LLVMCreateTargetDataLayout(T: *TargetMachine) ?*TargetData; |
| 165 | 165 | pub const CreateTargetMachine = ZigLLVMCreateTargetMachine; |
| 166 | 166 | extern fn ZigLLVMCreateTargetMachine( |
| 167 | 167 | 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, | |
| 171 | 171 | Level: CodeGenOptLevel, |
| 172 | 172 | Reloc: RelocMode, |
| 173 | 173 | CodeModel: CodeModel, |
| ... | ... | @@ -175,10 +175,10 @@ extern fn ZigLLVMCreateTargetMachine( |
| 175 | 175 | ) ?*TargetMachine; |
| 176 | 176 | |
| 177 | 177 | pub const GetHostCPUName = LLVMGetHostCPUName; |
| 178 | extern fn LLVMGetHostCPUName() ?[*]u8; | |
| 178 | extern fn LLVMGetHostCPUName() ?[*:0]u8; | |
| 179 | 179 | |
| 180 | 180 | pub const GetNativeFeatures = ZigLLVMGetNativeFeatures; |
| 181 | extern fn ZigLLVMGetNativeFeatures() ?[*]u8; | |
| 181 | extern fn ZigLLVMGetNativeFeatures() ?[*:0]u8; | |
| 182 | 182 | |
| 183 | 183 | pub const GetElementType = LLVMGetElementType; |
| 184 | 184 | extern fn LLVMGetElementType(Ty: *Type) *Type; |
| ... | ... | @@ -190,16 +190,16 @@ pub const BuildStore = LLVMBuildStore; |
| 190 | 190 | extern fn LLVMBuildStore(arg0: *Builder, Val: *Value, Ptr: *Value) ?*Value; |
| 191 | 191 | |
| 192 | 192 | pub const BuildAlloca = LLVMBuildAlloca; |
| 193 | extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*]const u8) ?*Value; | |
| 193 | extern fn LLVMBuildAlloca(arg0: *Builder, Ty: *Type, Name: ?[*:0]const u8) ?*Value; | |
| 194 | 194 | |
| 195 | 195 | pub const ConstInBoundsGEP = LLVMConstInBoundsGEP; |
| 196 | 196 | pub extern fn LLVMConstInBoundsGEP(ConstantVal: *Value, ConstantIndices: [*]*Value, NumIndices: c_uint) ?*Value; |
| 197 | 197 | |
| 198 | 198 | pub const GetTargetFromTriple = LLVMGetTargetFromTriple; |
| 199 | extern fn LLVMGetTargetFromTriple(Triple: [*]const u8, T: **Target, ErrorMessage: ?*[*]u8) Bool; | |
| 199 | extern fn LLVMGetTargetFromTriple(Triple: [*:0]const u8, T: **Target, ErrorMessage: ?*[*:0]u8) Bool; | |
| 200 | 200 | |
| 201 | 201 | pub const VerifyModule = LLVMVerifyModule; |
| 202 | extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*]u8) Bool; | |
| 202 | extern fn LLVMVerifyModule(M: *Module, Action: VerifierFailureAction, OutMessage: *?[*:0]u8) Bool; | |
| 203 | 203 | |
| 204 | 204 | pub const GetInsertBlock = LLVMGetInsertBlock; |
| 205 | 205 | extern fn LLVMGetInsertBlock(Builder: *Builder) *BasicBlock; |
| ... | ... | @@ -216,7 +216,7 @@ pub const GetParam = LLVMGetParam; |
| 216 | 216 | extern fn LLVMGetParam(Fn: *Value, Index: c_uint) *Value; |
| 217 | 217 | |
| 218 | 218 | pub const AppendBasicBlockInContext = LLVMAppendBasicBlockInContext; |
| 219 | extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*]const u8) ?*BasicBlock; | |
| 219 | extern fn LLVMAppendBasicBlockInContext(C: *Context, Fn: *Value, Name: [*:0]const u8) ?*BasicBlock; | |
| 220 | 220 | |
| 221 | 221 | pub const PositionBuilderAtEnd = LLVMPositionBuilderAtEnd; |
| 222 | 222 | extern fn LLVMPositionBuilderAtEnd(Builder: *Builder, Block: *BasicBlock) void; |
| ... | ... | @@ -278,14 +278,14 @@ pub const TargetMachineEmitToFile = ZigLLVMTargetMachineEmitToFile; |
| 278 | 278 | extern fn ZigLLVMTargetMachineEmitToFile( |
| 279 | 279 | targ_machine_ref: *TargetMachine, |
| 280 | 280 | module_ref: *Module, |
| 281 | filename: [*]const u8, | |
| 281 | filename: [*:0]const u8, | |
| 282 | 282 | output_type: EmitOutputType, |
| 283 | error_message: *[*]u8, | |
| 283 | error_message: *[*:0]u8, | |
| 284 | 284 | is_debug: bool, |
| 285 | 285 | is_small: bool, |
| 286 | 286 | ) bool; |
| 287 | 287 | |
| 288 | 288 | pub const BuildCall = ZigLLVMBuildCall; |
| 289 | extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*]const u8) ?*Value; | |
| 289 | extern fn ZigLLVMBuildCall(B: *Builder, Fn: *Value, Args: [*]*Value, NumArgs: c_uint, CC: c_uint, fn_inline: FnInline, Name: [*:0]const u8) ?*Value; | |
| 290 | 290 | |
| 291 | 291 | pub 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 { |
| 144 | 144 | |
| 145 | 145 | // TODO: just use the actual self-hosted zig fmt. Until https://github.com/ziglang/zig/issues/2377, |
| 146 | 146 | // we use a blocking implementation. |
| 147 | export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int { | |
| 147 | export fn stage2_fmt(argc: c_int, argv: [*]const [*:0]const u8) c_int { | |
| 148 | 148 | if (std.debug.runtime_safety) { |
| 149 | 149 | fmtMain(argc, argv) catch unreachable; |
| 150 | 150 | } else { |
| ... | ... | @@ -156,7 +156,7 @@ export fn stage2_fmt(argc: c_int, argv: [*]const [*]const u8) c_int { |
| 156 | 156 | return 0; |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | fn fmtMain(argc: c_int, argv: [*]const [*]const u8) !void { | |
| 159 | fn fmtMain(argc: c_int, argv: [*]const [*:0]const u8) !void { | |
| 160 | 160 | const allocator = std.heap.c_allocator; |
| 161 | 161 | var args_list = std.ArrayList([]const u8).init(allocator); |
| 162 | 162 | const argc_usize = @intCast(usize, argc); |
src-self-hosted/translate_c.zig+1-1| ... | ... | @@ -113,7 +113,7 @@ const Context = struct { |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /// 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 { | |
| 117 | 117 | return std.mem.dupe(c.a(), u8, std.mem.toSliceConst(u8, s)); |
| 118 | 118 | } |
| 119 | 119 |
src-self-hosted/util.zig+3-3| ... | ... | @@ -172,9 +172,9 @@ pub fn getDarwinArchString(self: Target) []const u8 { |
| 172 | 172 | |
| 173 | 173 | pub fn llvmTargetFromTriple(triple: std.Buffer) !*llvm.Target { |
| 174 | 174 | 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); | |
| 178 | 178 | return error.UnsupportedTarget; |
| 179 | 179 | } |
| 180 | 180 | return result; |
src/analyze.cpp+4-2| ... | ... | @@ -7792,7 +7792,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa |
| 7792 | 7792 | |
| 7793 | 7793 | bool done = false; |
| 7794 | 7794 | 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) | |
| 7796 | 7797 | { |
| 7797 | 7798 | ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false, |
| 7798 | 7799 | PtrLenUnknown, 0, 0, 0, false); |
| ... | ... | @@ -7811,7 +7812,8 @@ static void resolve_llvm_types_slice(CodeGen *g, ZigType *type, ResolveStatus wa |
| 7811 | 7812 | ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index]->type_entry; |
| 7812 | 7813 | assert(child_ptr_type->id == ZigTypeIdPointer); |
| 7813 | 7814 | 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) | |
| 7815 | 7817 | { |
| 7816 | 7818 | ZigType *grand_child_type = child_ptr_type->data.pointer.child_type; |
| 7817 | 7819 | 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 { |
| 348 | 348 | test "cast *[1][*]const u8 to [*]const ?[*]const u8" { |
| 349 | 349 | const window_name = [1][*]const u8{"window name"}; |
| 350 | 350 | 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")); | |
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | test "@intCast comptime_int" { |
test/stage1/behavior/pointers.zig+2-1| ... | ... | @@ -207,7 +207,8 @@ test "null terminated pointer" { |
| 207 | 207 | var array_with_zero = [_:0]u8{'h', 'e', 'l', 'l', 'o'}; |
| 208 | 208 | var zero_ptr: [*:0]const u8 = @ptrCast([*:0]const u8, &array_with_zero); |
| 209 | 209 | 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")); | |
| 211 | 212 | } |
| 212 | 213 | }; |
| 213 | 214 | S.doTheTest(); |