On 09/12/2021 19.26, Petr Viktorin wrote:
I'll not get back to CPython until Tuesday, but I'll add a quick note
for now. It's a bit blunt for lack of time; please don't be offended.
If the code is the authoritative source of truth, we need a proper
parser to extract the information. But we can't really use an existing
parser (e.g. we need to navigate various #ifdef combinations), and
writing a correct (=tested) custom C parser is pretty expensive. C
declarations being "deterministically discoverable by tools" is a
myth.
I know you wrote a parser (kudos!), but unfortunately I don't trust it
enough to let it define the API. Bugs in the parser could result in
the API definition silently changing.
There are other options than writing a new parser. GCC and Clang are
flexible. For example GCC can be extended with plugins and custom
attributes. We could extend the header files with custom attributes and
then use a plugin to create an ABI file from the attributes.
I created a quick n' hack
https://github.com/python/cpython/compare/main...tiran:gcc-pythonapi-plugin?expand=1
as proof of concept.
The plugin takes
PyAPI_ABI_FUNC(PyObject *) PyLong_FromLong(long);
and dumps the declaration as:
extern struct PyObject * PyLong_FromLong (long int); "abi_func"
Christian
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/N5ZTLGPLWHVI5UECVGVND43MBI4FAQN7/
Code of Conduct: http://python.org/psf/codeofconduct/