[Openmcl-devel] Bug in concatenated-stream implementation

Paul Meurer paul.meurer at uni.no
Thu Mar 16 06:22:20 PDT 2017


I see, thanks. So this is a bug in mel-base only, which relies on with-open-stream() closing the underlying streams. Still, this somewhat counterintuitive.

Best wishes,
Paul

> Am 16.03.2017 um 14:10 schrieb Stas Boukarev <stassats at gmail.com>:
> 
> Which would violate the standard, as "The effect of close on a constructed stream is to close the argument stream only. There is no effect on the constituents of composite streams."
> 
> On Thu, Mar 16, 2017 at 3:54 PM, Paul Meurer <paul.meurer at uni.no <mailto:paul.meurer at uni.no>> wrote:
> Hello,
> 
> 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
> 
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com <mailto:Openmcl-devel at clozure.com>
> https://lists.clozure.com/mailman/listinfo/openmcl-devel <https://lists.clozure.com/mailman/listinfo/openmcl-devel>
> 
> 
> 
> -- 
> With best regards, Stas.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20170316/0a309879/attachment.htm>


More information about the Openmcl-devel mailing list