Skip to content

Conversation

@ngoldbaum
Copy link
Member

@ngoldbaum ngoldbaum commented Apr 9, 2024

PEP 703 has some discussion about why this is necessary. In short, in a GIL-less python, it's possible for item in all three cases to be garbage collected before the PyTuple_GetItem call can execute. Using PyList_GetItemRef ensures that can't happen.

There's still one more PyList_GetItem usage in a test, but it's there specifically to test C API usages that create borrowed references, so I left it alone.

@ngoldbaum
Copy link
Member Author

If this sort of migration is fine, I'll start next on migrating usages of PyDict_GetItem and similar PyDict APIs that return borrowed references.

Copy link
Contributor

@mhvk mhvk left a comment

Choose a reason for hiding this comment

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

Seems sensible. Doing quick git grep, it seems the total number of cases of any of these is, thankfully, not all that large!

@charris charris merged commit 35bce08 into numpy:main Apr 9, 2024
@charris
Copy link
Member

charris commented Apr 9, 2024

Thanks Nathan.

@rgommers rgommers added 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703) 03 - Maintenance labels Apr 10, 2024
@rgommers rgommers added this to the 2.1.0 release milestone Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

03 - Maintenance 39 - free-threading PRs and issues related to support for free-threading CPython (a.k.a. no-GIL, PEP 703)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants