From 46e02fa30d45f23fe98aed2ff4233fa0eba26415 Mon Sep 17 00:00:00 2001 From: sheeple Date: Mon, 4 Feb 2008 11:50:02 -0600 Subject: [PATCH 1/3] Linux inotify works --- extra/io/monitor/monitor.factor | 4 ++-- extra/io/unix/linux/linux.factor | 27 +++++++++++----------- extra/io/windows/nt/monitor/monitor.factor | 7 +++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/extra/io/monitor/monitor.factor b/extra/io/monitor/monitor.factor index 11d1b6ecf9..1d8499b392 100755 --- a/extra/io/monitor/monitor.factor +++ b/extra/io/monitor/monitor.factor @@ -17,7 +17,7 @@ TUPLE: monitor queue closed? ; set-monitor-queue } monitor construct ; -HOOK: fill-queue io-backend ( monitor -- assoc ) +HOOK: fill-queue io-backend ( monitor -- ) : changed-file ( changed path -- ) namespace [ append ] change-at ; @@ -32,7 +32,7 @@ HOOK: io-backend ( path recursive? -- monitor ) : next-change ( monitor -- path changed ) dup check-monitor dup monitor-queue dup assoc-empty? [ - drop dup fill-queue over set-monitor-queue next-change + drop dup fill-queue next-change ] [ nip dequeue-change ] if ; SYMBOL: +add-file+ diff --git a/extra/io/unix/linux/linux.factor b/extra/io/unix/linux/linux.factor index 9751cefe91..1707ac9546 100755 --- a/extra/io/unix/linux/linux.factor +++ b/extra/io/unix/linux/linux.factor @@ -54,21 +54,22 @@ TUPLE: inotify watches ; M: linux-io ( path recursive? -- monitor ) drop IN_CHANGE_EVENTS add-watch ; -: notify-callback ( assoc monitor -- ) - linux-monitor-callback dup - [ schedule-thread-with ] [ 2drop ] if ; +: notify-callback ( monitor -- ) + dup linux-monitor-callback + f rot set-linux-monitor-callback + [ schedule-thread ] when* ; -M: linux-io fill-queue ( monitor -- assoc ) +M: linux-io fill-queue ( monitor -- ) dup linux-monitor-callback [ "Cannot wait for changes on the same file from multiple threads" throw ] when - [ swap set-linux-monitor-callback stop ] callcc1 - swap check-monitor ; + [ swap set-linux-monitor-callback stop ] callcc0 + check-monitor ; M: linux-monitor dispose ( monitor -- ) dup check-monitor t over set-monitor-closed? - H{ } over notify-callback + dup notify-callback remove-watch ; : ?flag ( n mask symbol -- n ) @@ -106,13 +107,13 @@ M: linux-monitor dispose ( monitor -- ) inotify-event-len "inotify-event" heap-size + swap >r + r> ; -: wd>queue ( wd -- queue ) - inotify-event-wd wd>monitor monitor-queue ; - : parse-file-notifications ( i buffer -- ) 2dup events-exhausted? [ 2drop ] [ - 2dup inotify-event@ dup inotify-event-wd wd>queue - [ parse-file-notify changed-file ] bind + 2dup inotify-event@ dup inotify-event-wd wd>monitor [ + monitor-queue [ + parse-file-notify changed-file + ] bind + ] keep notify-callback next-event parse-file-notifications ] if ; @@ -135,7 +136,7 @@ M: inotify-task do-io-task ( task -- ) io-task-port read-notifications f ; M: linux-io init-io ( -- ) - mx set-global ; ! init-inotify ; + dup mx set-global init-inotify ; T{ linux-io } set-io-backend diff --git a/extra/io/windows/nt/monitor/monitor.factor b/extra/io/windows/nt/monitor/monitor.factor index f2cc4ef92a..d418dff270 100755 --- a/extra/io/windows/nt/monitor/monitor.factor +++ b/extra/io/windows/nt/monitor/monitor.factor @@ -78,6 +78,7 @@ M: windows-nt-io ( path recursive? -- monitor ) dup FILE_NOTIFY_INFORMATION-NextEntryOffset dup zero? [ 3drop ] [ swap (changed-files) ] if ; -M: windows-nt-io fill-queue ( monitor -- assoc ) - dup win32-monitor-path over buffer-ptr rot read-changes - [ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc ; +M: windows-nt-io fill-queue ( monitor -- ) + dup win32-monitor-path over buffer-ptr pick read-changes + [ zero? [ 2drop ] [ (changed-files) ] if ] H{ } make-assoc + swap set-monitor-queue ; From f2af000ed040468ed6377ad526c461fbff66b6af Mon Sep 17 00:00:00 2001 From: sheeple Date: Mon, 4 Feb 2008 11:50:20 -0600 Subject: [PATCH 2/3] refresh-all fix, new show word for debugging --- core/io/crc32/crc32-docs.factor | 10 +++++----- core/io/crc32/crc32.factor | 2 -- core/io/streams/c/c.factor | 7 +++++++ core/source-files/source-files.factor | 2 +- extra/tools/deploy/shaker/shaker.factor | 5 ----- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/io/crc32/crc32-docs.factor b/core/io/crc32/crc32-docs.factor index 020f2668b0..3855c77cd8 100644 --- a/core/io/crc32/crc32-docs.factor +++ b/core/io/crc32/crc32-docs.factor @@ -2,16 +2,16 @@ USING: help.markup help.syntax math ; IN: io.crc32 HELP: crc32 -{ $values { "seq" "a sequence" } { "n" integer } } +{ $values { "seq" "a sequence of bytes" } { "n" integer } } { $description "Computes the CRC32 checksum of a sequence of bytes." } ; -HELP: file-crc32 -{ $values { "path" "a pathname string" } { "n" integer } } -{ $description "Computes the CRC32 checksum of a file's contents." } ; +HELP: lines-crc32 +{ $values { "lines" "a sequence of strings" } { "n" integer } } +{ $description "Computes the CRC32 checksum of a sequence of lines of bytes." } ; ARTICLE: "io.crc32" "CRC32 checksum calculation" "The CRC32 checksum algorithm provides a quick but unreliable way to detect changes in data." { $subsection crc32 } -{ $subsection file-crc32 } ; +{ $subsection lines-crc32 } ; ABOUT: "io.crc32" diff --git a/core/io/crc32/crc32.factor b/core/io/crc32/crc32.factor index b83943df48..afe7e4bfb7 100755 --- a/core/io/crc32/crc32.factor +++ b/core/io/crc32/crc32.factor @@ -23,8 +23,6 @@ IN: io.crc32 : crc32 ( seq -- n ) >r HEX: ffffffff dup r> [ (crc32) ] each bitxor ; -: file-crc32 ( path -- n ) file-contents crc32 ; - : lines-crc32 ( seq -- n ) HEX: ffffffff tuck [ [ (crc32) ] each CHAR: \n (crc32) diff --git a/core/io/streams/c/c.factor b/core/io/streams/c/c.factor index b02c3367d4..288ab212d1 100755 --- a/core/io/streams/c/c.factor +++ b/core/io/streams/c/c.factor @@ -74,3 +74,10 @@ M: object M: object "ab" fopen ; + +: show ( msg -- ) + #! A word which directly calls primitives. It is used to + #! print stuff from contexts where the I/O system would + #! otherwise not work (tools.deploy.shaker, the I/O + #! multiplexer thread). + "\r\n" append stdout-handle fwrite stdout-handle fflush ; diff --git a/core/source-files/source-files.factor b/core/source-files/source-files.factor index 8bbf329491..c974145928 100755 --- a/core/source-files/source-files.factor +++ b/core/source-files/source-files.factor @@ -17,7 +17,7 @@ uses definitions ; : (source-modified?) ( path modified checksum -- ? ) pick file-modified rot [ 0 or ] 2apply > - [ swap file-crc32 number= not ] [ 2drop f ] if ; + [ swap file-lines lines-crc32 = not ] [ 2drop f ] if ; : source-modified? ( path -- ? ) dup source-files get at [ diff --git a/extra/tools/deploy/shaker/shaker.factor b/extra/tools/deploy/shaker/shaker.factor index f2b951ad16..16507232ae 100755 --- a/extra/tools/deploy/shaker/shaker.factor +++ b/extra/tools/deploy/shaker/shaker.factor @@ -8,11 +8,6 @@ debugger io.streams.c io.streams.duplex io.files io.backend quotations words.private tools.deploy.config compiler.units ; IN: tools.deploy.shaker -: show ( msg -- ) - #! Use primitives directly so that we can print stuff even - #! after most of the image has been stripped away - "\r\n" append stdout-handle fwrite stdout-handle fflush ; - : strip-init-hooks ( -- ) "Stripping startup hooks" show "command-line" init-hooks get delete-at From 53cb45c9ff3a53ea1cce2679e9a772ea94d3b24a Mon Sep 17 00:00:00 2001 From: sheeple Date: Mon, 4 Feb 2008 12:03:48 -0600 Subject: [PATCH 3/3] Fix TYPEDEF: issue --- extra/unix/linux/linux.factor | 4 +--- extra/unix/solaris/solaris.factor | 2 -- extra/unix/unix.factor | 4 +++- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/extra/unix/linux/linux.factor b/extra/unix/linux/linux.factor index d25ff71d65..0a3eb7ee5f 100644 --- a/extra/unix/linux/linux.factor +++ b/extra/unix/linux/linux.factor @@ -1,10 +1,8 @@ -! Copyright (C) 2005 Slava Pestov. +! Copyright (C) 2005, 2008 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. IN: unix USING: alien.syntax ; -TYPEDEF: ulong off_t - ! Linux. : O_RDONLY HEX: 0000 ; inline diff --git a/extra/unix/solaris/solaris.factor b/extra/unix/solaris/solaris.factor index b4aa8285eb..2bca20c6b6 100644 --- a/extra/unix/solaris/solaris.factor +++ b/extra/unix/solaris/solaris.factor @@ -3,8 +3,6 @@ IN: unix USING: alien.syntax system kernel ; -TYPEDEF: ulong off_t - ! Solaris. : O_RDONLY HEX: 0000 ; inline diff --git a/extra/unix/unix.factor b/extra/unix/unix.factor index bcfbb3a214..7c3467b052 100755 --- a/extra/unix/unix.factor +++ b/extra/unix/unix.factor @@ -19,11 +19,13 @@ TYPEDEF: uint time_t TYPEDEF: uint uid_t TYPEDEF: ulong size_t TYPEDEF: ulong u_long -TYPEDEF: ulonglong off_t TYPEDEF: ushort mode_t TYPEDEF: ushort nlink_t TYPEDEF: void* caddr_t +TYPEDEF: ulong off_t +TYPEDEF-IF: bsd? ulonglong off_t + C-STRUCT: tm { "int" "sec" } ! Seconds: 0-59 (K&R says 0-61?) { "int" "min" } ! Minutes: 0-59