]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/io/launcher/unix/unix.factor
Updating code to use with-out-parameters
[factor.git] / basis / io / launcher / unix / unix.factor
index aaaccd4719e1d9b92a32324763a33da2459accdc..e036f34cc600bb1bde297bb206259867791b92d5 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2007, 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien.c-types arrays assocs combinators
-continuations environment io io.backend io.backend.unix
-io.files io.files.private io.files.unix io.launcher io.pathnames
-io.ports kernel math namespaces sequences strings system threads
-unix unix.process unix.ffi simple-tokenizer ;
+USING: accessors alien.c-types alien.data arrays assocs
+combinators continuations environment io io.backend
+io.backend.unix io.files io.files.private io.files.unix
+io.launcher io.pathnames io.ports kernel math namespaces
+sequences strings system threads unix unix.process unix.ffi
+simple-tokenizer ;
 IN: io.launcher.unix
 
 : get-arguments ( process -- seq )
@@ -68,12 +69,13 @@ IN: io.launcher.unix
     ] when ;
 
 : spawn-process ( process -- * )
-    [ setup-priority ] [ 250 _exit ] recover
-    [ setup-redirection ] [ 251 _exit ] recover
-    [ current-directory get absolute-path cd ] [ 252 _exit ] recover
-    [ setup-environment ] [ 253 _exit ] recover
-    [ get-arguments exec-args-with-path ] [ 254 _exit ] recover
-    255 _exit ;
+    [ setup-priority ] [ 2drop 250 _exit ] recover
+    [ setup-redirection ] [ 2drop 251 _exit ] recover
+    [ current-directory get absolute-path cd ] [ 2drop 252 _exit ] recover
+    [ setup-environment ] [ 2drop 253 _exit ] recover
+    [ get-arguments exec-args-with-path ] [ 2drop 254 _exit ] recover
+    255 _exit
+    f throw ;
 
 M: unix current-process-handle ( -- handle ) getpid ;
 
@@ -93,10 +95,10 @@ TUPLE: signal n ;
     dup WIFSIGNALED [ WTERMSIG signal boa ] [ WEXITSTATUS ] if ;
 
 M: unix wait-for-processes ( -- ? )
-    0 <int> -1 over WNOHANG waitpid
-    dup 0 <= [
+    { int } [ -1 swap WNOHANG waitpid ] [ ] with-out-parameters
+    swap dup 0 <= [
         2drop t
     ] [
         find-process dup
-        [ swap *int code>status notify-exit f ] [ 2drop f ] if
+        [ swap code>status notify-exit f ] [ 2drop f ] if
     ] if ;