STREAMs and :ELEMENT-TYPE with large and uncommon bytesizes

Bug #309092 reported by Nikodemus Siivola on 2008-12-17
Affects Status Importance Assigned to Milestone

Bug Description

  In theory, (open foo :element-type '(unsigned-byte <x>)) should work
  for all positive integral <x>. At present, it only works for <x> up
  to about 1024 (and similarly for signed-byte), so
    (open "/dev/zero" :element-type '(unsigned-byte 1025))
  gives an error in sbcl-0.8.10.


(defun test-ub (n)
  (with-open-file (f "/tmp/foo.bin"
                     :direction :output
                     :element-type `(unsigned-byte ,n)
                     :if-exists :supersede)
    (write-byte 1 f))
  (with-open-file (f "/tmp/foo.bin"
                     :direction :input
                     :element-type 'bit)
    (let* ((size (file-length f))
           (buffer (make-array size :element-type 'bit)))
      (and (= size (read-sequence buffer f))
           (= (- size 1) (position 1 buffer))))))

(loop for i from 1 upto 1024
        unless (test-ub i)
           collect i)
   ; => (9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32)

description: updated
Changed in sbcl:
importance: Undecided → Low
status: New → Confirmed
importance: Low → Medium
Daniel Herring (dherring) wrote :

Just hit another rendition of the bug in the wild. Here, SBCL thankfully ignored the bogus byte size (Clisp crashed).

(defun READ-RAW-CANNY-EDGES (file &key (width 640) (height 486))
  (let ((a (make-array (list height width) :element-type 'bit :initial-element 0)))
   (with-open-file (s file :direction :input :element-type '(unsigned-byte 1))
     (loop for i from 0 below height doing
           (loop for j from 0 below width doing
                 (when (= 255 (read-byte s)) (setf (aref a i j) 1)))))

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers