If you get some free time I would love to see a concrete example, but I do appreciate you time so far and don't want to put you out in any way.. I'm building a big library and the better I can make each individual component the better
On Sunday, April 13, 2014 8:26 AM, Willem Rein Oudshoorn woudshoo@xs4all.nl wrote:
Joeish W joeish80829@yahoo.com writes:
I already figured out a great finalizer, I could just use help on one thing. The below finalizer is for the %mat defcfun below that. How do I update the finalizer below to be for the mat-data defcfun at the bottom of the page. So where do I put the rows cols params, there seems to be no place for them in the defstruct wwhere %mat is called. Any help is appreciated
Hm, I feel this is not the right way to approach this. However, there is a bug in your finalize logic.
- If you call make-cvmatrix with enable-finalizer true you attach a
finalize on the new instance of cvmatrix. 2. However you return the SAP. 3. As a consequence the cvmatrix instance can be immediately garbage collected, even if the returned SAP still has references to it.
(defstruct (cvmatrix (:constructor %make-cvmatrix)) (sap (%mat) :type sb-sys:system-area-pointer :read-only t)) (defun make-cvmatrix (&optional enable-finalizer) (let* ((matrix (%make-cvmatrix)) (sap (cvmatrix-sap matrix))) (when enable-finalizer (tg:finalize matrix (lambda () (del-mat sap)))) sap))
I do not think that this is what you want.
Two remarks for future improvement:
- You use sb-sys:system-area-pointer as type, and this will tie you to
SBCL. There is no reason for that.
- You should read up on `translate-to-foreign' and
`translate-from-foreign' in the cffi documentation. It will really help to make the code simpler, cleaner and more robust.
If I have more time I might give some more detailed suggestions. But I hope this helps a bit.
Wim Oudshoorn.
Cffi-devel mailing list Cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel