<br>
<div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Stephen Compall <<a href="mailto:s11@member.fsf.org">s11@member.fsf.org</a>> wrote:
<br>...<br>The attached should give you a good general idea of how to do it. It is<br>untested. ....<br>
</blockquote><div><br>
</div><br><div><br>
<br>
Thank you for the pointers.<br>
<br>
I've managed to write a macro that does the wrapping that is necessary to implement sbcl-style<br>
:out and :in-out pointers using the tools in cffi. This is useful for porting sbcl/cmucl FFIs over to<br>
CFFI. Having always used SBCL in the past, I've always found the :OUT and :IN-OUT syntax<br>
of their FFI to be very nice because it allows one to hide a lot of pointer ugliness with just a single<br>
keyword. I wonder it something like this would be useful for CFFI defcfun? But as the attached<br>
macro code shows, it seems to be easy to implement atop CFFI.<br>
<br>
Thanks again for the tips.<br>
Jan<br>
<br>
<br>
;; example use of %define-alien-routine macro to implement :OUT and :IN-OUT args like SBCL<br>
<br>
(defctype int :int) ;; define a new type to be more like SBCL<br>
<br>
(macroexpand <br>
'(%define-alien-routine ("ffopen" fits-file-open) int <br>
(fptr int :out) <br>
(filename :string)<br>
(mode int)<br>
(status int :in-out)))<br>
<br>
==> ;; expands to<br>
<br>
(progn<br>
(declaim (inline %defcfun-ffopen))<br>
(defcfun ("ffopen" %defcfun-ffopen) int (fptr :pointer) (filename :string)<br>
(mode int) (status :pointer))<br>
(defun fits-file-open (filename mode status)<br>
(with-foreign-object (#:status2488 'int)<br>
(setf (mem-ref #:status2488 'int 0) status)<br>
(let ((#:mode2487 mode))<br>
(let ((#:filename2486 filename))<br>
(with-foreign-object (#:fptr2485 'int) nil<br>
(values<br>
(%defcfun-ffopen #:fptr2485<br>
#:filename2486<br>
#:mode2487<br>
#:status2488)<br>
(mem-ref #:fptr2485 'int 0)<br>
(mem-ref #:status2488 'int<br>
0))))))))<br>
<br>
</div><br></div><br>