From 709e35a392a9214888e448f419efc4f34e00fe28 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 05:40:00 -0500 Subject: [PATCH 1/7] Add the 'unix-system-call' macro --- extra/unix/system-call/system-call.factor | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 extra/unix/system-call/system-call.factor diff --git a/extra/unix/system-call/system-call.factor b/extra/unix/system-call/system-call.factor new file mode 100644 index 0000000000..5a77693ed7 --- /dev/null +++ b/extra/unix/system-call/system-call.factor @@ -0,0 +1,15 @@ + +USING: kernel continuations sequences math accessors inference macros + fry arrays.lib unix ; + +IN: unix.system-call + +ERROR: unix-system-call-error word args message ; + +MACRO: unix-system-call ( quot -- ) + [ ] [ infer in>> ] [ first ] tri + '[ + [ @ dup 0 < [ dup throw ] [ ] if ] + [ drop , narray , swap err_no strerror unix-system-call-error ] + recover + ] ; From 8e341475fe4f562919e73bee6e5f360a86409c5d Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 05:41:00 -0500 Subject: [PATCH 2/7] unix: Convert a couple of words to the 'unix-system-call' macro --- extra/unix/unix.factor | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index fcbd96177b..ad8b5711b8 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -2,8 +2,8 @@ ! See http://factorcode.org/license.txt for BSD license. USING: alien alien.c-types alien.syntax kernel libc structs - math namespaces system combinators vocabs.loader unix.ffi unix.types - qualified ; + math namespaces system combinators vocabs.loader qualified + unix.ffi unix.types unix.system-call ; QUALIFIED: unix.ffi @@ -80,17 +80,9 @@ FUNCTION: uint ntohl ( uint n ) ; FUNCTION: ushort ntohs ( ushort n ) ; FUNCTION: char* strerror ( int errno ) ; -ERROR: open-error path flags prot message ; +: open ( path flags prot -- int ) [ unix.ffi:open ] unix-system-call ; -: open ( path flags prot -- int ) - 3dup unix.ffi:open - dup 0 >= [ >r 3drop r> ] [ drop err_no strerror open-error ] if ; - -ERROR: utime-error path message ; - -: utime ( path buf -- ) - dupd unix.ffi:utime - 0 = [ drop ] [ err_no strerror utime-error ] if ; +: utime ( path buf -- ) [ unix.ffi:utime ] unix-system-call drop ; FUNCTION: int pclose ( void* file ) ; FUNCTION: int pipe ( int* filedes ) ; From 6da3e88de5b8c01135c23b4ba418296829207e02 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 06:12:54 -0500 Subject: [PATCH 3/7] Move error words from unix to unix.ffi --- extra/unix/ffi/ffi.factor | 5 ++++- extra/unix/unix.factor | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/extra/unix/ffi/ffi.factor b/extra/unix/ffi/ffi.factor index ec3daab880..e39d95dfa3 100644 --- a/extra/unix/ffi/ffi.factor +++ b/extra/unix/ffi/ffi.factor @@ -9,4 +9,7 @@ C-STRUCT: utimbuf { "time_t" "actime" } { "time_t" "modtime" } ; -FUNCTION: int utime ( char* path, utimebuf* buf ) ; \ No newline at end of file +FUNCTION: int utime ( char* path, utimebuf* buf ) ; + +FUNCTION: int err_no ( ) ; +FUNCTION: char* strerror ( int errno ) ; \ No newline at end of file diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index ad8b5711b8..96c5c7bf66 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -29,7 +29,7 @@ TYPEDEF: ulong size_t ! ! ! Unix functions LIBRARY: factor -FUNCTION: int err_no ( ) ; +! FUNCTION: int err_no ( ) ; FUNCTION: void clear_err_no ( ) ; LIBRARY: libc @@ -78,7 +78,7 @@ FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_ FUNCTION: int munmap ( void* addr, size_t len ) ; FUNCTION: uint ntohl ( uint n ) ; FUNCTION: ushort ntohs ( ushort n ) ; -FUNCTION: char* strerror ( int errno ) ; +! FUNCTION: char* strerror ( int errno ) ; : open ( path flags prot -- int ) [ unix.ffi:open ] unix-system-call ; From 4aacf9b3e9dc423e198e929f1b60168e3d257281 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 06:13:44 -0500 Subject: [PATCH 4/7] Update USING: --- extra/io/unix/backend/backend.factor | 2 +- extra/io/unix/sockets/sockets.factor | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extra/io/unix/backend/backend.factor b/extra/io/unix/backend/backend.factor index 08ff526f14..902af8fe0d 100644 --- a/extra/io/unix/backend/backend.factor +++ b/extra/io/unix/backend/backend.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2004, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: alien generic assocs kernel kernel.private math -io.nonblocking sequences strings structs sbufs threads unix +io.nonblocking sequences strings structs sbufs threads unix.ffi unix vectors io.buffers io.backend io.encodings math.parser continuations system libc qualified namespaces io.timeouts io.encodings.utf8 accessors ; diff --git a/extra/io/unix/sockets/sockets.factor b/extra/io/unix/sockets/sockets.factor index b60cb5760e..71edbc5500 100755 --- a/extra/io/unix/sockets/sockets.factor +++ b/extra/io/unix/sockets/sockets.factor @@ -5,7 +5,7 @@ namespaces threads sequences byte-arrays io.nonblocking io.binary io.unix.backend io.streams.duplex io.sockets.impl io.backend io.files io.files.private io.encodings.utf8 math.parser continuations libc combinators system accessors -qualified unix ; +qualified unix.ffi unix ; EXCLUDE: io => read write close ; EXCLUDE: io.sockets => accept ; From 0c1801d213c30db6ab7a6a71c95e87acbfcf036a Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 06:14:08 -0500 Subject: [PATCH 5/7] unix.system-call: Fix circularity --- extra/unix/system-call/system-call.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/unix/system-call/system-call.factor b/extra/unix/system-call/system-call.factor index 5a77693ed7..f1a6f8811e 100644 --- a/extra/unix/system-call/system-call.factor +++ b/extra/unix/system-call/system-call.factor @@ -1,6 +1,6 @@ USING: kernel continuations sequences math accessors inference macros - fry arrays.lib unix ; + fry arrays.lib unix.ffi ; IN: unix.system-call From d1775f9bfa02d81aaf4f59d2b0c64a46ff873584 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 06:36:43 -0500 Subject: [PATCH 6/7] io.unix.kqueue: Fix using --- extra/io/unix/kqueue/kqueue.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 extra/io/unix/kqueue/kqueue.factor diff --git a/extra/io/unix/kqueue/kqueue.factor b/extra/io/unix/kqueue/kqueue.factor old mode 100644 new mode 100755 index 8e8fb0ec74..ec82a426d3 --- a/extra/io/unix/kqueue/kqueue.factor +++ b/extra/io/unix/kqueue/kqueue.factor @@ -3,7 +3,7 @@ USING: alien.c-types kernel math math.bitfields namespaces locals accessors combinators threads vectors hashtables sequences assocs continuations sets -unix unix.time unix.kqueue unix.process +unix.ffi unix unix.time unix.kqueue unix.process io.nonblocking io.unix.backend io.launcher io.unix.launcher io.monitors ; IN: io.unix.kqueue From a9bc2309ea0ffaff763b7ede8e9ebca90d319452 Mon Sep 17 00:00:00 2001 From: Eduardo Cavazos Date: Sat, 10 May 2008 09:10:16 -0500 Subject: [PATCH 7/7] unix: Minor cleanups --- extra/unix/system-call/system-call.factor | 12 ++++++------ extra/unix/unix.factor | 2 -- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/extra/unix/system-call/system-call.factor b/extra/unix/system-call/system-call.factor index f1a6f8811e..bfcb9ae6ea 100644 --- a/extra/unix/system-call/system-call.factor +++ b/extra/unix/system-call/system-call.factor @@ -7,9 +7,9 @@ IN: unix.system-call ERROR: unix-system-call-error word args message ; MACRO: unix-system-call ( quot -- ) - [ ] [ infer in>> ] [ first ] tri - '[ - [ @ dup 0 < [ dup throw ] [ ] if ] - [ drop , narray , swap err_no strerror unix-system-call-error ] - recover - ] ; + [ ] [ infer in>> ] [ first ] tri + '[ + [ @ dup 0 < [ dup throw ] [ ] if ] + [ drop , narray , swap err_no strerror unix-system-call-error ] + recover + ] ; diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index 96c5c7bf66..e00a2e068a 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -29,7 +29,6 @@ TYPEDEF: ulong size_t ! ! ! Unix functions LIBRARY: factor -! FUNCTION: int err_no ( ) ; FUNCTION: void clear_err_no ( ) ; LIBRARY: libc @@ -78,7 +77,6 @@ FUNCTION: void* mmap ( void* addr, size_t len, int prot, int flags, int fd, off_ FUNCTION: int munmap ( void* addr, size_t len ) ; FUNCTION: uint ntohl ( uint n ) ; FUNCTION: ushort ntohs ( ushort n ) ; -! FUNCTION: char* strerror ( int errno ) ; : open ( path flags prot -- int ) [ unix.ffi:open ] unix-system-call ;