anchor.diff:  (defmethod allocate-foreign ((surface image-surface) &key source type
   			     width height stride format)
     (etypecase source
  -   (stream
  +   (null (%image-surface-create format width height))
  +   ((or stream function symbol)
       (let ((stream-id (register-user-data source)))
         (unwind-protect
   	   (cond
  
positive.code:       ((error "Can't handle image type ~A" type))))
     (pointer
      (%image-surface-create-for-data source format width height 
       (or stride (format-stride-for-width format width))))
     (null (%image-surface-create format width height))))
  
  #?(pkg-exists-p "cairo" :atleast-version "1.6")
  (defbinding format-stride-for-width () int
  
negative.code:     :write-error))
  
  (defun %stream-read-func (stream-id data length)
    (let* ((stream (find-user-data stream-id)))
      (handler-case                              
          (multiple-value-bind (sequence bytes-read)
              (etypecase stream
                (stream
                 (let ((sequence (make-array length
                                  :element-type '(unsigned-byte 8))))
                   (values sequence (read-sequence sequence stream))))
                ((or symbol function) (funcall stream length)))
            (make-c-vector '(unsigned-byte 8) (or bytes-read (length sequence))
             :content sequence :location data)
            (or bytes-read (length sequence)))
        (serious-condition (condition)
          (declare (ignore condition))
          0))))
  
  (define-callback stream-read-func status 
      ((stream-id pointer-data) (data pointer) (length unsigned-int))
  