r10100: move function so that deref-array macro is defined
[uffi.git] / src / aggregates.lisp
index 6ee0ac79ca072cc87e1dc4850ef180674dc2ff72..5fdc9081d430acc5e83ec570f01d3d99764d00f2 100644 (file)
@@ -7,7 +7,7 @@
 ;;;; Programmer:    Kevin M. Rosenberg
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: aggregates.lisp,v 1.7 2003/06/06 21:59:18 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;;
@@ -80,7 +80,8 @@ of the enum-name name, separator-string, and field-name"
                              #+(or cmu scl) `((* (alien:struct ,name)))
                              #+sbcl `((* (sb-alien:struct ,name)))
                              #+mcl `((:* (:struct ,name)))
-                             #-(or cmu sbcl scl mcl) `((* ,name))
+                             #+lispworks `((:pointer ,name))
+                             #-(or cmu sbcl scl mcl lispworks) `((* ,name))
                              `(,(convert-from-uffi-type type :struct))))))
        (if variant
            (push (list def) processed)
@@ -117,7 +118,8 @@ of the enum-name name, separator-string, and field-name"
   #+sbcl
   `(sb-alien:slot ,obj ,slot)
   #+mcl
-  `(ccl:pref ,obj ,(read-from-string (format nil ":~a.~a" (keyword type) (keyword slot))))
+  `(ccl:pref ,obj ,(intern (concatenate 'string (symbol-name type) "." (symbol-name slot))
+                         :keyword))
   )
 
 #+mcl
@@ -160,20 +162,29 @@ of the enum-name name, separator-string, and field-name"
   "Returns a field from a row"
   #+(or lispworks cmu sbcl scl) (declare (ignore type))
   #+(or cmu scl)  `(alien:deref ,obj ,i)
-  #+sbcl  `(sb-alien:deref ,obj ,i)
-  #+lispworks `(fli:dereference ,obj :index ,i)
+  #+sbcl `(sb-alien:deref ,obj ,i)
+  #+lispworks `(fli:dereference ,obj :index ,i :copy-foreign-object nil)
   #+allegro `(ff:fslot-value-typed (quote ,(convert-from-uffi-type type :type)) :c ,obj ,i)
-  #+mcl
+  #+openmcl
   (let* ((array-type (array-type type))
          (local-type (convert-from-uffi-type array-type :allocation))
-         (accessor (first (macroexpand `(ccl:pref obj ,local-type)))))
-    `(,accessor 
+        (element-size-in-bits (ccl::%foreign-type-or-record-size local-type :bits)))
+    (ccl::%foreign-access-form
+     obj
+     (ccl::%foreign-type-or-record local-type)
+     `(* ,i ,element-size-in-bits)
+     nil))
+  #+(and mcl (not openmcl))
+  (let* ((array-type (array-type type))
+        (local-type (convert-from-uffi-type array-type :allocation))
+        (accessor (first (macroexpand `(ccl:pref obj ,local-type)))))
+    `(,accessor
       ,obj
       (* (the fixnum ,i) ,(size-of-foreign-type local-type))))
   )
 
 ; this expands to the %set-xx functions which has different params than %put-xx
-#+mcl
+#+(and mcl (not openmcl))
 (defmacro deref-array-set (obj type i value)
   (let* ((array-type (array-type type))
          (local-type (convert-from-uffi-type array-type :allocation))
@@ -184,7 +195,7 @@ of the enum-name name, separator-string, and field-name"
       (* (the fixnum ,i) ,(size-of-foreign-type local-type)) 
       ,value)))
 
-#+mcl
+#+(and mcl (not openmcl))
 (defsetf deref-array deref-array-set)
 
 (defmacro def-union (name &rest fields)
@@ -202,3 +213,37 @@ of the enum-name name, separator-string, and field-name"
   `(ccl::def-foreign-type nil 
                          (:union ,name ,@(process-struct-fields name fields)))
 )
+
+
+#-(or sbcl cmu)
+(defun convert-from-foreign-usb8 (s len)
+  (declare (optimize (speed 3) (space 0) (safety 0) (compilation-speed 0))
+          (fixnum len))
+  (let ((a (make-array len :element-type '(unsigned-byte 8))))
+    (dotimes (i len a)
+      (declare (fixnum i))
+      (setf (aref a i) (uffi:deref-array s '(:array :unsigned-byte) i)))))
+
+#+sbcl
+(defun convert-from-foreign-usb8 (s len)
+  (declare (type sb-sys:system-area-pointer sap))
+  (locally
+      (declare (optimize (speed 3) (safety 0)))
+    (let ((result (make-array len :element-type '(unsiged-byte 8))))
+      (sb-kernel:copy-from-system-area s 0
+                                      result (* sb-vm:vector-data-offset
+                                                sb-vm:n-word-bits)
+                                      (* len sb-vm:n-byte-bits))
+      result)))
+
+#+cmu
+(defun convert-from-foreign-usb8 (s le)
+  (declare (type system:system-area-pointer sap))
+  (locally
+      (declare (optimize (speed 3) (safety 0)))
+    (let ((result (make-array len :element-type '(unsiged-byte 8))))
+      (kernel:copy-from-system-area s 0
+                                   result (* vm:vector-data-offset
+                                             vm:word-bits)
+                                   (* len vm:byte-bits))
+      result)))