/[cffi-objects]/array.lisp
ViewVC logotype

Diff of /array.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 8 by rklochkov, Sun Aug 12 17:36:30 2012 UTC revision 13 by rklochkov, Sat Dec 22 19:24:45 2012 UTC
# Line 22  Line 22 
22        (let* ((length (length value))        (let* ((length (length value))
23               (type (element-type cffi-array))               (type (element-type cffi-array))
24               (res (foreign-alloc type :count length)))               (res (foreign-alloc type :count length)))
25          (dotimes (i length (values res t))          (if (struct-p type)
26            (setf (mem-aref res type i) (elt value i)))              (dotimes (i length (values res t))
27          res)))                (clos->struct (second type) (elt value i) (mem-aptr res type i)))
28                (dotimes (i length (values res t))
29                  (setf (mem-aref res type i) (elt value i)))))))
30    
31  (defmethod translate-from-foreign (ptr (cffi-array cffi-array))  (defmethod translate-from-foreign (ptr (cffi-array cffi-array))
32    (let ((array-length (mem-ref *array-length* :uint)))    (let ((array-length (mem-ref *array-length* :uint)))
33      (let* ((res (make-array array-length))      (let* ((res (make-array array-length))
34             (el-type (element-type cffi-array)))             (type (element-type cffi-array)))
35        (dotimes (i array-length)        (if (struct-p type)
36          (setf (aref res i) (mem-aref ptr el-type i)))            (dotimes (i array-length res)
37        res)))              (setf (aref res i) (convert-from-foreign (mem-aptr ptr type i)
38                                                         type)))
39              (dotimes (i array-length res)
40                (setf (aref res i) (mem-aref ptr type i)))))))
41    
42  (define-foreign-type cffi-null-array (freeable)  (define-foreign-type cffi-null-array (freeable)
43    ((element-type :initarg :type :accessor element-type))    ((element-type :initarg :type :accessor element-type))
# Line 59  Line 64 
64        (push (mem-aref ptr el-type i) res))        (push (mem-aref ptr el-type i) res))
65      (coerce (nreverse res) 'array)))      (coerce (nreverse res) 'array)))
66    
 (defctype string-array (null-array :string) "Zero-terminated string array")  
67    (defctype string-array (null-array :string) "Zero-terminated string array")
68    

Legend:
Removed from v.8  
changed lines
  Added in v.13

  ViewVC Help
Powered by ViewVC 1.1.5