X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=contrib%2Fsb-simple-streams%2Ffile.lisp;h=48d48ade5b164f8ca28c521eb1e10d78429e6f4d;hb=f057566fe993f008a9b34dc87b026e7c8ef2611d;hp=01da23bff2caa94319bb274eef14c05af7dbda34;hpb=d8e0a653d6974279581a3d1a151bde02ea6023c9;p=sbcl.git diff --git a/contrib/sb-simple-streams/file.lisp b/contrib/sb-simple-streams/file.lisp index 01da23b..48d48ad 100644 --- a/contrib/sb-simple-streams/file.lisp +++ b/contrib/sb-simple-streams/file.lisp @@ -152,15 +152,18 @@ (defmethod device-close ((stream file-simple-stream) abort) (with-stream-class (file-simple-stream stream) - (let ((fd (or (sm input-handle stream) (sm output-handle stream)))) + (let ((fd (or (sm input-handle stream) (sm output-handle stream))) + (closed nil)) (when (sb-int:fixnump fd) (cond (abort (when (any-stream-instance-flags stream :output) + #+win32 (progn (sb-unix:unix-close fd) (setf closed t)) (revert-file (sm filename stream) (sm original stream)))) (t (when (sm delete-original stream) (delete-original (sm filename stream) (sm original stream))))) - (sb-unix:unix-close fd)) + (unless closed + (sb-unix:unix-close fd))) (when (sm buffer stream) (free-buffer (sm buffer stream)) (setf (sm buffer stream) nil)))) @@ -222,9 +225,20 @@ (warn "Unable to memory-map entire file.") (setf size (1- most-positive-fixnum))) (let ((buffer + #-win32 (handler-case - (sb-posix:mmap nil size prot sb-posix::MAP-SHARED fd 0) - (sb-posix:syscall-error nil)))) + (sb-posix:mmap nil size prot sb-posix::MAP-SHARED fd 0) + (sb-posix:syscall-error nil)) + #+win32 + (let ((mapping + (sb-win32:create-file-mapping + (sb-win32:get-osfhandle fd) nil 2 0 size nil))) + (typecase mapping + ((integer -1 0) nil) + (t (let ((sap (prog1 (sb-win32:map-view-of-file + mapping 4 0 0 size) + (sb-win32:close-handle mapping)))) + (and (not (zerop (sb-sys:sap-int sap))) sap))))))) (when (null buffer) (sb-unix:unix-close fd) (sb-ext:cancel-finalization stream) @@ -244,7 +258,8 @@ (melding-stream stream) efmt 'mapped)) (sb-ext:finalize stream (lambda () - (sb-posix:munmap buffer size) + #+win32 (sb-win32:unmap-view-of-file buffer) + #-win32 (sb-posix:munmap buffer size) (format *terminal-io* "~&;;; ** unmapped ~S" buffer)) :dont-save t)))) stream))) @@ -253,7 +268,8 @@ (defmethod device-close ((stream mapped-file-simple-stream) abort) (with-stream-class (mapped-file-simple-stream stream) (when (sm buffer stream) - (sb-posix:munmap (sm buffer stream) (sm buf-len stream)) + #+win32 (sb-win32:unmap-view-of-file (sm buffer stream)) + #-win32 (sb-posix:munmap (sm buffer stream) (sm buf-len stream)) (setf (sm buffer stream) nil)) (sb-unix:unix-close (or (sm input-handle stream) (sm output-handle stream)))) t)