[Openmcl-devel] flexi-streams vs. stream-read-vector

Pascal J. Bourguignon pjb at informatimago.com
Mon Oct 1 09:35:59 PDT 2012


I've got a problem with this method:

    (defmethod stream-read-vector ((s echo-stream) vector start end)
      (if (subtypep (stream-element-type s) 'character)
          (generic-character-read-vector s vector start end)
        (generic-binary-read-vector s vector start end)))


I'm building a "tracing stream" with:

  (let ((in  (make-echo-stream stream trace-output))
        (out (make-broadcast-stream stream trace-output)))
    (make-two-way-stream in out))

The purpose being to copy to trace-output any input or output made on
the stream, by wrapping it thusly.

Unfortunately, that stream is a flexi-streams (people seem to like that
instead of just using binary stream, I can't fathom why, but that's not
the question).

So I have to use a flexi-stream too for trace-output, so we have two
flexi-streams, stream and trace-output, combined as above.

But this doesn't work, because stream-read-vector tests the stream to
know how to read from the stream, instead of using the vector element
type, so we get:

#\t doesn't match array element type of #(60
                                          115
                                          0
                                          …
                                          0).
   [Condition of type ccl::array-element-type-error]

Restarts:
 0: [retry] Retry SLIME REPL evaluation request.
 1: [*abort] Return to SLIME's top level.
 2: [abort-break] Reset this thread
 3: [abort] Kill this thread

Backtrace:
  0: (ccl::generic-character-read-vector #<echo-stream input #<flexi-streams:flexi-io-stream #x30200FBB2D1D>, outpu..
      Locals:
        stream = #<echo-stream input #<flexi-streams:flexi-io-stream #x30200FBB2D1D>, output #<flexi-streams:flexi-output-strea..
        vector = #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..
        ccl::start = 2
        ccl::end = 3
        ccl::i = 2
        ccl::ch = #\t
  1: (read-sequence #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ..
      Locals:
        ccl::seq = #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..
        stream = #<two-way-stream input #<echo-stream input #<flexi-streams:flexi-io-stream #x30200FBB2D1D>, output #<flexi-str..
        ccl::start = 2
        ccl::end = 3
        vector = #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..
        ccl::offset = 0
  2: (#<standard-method runes::read-octets (t stream t t)> #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..
      Locals:
        sequence = #(60 115 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0..
        stream = #<two-way-stream input #<echo-stream input #<flexi-streams:flexi-io-stream #x30200FA30F8D>, output #<flexi-str..
        runes::start = 2
        runes::end = 3



When I redefine stream-read-vector as:

    (defmethod stream-read-vector ((s echo-stream) vector start end)
      (if (subtypep (array-element-type vector) 'character)
          (generic-character-read-vector s vector start end)
          (generic-binary-read-vector    s vector start end)))

it works nicely.



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.




More information about the Openmcl-devel mailing list