r9418: rework cmucl/sbcl arrays in deref-array, allocate-foreign-object, and with...
[uffi.git] / src / objects.lisp
index 940c941cc42f6d09338c22f90b8bc0d9e45949e0..6ec32234aaa87792332dc39ebc2bb0a4c65784ed 100644 (file)
@@ -51,9 +51,21 @@ an array of TYPE with size SIZE. The TYPE parameter is evaluated."
        )
       (progn
        #+(or cmu scl)
-       `(alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+       (if (integerp size)
+           `(alien:cast
+             (alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+             (array ,(convert-from-uffi-type (eval type) :allocation) ,size))
+           `(alien:cast
+             (alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+             (array ,(convert-from-uffi-type (eval type) :allocation) nil)))
        #+sbcl
-       `(sb-alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+       (if (integerp size)
+           `(sb-alien:cast
+             (sb-alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+             (array ,(convert-from-uffi-type (eval type) :allocation) ,size))
+           `(sb-alien:cast
+             (sb-alien:make-alien ,(convert-from-uffi-type (eval type) :allocation) ,size)
+             (array ,(convert-from-uffi-type (eval type) :allocation) nil)))
        #+lispworks
        `(fli:allocate-foreign-object :type ',(convert-from-uffi-type type :allocate) :nelems ,size)
        #+allegro
@@ -171,10 +183,15 @@ an array of TYPE with size SIZE. The TYPE parameter is evaluated."
        (let ((,var (alien:addr ,obj)))
         ,@body)))
   #+sbcl
-  (let ((obj (gensym)))
-    `(sb-alien:with-alien ((,obj ,(convert-from-uffi-type (eval type) :allocate)))
-       (let ((,var (sb-alien:addr ,obj)))
-        ,@body)))
+  (let ((obj (gensym))
+       (ctype (convert-from-uffi-type (eval type) :allocate)))
+    (if (and (consp ctype) (eq 'array (car ctype)))
+       `(sb-alien:with-alien ((,obj ,ctype))
+         (let* ((,var ,obj))
+           ,@body))
+       `(sb-alien:with-alien ((,obj ,ctype))
+         (let* ((,var (sb-alien:addr ,obj)))
+           ,@body))))
   #+lispworks
   `(fli:with-dynamic-foreign-objects ((,var ,(convert-from-uffi-type
                                              (eval type) :allocate)))