[pypy-dev] Best way to inline a primitive array in RPython?

Armin Rigo armin.rigo at gmail.com
Tue Oct 30 03:58:06 EDT 2018

Hi Timothy,

On Tue, 30 Oct 2018 at 00:42, Timothy Baldridge <tbaldridge at gmail.com> wrote:
> typedef struct foo_t {
> int a, b;
> int _data[0];
> }
> foo_t tmp = malloc(sizeof(foo_t) + 64);

You can do that if you use the lltype.GcStruct type directly, not
using "regular" RPython code.  See the main example in
rpython.rtyper.lltypesystem.rstr: the types STR and UNICODE.  They are
defined as lltype.GcStruct('name', ..some_regular_fields..,
inlined_array_field), and allocated with lltype.malloc(STR,

Note that you also need to prevent the JIT from seeing any such type:
it has got special case for STR and UNICODE but doesn't handle the
general case.

A bientôt,


More information about the pypy-dev mailing list