From 003db124e244d5001b0f74fc6b17a73d2553cf56 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Tue, 25 Aug 2009 17:46:07 -0500 Subject: [PATCH] use structs in process launcher --- basis/io/launcher/windows/nt/nt.factor | 10 ++--- basis/io/launcher/windows/windows.factor | 22 +++++------ basis/windows/kernel32/kernel32.factor | 48 ++++++++++++------------ 3 files changed, 40 insertions(+), 40 deletions(-) diff --git a/basis/io/launcher/windows/nt/nt.factor b/basis/io/launcher/windows/nt/nt.factor index e62373cbd7..16d9cbf6c9 100755 --- a/basis/io/launcher/windows/nt/nt.factor +++ b/basis/io/launcher/windows/nt/nt.factor @@ -85,7 +85,7 @@ IN: io.launcher.windows.nt : redirect-stderr ( process args -- handle ) over stderr>> +stdout+ eq? [ nip - lpStartupInfo>> STARTUPINFO-hStdOutput + lpStartupInfo>> hStdOutput>> ] [ drop stderr>> @@ -104,7 +104,7 @@ IN: io.launcher.windows.nt STD_INPUT_HANDLE GetStdHandle or ; M: winnt fill-redirection ( process args -- ) - [ 2dup redirect-stdout ] keep lpStartupInfo>> set-STARTUPINFO-hStdOutput - [ 2dup redirect-stderr ] keep lpStartupInfo>> set-STARTUPINFO-hStdError - [ 2dup redirect-stdin ] keep lpStartupInfo>> set-STARTUPINFO-hStdInput - 2drop ; + dup lpStartupInfo>> + [ [ redirect-stdout ] dip (>>hStdOutput) ] + [ [ redirect-stderr ] dip (>>hStdError) ] + [ [ redirect-stdin ] dip (>>hStdInput) ] 3tri ; diff --git a/basis/io/launcher/windows/windows.factor b/basis/io/launcher/windows/windows.factor index d17cd1ff80..45aeec0a80 100755 --- a/basis/io/launcher/windows/windows.factor +++ b/basis/io/launcher/windows/windows.factor @@ -7,7 +7,7 @@ namespaces make io.launcher kernel sequences windows.errors splitting system threads init strings combinators io.backend accessors concurrency.flags io.files assocs io.files.private windows destructors specialized-arrays.ushort -specialized-arrays.alien ; +specialized-arrays.alien classes classes.struct ; IN: io.launcher.windows TUPLE: CreateProcess-args @@ -24,9 +24,10 @@ TUPLE: CreateProcess-args : default-CreateProcess-args ( -- obj ) CreateProcess-args new - "STARTUPINFO" - "STARTUPINFO" heap-size over set-STARTUPINFO-cb >>lpStartupInfo - "PROCESS_INFORMATION" >>lpProcessInformation + STARTUPINFO + dup class heap-size >>cb + >>lpStartupInfo + PROCESS_INFORMATION >>lpProcessInformation TRUE >>bInheritHandles 0 >>dwCreateFlags ; @@ -108,7 +109,7 @@ TUPLE: CreateProcess-args ] when ; : fill-startup-info ( process args -- process args ) - STARTF_USESTDHANDLES over lpStartupInfo>> set-STARTUPINFO-dwFlags ; + dup lpStartupInfo>> STARTF_USESTDHANDLES >>dwFlags drop ; HOOK: fill-redirection io-backend ( process args -- ) @@ -136,17 +137,16 @@ M: windows run-process* ( process -- handle ) ] with-destructors ; M: windows kill-process* ( handle -- ) - PROCESS_INFORMATION-hProcess - 255 TerminateProcess win32-error=0/f ; + hProcess>> 255 TerminateProcess win32-error=0/f ; : dispose-process ( process-information -- ) #! From MSDN: "Handles in PROCESS_INFORMATION must be closed #! with CloseHandle when they are no longer needed." - dup PROCESS_INFORMATION-hProcess [ CloseHandle drop ] when* - PROCESS_INFORMATION-hThread [ CloseHandle drop ] when* ; + [ hProcess>> [ CloseHandle drop ] when* ] + [ hThread>> [ CloseHandle drop ] when* ] bi ; : exit-code ( process -- n ) - PROCESS_INFORMATION-hProcess + hProcess>> 0 [ GetExitCodeProcess ] keep *ulong swap win32-error=0/f ; @@ -157,7 +157,7 @@ M: windows kill-process* ( handle -- ) M: windows wait-for-processes ( -- ? ) processes get keys dup - [ handle>> PROCESS_INFORMATION-hProcess ] void*-array{ } map-as + [ handle>> hProcess>> ] void*-array{ } map-as [ length ] keep 0 0 WaitForMultipleObjects dup HEX: ffffffff = [ win32-error ] when diff --git a/basis/windows/kernel32/kernel32.factor b/basis/windows/kernel32/kernel32.factor index 65425c2685..2e8be04717 100755 --- a/basis/windows/kernel32/kernel32.factor +++ b/basis/windows/kernel32/kernel32.factor @@ -239,33 +239,33 @@ STRUCT: FILETIME { dwLowDateTime DWORD } { dwHighDateTime DWORD } ; -C-STRUCT: STARTUPINFO - { "DWORD" "cb" } - { "LPTSTR" "lpReserved" } - { "LPTSTR" "lpDesktop" } - { "LPTSTR" "lpTitle" } - { "DWORD" "dwX" } - { "DWORD" "dwY" } - { "DWORD" "dwXSize" } - { "DWORD" "dwYSize" } - { "DWORD" "dwXCountChars" } - { "DWORD" "dwYCountChars" } - { "DWORD" "dwFillAttribute" } - { "DWORD" "dwFlags" } - { "WORD" "wShowWindow" } - { "WORD" "cbReserved2" } - { "LPBYTE" "lpReserved2" } - { "HANDLE" "hStdInput" } - { "HANDLE" "hStdOutput" } - { "HANDLE" "hStdError" } ; +STRUCT: STARTUPINFO + { cb DWORD } + { lpReserved LPTSTR } + { lpDesktop LPTSTR } + { lpTitle LPTSTR } + { dwX DWORD } + { dwY DWORD } + { dwXSize DWORD } + { dwYSize DWORD } + { dwXCountChars DWORD } + { dwYCountChars DWORD } + { dwFillAttribute DWORD } + { dwFlags DWORD } + { wShowWindow WORD } + { cbReserved2 WORD } + { lpReserved2 LPBYTE } + { hStdInput HANDLE } + { hStdOutput HANDLE } + { hStdError HANDLE } ; TYPEDEF: void* LPSTARTUPINFO -C-STRUCT: PROCESS_INFORMATION - { "HANDLE" "hProcess" } - { "HANDLE" "hThread" } - { "DWORD" "dwProcessId" } - { "DWORD" "dwThreadId" } ; +STRUCT: PROCESS_INFORMATION + { hProcess HANDLE } + { hThread HANDLE } + { dwProcessId DWORD } + { dwThreadId DWORD } ; C-STRUCT: SYSTEM_INFO { "DWORD" "dwOemId" } -- 2.34.1