Embedding PyPy + cpyext API calls
Created originally on Bitbucket by benamram (Omer Ben-Amram)
Hi guys,
I've been fiddling around with adding pypy support for the rust PyO3.
I've been quite successful with the original intent of generating PyPy compatible rust extensions! (wrapped as cpython modules) (the modifications are at - my fork) by correctly linking to libpypy, changing the exported names and re implementing some missing macros in rust.
However, the other direction (rust code that embeds pypy) - which would try to call cpyext functions directly from rust works for cpython (since PyO3 handles all cpython initialization correctly), but crashes with PyPy.
I'm linking my rust library against a debug version of libpypy (5.10, haven't downloaded 6 yet) I've tried several combinations of calls to rpython_startup_code
, pypy_setup_home
(as referenced here), all of them yielded the following results:
So something like this works (will exit without crashing):
But importing via regular API would crash, interestingly after printing the zen:
Interestingly, using an API that doesn't allocate anything, such as PyBool_FromLong
results in a more verbose crash.
I'm suspicious that there is some ref counting/GIL management issue that is causing the crashes.
Am I missing something here? would it be possible to use the embedding API to call cpyext emulated functions from rust?
A minimal code sample to reproduce the situation can be found here
Thanks!
Omer