(Follow-up)
So I started to write a test suite for the C API. I chose to write them using "Check", a C framework to write unit tests in C.
Check looks nice:
- use fork() on UNIX/BSD to catch crashes (signals) and implement timeout
- JUnit (XML) output
- Selection of test at runtime
- straighforward API, with a short "ck_" prefix on symbols
See: https://github.com/pythoncapi/cpython/blob/pythoncapi/capi_tests/test_tuple....
For the long term, I would like to no longer support borrowed references, so I wrote *two* new C APIs:
Py_NEWAPI_BORROWED_REF: replace macros with function calls (PyTuple_GET_ITEM() calls PyTuple_GetItem()). I also added PyTuple_GetItemRef() and PyTuple_SetItemRef() to this API: similar to PyTuple_GetItem()/PyTuple_SetItem(), but use a strong reference instead of a borrowed reference. This API should provide stable ABI for the long term.
Py_NEWAPI: Py_NEWAPI_BORROWED_REF without borrowed refererences, PyTuple_GetItem() and PyTuple_SetItem() are done. This API allows to experiment more optimization inside a Python runtime: the API tracks the object lifetime.
I added a test matrix for the 3 API:
- "full API": current/old Python 3.8 API
- new C API with borrowed references: Py_NEWAPI_BORROWED_REF
- new C API without borrowed reference: Py_NEWAPI
Victor
Le ven. 31 août 2018 à 10:31, Victor Stinner <vstinner@redhat.com> a écrit :
Hi,
To be able to work on a fork of CPython, I decided to create a new GitHub organization:
https://github.com/pythoncapi/
I didn't want to work on my personal fork of CPython (vstinner/cpython). The organization has a single member: me, but I invited Eric Snow, Barry Warsaw and Pablo Galindo. Tell me if you want to join!
I moved my documentation there, the source of https://pythoncapi.readthedocs.io/ website:
https://github.com/pythoncapi/pythoncapi/
And I just forked CPython:
https://github.com/pythoncapi/cpython
I will experiment to implement the new C API in this fork, to not bother the upstream CPython.
I started with a very simple change, replace PyTuple_GET_ITEM() macro with a function call. I also started to write unit tests:
https://github.com/pythoncapi/cpython/blob/pythoncapi/capi/tests/test_tuple....
I quickly experimented to write my own C unit test framework, but I'm not really satisfied of the "verbose" API. I'm looking at googletest and Check, does someone have an experience with a C unit test framework?
I don't wante to write unit tests with Cython, cffi or anything else, because I really need very thin control on everything.
Victor