diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-06-10 01:13:51 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-06-10 01:13:51 -0400 |
| commit | 77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4 (patch) | |
| tree | 207f75d690aa32ba054c0a4a78ad05ad1ca9902e /std/os | |
| parent | ec1b6f66737f8c3cbc0420715c2c502c7e710081 (diff) | |
| download | zig-77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4.tar.gz zig-77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4.zip | |
breaking syntax change: orelse keyword instead of ?? (#1096)
use the `zig-fmt-optional-default` branch to have zig fmt
automatically do the changes.
closes #1023
Diffstat (limited to 'std/os')
| -rw-r--r-- | std/os/index.zig | 14 | ||||
| -rw-r--r-- | std/os/linux/vdso.zig | 8 | ||||
| -rw-r--r-- | std/os/path.zig | 12 | ||||
| -rw-r--r-- | std/os/windows/util.zig | 2 |
4 files changed, 18 insertions, 18 deletions
diff --git a/std/os/index.zig b/std/os/index.zig index 807b2c398b..6a13ff94d4 100644 --- a/std/os/index.zig +++ b/std/os/index.zig @@ -425,7 +425,7 @@ pub fn posixExecve(argv: []const []const u8, env_map: *const BufMap, allocator: return posixExecveErrnoToErr(posix.getErrno(posix.execve(argv_buf[0].?, argv_buf.ptr, envp_buf.ptr))); } - const PATH = getEnvPosix("PATH") ?? "/usr/local/bin:/bin/:/usr/bin"; + const PATH = getEnvPosix("PATH") orelse "/usr/local/bin:/bin/:/usr/bin"; // PATH.len because it is >= the largest search_path // +1 for the / to join the search path and exe_path // +1 for the null terminating byte @@ -490,7 +490,7 @@ pub fn getEnvMap(allocator: *Allocator) !BufMap { errdefer result.deinit(); if (is_windows) { - const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory; + const ptr = windows.GetEnvironmentStringsA() orelse return error.OutOfMemory; defer assert(windows.FreeEnvironmentStringsA(ptr) != 0); var i: usize = 0; @@ -573,7 +573,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) ![]u8 { return allocator.shrink(u8, buf, result); } } else { - const result = getEnvPosix(key) ?? return error.EnvironmentVariableNotFound; + const result = getEnvPosix(key) orelse return error.EnvironmentVariableNotFound; return mem.dupe(allocator, u8, result); } } @@ -1641,7 +1641,7 @@ pub const ArgIterator = struct { if (builtin.os == Os.windows) { return self.inner.next(allocator); } else { - return mem.dupe(allocator, u8, self.inner.next() ?? return null); + return mem.dupe(allocator, u8, self.inner.next() orelse return null); } } @@ -2457,9 +2457,9 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread } }; - const heap_handle = windows.GetProcessHeap() ?? return SpawnThreadError.OutOfMemory; + const heap_handle = windows.GetProcessHeap() orelse return SpawnThreadError.OutOfMemory; const byte_count = @alignOf(WinThread.OuterContext) + @sizeOf(WinThread.OuterContext); - const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) ?? return SpawnThreadError.OutOfMemory; + const bytes_ptr = windows.HeapAlloc(heap_handle, 0, byte_count) orelse return SpawnThreadError.OutOfMemory; errdefer assert(windows.HeapFree(heap_handle, 0, bytes_ptr) != 0); const bytes = @ptrCast([*]u8, bytes_ptr)[0..byte_count]; const outer_context = std.heap.FixedBufferAllocator.init(bytes).allocator.create(WinThread.OuterContext) catch unreachable; @@ -2468,7 +2468,7 @@ pub fn spawnThread(context: var, comptime startFn: var) SpawnThreadError!*Thread outer_context.thread.data.alloc_start = bytes_ptr; const parameter = if (@sizeOf(Context) == 0) null else @ptrCast(*c_void, &outer_context.inner); - outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) ?? { + outer_context.thread.data.handle = windows.CreateThread(null, default_stack_size, WinThread.threadMain, parameter, 0, null) orelse { const err = windows.GetLastError(); return switch (err) { else => os.unexpectedErrorWindows(err), diff --git a/std/os/linux/vdso.zig b/std/os/linux/vdso.zig index 1414b8185b..cbd0cd1df5 100644 --- a/std/os/linux/vdso.zig +++ b/std/os/linux/vdso.zig @@ -28,7 +28,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { } } } - const dynv = maybe_dynv ?? return 0; + const dynv = maybe_dynv orelse return 0; if (base == @maxValue(usize)) return 0; var maybe_strings: ?[*]u8 = null; @@ -52,9 +52,9 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { } } - const strings = maybe_strings ?? return 0; - const syms = maybe_syms ?? return 0; - const hashtab = maybe_hashtab ?? return 0; + const strings = maybe_strings orelse return 0; + const syms = maybe_syms orelse return 0; + const hashtab = maybe_hashtab orelse return 0; if (maybe_verdef == null) maybe_versym = null; const OK_TYPES = (1 << elf.STT_NOTYPE | 1 << elf.STT_OBJECT | 1 << elf.STT_FUNC | 1 << elf.STT_COMMON); diff --git a/std/os/path.zig b/std/os/path.zig index 430dda2934..a3ad23b1a9 100644 --- a/std/os/path.zig +++ b/std/os/path.zig @@ -182,8 +182,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { } var it = mem.split(path, []u8{this_sep}); - _ = (it.next() ?? return relative_path); - _ = (it.next() ?? return relative_path); + _ = (it.next() orelse return relative_path); + _ = (it.next() orelse return relative_path); return WindowsPath{ .is_abs = isAbsoluteWindows(path), .kind = WindowsPath.Kind.NetworkShare, @@ -200,8 +200,8 @@ pub fn windowsParsePath(path: []const u8) WindowsPath { } var it = mem.split(path, []u8{this_sep}); - _ = (it.next() ?? return relative_path); - _ = (it.next() ?? return relative_path); + _ = (it.next() orelse return relative_path); + _ = (it.next() orelse return relative_path); return WindowsPath{ .is_abs = isAbsoluteWindows(path), .kind = WindowsPath.Kind.NetworkShare, @@ -923,7 +923,7 @@ pub fn relativeWindows(allocator: *Allocator, from: []const u8, to: []const u8) var from_it = mem.split(resolved_from, "/\\"); var to_it = mem.split(resolved_to, "/\\"); while (true) { - const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); + const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest()); const to_rest = to_it.rest(); if (to_it.next()) |to_component| { // TODO ASCII is wrong, we actually need full unicode support to compare paths. @@ -974,7 +974,7 @@ pub fn relativePosix(allocator: *Allocator, from: []const u8, to: []const u8) ![ var from_it = mem.split(resolved_from, "/"); var to_it = mem.split(resolved_to, "/"); while (true) { - const from_component = from_it.next() ?? return mem.dupe(allocator, u8, to_it.rest()); + const from_component = from_it.next() orelse return mem.dupe(allocator, u8, to_it.rest()); const to_rest = to_it.rest(); if (to_it.next()) |to_component| { if (mem.eql(u8, from_component, to_component)) diff --git a/std/os/windows/util.zig b/std/os/windows/util.zig index 7170346108..f93a673be0 100644 --- a/std/os/windows/util.zig +++ b/std/os/windows/util.zig @@ -153,7 +153,7 @@ pub fn createWindowsEnvBlock(allocator: *mem.Allocator, env_map: *const BufMap) pub fn windowsLoadDll(allocator: *mem.Allocator, dll_path: []const u8) !windows.HMODULE { const padded_buff = try cstr.addNullByte(allocator, dll_path); defer allocator.free(padded_buff); - return windows.LoadLibraryA(padded_buff.ptr) ?? error.DllNotFound; + return windows.LoadLibraryA(padded_buff.ptr) orelse error.DllNotFound; } pub fn windowsUnloadDll(hModule: windows.HMODULE) void { |
