From f24bf512890bc009b47f54113e395eada3510606 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 25 Apr 2009 16:52:23 -0500 Subject: [PATCH 1/9] mason: some fixes --- extra/mason/notify/notify.factor | 4 ++-- extra/mason/report/report.factor | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/extra/mason/notify/notify.factor b/extra/mason/notify/notify.factor index 6bf4ae090d..96e31c4a45 100644 --- a/extra/mason/notify/notify.factor +++ b/extra/mason/notify/notify.factor @@ -2,7 +2,7 @@ ! See http://factorcode.org/license.txt for BSD license. USING: arrays accessors io io.sockets io.encodings.utf8 io.files io.launcher kernel make mason.config mason.common mason.email -mason.twitter namespaces sequences ; +mason.twitter namespaces sequences prettyprint ; IN: mason.notify : status-notify ( input-file args -- ) @@ -38,7 +38,7 @@ IN: mason.notify f { "test" } status-notify ; : notify-report ( status -- ) - [ "Build finished with status: " write print flush ] + [ "Build finished with status: " write . flush ] [ [ "report" utf8 file-contents ] dip email-report "report" { "report" } status-notify diff --git a/extra/mason/report/report.factor b/extra/mason/report/report.factor index edc8416235..64d31b4368 100644 --- a/extra/mason/report/report.factor +++ b/extra/mason/report/report.factor @@ -28,7 +28,7 @@ IN: mason.report common-report _ call( -- xml ) [XML <-><-> XML] - pprint-xml + write-xml ] with-file-writer ; inline :: failed-report ( error file what -- status ) From 66b4d42e133a412bbf6f844fab4168ed16804440 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sat, 25 Apr 2009 17:03:50 -0500 Subject: [PATCH 2/9] math.blas: use gfortran by default on linux-x86-64 since latest ubuntu blas packages are compiled with gfortran abi --- basis/math/blas/config/config.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/math/blas/config/config.factor b/basis/math/blas/config/config.factor index 327c546963..09f736c036 100644 --- a/basis/math/blas/config/config.factor +++ b/basis/math/blas/config/config.factor @@ -18,7 +18,7 @@ blas-fortran-abi [ { [ os netbsd? cpu x86.64? and ] [ g95-abi ] } { [ os windows? cpu x86.64? and ] [ gfortran-abi ] } { [ os freebsd? ] [ gfortran-abi ] } - { [ os linux? cpu x86.32? and ] [ gfortran-abi ] } + { [ os linux? ] [ gfortran-abi ] } [ f2c-abi ] } cond ] initialize From 2330ec3042f986abd8714837ca359563ad5f6c55 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 18:59:03 -0500 Subject: [PATCH 3/9] use ui.images drawing code in images.viewer --- extra/images/viewer/viewer.factor | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/extra/images/viewer/viewer.factor b/extra/images/viewer/viewer.factor index cf9e9c836a..2818c16f9f 100644 --- a/extra/images/viewer/viewer.factor +++ b/extra/images/viewer/viewer.factor @@ -2,33 +2,26 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors images images.loader io.pathnames kernel namespaces opengl opengl.gl opengl.textures sequences strings ui ui.gadgets -ui.gadgets.panes ui.render ; +ui.gadgets.panes ui.render ui.images ; IN: images.viewer -TUPLE: image-gadget < gadget { image image } ; +TUPLE: image-gadget < gadget image-name ; M: image-gadget pref-dim* - image>> dim>> ; - -: draw-image ( image -- ) - 0 0 glRasterPos2i 1.0 -1.0 glPixelZoom - [ dim>> first2 ] [ component-order>> component-order>format ] [ bitmap>> ] tri - glDrawPixels ; + image-name>> image-dim ; M: image-gadget draw-gadget* ( gadget -- ) - image>> draw-image ; + image-name>> draw-image ; -: ( image -- gadget ) +: ( image-name -- gadget ) \ image-gadget new - swap >>image ; + swap >>image-name ; : image-window ( path -- gadget ) - [ load-image dup ] [ open-window ] bi ; + [ dup ] [ open-window ] bi ; GENERIC: image. ( object -- ) -M: string image. ( image -- ) load-image image. ; +M: string image. ( image -- ) gadget. ; -M: pathname image. ( image -- ) load-image image. ; - -M: image image. ( image -- ) gadget. ; +M: pathname image. ( image -- ) gadget. ; From 2484ea07b0f7de236bbb5260116a8243f35ea453 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 19:22:00 -0500 Subject: [PATCH 4/9] support read-only mmap --- basis/io/mmap/functor/functor.factor | 12 ++++++++---- basis/io/mmap/mmap-docs.factor | 8 +++++++- basis/io/mmap/mmap.factor | 24 ++++++++++++++++++++---- basis/io/mmap/unix/unix.factor | 7 ++++++- basis/io/mmap/windows/windows.factor | 11 ++++++++++- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/basis/io/mmap/functor/functor.factor b/basis/io/mmap/functor/functor.factor index 21b3d294c9..a80ce3bc82 100644 --- a/basis/io/mmap/functor/functor.factor +++ b/basis/io/mmap/functor/functor.factor @@ -9,13 +9,14 @@ SLOT: length : mapped-file>direct ( mapped-file type -- alien length ) [ [ address>> ] [ length>> ] bi ] dip - heap-size [ 1- + ] keep /i ; + heap-size [ 1 - + ] keep /i ; FUNCTOR: define-mapped-array ( T -- ) - DEFINES - IS -with-mapped-A-file DEFINES with-mapped-${T}-file + DEFINES + IS +with-mapped-A-file DEFINES with-mapped-${T}-file +with-mapped-A-file-reader DEFINES with-mapped-${T}-file-reader WHERE @@ -25,4 +26,7 @@ WHERE : with-mapped-A-file ( path quot -- ) '[ @ ] with-mapped-file ; inline +: with-mapped-A-file-reader ( path quot -- ) + '[ @ ] with-mapped-file-reader ; inline + ;FUNCTOR diff --git a/basis/io/mmap/mmap-docs.factor b/basis/io/mmap/mmap-docs.factor index f0adb47321..1da82e42e2 100644 --- a/basis/io/mmap/mmap-docs.factor +++ b/basis/io/mmap/mmap-docs.factor @@ -18,7 +18,13 @@ HELP: HELP: with-mapped-file { $values { "path" "a pathname string" } { "quot" { $quotation "( mmap -- )" } } } -{ $contract "Opens a file and maps its contents into memory, passing the " { $link mapped-file } " instance to the quotation. The mapped file is disposed of when the quotation returns, or if an error is thrown." } +{ $contract "Opens a file for read/write access and maps its contents into memory, passing the " { $link mapped-file } " instance to the quotation. The mapped file is disposed of when the quotation returns, or if an error is thrown." } +{ $notes "This is a low-level word, because " { $link mapped-file } " objects simply expose their base address and length. Most applications should use " { $link "io.mmap.arrays" } " instead." } +{ $errors "Throws an error if a memory mapping could not be established." } ; + +HELP: with-mapped-file-reader +{ $values { "path" "a pathname string" } { "quot" { $quotation "( mmap -- )" } } } +{ $contract "Opens a file for read-only access and maps its contents into memory, passing the " { $link mapped-file } " instance to the quotation. The mapped file is disposed of when the quotation returns, or if an error is thrown." } { $notes "This is a low-level word, because " { $link mapped-file } " objects simply expose their base address and length. Most applications should use " { $link "io.mmap.arrays" } " instead." } { $errors "Throws an error if a memory mapping could not be established." } ; diff --git a/basis/io/mmap/mmap.factor b/basis/io/mmap/mmap.factor index 1a58471514..e03d5fb30b 100644 --- a/basis/io/mmap/mmap.factor +++ b/basis/io/mmap/mmap.factor @@ -8,14 +8,27 @@ IN: io.mmap TUPLE: mapped-file address handle length disposed ; -HOOK: (mapped-file) os ( path length -- address handle ) +HOOK: (mapped-file-reader) os ( path length -- address handle ) +HOOK: (mapped-file-r/w) os ( path length -- address handle ) ERROR: bad-mmap-size path size ; -: ( path -- mmap ) +> ] bi - dup 0 <= [ bad-mmap-size ] when - [ (mapped-file) ] keep + dup 0 <= [ bad-mmap-size ] when ; + +PRIVATE> + +: ( path -- mmap ) + prepare-mapped-file + [ (mapped-file-reader) ] keep + f mapped-file boa ; + +: ( path -- mmap ) + prepare-mapped-file + [ (mapped-file-r/w) ] keep f mapped-file boa ; HOOK: close-mapped-file io-backend ( mmap -- ) @@ -25,6 +38,9 @@ M: mapped-file dispose* ( mmap -- ) close-mapped-file ; : with-mapped-file ( path quot -- ) [ ] dip with-disposal ; inline +: with-mapped-file-reader ( path quot -- ) + [ ] dip with-disposal ; inline + { { [ os unix? ] [ "io.mmap.unix" require ] } { [ os winnt? ] [ "io.mmap.windows" require ] } diff --git a/basis/io/mmap/unix/unix.factor b/basis/io/mmap/unix/unix.factor index 0fa8e1151f..0424321b84 100644 --- a/basis/io/mmap/unix/unix.factor +++ b/basis/io/mmap/unix/unix.factor @@ -13,11 +13,16 @@ IN: io.mmap.unix [ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep ] with-destructors ; -M: unix (mapped-file) +M: unix (mapped-file-r/w) { PROT_READ PROT_WRITE } flags { MAP_FILE MAP_SHARED } flags mmap-open ; +M: unix (mapped-file-reader) + { PROT_READ } flags + { MAP_FILE MAP_SHARED } flags + mmap-open ; + M: unix close-mapped-file ( mmap -- ) [ [ address>> ] [ length>> ] bi munmap io-error ] [ handle>> close-file ] diff --git a/basis/io/mmap/windows/windows.factor b/basis/io/mmap/windows/windows.factor index fcdf416511..ebd8109d14 100644 --- a/basis/io/mmap/windows/windows.factor +++ b/basis/io/mmap/windows/windows.factor @@ -28,7 +28,7 @@ M: win32-mapped-file dispose C: win32-mapped-file -M: windows (mapped-file) +M: windows (mapped-file-r/w) [ { GENERIC_WRITE GENERIC_READ } flags OPEN_ALWAYS @@ -37,6 +37,15 @@ M: windows (mapped-file) -rot ] with-destructors ; +M: windows (mapped-file-reader) + [ + GENERIC_READ + OPEN_ALWAYS + { PAGE_READONLY SEC_COMMIT } flags + FILE_MAP_READ mmap-open + -rot + ] with-destructors ; + M: windows close-mapped-file ( mapped-file -- ) [ [ handle>> &dispose drop ] From 90d40a7650c16dda91e8bc01c33676a8cb0c71cd Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 19:22:46 -0500 Subject: [PATCH 5/9] calculate a magic number in md5 --- basis/checksums/md5/md5.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basis/checksums/md5/md5.factor b/basis/checksums/md5/md5.factor index 04c6c2497e..29620b089d 100644 --- a/basis/checksums/md5/md5.factor +++ b/basis/checksums/md5/md5.factor @@ -14,7 +14,7 @@ IN: checksums.md5 SYMBOLS: a b c d old-a old-b old-c old-d ; : T ( N -- Y ) - sin abs 4294967296 * >integer ; foldable + sin abs 32 2^ * >integer ; foldable : initialize-md5 ( -- ) 0 bytes-read set From 71f2e997a6febc2787413bcb28877aac99a4f953 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 19:26:16 -0500 Subject: [PATCH 6/9] use read-only mmap in id3. save id3 parsing errors --- extra/id3/id3.factor | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/extra/id3/id3.factor b/extra/id3/id3.factor index a5671a5822..6025af4926 100644 --- a/extra/id3/id3.factor +++ b/extra/id3/id3.factor @@ -6,7 +6,7 @@ combinators math.ranges unicode.categories byte-arrays io.encodings.string io.encodings.utf16 assocs math.parser combinators.short-circuit fry namespaces combinators.smart splitting io.encodings.ascii arrays io.files.info unicode.case -io.directories.search literals math.functions ; +io.directories.search literals math.functions continuations ; IN: id3 id3) ( path -- id3v2/f ) +PRIVATE> + +: mp3>id3 ( path -- id3v2/f ) [ [ ] dip { @@ -213,12 +215,7 @@ CONSTANT: id3v1+-offset $[ 128 227 + ] [ dup id3v1+? [ read-v1+-tags merge-id3v1 ] [ drop ] if ] [ dup id3v2? [ read-v2-tags ] [ drop ] if ] } cleave - ] with-mapped-uchar-file ; - -PRIVATE> - -: mp3>id3 ( path -- id3/f ) - dup file-info size>> 0 <= [ drop f ] [ (mp3>id3) ] if ; + ] with-mapped-uchar-file-reader ; : find-id3-frame ( id3 name -- obj/f ) swap frames>> at* [ data>> ] when ; @@ -239,8 +236,14 @@ PRIVATE> : find-mp3s ( path -- seq ) [ >lower ".mp3" tail? ] find-all-files ; +ERROR: id3-parse-error path error ; + +: (mp3-paths>id3s) ( seq -- seq' ) + [ dup [ mp3>id3 ] [ \ id3-parse-error boa ] recover ] { } map>assoc ; + : mp3-paths>id3s ( seq -- seq' ) - [ dup mp3>id3 ] { } map>assoc ; + (mp3-paths>id3s) + [ dup second id3-parse-error? [ f over set-second ] when ] map ; : parse-mp3-directory ( path -- seq ) find-mp3s mp3-paths>id3s ; From c44349c74eaca7dea0b41ec86673625ce8480248 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 19:32:44 -0500 Subject: [PATCH 7/9] test read-only mmap --- basis/io/mmap/mmap-tests.factor | 1 + 1 file changed, 1 insertion(+) diff --git a/basis/io/mmap/mmap-tests.factor b/basis/io/mmap/mmap-tests.factor index a4d55f3c1e..0e1cd1a036 100644 --- a/basis/io/mmap/mmap-tests.factor +++ b/basis/io/mmap/mmap-tests.factor @@ -7,6 +7,7 @@ IN: io.mmap.tests [ ] [ "12345" "mmap-test-file.txt" temp-file ascii set-file-contents ] unit-test [ ] [ "mmap-test-file.txt" temp-file [ CHAR: 2 0 pick set-nth drop ] with-mapped-char-file ] unit-test [ 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-reader ] unit-test [ "22345" ] [ "mmap-test-file.txt" temp-file ascii file-contents ] unit-test [ "mmap-test-file.txt" temp-file delete-file ] ignore-errors From 3f764fc8720469b77ed3d37b7069d5bc0b8e675a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 20:02:41 -0500 Subject: [PATCH 8/9] fix file mode for read only mmap in unix --- basis/io/mmap/unix/unix.factor | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/basis/io/mmap/unix/unix.factor b/basis/io/mmap/unix/unix.factor index 0424321b84..7d12d52361 100644 --- a/basis/io/mmap/unix/unix.factor +++ b/basis/io/mmap/unix/unix.factor @@ -4,26 +4,23 @@ USING: alien io io.files kernel math math.bitwise system unix io.backend.unix io.ports io.mmap destructors locals accessors ; IN: io.mmap.unix -: open-r/w ( path -- fd ) O_RDWR file-mode open-file ; - -:: mmap-open ( path length prot flags -- alien fd ) +:: mmap-open ( path length prot flags open-mode -- alien fd ) [ f length prot flags - path open-r/w [ |dispose drop ] keep + path open-mode file-mode open-file [ |dispose drop ] keep [ 0 mmap dup MAP_FAILED = [ (io-error) ] when ] keep ] with-destructors ; M: unix (mapped-file-r/w) { PROT_READ PROT_WRITE } flags { MAP_FILE MAP_SHARED } flags - mmap-open ; + O_RDWR mmap-open ; M: unix (mapped-file-reader) { PROT_READ } flags { MAP_FILE MAP_SHARED } flags - mmap-open ; + O_RDONLY mmap-open ; M: unix close-mapped-file ( mmap -- ) [ [ address>> ] [ length>> ] bi munmap io-error ] - [ handle>> close-file ] - bi ; + [ handle>> close-file ] bi ; From 81bef5d62c6f893110871211798168eb5b4f709b Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Sat, 25 Apr 2009 21:03:12 -0500 Subject: [PATCH 9/9] fix help lint for id3 --- extra/id3/id3.factor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/id3/id3.factor b/extra/id3/id3.factor index 6025af4926..79df00ff5e 100644 --- a/extra/id3/id3.factor +++ b/extra/id3/id3.factor @@ -207,7 +207,7 @@ CONSTANT: id3v1+-offset $[ 128 227 + ] PRIVATE> -: mp3>id3 ( path -- id3v2/f ) +: mp3>id3 ( path -- id3/f ) [ [ ] dip {