Hello,<br>
<br>
The SBCL/CMUCL ffi has a useful form of pointer handling, shown<br>
in the following example that defines the lisp function<br>
fits-open-file from the C function ffopen:<br>
<br>
<br>
;; int ffopen(int *fptr, char *filename, int mode, int *status)<br>
(define-alien-routine ("ffopen" fits-open-file) <br>
int ;; ffopen returns INT<br>
(fptr unsigned-int :out) ;; a pointer to an unsigned int, that is set by function<br>
(filename c-string)<br>
(mode int)<br>
(status int :in-out)) ;; a pointer to an int, that is passed to function, and set by function<br>
<br>
fptr and status are actually pointers, and the values that they point to<br>
are returned along with the INT that the function itself returns. But on the <br>
lisp side, you never see their pointer nature - you just pass and accept <br>
normal integers, and the FFI boxes them up an creates pointers to them,<br>
passes the pointers to the C function, and unboxes them on return.<br>
<br>
A call to this function including the collection of return values, <br>
takes the form<br>
<br>
(multiple-value-bind (return-value-of-function fptr new-status)<br>
(fits-open-file filename mode status)<br>
.... )<br>
<br>
fptr, as an :OUT pointer, is not passed to the function call, but status, as an<br>
:IN-OUT pointer, is passed to ffopen<br>
<br>
The return values are the value of the function,<br>
and the values pointed to by the pointers fptr and status.<br>
<br>
<br>
My question is: Is there any way to make CFFI handle pointers in a similar<br>
manner? How can I do the above in CFFI?<br>
<br>
Many thanks,<br>
Jan