Use destructors in io.unix.mmap
parent
7ac5747de8
commit
58e4106a27
|
@ -1,22 +1,25 @@
|
||||||
! Copyright (C) 2007 Doug Coleman.
|
! Copyright (C) 2007 Doug Coleman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien io io.files kernel math system unix io.unix.backend
|
USING: alien io io.files kernel math system unix io.unix.backend
|
||||||
io.mmap ;
|
io.mmap destructors ;
|
||||||
IN: io.unix.mmap
|
IN: io.unix.mmap
|
||||||
|
|
||||||
: open-r/w ( path -- fd ) O_RDWR file-mode open-file ;
|
: open-r/w ( path -- fd ) O_RDWR file-mode open-file ;
|
||||||
|
|
||||||
: mmap-open ( length prot flags path -- alien fd )
|
: mmap-open ( length prot flags path -- alien fd )
|
||||||
>r f -roll r> open-r/w [ 0 mmap ] keep
|
[
|
||||||
over MAP_FAILED = [ close-file (io-error) ] when ;
|
>r f -roll r> open-r/w dup close-later
|
||||||
|
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
|
||||||
|
] with-destructors ;
|
||||||
|
|
||||||
M: unix (mapped-file) ( path length -- obj )
|
M: unix (mapped-file) ( path length -- obj )
|
||||||
swap >r
|
swap >r
|
||||||
dup PROT_READ PROT_WRITE bitor MAP_FILE MAP_SHARED bitor
|
dup
|
||||||
|
PROT_READ PROT_WRITE bitor
|
||||||
|
MAP_FILE MAP_SHARED bitor
|
||||||
r> mmap-open f mapped-file boa ;
|
r> mmap-open f mapped-file boa ;
|
||||||
|
|
||||||
M: unix close-mapped-file ( mmap -- )
|
M: unix close-mapped-file ( mmap -- )
|
||||||
[ mapped-file-address ] keep
|
[ [ address>> ] [ length>> ] bi munmap io-error ]
|
||||||
[ mapped-file-length munmap ] keep
|
[ handle>> close-file ]
|
||||||
mapped-file-handle close-file
|
bi ;
|
||||||
io-error ;
|
|
||||||
|
|
Loading…
Reference in New Issue