r10387: support new sbcl
[kmrcl.git] / byte-stream.lisp
index 36f77e7048ff9822b83a66aab06db3e506312adf..79ce9df449d930637e5a0464a6ca273afc688850 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  June 2003
 ;;;;
-;;;; $Id: byte-stream.lisp,v 1.1 2003/07/05 02:32:08 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; Works for CMUCL, SBCL, and AllergoCL only
 ;;;;
 
 (in-package #:kmrcl)
 
+;; Intial CMUCL version by OnShored. Ported to SBCL by Kevin Rosenberg
+
 #+(or cmu sbcl)
 (progn
 (defstruct (byte-array-output-stream
              (:include #+cmu system:lisp-stream
-                      #+sbcl sb-impl::file-stream
+                      #+sbcl sb-impl::fd-stream
                        (bout #'byte-array-bout)
                        (misc #'byte-array-out-misc))
              (:print-function %print-byte-array-output-stream)
@@ -83,11 +85,24 @@ Make-Byte-Array-Output-Stream since the last call to this function."
 ) ; progn
 
 
+#+sbcl
+(sb-ext:without-package-locks
+ (defvar *system-copy-fn* (if (fboundp (intern "COPY-SYSTEM-AREA" "SB-KERNEL"))
+                             (intern "COPY-SYSTEM-AREA" "SB-KERNEL")
+                           (intern "COPY-SYSTEM-UB8-AREA" "SB-KERNEL")))
+ (defconstant *system-copy-offset* (if (fboundp (intern "COPY-FROM-SYSTEM-AREA" "SB-KERNEL"))
+                                      (* sb-vm:vector-data-offset sb-vm:n-word-bits)
+                                    0))
+ (defconstant *system-copy-multiplier* (if (fboundp (intern "COPY-FROM-SYSTEM-AREA" "SB-KERNEL"))
+                                          sb-vm:n-byte-bits
+                                        1)))
+
 #+(or cmu sbcl)
 (progn
   (defstruct (byte-array-input-stream
             (:include #+cmu system:lisp-stream
-                      #+sbcl sb-impl::file-stream
+                      ;;#+sbcl sb-impl::file-stream
+                      #+sbcl sb-sys:fd-stream
                       (in #'byte-array-inch)
                       (bin #'byte-array-binch)
                       (n-bin #'byte-array-stream-read-n-bytes)
@@ -100,15 +115,20 @@ Make-Byte-Array-Output-Stream since the last call to this function."
   (current nil)
   (end nil))
 
+  
 (defun %print-byte-array-input-stream (s stream d)
   (declare (ignore s d))
   (write-string "#<Byte-Array-Input Stream>" stream))
-  
+
 (defun byte-array-inch (stream eof-errorp eof-value)
   (let ((byte-array (byte-array-input-stream-byte-array stream))
        (index (byte-array-input-stream-current stream)))
     (cond ((= index (byte-array-input-stream-end stream))
-          (eof-or-lose stream eof-errorp eof-value))
+          #+cmu
+          (eof-or-lose stream eof-errorp eof-value)
+          #+sbcl
+          (sb-impl::eof-or-lose stream eof-errorp eof-value)
+          )
          (t
           (setf (byte-array-input-stream-current stream) (1+ index))
           (aref byte-array index)))))
@@ -117,7 +137,11 @@ Make-Byte-Array-Output-Stream since the last call to this function."
   (let ((byte-array (byte-array-input-stream-byte-array stream))
        (index (byte-array-input-stream-current stream)))
     (cond ((= index (byte-array-input-stream-end stream))
-          (eof-or-lose stream eof-errorp eof-value))
+          #+cmu
+          (eof-or-lose stream eof-errorp eof-value)
+          #+sbcl
+          (sb-impl::eof-or-lose stream eof-errorp eof-value)
+          )
          (t
           (setf (byte-array-input-stream-current stream) (1+ index))
           (aref byte-array index)))))
@@ -142,13 +166,13 @@ Make-Byte-Array-Output-Stream since the last call to this function."
                         (* copy vm:byte-bits)))
       #+sbcl
       (sb-sys:without-gcing
-       (sb-kernel:system-area-copy (sb-sys:vector-sap byte-array)
-                        (* index sb-vm:n-byte-bits)
+       (funcall *system-copy-fn* (sb-sys:vector-sap byte-array)
+                        (* index *system-copy-multiplier*)
                         (if (typep buffer 'sb-sys::system-area-pointer)
                             buffer
                             (sb-sys:vector-sap buffer))
-                        (* start sb-vm:n-byte-bits)
-                        (* copy sb-vm:n-byte-bits))))
+                        (* start *system-copy-multiplier*)
+                        (* copy *system-copy-multiplier*))))
     (if (and (> requested copy) eof-errorp)
        (error 'end-of-file :stream stream)
        copy)))
@@ -174,6 +198,9 @@ Make-Byte-Array-Output-Stream since the last call to this function."
 
 ) ;; progn
 
+
+;;; Simple streams implementation by Kevin Rosenberg
+
 #+allegro
 (progn
 
@@ -207,6 +234,7 @@ Make-Byte-Array-Output-Stream since the last call to this function."
   
   (defmethod excl:device-extend ((stream extendable-buffer-output-stream)
                                 need action)
+    (declare (ignore action))
     (let* ((len (file-position stream))
           (new-len (max (+ len need) (* 2 len)))
           (old-buf (slot-value stream 'excl::buffer))