Skip to content

Commit a98373f

Browse files
committed
use correct integer type for windows BOOL
1 parent 3c19883 commit a98373f

6 files changed

Lines changed: 37 additions & 30 deletions

File tree

std/io.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ pub const InStream = struct {
305305
while (index < buf.len) {
306306
const want_read_count = system.DWORD(math.min(system.DWORD(@maxValue(system.DWORD)), buf.len - index));
307307
var amt_read: system.DWORD = undefined;
308-
if (!system.ReadFile(handle, @ptrCast(&c_void, &buf[index]), want_read_count, &amt_read, null)) {
308+
if (system.ReadFile(handle, @ptrCast(&c_void, &buf[index]), want_read_count, &amt_read, null) == 0) {
309309
const err = system.GetLastError();
310310
return switch (err) {
311311
system.ERROR.OPERATION_ABORTED => continue,

std/os/child_process.zig

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const is_windows = builtin.os == Os.windows;
2424
pub const ChildProcess = struct {
2525
pub pid: if (is_windows) void else i32,
2626
pub handle: if (is_windows) windows.HANDLE else void,
27+
pub thread_handle: if (is_windows) windows.HANDLE else void,
2728

2829
pub allocator: &mem.Allocator,
2930

@@ -82,6 +83,7 @@ pub const ChildProcess = struct {
8283
.argv = argv,
8384
.pid = undefined,
8485
.handle = undefined,
86+
.thread_handle = undefined,
8587
.err_pipe = undefined,
8688
.llnode = undefined,
8789
.term = null,
@@ -210,14 +212,15 @@ pub const ChildProcess = struct {
210212

211213
self.term = (%Term)({
212214
var exit_code: windows.DWORD = undefined;
213-
if (!windows.GetExitCodeProcess(self.handle, &exit_code)) {
215+
if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {
214216
Term.Unknown{0}
215217
} else {
216218
Term.Exited {@bitCast(i32, exit_code)}
217219
}
218220
});
219221

220222
os.windowsClose(self.handle);
223+
os.windowsClose(self.thread_handle);
221224
self.cleanupStreams();
222225
return result;
223226
}
@@ -430,10 +433,11 @@ pub const ChildProcess = struct {
430433
}
431434

432435
fn spawnWindows(self: &ChildProcess) -> %void {
433-
var saAttr: windows.SECURITY_ATTRIBUTES = undefined;
434-
saAttr.nLength = @sizeOf(windows.SECURITY_ATTRIBUTES);
435-
saAttr.bInheritHandle = true;
436-
saAttr.lpSecurityDescriptor = null;
436+
var saAttr = windows.SECURITY_ATTRIBUTES {
437+
.nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
438+
.bInheritHandle = windows.TRUE,
439+
.lpSecurityDescriptor = null,
440+
};
437441

438442
const any_ignore = (self.stdin_behavior == StdIo.Ignore or
439443
self.stdout_behavior == StdIo.Ignore or
@@ -571,9 +575,9 @@ pub const ChildProcess = struct {
571575
defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);
572576
const envp_ptr = if (maybe_envp_buf) |envp_buf| envp_buf.ptr else null;
573577

574-
if (!windows.CreateProcessA(app_name.ptr, cmd_line.ptr, null, null, true, 0,
578+
if (windows.CreateProcessA(app_name.ptr, cmd_line.ptr, null, null, windows.TRUE, 0,
575579
@ptrCast(?&c_void, envp_ptr),
576-
cwd_ptr, &siStartInfo, &piProcInfo))
580+
cwd_ptr, &siStartInfo, &piProcInfo) == windows.FALSE)
577581
{
578582
const err = windows.GetLastError();
579583
return switch (err) {
@@ -582,7 +586,6 @@ pub const ChildProcess = struct {
582586
else => error.Unexpected,
583587
};
584588
}
585-
os.windowsClose(piProcInfo.hThread);
586589

587590
if (stdin_ptr) |outstream| {
588591
*outstream = io.OutStream {
@@ -609,6 +612,7 @@ pub const ChildProcess = struct {
609612
}
610613

611614
self.handle = piProcInfo.hProcess;
615+
self.thread_handle = piProcInfo.hThread;
612616
self.term = null;
613617
self.stdin = stdin_ptr;
614618
self.stdout = stdout_ptr;
@@ -672,7 +676,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) {
672676
}
673677

674678
fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SECURITY_ATTRIBUTES) -> %void {
675-
if (!windows.CreatePipe(rd, wr, sattr, 0)) {
679+
if (windows.CreatePipe(rd, wr, sattr, 0) == 0) {
676680
const err = windows.GetLastError();
677681
return switch (err) {
678682
else => error.Unexpected,
@@ -681,7 +685,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SEC
681685
}
682686

683687
fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) -> %void {
684-
if (!windows.SetHandleInformation(h, mask, flags)) {
688+
if (windows.SetHandleInformation(h, mask, flags) == 0) {
685689
const err = windows.GetLastError();
686690
return switch (err) {
687691
else => error.Unexpected,

std/os/index.zig

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ pub fn getRandomBytes(buf: []u8) -> %void {
9595
},
9696
Os.windows => {
9797
var hCryptProv: windows.HCRYPTPROV = undefined;
98-
if (!windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0)) {
98+
if (windows.CryptAcquireContextA(&hCryptProv, null, null, windows.PROV_RSA_FULL, 0) == 0) {
9999
return error.Unexpected;
100100
}
101101
defer _ = windows.CryptReleaseContext(hCryptProv, 0);
102102

103-
if (!windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr)) {
103+
if (windows.CryptGenRandom(hCryptProv, windows.DWORD(buf.len), buf.ptr) == 0) {
104104
return error.Unexpected;
105105
}
106106
},
@@ -417,7 +417,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {
417417

418418
if (is_windows) {
419419
const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory;
420-
defer assert(windows.FreeEnvironmentStringsA(ptr));
420+
defer assert(windows.FreeEnvironmentStringsA(ptr) != 0);
421421

422422
var i: usize = 0;
423423
while (true) {
@@ -657,7 +657,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void
657657
mem.copy(u8, buf, file_path);
658658
buf[file_path.len] = 0;
659659

660-
if (!windows.DeleteFileA(buf.ptr)) {
660+
if (windows.DeleteFileA(buf.ptr) == 0) {
661661
const err = windows.GetLastError();
662662
return switch (err) {
663663
windows.ERROR.FILE_NOT_FOUND => error.FileNotFound,
@@ -740,7 +740,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
740740

741741
if (is_windows) {
742742
const flags = windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_WRITE_THROUGH;
743-
if (!windows.MoveFileExA(old_buf.ptr, new_buf.ptr, flags)) {
743+
if (windows.MoveFileExA(old_buf.ptr, new_buf.ptr, flags) == 0) {
744744
const err = windows.GetLastError();
745745
return switch (err) {
746746
else => return error.Unexpected,
@@ -783,7 +783,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {
783783
const path_buf = %return cstr.addNullByte(allocator, dir_path);
784784
defer allocator.free(path_buf);
785785

786-
if (!windows.CreateDirectoryA(path_buf.ptr, null)) {
786+
if (windows.CreateDirectoryA(path_buf.ptr, null) == 0) {
787787
const err = windows.GetLastError();
788788
return switch (err) {
789789
windows.ERROR.ALREADY_EXISTS => error.PathAlreadyExists,

std/os/path.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
941941
else => error.Unexpected,
942942
};
943943
}
944-
defer assert(windows.CloseHandle(h_file));
944+
defer os.windowsClose(h_file);
945945
var buf = %return allocator.alloc(u8, 256);
946946
%defer allocator.free(buf);
947947
while (true) {

std/os/windows/index.zig

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pub const ERROR = @import("error.zig");
22

33
pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,
4-
pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> bool;
4+
pszProvider: ?LPCSTR, dwProvType: DWORD, dwFlags: DWORD) -> BOOL;
55

6-
pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;
6+
pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
77

8-
pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;
8+
pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> BOOL;
99

1010

1111
pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
@@ -28,15 +28,15 @@ pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lp
2828
pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,
2929
dwFlags: DWORD) -> BOOLEAN;
3030

31-
pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;
31+
pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> BOOL;
3232

3333
pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;
3434

3535
pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL;
3636

3737
pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR;
3838

39-
pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> bool;
39+
pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> BOOL;
4040

4141
pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD;
4242

@@ -50,7 +50,7 @@ pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5050

5151
pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
5252
in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void,
53-
in_dwBufferSize: DWORD) -> bool;
53+
in_dwBufferSize: DWORD) -> BOOL;
5454

5555
pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR,
5656
cchFilePath: DWORD, dwFlags: DWORD) -> DWORD;
@@ -86,7 +86,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp
8686

8787
pub const PROV_RSA_FULL = 1;
8888

89-
pub const BOOL = bool;
89+
pub const BOOL = c_int;
9090
pub const BOOLEAN = BYTE;
9191
pub const BYTE = u8;
9292
pub const CHAR = u8;
@@ -116,6 +116,9 @@ pub const UNICODE = false;
116116
pub const WCHAR = u16;
117117
pub const WORD = u16;
118118

119+
pub const TRUE = 1;
120+
pub const FALSE = 0;
121+
119122
/// The standard input device. Initially, this is the console input buffer, CONIN$.
120123
pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;
121124

std/os/windows/util.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) ->
2222
}
2323

2424
pub fn windowsClose(handle: windows.HANDLE) {
25-
assert(windows.CloseHandle(handle));
25+
assert(windows.CloseHandle(handle) != 0);
2626
}
2727

2828
error SystemResources;
@@ -31,7 +31,7 @@ error IoPending;
3131
error BrokenPipe;
3232

3333
pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void {
34-
if (!windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null)) {
34+
if (windows.WriteFile(handle, @ptrCast(&const c_void, bytes.ptr), u32(bytes.len), null, null) == 0) {
3535
return switch (windows.GetLastError()) {
3636
windows.ERROR.INVALID_USER_BUFFER => error.SystemResources,
3737
windows.ERROR.NOT_ENOUGH_MEMORY => error.SystemResources,
@@ -49,15 +49,15 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool {
4949
return true;
5050

5151
var out: windows.DWORD = undefined;
52-
return windows.GetConsoleMode(handle, &out);
52+
return windows.GetConsoleMode(handle, &out) != 0;
5353
}
5454

5555
pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {
5656
const size = @sizeOf(windows.FILE_NAME_INFO);
5757
var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
5858

59-
if (!windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,
60-
@ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)))
59+
if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,
60+
@ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0)
6161
{
6262
return true;
6363
}

0 commit comments

Comments
 (0)