Add symbols of the stable ABI to python3dll.c by vstinner · Pull Request #23598 · python/cpython · GitHub
Skip to content

Add symbols of the stable ABI to python3dll.c - #23598

Merged
vstinner merged 1 commit into
python:masterfrom
vstinner:stable_abi
Dec 16, 2020
Merged

Add symbols of the stable ABI to python3dll.c#23598
vstinner merged 1 commit into
python:masterfrom
vstinner:stable_abi

Conversation

@vstinner

@vstinner vstinner commented Dec 1, 2020

Copy link
Copy Markdown
Member

Add the following symbols to python3dll.c:

Add the following symbols to python3dll.c:

* PyFrame_GetCode (bpo-40421)
* PyFrame_GetLineNumber (bpo-40421)
* PyModule_AddObjectRef (bpo-1635741)
* PyObject_CallNoArgs (bpo-37194)
* PyThreadState_GetFrame (bpo-39947)
* PyThreadState_GetID (bpo-39947)
* PyThreadState_GetInterpreter (bpo-39947)
@vstinner

vstinner commented Dec 1, 2020

Copy link
Copy Markdown
Member Author

@markshannon

Copy link
Copy Markdown
Member

Can we please stop exposing PyThreadState in the API. It is unsafe.

There is no way to prevent race conditions when used from without the GIL held.
If the GIL is held for more than one independent interpreters, then deadlock becomes a real risk.
If the functions are only called from threads associated with one interpreter then PyThreadState_GetInterpreter is redundant.

The lifetime of a PyThreadState struct is poorly defined, since it isn't a reference counted object, so use-after-free is possible.

@vstinner

vstinner commented Dec 1, 2020

Copy link
Copy Markdown
Member Author

Can we please stop exposing PyThreadState in the API. It is unsafe.

I guess that you are talking about bpo-39947. Functions are added to the limited C API in Python 3.9. The purpose of this issue is to make the PyThreadState structure opaque, currently C extensions access directly PyThreadState members. I suggest you to discuss on bpo-39947 directly.

This issue is only about fixing the Windows implementation for the stable ABI.

@ZackerySpytz

Copy link
Copy Markdown
Contributor

I like this PR, but GH-23415 is already open for the addition of PyObject_CallNoArgs() to python3dll.c.

@alex

alex commented Dec 15, 2020

Copy link
Copy Markdown
Member

Are these already exposed in the headers with #define PY_LIMITED_API?

@vstinner

Copy link
Copy Markdown
Member Author

Are these already exposed in the headers with #define PY_LIMITED_API?

This PR doesn't move any function to the stable ABI. They are already part of the stable API.

This PR only fix the Windows implementation of the stable ABI.

@alex alex left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to find a way to make sure we're not constantly leaving windows abi3 in a broken state.

@vstinner

Copy link
Copy Markdown
Member Author

@alex: "We really need to find a way to make sure we're not constantly leaving windows abi3 in a broken state."

Pablo is working on a Linux tool for that: Tools/scripts/stable_abi.py

It shouldn't be too hard to check that Doc/data/stable_abi.dat and PC/python3dll.c are kept in sync (in the "Tests / Check if generated files are up to date" CI job).

@vstinner
vstinner merged commit fcc6935 into python:master Dec 16, 2020
@vstinner
vstinner deleted the stable_abi branch December 16, 2020 14:08
@alex

alex commented Dec 16, 2020 via email

Copy link
Copy Markdown
Member

@vstinner

Copy link
Copy Markdown
Member Author

I manually backported the change to 3.9 which uses a different format for the Windows stable ABI: PR #23801.

@bedevere-bot

Copy link
Copy Markdown

vstinner added a commit that referenced this pull request Dec 16, 2020
Add the following symbols to python3dll.c:

* PyFrame_GetCode (bpo-40421)
* PyFrame_GetLineNumber (bpo-40421)
* PyObject_CallNoArgs (bpo-37194)
* PyThreadState_GetFrame (bpo-39947)
* PyThreadState_GetID (bpo-39947)
* PyThreadState_GetInterpreter (bpo-39947)

(cherry picked from commit fcc6935)
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
Add the following symbols to python3dll.c:

* PyFrame_GetCode (bpo-40421)
* PyFrame_GetLineNumber (bpo-40421)
* PyModule_AddObjectRef (bpo-1635741)
* PyObject_CallNoArgs (bpo-37194)
* PyThreadState_GetFrame (bpo-39947)
* PyThreadState_GetID (bpo-39947)
* PyThreadState_GetInterpreter (bpo-39947)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants