You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[C API] Add explicit support for Cython to the C API #89410
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2021-09-20.10:59:47.125>labels= ['expert-C-API', 'type-feature']
title='[C API] Add explicit support for Cython to the C API'updated_at=<Date2022-02-23.15:21:36.827>user='https://github.com/markshannon'
As the C API has evolved it has grown features in an ad-hoc way, driven by the needs to whoever has bothered to add the code.
Maybe we should be a bit more principled about this. Specifically we should make sure that there is a well defined interface between CPython and the other major components of the Python ecosystem.
The obvious places to start are with Cython and Numpy.
This issue deals specifically with Cython. I will leave it to someone who know more about Numpy to open an issue for Numpy.
I disagree. All that is doing is locking in the current poor interface.
We do need to extend the C API for these uses, yes. But we need an API that addresses Cython's needs directly and at a higher level.
For example, Cython often wants to insert a frame into the call stack for debugging and introspection.
Rather than have Cython laboriously create a Python frame with fake code object, etc., it would make much more sense for us to offer an API to insert a "native" frame into the stack and update the line number.
Rather than have Cython laboriously create a Python frame with fake code object, etc., it would make much more sense for us to offer an API to insert a "native" frame into the stack and update the line number.
I agree with Mark. Instead of exposing internal details in low-level API we should add more high-level API to satisfy concrete needs. It will give us more freedom of changing internals in future.
Activity
markshannon commentedon Sep 20, 2021
As the C API has evolved it has grown features in an ad-hoc way, driven by the needs to whoever has bothered to add the code.
Maybe we should be a bit more principled about this. Specifically we should make sure that there is a well defined interface between CPython and the other major components of the Python ecosystem.
The obvious places to start are with Cython and Numpy.
This issue deals specifically with Cython. I will leave it to someone who know more about Numpy to open an issue for Numpy.
Matching Cython issue: cython/cython#4382
This issue is an attempt to stop the annual occurrence of bugs like https://bugs.python.org/issue43760#msg393401
vstinner commentedon Oct 13, 2021
We need to add C API to abstract access to structures used by Cython:
[-]Add explicit support for Cython to the C API.[/-][+][C API] Add explicit support for Cython to the C API[/+]markshannon commentedon Oct 13, 2021
I disagree. All that is doing is locking in the current poor interface.
We do need to extend the C API for these uses, yes. But we need an API that addresses Cython's needs directly and at a higher level.
For example, Cython often wants to insert a frame into the call stack for debugging and introspection.
Rather than have Cython laboriously create a Python frame with fake code object, etc., it would make much more sense for us to offer an API to insert a "native" frame into the stack and update the line number.
E.g. something like:
We might even want to use such an API ourselves in some modules.
vstinner commentedon Oct 13, 2021
I agree with that.
serhiy-storchaka commentedon Oct 13, 2021
I agree with Mark. Instead of exposing internal details in low-level API we should add more high-level API to satisfy concrete needs. It will give us more freedom of changing internals in future.
vstinner commentedon Oct 14, 2021
My first attempt: Add PyThreadState_EnterTracing() and PyThreadState_LeaveTracing()
#28542
It adds an abstraction on accesses to PyThreadState.tracing and PyThreadState.cframe.use_tracing members.
vstinner commentedon Feb 23, 2022
I created bpo-46836: "[C API] Move PyFrameObject to the internal C API".
vstinner commentedon Dec 20, 2023
I closed #107076 as a duplicate of this issue.
vstinner commentedon Oct 9, 2025
See also:
vstinner commentedon Oct 9, 2025
@da-woods created a list of Python internals used by Cython in 2022: cython/cython#4635