From 7122f9fccb444f33f34f7180304d855b06eeb7ee Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Fri, 17 Sep 2010 14:19:10 -0500 Subject: [PATCH] Make sure io.backend.windows loads the implementations for the generics it defines. Make windows.handles not depend on io.timeouts. Fix typo in win32-file-attributes. Fix bug in null-output word. Clean up error checking code. --- basis/io/backend/windows/nt/nt.factor | 9 +++++---- basis/io/backend/windows/windows.factor | 20 ++++++++++++++------ basis/io/files/windows/nt/nt.factor | 3 +-- basis/io/files/windows/windows.factor | 10 ++++++---- basis/io/launcher/windows/nt/nt.factor | 4 ++-- basis/io/sockets/windows/windows.factor | 2 +- basis/io/timeouts/timeouts.factor | 4 ++-- basis/windows/errors/errors.factor | 6 ++---- basis/windows/handles/handles.factor | 10 +--------- 9 files changed, 34 insertions(+), 34 deletions(-) diff --git a/basis/io/backend/windows/nt/nt.factor b/basis/io/backend/windows/nt/nt.factor index 3114073c9d..b34902f7f1 100755 --- a/basis/io/backend/windows/nt/nt.factor +++ b/basis/io/backend/windows/nt/nt.factor @@ -3,8 +3,8 @@ arrays assocs classes.struct combinators combinators.short-circuit destructors io io.backend io.backend.windows io.buffers io.files.windows io.ports io.streams.c io.streams.null io.timeouts kernel libc locals -math namespaces sequences system threads windows.errors -windows.handles windows.kernel32 ; +math namespaces sequences system threads vocabs.loader +windows.errors windows.handles windows.kernel32 ; IN: io.backend.windows.nt ! Global variable with assoc mapping overlapped to threads @@ -32,8 +32,8 @@ SYMBOL: master-completion-port : ( -- handle ) INVALID_HANDLE_VALUE f ; -M: winnt add-completion ( win32-handle -- ) - handle>> master-completion-port get-global drop ; +M: winnt add-completion ( win32-handle -- win32-handle ) + dup handle>> master-completion-port get-global drop ; : eof? ( error -- ? ) { [ ERROR_HANDLE_EOF = ] [ ERROR_BROKEN_PIPE = ] } 1|| ; @@ -144,4 +144,5 @@ M: winnt init-stdio [ init-c-stdio ] [ null-reader null-writer null-writer set-stdio ] if ; +"io.files.windows.nt" require winnt set-io-backend diff --git a/basis/io/backend/windows/windows.factor b/basis/io/backend/windows/windows.factor index e0dd806212..7ecb5765a1 100755 --- a/basis/io/backend/windows/windows.factor +++ b/basis/io/backend/windows/windows.factor @@ -1,18 +1,24 @@ ! Copyright (C) 2004, 2010 Mackenzie Straight, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types classes.struct destructors -io.backend kernel literals windows.errors windows.handles -windows.kernel32 ; +io.backend io.timeouts kernel literals windows.errors +windows.handles windows.kernel32 vocabs.loader ; IN: io.backend.windows HOOK: CreateFile-flags io-backend ( DWORD -- DWORD ) HOOK: FileArgs-overlapped io-backend ( port -- overlapped/f ) -HOOK: add-completion io-backend ( port -- ) +HOOK: add-completion io-backend ( port -- port ) +TUPLE: win32-file < win32-handle ptr ; + +: ( handle -- win32-file ) + win32-file new-win32-handle ; + +M: win32-file dispose + [ cancel-operation ] [ call-next-method ] bi ; + : opened-file ( handle -- win32-file ) - dup invalid-handle? - |dispose - dup add-completion ; + check-invalid-handle |dispose add-completion ; CONSTANT: share-mode flags{ @@ -24,3 +30,5 @@ CONSTANT: share-mode : default-security-attributes ( -- obj ) SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES heap-size >>nLength ; + +"io.files.windows" require \ No newline at end of file diff --git a/basis/io/files/windows/nt/nt.factor b/basis/io/files/windows/nt/nt.factor index a2d6d90f6b..4046522a1b 100644 --- a/basis/io/files/windows/nt/nt.factor +++ b/basis/io/files/windows/nt/nt.factor @@ -2,8 +2,7 @@ USING: accessors alien.c-types alien.strings classes.struct combinators combinators.short-circuit continuations environment io.backend io.backend.windows io.encodings.utf16n io.files.private io.files.windows io.pathnames kernel math -sequences specialized-arrays -specialized-arrays.instances.alien.c-types.ushort system tr +sequences specialized-arrays system tr windows windows.errors windows.kernel32 windows.shell32 windows.time ; SPECIALIZED-ARRAY: ushort diff --git a/basis/io/files/windows/windows.factor b/basis/io/files/windows/windows.factor index b0fa0472ca..3b4df85371 100644 --- a/basis/io/files/windows/windows.factor +++ b/basis/io/files/windows/windows.factor @@ -2,9 +2,9 @@ ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien.c-types alien.data combinators destructors io.backend.windows io.binary io.buffers io.files -io.files.types io.ports kernel literals make math.bitwise -system windows.errors windows.handles windows.kernel32 -windows.time windows.types ; +io.files.types io.ports kernel literals make +math.bitwise system windows.errors windows.handles +windows.kernel32 windows.time windows.types vocabs.loader ; IN: io.files.windows : open-file ( path access-mode create-mode flags -- handle ) @@ -98,7 +98,7 @@ SYMBOLS: +read-only+ +hidden+ +system+ +sparse-file+ +reparse-point+ +compressed+ +offline+ +not-content-indexed+ +encrypted+ ; -: win32-file-attribute ( n attr symbol -- ) +: win32-file-attribute ( n symbol attr -- ) rot mask? [ , ] [ drop ] if ; : win32-file-attributes ( n -- seq ) @@ -127,3 +127,5 @@ SYMBOLS: +read-only+ +hidden+ +system+ : (set-file-times) ( handle timestamp/f timestamp/f timestamp/f -- ) [ timestamp>FILETIME ] tri@ SetFileTime win32-error=0/f ; + +"io.files.windows.nt" require \ No newline at end of file diff --git a/basis/io/launcher/windows/nt/nt.factor b/basis/io/launcher/windows/nt/nt.factor index 3651785242..a9c66d202e 100644 --- a/basis/io/launcher/windows/nt/nt.factor +++ b/basis/io/launcher/windows/nt/nt.factor @@ -23,7 +23,7 @@ IN: io.launcher.windows.nt (pipe) [ in>> &dispose ] [ out>> dispose ] bi ; : null-output ( -- pipe ) - (pipe) [ in>> dispose ] [ out>> &dispose ] bi ; + (pipe) [ out>> &dispose ] [ in>> dispose ] bi ; : null-pipe ( mode -- pipe ) { @@ -48,7 +48,7 @@ IN: io.launcher.windows.nt create-mode FILE_ATTRIBUTE_NORMAL ! flags and attributes f ! template file - CreateFile dup invalid-handle? &dispose ; + CreateFile check-invalid-handle &dispose ; : redirect-append ( path access-mode create-mode -- handle ) [ path>> ] 2dip diff --git a/basis/io/sockets/windows/windows.factor b/basis/io/sockets/windows/windows.factor index 3d9b3a6e14..d41240d1b3 100755 --- a/basis/io/sockets/windows/windows.factor +++ b/basis/io/sockets/windows/windows.factor @@ -38,7 +38,7 @@ M: win32-socket dispose* ( stream -- ) [ empty-sockaddr/size ] [ protocol-family ] bi pick family<< ; : opened-socket ( handle -- win32-socket ) - |dispose dup add-completion ; + |dispose add-completion ; : open-socket ( addrspec type -- win32-socket ) [ protocol-family ] dip diff --git a/basis/io/timeouts/timeouts.factor b/basis/io/timeouts/timeouts.factor index 68110ded15..c024e49856 100644 --- a/basis/io/timeouts/timeouts.factor +++ b/basis/io/timeouts/timeouts.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2008 Slava Pestov, Doug Coleman ! See http://factorcode.org/license.txt for BSD license. -USING: kernel calendar timers io io.encodings accessors -namespaces fry io.streams.null ; +USING: accessors fry io io.encodings io.streams.null kernel +namespaces timers ; IN: io.timeouts GENERIC: timeout ( obj -- dt/f ) diff --git a/basis/windows/errors/errors.factor b/basis/windows/errors/errors.factor index a4943ef877..99284bdb80 100755 --- a/basis/windows/errors/errors.factor +++ b/basis/windows/errors/errors.factor @@ -734,10 +734,8 @@ ERROR: windows-error n string ; : win32-error<0 ( n -- ) 0 < [ win32-error ] when ; : win32-error<>0 ( n -- ) zero? [ win32-error ] unless ; -: invalid-handle? ( handle -- ) - INVALID_HANDLE_VALUE = [ - win32-error-string throw - ] when ; +: check-invalid-handle ( handle -- handle ) + dup INVALID_HANDLE_VALUE = [ win32-error-string throw ] when ; CONSTANT: expected-io-errors ${ diff --git a/basis/windows/handles/handles.factor b/basis/windows/handles/handles.factor index 70ffdf80a6..07d6c8f5d2 100644 --- a/basis/windows/handles/handles.factor +++ b/basis/windows/handles/handles.factor @@ -1,6 +1,6 @@ ! Copyright (C) 2010 Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors destructors io.timeouts kernel windows.errors +USING: accessors destructors kernel windows.errors windows.kernel32 windows.types ; IN: windows.handles @@ -19,11 +19,3 @@ TUPLE: win32-handle < disposable handle ; M: win32-handle dispose* ( handle -- ) handle>> CloseHandle win32-error=0/f ; - -TUPLE: win32-file < win32-handle ptr ; - -: ( handle -- win32-file ) - win32-file new-win32-handle ; - -M: win32-file dispose - [ cancel-operation ] [ call-next-method ] bi ; -- 2.34.1