Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to deal with C-API extensions? #158

Open
windelbouwman opened this issue Oct 15, 2018 · 3 comments
Open

How to deal with C-API extensions? #158

windelbouwman opened this issue Oct 15, 2018 · 3 comments
Labels
A-design About RustPython's own implementation C-discussion A discussion E-help-wanted Extra attention is needed

Comments

@windelbouwman
Copy link
Contributor

Create a prototype on how to interact with a python library with a C-API extension.

See also:
https://pythoncapi.readthedocs.io/

There are some questions regarding C extensions. Primary question: how to handle this? Maybe in a similar way to cpyext?

@windelbouwman windelbouwman added E-help-wanted Extra attention is needed question labels Oct 15, 2018
@windelbouwman
Copy link
Contributor Author

Just wanted to bump this issue with a link to handlepy: https://github.com/pyhandle/hpy this might be the way to go forwards.

@ShadowJonathan
Copy link

hpy is definitely the way, it's getting increasing support and attention from the python community

@youknowone youknowone added the A-design About RustPython's own implementation label Apr 18, 2022
@encukou
Copy link

encukou commented Jan 16, 2023

Hi!
I help maintain CPython's Limited API & Stable ABI. If you want to support a subset of the C API, here's one. Not perfect -- it has decade of historical baggage itself -- but it's there. A bunch of real-world extensions use it, including PyO3 (there's even a suggestion to make it the default).

To support it, you'd need to expose a PyObject struct with a refcount (C int) and a type (C pointer). Roughly speaking, those are the only two instances where Stable ABI extensions reach directly into memory; everything else is a function call. (Replacing refcounting by function calls turned out to be too slow, unfortunately.)

I'd love feedback on what is hard to implement in Rust. We can add better API for the bad parts, and eventually even deprecate/remove stuff.
Feel free to contribute to my shared notes, post here, or reach me in any other way :)

@youknowone youknowone added C-discussion A discussion and removed question labels Feb 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-design About RustPython's own implementation C-discussion A discussion E-help-wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants