/[cl-gsl]/cl-gsl/ffi.lisp
ViewVC logotype

Diff of /cl-gsl/ffi.lisp

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

revision 1.1 by edenny, Wed Mar 2 01:04:53 2005 UTC revision 1.2 by edenny, Fri Mar 4 01:52:38 2005 UTC
# Line 57  Line 57 
57  ;; ----------------------------------------------------------------------  ;; ----------------------------------------------------------------------
58    
59  ;; TODO: size_t may not always be unsigned long, could also be unsigned int.  ;; TODO: size_t may not always be unsigned long, could also be unsigned int.
60  (define-foreign-type (size-t :unsigned-long))  (define-foreign-type size-t :unsigned-long)
61    
62  (def-foreign-struct gsl-complex  (def-foreign-struct gsl-complex
63      (dat (:array :double 2)))      (dat (:array :double 2)))
# Line 212  Line 212 
212      (complex (uffi:deref-array dat-array :float 0)      (complex (uffi:deref-array dat-array :float 0)
213               (uffi:deref-array dat-array :float 1))))               (uffi:deref-array dat-array :float 1))))
214    
215    ;; FIXME: this returns a pointer to a gsl-complex. Is this correct?
216    ;; How do we free it?
217    ;; Replace with a with-complex->gsl-complex macro that cleans up after
218    ;; itself
219  (defun complex->gsl-complex (z)  (defun complex->gsl-complex (z)
220    (let* ((z-ptr (uffi:allocate-foreign-object 'gsl-complex))    (let* ((z-ptr (uffi:allocate-foreign-object 'gsl-complex))
221           (uffi:get-slot-pointer z-ptr 'double-ptr 'cl-gsl::dat))           (dat-array (uffi:get-slot-value z-ptr (:array :float) 'cl-gsl::dat)))
222      ))      (setf (uffi:deref-array dat-array :double 0) (realpart z))
223        (setf (uffi:deref-array dat-array :double 1) (imagpart z))
224        z-ptr))
225    
226    ;; FIXME: see above
227  (defun complex->gsl-complex-float (z)  (defun complex->gsl-complex-float (z)
228    (let ((z-ptr (uffi:allocate-foreign-object 'gsl-complex-float)))    (let* ((z-ptr (uffi:allocate-foreign-object 'gsl-complex-float))
229      ))           (dat-array (uffi:get-slot-value z-ptr (:array :float) 'cl-gsl::dat)))
230        (setf (uffi:deref-array dat-array :double 0) (realpart z))
231        (setf (uffi:deref-array dat-array :double 1) (imagpart z))
232        z-ptr))
233    
234  ;; TODO: generalize to all supported types  
235    ;; TODO: generalize to all supported types?
236  (defun lisp-vec->c-array (v)  (defun lisp-vec->c-array (v)
237    (declare (vector v))    (declare (vector v))
238    (let* ((len (length v))    (let* ((len (length v))
# Line 230  Line 241 
241        (setf (uffi:deref-array c-ptr :double i) (aref v i)))        (setf (uffi:deref-array c-ptr :double i) (aref v i)))
242      c-ptr))      c-ptr))
243    
244  ;; TODO: generalize to all supported types  ;; TODO: generalize to all supported types?
245  (defun c-array->lisp-vec (c-ptr len)  (defun c-array->lisp-vec (c-ptr len)
246    (let ((lisp-vec (make-array len :element-type 'double-float)))    (let ((lisp-vec (make-array len :element-type 'double-float)))
247      (dotimes (i len)      (dotimes (i len)

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

  ViewVC Help
Powered by ViewVC 1.1.5