Could use help with foreign-free in Lisp's CFFI ?

Discussion of Common Lisp

Could use help with foreign-free in Lisp's CFFI ?

Postby joeish80829 » Wed Oct 02, 2013 7:50 am

Some one suggested i call foreign-alloc inside my defun associated with my defcfun....the defun & defcfun are here:

[/code]
Code: Select all
 ;; CvMatND* cvInitMatNDHeader(CvMatND* mat,
   int dims, const int* sizes, int type, void* data=NULL)
(cffi:defcfun ("cvInitMatNDHeader" %init-mat-nd-header) cv-mat-nd
  (mat cv-mat-nd)
  (dims :int)
  (sizes :pointer)
  (type :int)
  (data :pointer))

(defun init-mat-nd-header (mat dims sizes type &optional (data (cffi:null-pointer)))
  "Initializes a pre-allocated multi-dimensional array header."
  (%init-mat-nd-header mat dims (cffi:foreign-alloc :int
   :initial-contents sizes) type
     (cffi:foreign-alloc :int :initial-contents data)))


its a nice idea because i can write my code w/o usind the long foreign-alloc's in it but i was wondering how i use foreign-free then

I tried

Code: Select all
  (defun init-mat-nd-header (mat dims sizes type &optional
     (data (cffi:null-pointer)))
     "Initializes a pre-allocated multi-dimensional array header."
     (%init-mat-nd-header mat dims (cffi:foreign-alloc :int
                                      :initial-contents sizes) type
    (cffi:foreign-alloc :int :initial-contents data))               
              (return-from init-mat-nd-header data))


and just

Code: Select all
 (defun init-mat-nd-header (mat dims sizes type &optional
     (data (cffi:null-pointer)))
     "Initializes a pre-allocated multi-dimensional array header."
     (%init-mat-nd-header mat dims (cffi:foreign-alloc :int
                                     :initial-contents sizes) type
    (cffi:foreign-alloc :int :initial-contents data))               
              data)


I thought of a block return-from but that seems like the same thing as above if you are a cffi user....how would you accomplish this:
joeish80829
 
Posts: 96
Joined: Tue Sep 03, 2013 5:32 am

Return to Common Lisp

Who is online

Users browsing this forum: Google [Bot] and 3 guests