[Cffi-devel] How do I make the :actual-type of a define-foreign-type a (:pointer (:struct ...))

Joeish W joeish80829 at yahoo.com
Sat Jul 12 08:51:19 UTC 2014


 I have a define-foreign-type, translate-to-foreign, translate-from-foreign and a defclass at bottom of this page

  These four sections of code make up my types. At the top of the code is a defcstruct that, I am trying to make a part of my types  by changing the :actual-type in the define-foreign-type to:   


   (:actual-type '(:pointer (:struct rect1))).


The :actual-type is normally :pointer and that makes it so the defcfun at the bottom of code section compiles no problem.  When I compile the code here I get an error in my defcun saying that "(:pointer (:struct rect1)) is not a cffi type".  Why is it doing this and how can I make the actual type of my define-foreign-type a (:pointer (:struct rect1))?  The reason I would like to do this is so I can convert the C data to lisp data as soon as possible. If this won't work and you have any other suggestions on how to do this professionally. pls let me know. Thank you.



;;;;Code

(cffi:defcstruct rect1
(x :int)
(y :int)
(width :int)
(height :int))
 
 
(define-foreign-type rect ()
((garbage-collect  :reader garbage-collect :initform nil :initarg 
:garbage-collect))
(:actual-type '(:pointer (:struct rect1)))
(:simple-parser rect))
 
 
(defclass cv-rect ()
((c-pointer :reader c-pointer :initarg :c-pointer)))
 
 
(defmethod translate-to-foreign ((lisp-value cv-rect) (c-type rect))
(values  (c-pointer lisp-value) lisp-value))
 
 
(defmethod translate-from-foreign (c-pointer (c-type rect))
(let ((rectangle  (make-instance 'cv-rect :c-pointer c-pointer)))
(when (garbage-collect c-type)
(tg:finalize rectangle (lambda () (del-rect c-pointer))))
rectangle))
 
 
 
(defcfun ("cv_create_Rect4" rect-4) rect
"RECT constructor."
(x :int)
(y :int)
(width :int)
(height :int))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20140712/b39fa75d/attachment.html>


More information about the cffi-devel mailing list