authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-15 14:01:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-10-15 14:01:55-04:00
loga98373f144b19cae1fd943a3c1ab655a8970b1a6
treec0a9f9b1e245c0dc0b0894a7d4109ce22387fc5d
parent3c198834930e9628802d2935e32e14e75baf2605

use correct integer type for windows BOOL


6 files changed, 37 insertions(+), 30 deletions(-)

std/io.zig+1-1
...@@ -305,7 +305,7 @@ pub const InStream = struct {...@@ -305,7 +305,7 @@ pub const InStream = struct {
305 while (index < buf.len) {305 while (index < buf.len) {
306 const want_read_count = system.DWORD(math.min(system.DWORD(@maxValue(system.DWORD)), buf.len - index));306 const want_read_count = system.DWORD(math.min(system.DWORD(@maxValue(system.DWORD)), buf.len - index));
307 var amt_read: system.DWORD = undefined;307 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) {
309 const err = system.GetLastError();309 const err = system.GetLastError();
310 return switch (err) {310 return switch (err) {
311 system.ERROR.OPERATION_ABORTED => continue,311 system.ERROR.OPERATION_ABORTED => continue,
std/os/child_process.zig+14-10
...@@ -24,6 +24,7 @@ const is_windows = builtin.os == Os.windows;...@@ -24,6 +24,7 @@ const is_windows = builtin.os == Os.windows;
24pub const ChildProcess = struct {24pub const ChildProcess = struct {
25 pub pid: if (is_windows) void else i32,25 pub pid: if (is_windows) void else i32,
26 pub handle: if (is_windows) windows.HANDLE else void,26 pub handle: if (is_windows) windows.HANDLE else void,
27 pub thread_handle: if (is_windows) windows.HANDLE else void,
2728
28 pub allocator: &mem.Allocator,29 pub allocator: &mem.Allocator,
2930
...@@ -82,6 +83,7 @@ pub const ChildProcess = struct {...@@ -82,6 +83,7 @@ pub const ChildProcess = struct {
82 .argv = argv,83 .argv = argv,
83 .pid = undefined,84 .pid = undefined,
84 .handle = undefined,85 .handle = undefined,
86 .thread_handle = undefined,
85 .err_pipe = undefined,87 .err_pipe = undefined,
86 .llnode = undefined,88 .llnode = undefined,
87 .term = null,89 .term = null,
...@@ -210,7 +212,7 @@ pub const ChildProcess = struct {...@@ -210,7 +212,7 @@ pub const ChildProcess = struct {
210212
211 self.term = (%Term)({213 self.term = (%Term)({
212 var exit_code: windows.DWORD = undefined;214 var exit_code: windows.DWORD = undefined;
213 if (!windows.GetExitCodeProcess(self.handle, &exit_code)) {215 if (windows.GetExitCodeProcess(self.handle, &exit_code) == 0) {
214 Term.Unknown{0}216 Term.Unknown{0}
215 } else {217 } else {
216 Term.Exited {@bitCast(i32, exit_code)}218 Term.Exited {@bitCast(i32, exit_code)}
...@@ -218,6 +220,7 @@ pub const ChildProcess = struct {...@@ -218,6 +220,7 @@ pub const ChildProcess = struct {
218 });220 });
219221
220 os.windowsClose(self.handle);222 os.windowsClose(self.handle);
223 os.windowsClose(self.thread_handle);
221 self.cleanupStreams();224 self.cleanupStreams();
222 return result;225 return result;
223 }226 }
...@@ -430,10 +433,11 @@ pub const ChildProcess = struct {...@@ -430,10 +433,11 @@ pub const ChildProcess = struct {
430 }433 }
431434
432 fn spawnWindows(self: &ChildProcess) -> %void {435 fn spawnWindows(self: &ChildProcess) -> %void {
433 var saAttr: windows.SECURITY_ATTRIBUTES = undefined;436 var saAttr = windows.SECURITY_ATTRIBUTES {
434 saAttr.nLength = @sizeOf(windows.SECURITY_ATTRIBUTES);437 .nLength = @sizeOf(windows.SECURITY_ATTRIBUTES),
435 saAttr.bInheritHandle = true;438 .bInheritHandle = windows.TRUE,
436 saAttr.lpSecurityDescriptor = null;439 .lpSecurityDescriptor = null,
440 };
437441
438 const any_ignore = (self.stdin_behavior == StdIo.Ignore or442 const any_ignore = (self.stdin_behavior == StdIo.Ignore or
439 self.stdout_behavior == StdIo.Ignore or443 self.stdout_behavior == StdIo.Ignore or
...@@ -571,9 +575,9 @@ pub const ChildProcess = struct {...@@ -571,9 +575,9 @@ pub const ChildProcess = struct {
571 defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);575 defer if (maybe_envp_buf) |envp_buf| self.allocator.free(envp_buf);
572 const envp_ptr = if (maybe_envp_buf) |envp_buf| envp_buf.ptr else null;576 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,
575 @ptrCast(?&c_void, envp_ptr),579 @ptrCast(?&c_void, envp_ptr),
576 cwd_ptr, &siStartInfo, &piProcInfo))580 cwd_ptr, &siStartInfo, &piProcInfo) == windows.FALSE)
577 {581 {
578 const err = windows.GetLastError();582 const err = windows.GetLastError();
579 return switch (err) {583 return switch (err) {
...@@ -582,7 +586,6 @@ pub const ChildProcess = struct {...@@ -582,7 +586,6 @@ pub const ChildProcess = struct {
582 else => error.Unexpected,586 else => error.Unexpected,
583 };587 };
584 }588 }
585 os.windowsClose(piProcInfo.hThread);
586589
587 if (stdin_ptr) |outstream| {590 if (stdin_ptr) |outstream| {
588 *outstream = io.OutStream {591 *outstream = io.OutStream {
...@@ -609,6 +612,7 @@ pub const ChildProcess = struct {...@@ -609,6 +612,7 @@ pub const ChildProcess = struct {
609 }612 }
610613
611 self.handle = piProcInfo.hProcess;614 self.handle = piProcInfo.hProcess;
615 self.thread_handle = piProcInfo.hThread;
612 self.term = null;616 self.term = null;
613 self.stdin = stdin_ptr;617 self.stdin = stdin_ptr;
614 self.stdout = stdout_ptr;618 self.stdout = stdout_ptr;
...@@ -672,7 +676,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) {...@@ -672,7 +676,7 @@ fn windowsDestroyPipe(rd: ?windows.HANDLE, wr: ?windows.HANDLE) {
672}676}
673677
674fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SECURITY_ATTRIBUTES) -> %void {678fn 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) {
676 const err = windows.GetLastError();680 const err = windows.GetLastError();
677 return switch (err) {681 return switch (err) {
678 else => error.Unexpected,682 else => error.Unexpected,
...@@ -681,7 +685,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SEC...@@ -681,7 +685,7 @@ fn windowsMakePipe(rd: &windows.HANDLE, wr: &windows.HANDLE, sattr: &windows.SEC
681}685}
682686
683fn windowsSetHandleInfo(h: windows.HANDLE, mask: windows.DWORD, flags: windows.DWORD) -> %void {687fn 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) {
685 const err = windows.GetLastError();689 const err = windows.GetLastError();
686 return switch (err) {690 return switch (err) {
687 else => error.Unexpected,691 else => error.Unexpected,
std/os/index.zig+6-6
...@@ -95,12 +95,12 @@ pub fn getRandomBytes(buf: []u8) -> %void {...@@ -95,12 +95,12 @@ pub fn getRandomBytes(buf: []u8) -> %void {
95 },95 },
96 Os.windows => {96 Os.windows => {
97 var hCryptProv: windows.HCRYPTPROV = undefined;97 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) {
99 return error.Unexpected;99 return error.Unexpected;
100 }100 }
101 defer _ = windows.CryptReleaseContext(hCryptProv, 0);101 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) {
104 return error.Unexpected;104 return error.Unexpected;
105 }105 }
106 },106 },
...@@ -417,7 +417,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {...@@ -417,7 +417,7 @@ pub fn getEnvMap(allocator: &Allocator) -> %BufMap {
417417
418 if (is_windows) {418 if (is_windows) {
419 const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory;419 const ptr = windows.GetEnvironmentStringsA() ?? return error.OutOfMemory;
420 defer assert(windows.FreeEnvironmentStringsA(ptr));420 defer assert(windows.FreeEnvironmentStringsA(ptr) != 0);
421421
422 var i: usize = 0;422 var i: usize = 0;
423 while (true) {423 while (true) {
...@@ -657,7 +657,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void...@@ -657,7 +657,7 @@ pub fn deleteFileWindows(allocator: &Allocator, file_path: []const u8) -> %void
657 mem.copy(u8, buf, file_path);657 mem.copy(u8, buf, file_path);
658 buf[file_path.len] = 0;658 buf[file_path.len] = 0;
659659
660 if (!windows.DeleteFileA(buf.ptr)) {660 if (windows.DeleteFileA(buf.ptr) == 0) {
661 const err = windows.GetLastError();661 const err = windows.GetLastError();
662 return switch (err) {662 return switch (err) {
663 windows.ERROR.FILE_NOT_FOUND => error.FileNotFound,663 windows.ERROR.FILE_NOT_FOUND => error.FileNotFound,
...@@ -740,7 +740,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)...@@ -740,7 +740,7 @@ pub fn rename(allocator: &Allocator, old_path: []const u8, new_path: []const u8)
740740
741 if (is_windows) {741 if (is_windows) {
742 const flags = windows.MOVEFILE_REPLACE_EXISTING|windows.MOVEFILE_WRITE_THROUGH;742 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) {
744 const err = windows.GetLastError();744 const err = windows.GetLastError();
745 return switch (err) {745 return switch (err) {
746 else => return error.Unexpected,746 else => return error.Unexpected,
...@@ -783,7 +783,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {...@@ -783,7 +783,7 @@ pub fn makeDirWindows(allocator: &Allocator, dir_path: []const u8) -> %void {
783 const path_buf = %return cstr.addNullByte(allocator, dir_path);783 const path_buf = %return cstr.addNullByte(allocator, dir_path);
784 defer allocator.free(path_buf);784 defer allocator.free(path_buf);
785785
786 if (!windows.CreateDirectoryA(path_buf.ptr, null)) {786 if (windows.CreateDirectoryA(path_buf.ptr, null) == 0) {
787 const err = windows.GetLastError();787 const err = windows.GetLastError();
788 return switch (err) {788 return switch (err) {
789 windows.ERROR.ALREADY_EXISTS => error.PathAlreadyExists,789 windows.ERROR.ALREADY_EXISTS => error.PathAlreadyExists,
std/os/path.zig+1-1
...@@ -941,7 +941,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {...@@ -941,7 +941,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
941 else => error.Unexpected,941 else => error.Unexpected,
942 };942 };
943 }943 }
944 defer assert(windows.CloseHandle(h_file));944 defer os.windowsClose(h_file);
945 var buf = %return allocator.alloc(u8, 256);945 var buf = %return allocator.alloc(u8, 256);
946 %defer allocator.free(buf);946 %defer allocator.free(buf);
947 while (true) {947 while (true) {
std/os/windows/index.zig+10-7
...@@ -1,11 +1,11 @@...@@ -1,11 +1,11 @@
1pub const ERROR = @import("error.zig");1pub const ERROR = @import("error.zig");
22
3pub extern "advapi32" stdcallcc fn CryptAcquireContextA(phProv: &HCRYPTPROV, pszContainer: ?LPCSTR,3pub 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
6pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> bool;6pub extern "advapi32" stdcallcc fn CryptReleaseContext(hProv: HCRYPTPROV, dwFlags: DWORD) -> BOOL;
77
8pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> bool;8pub extern "advapi32" stdcallcc fn CryptGenRandom(hProv: HCRYPTPROV, dwLen: DWORD, pbBuffer: &BYTE) -> BOOL;
99
1010
11pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;11pub extern "kernel32" stdcallcc fn CloseHandle(hObject: HANDLE) -> BOOL;
...@@ -28,7 +28,7 @@ pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lp...@@ -28,7 +28,7 @@ pub extern "kernel32" stdcallcc fn CreateProcessA(lpApplicationName: ?LPCSTR, lp
28pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,28pub extern "kernel32" stdcallcc fn CreateSymbolicLinkA(lpSymlinkFileName: LPCSTR, lpTargetFileName: LPCSTR,
29 dwFlags: DWORD) -> BOOLEAN;29 dwFlags: DWORD) -> BOOLEAN;
3030
31pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> bool;31pub extern "kernel32" stdcallcc fn DeleteFileA(lpFileName: LPCSTR) -> BOOL;
3232
33pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;33pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: UINT) -> noreturn;
3434
...@@ -36,7 +36,7 @@ pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL;...@@ -36,7 +36,7 @@ pub extern "kernel32" stdcallcc fn FreeEnvironmentStringsA(penv: LPCH) -> BOOL;
3636
37pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR;37pub extern "kernel32" stdcallcc fn GetCommandLineA() -> LPSTR;
3838
39pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> bool;39pub extern "kernel32" stdcallcc fn GetConsoleMode(in_hConsoleHandle: HANDLE, out_lpMode: &DWORD) -> BOOL;
4040
41pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD;41pub extern "kernel32" stdcallcc fn GetCurrentDirectoryA(nBufferLength: WORD, lpBuffer: ?LPSTR) -> DWORD;
4242
...@@ -50,7 +50,7 @@ pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;...@@ -50,7 +50,7 @@ pub extern "kernel32" stdcallcc fn GetLastError() -> DWORD;
5050
51pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,51pub extern "kernel32" stdcallcc fn GetFileInformationByHandleEx(in_hFile: HANDLE,
52 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void,52 in_FileInformationClass: FILE_INFO_BY_HANDLE_CLASS, out_lpFileInformation: &c_void,
53 in_dwBufferSize: DWORD) -> bool;53 in_dwBufferSize: DWORD) -> BOOL;
5454
55pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR,55pub extern "kernel32" stdcallcc fn GetFinalPathNameByHandleA(hFile: HANDLE, lpszFilePath: LPSTR,
56 cchFilePath: DWORD, dwFlags: DWORD) -> DWORD;56 cchFilePath: DWORD, dwFlags: DWORD) -> DWORD;
...@@ -86,7 +86,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp...@@ -86,7 +86,7 @@ pub extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lp
8686
87pub const PROV_RSA_FULL = 1;87pub const PROV_RSA_FULL = 1;
8888
89pub const BOOL = bool;89pub const BOOL = c_int;
90pub const BOOLEAN = BYTE;90pub const BOOLEAN = BYTE;
91pub const BYTE = u8;91pub const BYTE = u8;
92pub const CHAR = u8;92pub const CHAR = u8;
...@@ -116,6 +116,9 @@ pub const UNICODE = false;...@@ -116,6 +116,9 @@ pub const UNICODE = false;
116pub const WCHAR = u16;116pub const WCHAR = u16;
117pub const WORD = u16;117pub const WORD = u16;
118118
119pub const TRUE = 1;
120pub const FALSE = 0;
121
119/// The standard input device. Initially, this is the console input buffer, CONIN$.122/// The standard input device. Initially, this is the console input buffer, CONIN$.
120pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;123pub const STD_INPUT_HANDLE = @maxValue(DWORD) - 10 + 1;
121124
std/os/windows/util.zig+5-5
...@@ -22,7 +22,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) ->...@@ -22,7 +22,7 @@ pub fn windowsWaitSingle(handle: windows.HANDLE, milliseconds: windows.DWORD) ->
22}22}
2323
24pub fn windowsClose(handle: windows.HANDLE) {24pub fn windowsClose(handle: windows.HANDLE) {
25 assert(windows.CloseHandle(handle));25 assert(windows.CloseHandle(handle) != 0);
26}26}
2727
28error SystemResources;28error SystemResources;
...@@ -31,7 +31,7 @@ error IoPending;...@@ -31,7 +31,7 @@ error IoPending;
31error BrokenPipe;31error BrokenPipe;
3232
33pub fn windowsWrite(handle: windows.HANDLE, bytes: []const u8) -> %void {33pub 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) {
35 return switch (windows.GetLastError()) {35 return switch (windows.GetLastError()) {
36 windows.ERROR.INVALID_USER_BUFFER => error.SystemResources,36 windows.ERROR.INVALID_USER_BUFFER => error.SystemResources,
37 windows.ERROR.NOT_ENOUGH_MEMORY => error.SystemResources,37 windows.ERROR.NOT_ENOUGH_MEMORY => error.SystemResources,
...@@ -49,15 +49,15 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool {...@@ -49,15 +49,15 @@ pub fn windowsIsTty(handle: windows.HANDLE) -> bool {
49 return true;49 return true;
5050
51 var out: windows.DWORD = undefined;51 var out: windows.DWORD = undefined;
52 return windows.GetConsoleMode(handle, &out);52 return windows.GetConsoleMode(handle, &out) != 0;
53}53}
5454
55pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {55pub fn windowsIsCygwinPty(handle: windows.HANDLE) -> bool {
56 const size = @sizeOf(windows.FILE_NAME_INFO);56 const size = @sizeOf(windows.FILE_NAME_INFO);
57 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);57 var name_info_bytes align(@alignOf(windows.FILE_NAME_INFO)) = []u8{0} ** (size + windows.MAX_PATH);
5858
59 if (!windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,59 if (windows.GetFileInformationByHandleEx(handle, windows.FileNameInfo,
60 @ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)))60 @ptrCast(&c_void, &name_info_bytes[0]), u32(name_info_bytes.len)) == 0)
61 {61 {
62 return true;62 return true;
63 }63 }