Przeglądaj źródła

better CLISP support for stream-read-sequence, stream-write-sequence

avodonosov 17 lat temu
rodzic
commit
4160f2e2bb
1 zmienionych plików z 30 dodań i 0 usunięć
  1. 30 0
      mixin.lisp

+ 30 - 0
mixin.lisp

@@ -69,8 +69,38 @@
       ((s trivial-gray-stream-mixin) seq start end)
     (stream-write-sequence s seq start end)))
 
+;; up to version 2.43 there were no
+;; stream-read-sequence, stream-write-sequence
+;; functions in CLISP
+#+clisp
+(eval-when (:compile-toplevel :load-toplevel :execute)
+  (when (find-symbol "STREAM-READ-SEQUENCE" "GRAY")
+    (pushnew :clisp-has-stream-read/write-sequence *features*)))
+
 #+clisp
 (progn
+
+  #+clisp-has-stream-read/write-sequence
+  (defmethod gray:stream-read-sequence
+      (seq (s trivial-gray-stream-mixin) &key start end)
+    (stream-read-sequence s seq (or start 0) (or end (length seq))))
+
+  #+clisp-has-stream-read/write-sequence
+  (defmethod gray:stream-write-sequence
+      (seq (s trivial-gray-stream-mixin) &key start end)
+    (stream-write-sequence s seq (or start 0) (or end (length seq))))
+  
+  ;; Even despite the stream-read/write-sequence are present in newer 
+  ;; CLISP, it's better to provide stream-(read/write)-(byte/char)-sequence
+  ;; methods too.
+  ;; Example: if fundamental-binary-input-stream comes in the
+  ;; class precedence list of your user-defined stream before
+  ;; the trivial-gray-steam-mixin, the default CLISP's implementation
+  ;; of the gray:stream-read-sequence will be used; and this default 
+  ;; implementation calls the gray:stream-read-byte-sequence.
+  ;; Therefore we override gray:stream-read-byte-sequence and call
+  ;; our stream-read-sequence.
+
   (defmethod gray:stream-read-byte-sequence
       ((s trivial-gray-stream-mixin)
        seq