DEREF-ARRAY in AllegroCL (Was: Coercing pointers)

Edi Weitz <[email protected]> 12 Aug 2003 21:15:14 +0200
Newsgroups gmane.lisp.uffi.general
Message-ID <[email protected]>
Just tried the same code with AllegroCL 6.2 trial. Here it is again
for reference:

  (def-function ("gdImagePngPtr" gd-image-png-ptr)
      ((im gd-image-ptr)
       (size (* :int)))
    :returning :pointer-void
    :module "gd")

  (defun png-to-stream (stream image)
    (cond ((subtypep (stream-element-type stream) 'character)
            (with-foreign-object (size :int)
              (with-foreign-object (memory :char)
                (setq memory (gd-image-png-ptr image size))
                (dotimes (i (deref-pointer size :int))
                  (write-char (ensure-char-character (deref-array memory :char i))
                              stream)))))
          ((subtypep (stream-element-type stream) '(unsigned-byte 8))
            (with-foreign-object (size :int)
              (with-foreign-object (memory :unsigned-byte)
                (setq memory (gd-image-png-ptr image size))
                (dotimes (i (deref-pointer size :int))
                  (write-byte (deref-array memory :unsigned-byte i)
                              stream)))))
          (t (error "Can't use a stream with element-type ~A"
                    (stream-element-type stream)))))

When I compile this I get

  ; While compiling PNG-TO-STREAM:
  Warning: slot name I can't be used for type
           #S(FOREIGN-FUNCTIONS::SIZED-FTYPE-PRIM :KIND :CHAR :WIDTH 1
                                                  :OFFSET 0 :ALIGN 1)
  Warning: slot name I can't be used for type
           #S(FOREIGN-FUNCTIONS::SIZED-FTYPE-PRIM :KIND :CHAR :WIDTH 1
                                                  :OFFSET 0 :ALIGN 1)
  Warning: slot name I can't be used for type
           #S(FOREIGN-FUNCTIONS::SIZED-FTYPE-PRIM :KIND :UNSIGNED-CHAR
                                                  :WIDTH 1 :OFFSET 0
                                                  :ALIGN 1)

and when I execute it I get

  Error: slot name 0 can't be used for type
         #S(FOREIGN-FUNCTIONS::SIZED-FTYPE-PRIM :KIND :UNSIGNED-CHAR
                                                :WIDTH 1 :OFFSET 0
                                                :ALIGN 1)
    [condition type: SIMPLE-ERROR]

What am I doing wrong? (This is the code which works fine with CMUCL
and LW.)

Thanks,
Edi.