Hi, All,
I found the format of my original email is not correct (sent with web mail), and I got no response for some while, so I resend it in Emacs, hopes it works better this time.
I am working on cl-gobject-introspection (https://github.com/andy128k/cl-gobject-introspection), a common lisp gobject introspection binding. I was trying to use extended foreign type system of CFFI to implement some foreign memory operations. I have some questions about that.
I need to manipulate foreign array. I tried to define an extended foreign array type because there are some features that are lacking in foreign-array-type of cffi. I can access/assign element of foreign array with cffi:mem-ref and (setf cffi:mem-ref). But I don't know how to free element of foreign array (the element type can be aggregated).
Then I checked foreign-array-type implementation of CFFI, and found there appears no way to free translated element of array with that type too. For example:
(defvar *string-array* (cffi:convert-to-foreign #("a" "b" "c") '(:array :string 3)))
(cffi:free-foreign-object *string-array* '(:array :string 3) t)
The translated foreign objects corresponding to string "a", "b" and "c" are not freed if my understanding were correct.
I think if there is a cffi:mem-free (I know, the name is bad) like cffi:mem-ref, may be this can be resolved.
(defun mem-free (ptr type param &optional (offset 0)) (let* ((parsed-type (parse-type type)) (ctype (canonicalize parsed-type))) (if (aggregatep parsed-type) (free-translated-object (inc-pointer ptr offset) parsed-type param) (free-translated-object (%mem-ref ptr ctype offset) parsed-type param))))
I think you guys may have better idea about how to resolve the question.
Best Regards, Huang, Ying