[cl-gsl-cvs] CVS update: cl-gsl/ffi.lisp
Edgar Denny
edenny at common-lisp.net
Fri Mar 4 01:52:40 UTC 2005
Update of /project/cl-gsl/cvsroot/cl-gsl
In directory common-lisp.net:/tmp/cvs-serv32738
Modified Files:
ffi.lisp
Log Message:
Add functions needed by vector.lisp.
Date: Fri Mar 4 02:52:39 2005
Author: edenny
Index: cl-gsl/ffi.lisp
diff -u cl-gsl/ffi.lisp:1.1.1.1 cl-gsl/ffi.lisp:1.2
--- cl-gsl/ffi.lisp:1.1.1.1 Wed Mar 2 02:04:53 2005
+++ cl-gsl/ffi.lisp Fri Mar 4 02:52:38 2005
@@ -57,7 +57,7 @@
;; ----------------------------------------------------------------------
;; TODO: size_t may not always be unsigned long, could also be unsigned int.
-(define-foreign-type (size-t :unsigned-long))
+(define-foreign-type size-t :unsigned-long)
(def-foreign-struct gsl-complex
(dat (:array :double 2)))
@@ -212,16 +212,27 @@
(complex (uffi:deref-array dat-array :float 0)
(uffi:deref-array dat-array :float 1))))
+;; FIXME: this returns a pointer to a gsl-complex. Is this correct?
+;; How do we free it?
+;; Replace with a with-complex->gsl-complex macro that cleans up after
+;; itself
(defun complex->gsl-complex (z)
(let* ((z-ptr (uffi:allocate-foreign-object 'gsl-complex))
- (uffi:get-slot-pointer z-ptr 'double-ptr 'cl-gsl::dat))
- ))
+ (dat-array (uffi:get-slot-value z-ptr (:array :float) 'cl-gsl::dat)))
+ (setf (uffi:deref-array dat-array :double 0) (realpart z))
+ (setf (uffi:deref-array dat-array :double 1) (imagpart z))
+ z-ptr))
+;; FIXME: see above
(defun complex->gsl-complex-float (z)
- (let ((z-ptr (uffi:allocate-foreign-object 'gsl-complex-float)))
- ))
+ (let* ((z-ptr (uffi:allocate-foreign-object 'gsl-complex-float))
+ (dat-array (uffi:get-slot-value z-ptr (:array :float) 'cl-gsl::dat)))
+ (setf (uffi:deref-array dat-array :double 0) (realpart z))
+ (setf (uffi:deref-array dat-array :double 1) (imagpart z))
+ z-ptr))
-;; TODO: generalize to all supported types
+
+;; TODO: generalize to all supported types?
(defun lisp-vec->c-array (v)
(declare (vector v))
(let* ((len (length v))
@@ -230,7 +241,7 @@
(setf (uffi:deref-array c-ptr :double i) (aref v i)))
c-ptr))
-;; TODO: generalize to all supported types
+;; TODO: generalize to all supported types?
(defun c-array->lisp-vec (c-ptr len)
(let ((lisp-vec (make-array len :element-type 'double-float)))
(dotimes (i len)
More information about the Cl-gsl-cvs
mailing list