[pypy-dev] Call rpython from outside

Armin Rigo armin.rigo at gmail.com
Sat Jul 15 02:02:01 EDT 2017


Hi Aleksandr,

On 11 July 2017 at 18:33, Aleksandr Koshkin <tinysnippets at gmail.com> wrote:
> So ok, I have to specify headers containing my structs and somehow push it
> to rpython toolchain, if I got you correctly.
> 0. Why? This structures are already described in the vm file as a bunch of
> ffi.CStruct objects.

rffi.CStruct() is used to declare the RPython interface for structs
that are originally defined in C.

You can use lltype.Struct(), but it's not recommended in your case
because lltype.Struct() is meant to define structs in RPython where
you *don't* need a precise C-level struct; for example,
lltype.Struct() could rename and reorder the fields in C if it is more
efficient.

We don't have a direct way to declare the struct in RPython but also
force it to generate exactly the C struct declaration you want,
because we never needed it.  You need to use rffi.CStruct() and write
the struct in the .h file manually too.

> 1. If I have to, how would I do that, is there any example of embedding
> rpython into something?

Not really.  Look maybe at tests using rpython.rlib.entrypoint, like
rpython/translator/c/test/test_genc:test_entrypoints.


A bientôt,

Armin.


More information about the pypy-dev mailing list