]> gitweb.factorcode.org Git - factor.git/commitdiff
use structs in process launcher
authorDoug Coleman <doug.coleman@gmail.com>
Tue, 25 Aug 2009 22:46:07 +0000 (17:46 -0500)
committerDoug Coleman <doug.coleman@gmail.com>
Tue, 25 Aug 2009 22:46:07 +0000 (17:46 -0500)
basis/io/launcher/windows/nt/nt.factor
basis/io/launcher/windows/windows.factor
basis/windows/kernel32/kernel32.factor

index e62373cbd7a9ee0def201fbadfead900a2092b63..16d9cbf6c9975cb480ef1cd124f1030a321d247c 100755 (executable)
@@ -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 ;
index d17cd1ff805965297df3a60c50185c9cc693ad3a..45aeec0a8098c1d3241df78643f402de5984a5d8 100755 (executable)
@@ -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" <c-object>
-    "STARTUPINFO" heap-size over set-STARTUPINFO-cb >>lpStartupInfo
-    "PROCESS_INFORMATION" <c-object> >>lpProcessInformation
+        STARTUPINFO <struct>
+        dup class heap-size >>cb
+    >>lpStartupInfo
+    PROCESS_INFORMATION <struct> >>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 <ulong> [ 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
index 65425c2685c5dde0af754a660fd7f24d180e36a9..2e8be04717b0a5260cee2c7fced16c321866c442 100755 (executable)
@@ -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" }