markshannon / New-C-API-for-Python

Design and discussion for the new C-API for Python
Creative Commons Zero v1.0 Universal
15 stars 1 forks source link

Don't return structs. #13

Closed markshannon closed 2 years ago

markshannon commented 2 years ago

While returning structs makes for a nicer C API, it doesn't necessarily map cleanly and obviously to the ABI. Which can make it tricky to use from Rust, or other languages. Different architectures and compilers have different ways of returning structs, whereas returning scalars is much more regular.

Therefore we should change

PyResult foo(int arg);

to

int foo(int arg, PyRef *result);

This will be a bit slower in some cases, but may be faster in others.