[cffi-devel] Re: [anaphora-devel] Python embedded API and passing arrays with CFFI

James Bielman jamesjb at jamesjb.com
Wed Feb 1 19:33:48 UTC 2006


Jeremy Smith <jeremy at decompiler.org> writes:

> I want an array of structs. Not pointers to structs, but actual
> structs.  So with an array of 4 16-byte structs, it should be 64
> bytes.
>
> I've got around the problem by using a struct which has 16 entries
> (4 * the 4-entry struct), but that's not desirable because it
> doesn't scale to more module entries without increasing the struct
> by 4 more entries.

I think this is what you want:

(defcstruct foo
  (x :int)
  (y :int)
  (z :int))

(with-foreign-object (foo-array 'foo 4)
  ...)

FOO-ARRAY will be a pointer to storage for 4 FOO structures.

Macroexpanding this WITH-FOREIGN-OBJECT:

(WITH-FOREIGN-POINTER (FOO-ARRAY 48)
  ...)

James



More information about the cffi-devel mailing list