[Openmcl-devel] FFI help...get address to element in structure
R. Matthew Emerson
rme at clozure.com
Sat Sep 19 05:05:57 UTC 2009
On Sep 18, 2009, at 6:24 PM, Michael Kohout wrote:
> Next week I'm doing a presentation to my local lisp user group on FFI
> (CFFI and CCL's FFI). My example is a simple network client and
> Anyways, the code I'm writing requires me to get the address to a
> field in a struct( &sa.sa_mask, where sa is a sigaction structure).
> Does CCL's ffi system allow me to get this without munging around
> with the internal layout of the structure? If so, how?
I don't know if this qualifies as munging around, but maybe this
example will help.
;; struct sigaction sa;
;; (sort of; in ccl, sa is a macptr referencing a stack-allocated
(rlet ((sa (:struct sigaction)))
;; sa.sa_mask = 999;
(setf (pref sa :sigaction.sa_mask) 999)
;; char *p = &sa.sa_mask
(with-macptrs ((p (%inc-ptr sa (ccl::get-field-
;; return *(long *)p;
If you don't really need a pointer to the sa_mask field and just want
to know what its contents are (or to set them), you can use (pref
More information about the Openmcl-devel