[Openmcl-devel] Bug in concatenated-stream implementation

Paul Meurer paul.meurer at uni.no
Thu Mar 16 05:54:58 PDT 2017


there seems to be a bug in the concatenated-stream class in connection with with-open-stream().

When a concatenated-stream is read from in the body of the macro, (e.g. with read-sequence()), concatenated-stream-next-input-stream() is called subsequently, which removes the first stream from the concatenated-stream-streams slot, eventually emptying this slot.

In its unwind-protect cleanup-form, with-open-stream() should close the stream, but there is no close method for concatenated-stream. (The superclass method on composite-stream-mixin just sets open-p to NIL.) With the concatenated-stream-streams slot being empty after an exhaustive read with e.g. read-sequence(), there is no obvious way either how the stream could be closed. The best way to solve this problem would probably be to have a copy of the stream list in an additional slot, and have close map over them when closing the concatenated-stream.

This bug manifests itself e.g. in the mel-base library.

My fix (in l1-streams.lisp) looks like this:

(defclass concatenated-stream (composite-stream-mixin fundamental-input-stream)
    ((streams :initarg :streams :accessor concatenated-stream-streams)
     (stream-list :initarg :stream-list :accessor concatenated-stream-stream-list)))

(defmethod close :after ((stream concatenated-stream) &key abort)
  (mapc (lambda (s) (close s :abort abort))
	(concatenated-stream-stream-list stream)))

(defun make-concatenated-stream (&rest streams)
  "Return a stream which takes its input from each of the streams in turn,
   going on to the next at EOF."
  (dolist (s streams (make-instance 'concatenated-stream :streams streams :stream-list streams))
    (unless (input-stream-p s)
      (error "~S is not an input stream" s))))

Paul Meurer

More information about the Openmcl-devel mailing list