[pypy-dev] Passing an array to C in RFFI

Armin Rigo arigo at tunes.org
Thu Jun 30 02:05:36 EDT 2016


Hi John,

On 28 June 2016 at 09:23, John Zhang <John.Zhang at anu.edu.au> wrote:
> I have another question regarding passing an array value to C function using
> RFFI.
> Suppose I have a function in C that’s like this:
> void fn(void** array_of_voips, int length)
> How do I in RPython call the function using RFFI passing an array value for
> it?
> it seems that I can’t just do
> fn([a, b, c], 3)

Indeed, this works in CFFI, but RFFI is by far not as nice as that.
You need to build the array value manually with
"ar=lltype.new(ARRAY_OF_VOIDP.TO, length, flavor='raw'); ar[0]=a; "
etc., remembering to do "lltype.free(ar, flavor='raw')" at the end.
Or use "with lltype.scoped_alloc(...)", which replaces both the malloc
at the start and the free at the end.


A bientôt,

Armin.


More information about the pypy-dev mailing list