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

Timothy Baldridge tbaldridge at gmail.com
Tue Oct 30 07:37:28 EDT 2018


Thanks, I'll check it out.

On Tue, Oct 30, 2018 at 1:58 AM Armin Rigo <armin.rigo at gmail.com> wrote:

> 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,
> length_of_array).
>
> 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,
>
> Armin.
>


-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20181030/f0f02045/attachment.html>


More information about the pypy-dev mailing list