Hi,
If I have a C function which allocates memory for a C string and returns a pointer to this memory (return type char *). How do I deallocate this memory? Should I use `foreign-string-free' or `foreign-free'.
I have been meaning to look into this. Right now, you'd have to use something like (foreign-funcall "free" :pointer <your-pointer>)
I don't understand why there's something unclear here. I thought that's why :string+ptr had been invented.
This is exactly the pattern of :string+ptr, and it's embodied in tests/misc-types.lisp:deftest misc-types.string+ptr: a) return string and b) (foreign-free pointer) Is that testcase broken? "Just" non-portable?
Well, since foreign-free's specification is to free only things allocated with foreign-alloc, maybe CFFI must export the general C free() as well? The :string+ptr type should then documented this.
Note that malloc()/free() is fine for a UNIX shared library. It's somewhat meaningless in the context of a DLL on MS-Windows. But there, one will probably not encounter such a protocol and will have to call the resource free'ing function via the FFI as well.
Regards, Jorg Hohle.