mirror of
https://github.com/odin-lang/Odin.git
synced 2026-01-04 12:07:45 +00:00
don't need to hang on to the null handle
This commit is contained in:
@@ -266,8 +266,6 @@ specific process, even after it has died.
|
||||
Process :: struct {
|
||||
pid: int,
|
||||
handle: uintptr,
|
||||
// Implementation specific state/data.
|
||||
_impl: _Process,
|
||||
}
|
||||
|
||||
Process_Open_Flags :: bit_set[Process_Open_Flag]
|
||||
|
||||
@@ -362,9 +362,6 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
||||
return _process_info_by_pid(get_pid(), selection, allocator)
|
||||
}
|
||||
|
||||
@(private="package")
|
||||
_Process :: struct {}
|
||||
|
||||
@(private="package")
|
||||
_process_open :: proc(pid: int, _: Process_Open_Flags) -> (process: Process, err: Error) {
|
||||
process.pid = pid
|
||||
|
||||
@@ -46,8 +46,6 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
||||
return _process_info_by_pid(_get_pid(), selection, allocator)
|
||||
}
|
||||
|
||||
_Process :: struct {}
|
||||
|
||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||
if len(desc.command) == 0 {
|
||||
err = .Invalid_Path
|
||||
|
||||
@@ -44,8 +44,6 @@ _current_process_info :: proc(selection: Process_Info_Fields, allocator: runtime
|
||||
return
|
||||
}
|
||||
|
||||
_Process :: struct {}
|
||||
|
||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||
err = .Unsupported
|
||||
return
|
||||
|
||||
@@ -417,11 +417,6 @@ _process_open :: proc(pid: int, flags: Process_Open_Flags) -> (process: Process,
|
||||
return
|
||||
}
|
||||
|
||||
@(private="package")
|
||||
_Process :: struct {
|
||||
null_handle: win32.HANDLE,
|
||||
}
|
||||
|
||||
@(private="package")
|
||||
_process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||
TEMP_ALLOCATOR_GUARD()
|
||||
@@ -438,8 +433,9 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||
stdout_handle: win32.HANDLE
|
||||
stdin_handle: win32.HANDLE
|
||||
|
||||
null_handle: win32.HANDLE
|
||||
if desc.stdout == nil || desc.stderr == nil || desc.stdin == nil {
|
||||
process._impl.null_handle = win32.CreateFileW(
|
||||
null_handle = win32.CreateFileW(
|
||||
win32.L("NUL"),
|
||||
win32.GENERIC_READ|win32.GENERIC_WRITE,
|
||||
win32.FILE_SHARE_READ|win32.FILE_SHARE_WRITE,
|
||||
@@ -451,23 +447,29 @@ _process_start :: proc(desc: Process_Desc) -> (process: Process, err: Error) {
|
||||
win32.FILE_ATTRIBUTE_NORMAL,
|
||||
nil,
|
||||
)
|
||||
assert(process._impl.null_handle != nil)
|
||||
// Opening NUL should always succeed.
|
||||
assert(null_handle != nil)
|
||||
}
|
||||
// NOTE(laytan): I believe it is fine to close this handle right after CreateProcess,
|
||||
// and we don't have to hold onto this until the process exits.
|
||||
defer if null_handle != nil {
|
||||
win32.CloseHandle(null_handle)
|
||||
}
|
||||
|
||||
if desc.stdout == nil {
|
||||
stdout_handle = process._impl.null_handle
|
||||
stdout_handle = null_handle
|
||||
} else {
|
||||
stdout_handle = win32.HANDLE((^File_Impl)(desc.stdout.impl).fd)
|
||||
}
|
||||
|
||||
if desc.stderr == nil {
|
||||
stderr_handle = process._impl.null_handle
|
||||
stderr_handle = null_handle
|
||||
} else {
|
||||
stderr_handle = win32.HANDLE((^File_Impl)(desc.stderr.impl).fd)
|
||||
}
|
||||
|
||||
if desc.stdin == nil {
|
||||
stdin_handle = process._impl.null_handle
|
||||
stdin_handle = null_handle
|
||||
} else {
|
||||
stdin_handle = win32.HANDLE((^File_Impl)(desc.stdin.impl).fd)
|
||||
}
|
||||
@@ -507,10 +509,6 @@ _process_wait :: proc(process: Process, timeout: time.Duration) -> (process_stat
|
||||
|
||||
switch win32.WaitForSingleObject(handle, timeout_ms) {
|
||||
case win32.WAIT_OBJECT_0:
|
||||
if process._impl.null_handle != nil {
|
||||
win32.CloseHandle(process._impl.null_handle)
|
||||
}
|
||||
|
||||
exit_code: u32
|
||||
if !win32.GetExitCodeProcess(handle, &exit_code) {
|
||||
err =_get_platform_error()
|
||||
@@ -537,10 +535,6 @@ _process_wait :: proc(process: Process, timeout: time.Duration) -> (process_stat
|
||||
err = General_Error.Timeout
|
||||
return
|
||||
case:
|
||||
if process._impl.null_handle != nil {
|
||||
win32.CloseHandle(process._impl.null_handle)
|
||||
}
|
||||
|
||||
err = _get_platform_error()
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user