Skip to content

Conversation

2bndy5
Copy link
Contributor

@2bndy5 2bndy5 commented Oct 15, 2025

resolves #1434

Instead use PyList_GetItem() for python < 3.13 or PyList_GetItemRef() for python >= 3.13.

Both are part of the Stable ABI but also propagate errors. Whereas the previous PyList_GET_ITEM() did not do any error checking and was not part of the Stable ABI.

@2bndy5

This comment was marked as resolved.

@2bndy5 2bndy5 marked this pull request as draft October 15, 2025 06:39
Comment on lines +602 to +607
py_commit_oid =
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13
PyList_GetItem(py_commit_oids, i);
#else
PyList_GetItemRef(py_commit_oids, i);
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see no .clang-format file or documented code style guidelines. So I just copied the style I observed in src/pygit2.c

This comment was marked as off-topic.

@2bndy5 2bndy5 force-pushed the replace-PyList_GET_ITEM branch from 158afd3 to 90569a5 Compare October 15, 2025 10:17
resolves libgit2#1434

Instead use [`PyList_GetItem()`] for python < 3.13 or [`PyList_GetItemRef()`] for python >= 3.13.

Both are part of the Stable ABI but also propagate errors.
Whereas the previous [`PyList_GET_ITEM()`] did not do any error checking and was not part of the Stable ABI.

[`PyList_GetItemRef()`]: https://docs.python.org/3/c-api/list.html#c.PyList_GetItemRef
[`PyList_GetItem()`]: https://docs.python.org/3/c-api/list.html#c.PyList_GetItem
[`PyList_GET_ITEM()`]: https://docs.python.org/3/c-api/list.html#c.PyList_GET_ITEM
@2bndy5 2bndy5 force-pushed the replace-PyList_GET_ITEM branch from 90569a5 to 8ada517 Compare October 19, 2025 05:34
@2bndy5 2bndy5 marked this pull request as ready for review October 19, 2025 05:35
@jdavid
Copy link
Member

jdavid commented Oct 19, 2025

PyList_GetItem returns a borrowed reference (like PyList_GET_ITEM) while PyList_GetItemRef returns a new reference, so you have to choose one, in this case use always PyList_GetItem regardless of the Python version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace PyList_GET_ITEM usages on the free-threaded build

2 participants