How do I write wrapper for foreign-alloc, that frees it....
Posted: Wed Jul 23, 2014 3:46 am
automatically when it goes out of scope(or the functions that can still access the data created by foreign-alloc go out of scope).
I'm trying to write a loose wrapper for cffi:foreign-alloc that finalizes(calls cffi:foreign-free on it) it automatically. For instance if I have a defcfun named "test" that expects a pointer to some data, I would run this to use it:
(test (foreign-alloc :int :initial-contents '(1 2 3)))
I would rather make it so I just have to run:
(test '(1 2 3))
but I would have to free foreign-alloc with foreign-free inside whatever defun wrapper I make for the decfun "test" and If I do so all the data is lost when I go to access the object created by (test '(1 2 3)).
I have been contemplating this for a while, can someone write me up a quick example of how to accomplish this.
I'm trying to write a loose wrapper for cffi:foreign-alloc that finalizes(calls cffi:foreign-free on it) it automatically. For instance if I have a defcfun named "test" that expects a pointer to some data, I would run this to use it:
(test (foreign-alloc :int :initial-contents '(1 2 3)))
I would rather make it so I just have to run:
(test '(1 2 3))
but I would have to free foreign-alloc with foreign-free inside whatever defun wrapper I make for the decfun "test" and If I do so all the data is lost when I go to access the object created by (test '(1 2 3)).
I have been contemplating this for a while, can someone write me up a quick example of how to accomplish this.