Merge branch 'master' of git://factorcode.org/git/factor
commit
d875033986
|
@ -1,6 +1,6 @@
|
||||||
USING: io io.mmap io.mmap.char io.files io.files.temp
|
USING: io io.mmap io.mmap.char io.files io.files.temp
|
||||||
io.directories kernel tools.test continuations sequences
|
io.directories kernel tools.test continuations sequences
|
||||||
io.encodings.ascii accessors ;
|
io.encodings.ascii accessors math ;
|
||||||
IN: io.mmap.tests
|
IN: io.mmap.tests
|
||||||
|
|
||||||
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
||||||
|
@ -9,3 +9,23 @@ IN: io.mmap.tests
|
||||||
[ 5 ] [ "mmap-test-file.txt" temp-file [ length ] with-mapped-char-file ] unit-test
|
[ 5 ] [ "mmap-test-file.txt" temp-file [ length ] with-mapped-char-file ] unit-test
|
||||||
[ "22345" ] [ "mmap-test-file.txt" temp-file ascii file-contents ] unit-test
|
[ "22345" ] [ "mmap-test-file.txt" temp-file ascii file-contents ] unit-test
|
||||||
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
[ "mmap-test-file.txt" temp-file delete-file ] ignore-errors
|
||||||
|
|
||||||
|
|
||||||
|
[ ]
|
||||||
|
[ "mmap-empty-file.txt" temp-file touch-file ] unit-test
|
||||||
|
|
||||||
|
! Test for leaking resources bug on Unix
|
||||||
|
[ ]
|
||||||
|
[
|
||||||
|
100000 [
|
||||||
|
[
|
||||||
|
"mmap-empty-file.txt" temp-file [
|
||||||
|
drop
|
||||||
|
] with-mapped-file
|
||||||
|
] [ dup bad-mmap-size? [ drop ] [ rethrow ] if ] recover
|
||||||
|
] times
|
||||||
|
|
||||||
|
"asdf" "mmap-asdf-file.txt" temp-file [ ascii set-file-contents ] keep [
|
||||||
|
drop
|
||||||
|
] with-mapped-file
|
||||||
|
] unit-test
|
||||||
|
|
|
@ -2,15 +2,20 @@
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: continuations destructors io.files io.files.info
|
USING: continuations destructors io.files io.files.info
|
||||||
io.backend kernel quotations system alien alien.accessors
|
io.backend kernel quotations system alien alien.accessors
|
||||||
accessors system vocabs.loader combinators alien.c-types ;
|
accessors system vocabs.loader combinators alien.c-types
|
||||||
|
math ;
|
||||||
IN: io.mmap
|
IN: io.mmap
|
||||||
|
|
||||||
TUPLE: mapped-file address handle length disposed ;
|
TUPLE: mapped-file address handle length disposed ;
|
||||||
|
|
||||||
HOOK: (mapped-file) os ( path length -- address handle )
|
HOOK: (mapped-file) os ( path length -- address handle )
|
||||||
|
|
||||||
|
ERROR: bad-mmap-size path size ;
|
||||||
|
|
||||||
: <mapped-file> ( path -- mmap )
|
: <mapped-file> ( path -- mmap )
|
||||||
[ normalize-path ] [ file-info size>> ] bi [ (mapped-file) ] keep
|
[ normalize-path ] [ file-info size>> ] bi
|
||||||
|
dup 0 <= [ bad-mmap-size ] when
|
||||||
|
[ (mapped-file) ] keep
|
||||||
f mapped-file boa ;
|
f mapped-file boa ;
|
||||||
|
|
||||||
HOOK: close-mapped-file io-backend ( mmap -- )
|
HOOK: close-mapped-file io-backend ( mmap -- )
|
||||||
|
|
|
@ -9,7 +9,7 @@ IN: io.mmap.unix
|
||||||
:: mmap-open ( path length prot flags -- alien fd )
|
:: mmap-open ( path length prot flags -- alien fd )
|
||||||
[
|
[
|
||||||
f length prot flags
|
f length prot flags
|
||||||
path open-r/w |dispose
|
path open-r/w [ <fd> |dispose drop ] keep
|
||||||
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
|
[ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep
|
||||||
] with-destructors ;
|
] with-destructors ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue