On Sat, 2007-01-13 at 22:36 -1000, J. T.K. wrote:
fptr, as an :OUT pointer, is not passed to the function call, but status, as an :IN-OUT pointer, is passed to ffopen
The return values are the value of the function, and the values pointed to by the pointers fptr and status.
My question is: Is there any way to make CFFI handle pointers in a similar manner? How can I do the above in CFFI?
The attached should give you a good general idea of how to do it. It is untested.
You can similarly handle out-arguments, but I don't think you can get away with dropping arguments to the lisp-function without wrapping defcfun in your package.
You just have to use (in-out :int) etc. as the argtype, and call the function like:
(call-with-in-out-arguments (lambda () (fits-open-file ...))
To do otherwise would change the argument translation semantics, which currently don't permit argument translators to change the result of calling a defcfun'd function. You could add a with-in-outs parametrized type to use as the rettype in defcfun to get around this, but only as long as defcfun and foreign-funcall continue to pass the real, complete call form to expand-type-from-foreign, as is done now.
I used private symbols. You could do it without private symbols, probably, but the current exported type translation interface breaks down when you want to parametrize your own types and have parameters affect translation.
I'll say here that I don't like the semantics of out and in-out foreign arguments, and I recommend using a wrapper macro that will more explicitly handle these results for you.