Fix bugs in unix ffi usage

db4
Erik Charlebois 2011-05-19 18:45:39 -04:00
parent 91e94a8438
commit 662bc3b07b
3 changed files with 8 additions and 5 deletions

View File

@ -3,7 +3,7 @@
USING: alien.data kernel bit-arrays sequences assocs math USING: alien.data kernel bit-arrays sequences assocs math
namespaces accessors math.order locals fry io.ports namespaces accessors math.order locals fry io.ports
io.backend.unix io.backend.unix.multiplexers unix unix.ffi io.backend.unix io.backend.unix.multiplexers unix unix.ffi
unix.time ; unix.time layouts ;
IN: io.backend.unix.multiplexers.select IN: io.backend.unix.multiplexers.select
TUPLE: select-mx < mx read-fdset write-fdset ; TUPLE: select-mx < mx read-fdset write-fdset ;
@ -12,7 +12,9 @@ TUPLE: select-mx < mx read-fdset write-fdset ;
! FD_SET to be an array of cells, so we have to account for ! FD_SET to be an array of cells, so we have to account for
! byte order differences on big endian platforms ! byte order differences on big endian platforms
: munge ( i -- i' ) : munge ( i -- i' )
little-endian? [ BIN: 11000 bitxor ] unless ; inline little-endian? [
cell 4 = [ BIN: 11000 ] [ BIN: 111000 ] if
bitxor ] unless ; inline
: <select-mx> ( -- mx ) : <select-mx> ( -- mx )
select-mx new-mx select-mx new-mx

View File

@ -146,7 +146,7 @@ M: stdin dispose*
: wait-for-stdin ( stdin -- size ) : wait-for-stdin ( stdin -- size )
[ control>> CHAR: X over io:stream-write1 io:stream-flush ] [ control>> CHAR: X over io:stream-write1 io:stream-flush ]
[ size>> ssize_t heap-size swap io:stream-read int deref ] [ size>> ssize_t heap-size swap io:stream-read ssize_t deref ]
bi ; bi ;
:: refill-stdin ( buffer stdin size -- ) :: refill-stdin ( buffer stdin size -- )

View File

@ -5,7 +5,7 @@ combinators continuations destructors fry io io.backend
io.backend.unix io.directories io.encodings.binary io.backend.unix io.directories io.encodings.binary
io.encodings.utf8 io.files io.pathnames io.files.types kernel io.encodings.utf8 io.files io.pathnames io.files.types kernel
math.bitwise sequences system unix unix.stat vocabs.loader math.bitwise sequences system unix unix.stat vocabs.loader
classes.struct unix.ffi literals ; classes.struct unix.ffi literals libc ;
IN: io.directories.unix IN: io.directories.unix
CONSTANT: touch-mode flags{ O_WRONLY O_APPEND O_CREAT O_EXCL } CONSTANT: touch-mode flags{ O_WRONLY O_APPEND O_CREAT O_EXCL }
@ -39,7 +39,8 @@ HOOK: find-next-file os ( DIR* -- byte-array )
M: unix find-next-file ( DIR* -- byte-array ) M: unix find-next-file ( DIR* -- byte-array )
dirent <struct> dirent <struct>
f void* <ref> f void* <ref>
[ readdir_r 0 = [ (io-error) ] unless ] 2keep 0 set-errno
[ readdir_r 0 = [ errno 0 = [ (io-error) ] unless ] unless ] 2keep
void* deref [ drop f ] unless ; void* deref [ drop f ] unless ;
: dirent-type>file-type ( ch -- type ) : dirent-type>file-type ( ch -- type )