[pypy-dev] how embed pypy into c?

Roberto De Ioris roberto at unbit.it
Tue Mar 20 08:36:03 CET 2012

> Hi all.
> I want to embed pypy  into c code, but in pypy's directory, i don't find
any pypy's c api, except in cypext directory.
> And I want to use stackless' c api too,. but i still have not found any
stackless api(example stackless_api.h)  in pypy.
> Thanks.
> --

Currently you are on your own.

This is the step i follow:

1) patch genc.py to export RPython_StartupCode in addition to

export_symbols=["pypy_main_startup", "RPython_StartupCode"]))

and run:

pypy translate.py -Ojit --shared

to build libpypy

2) add this declaration on top of your code

char *RPython_StartupCode(void);
#define pypy_asm_stack_bottom()  asm volatile ("/* GC_STACK_BOTTOM */" : :
: \


3) instead of Py_Initialize() call


After that you have an almost working pypy environment.

A bunch of python c api functions are not implemented (but you will find
it is pretty easy to add them, even as noop) so be prepared to some

What kills me is the amount of time taken to rebuild the whole library, so
i can work on it only on spare time (i am porting both mod_wsgi and uWSGI)

Roberto De Ioris

More information about the pypy-dev mailing list