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

John Zhang John.Zhang at anu.edu.au
Thu Jun 30 02:33:09 EDT 2016


Hi Armin,
Thanks for the help!
The scoped_alloc really is quite handy in these situations.

Cheers,
John Zhang

------------------------------------------------------
John Zhang
Research Assistant
Programming Languages, Design & Implementation Division
Computer Systems Group
ANU College of Engineering & Computer Science
108 North Rd
The Australian National University
Acton ACT 2601
john.zhang at anu.edu.au<mailto:john.zhang at anu.edu.au>





On 30 Jun 2016, at 16:05, Armin Rigo <arigo at tunes.org<mailto:arigo at tunes.org>> wrote:

Hi John,

On 28 June 2016 at 09:23, John Zhang <John.Zhang at anu.edu.au<mailto: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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20160630/7d568082/attachment.html>


More information about the pypy-dev mailing list