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 (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))
(defcfun ("cv_create_Mat" %mat) (:pointer mat) "MAT constructor") ;; Mat::Mat(int rows, int cols, int type, void* data) ;; Mat* cv_create_Mat_with_data(int rows, int cols, int type, void* data) (defcfun ("cv_create_Mat_with_data" mat-data) (:pointer mat) (rows :int) (cols :int) (type :int) (data :pointer))
On Sunday, April 13, 2014 12:28 AM, Willem Rein Oudshoorn woudshoo@xs4all.nl wrote:
Joeish W joeish80829@yahoo.com writes:
I have Lisp functions that wrap C wrappers for C++ functions that contain a new operator. The C wrappers have to stay the same I can't change those but I was advised to update my method of GC.
As already mentioned before, use the package 'trivial-garbage'.
The cl-git package that wraps the libgit2 C code might be a good example.
The cl-git code tries the handle automatic freeing by the garbage collector, but also allows you to free manually. In addition it keeps track of dependencies, e.g. in cl-git a 'commit' is only valid as long as the 'repository' is open.
It is not much code and might give some inspiration.
Disclaimer, I was quite involved in this bit of cl-git, the project is on github:
https://github.com/russell/cl-git
As an additional question, maybe not well suited for this list. I see you are wrapping the OpenCV code. There are already two other wrappers. So I am curious what are the deficiencies of the existing wrappers that your wrapper tries to solve?
Wim Oudshoorn.
Cffi-devel mailing list Cffi-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/cffi-devel