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

[C API] PyOS_ReadlineFunctionPointer API rely on private _PyOS_ReadlineTState variable removed in Python 3.13 #112446

Closed
vstinner opened this issue Nov 27, 2023 · 2 comments
Labels
3.13 bugs and security fixes topic-C-API

Comments

@vstinner
Copy link
Member

Hi,

I removed the _PyOS_ReadlineTState variable from the public C API (it was moved to the internal C API). The gdb project sets its readline callback and uses the _PyOS_ReadlineTState variable and so fails to build on Python 3.13.0 alpha2: https://bugzilla.redhat.com/show_bug.cgi?id=2250652

gdb: PyOS_ReadlineFunctionPointer = gdbpy_readline_wrapper;

The gdb function uses _PyOS_ReadlineTState to use the Python C API:

PyEval_RestoreThread (_PyOS_ReadlineTState);
gdbpy_convert_exception (except);
PyEval_SaveThread ();

source: py-gdb-readline.c

The _PyOS_ReadlineTState variable was added in 2004 by commit 30ea2f2.

The callback is called with the GIL released. The _PyOS_ReadlineTState variable is used to acquire again the GIL.


In 2020, I made fixes related to GIL but not directly to this issue:

@AlexWaygood AlexWaygood added the 3.13 bugs and security fixes label Nov 28, 2023
@vstinner
Copy link
Member Author

vstinner commented Dec 8, 2023

The documentation https://docs.python.org/dev/c-api/veryhigh.html#c.PyOS_ReadlineFunctionPointer should also mention the internal lock, at least explain that the callback cannot be called twice at the same time in two threads.

@vstinner
Copy link
Member Author

Well, if a readline callback needs to use the Python C API, PyGILState_Ensure() and PyGILState_Release() to be used to temporarily acquire/release the GIL. I'm not sure of the advantage of using PyEval_RestoreThread (_PyOS_ReadlineTState) and PyEval_SaveThread() instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes topic-C-API
Projects
None yet
Development

No branches or pull requests

2 participants