Skip to content

Commit 8ada517

Browse files
committed
fix: replace PyList_GET_ITEM()
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. [`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
1 parent 8fb06fa commit 8ada517

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/repository.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,14 @@ merge_base_xxx(Repository *self, PyObject *args, git_merge_base_xxx_t git_merge_
599599
}
600600

601601
for (; i < commit_oid_count; i++) {
602-
py_commit_oid = PyList_GET_ITEM(py_commit_oids, i);
602+
py_commit_oid =
603+
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13
604+
PyList_GetItem(py_commit_oids, i);
605+
#else
606+
PyList_GetItemRef(py_commit_oids, i);
607+
#endif
608+
if (py_commit_oid == NULL)
609+
goto out;
603610
err = py_oid_to_git_oid_expand(self->repo, py_commit_oid, &commit_oids[i]);
604611
if (err < 0)
605612
goto out;
@@ -1052,7 +1059,14 @@ Repository_create_commit(Repository *self, PyObject *args)
10521059
goto out;
10531060
}
10541061
for (; i < parent_count; i++) {
1055-
py_parent = PyList_GET_ITEM(py_parents, i);
1062+
py_parent =
1063+
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13
1064+
PyList_GetItem(py_parents, i);
1065+
#else
1066+
PyList_GetItemRef(py_parents, i);
1067+
#endif
1068+
if (py_parent == NULL)
1069+
goto out;
10561070
len = py_oid_to_git_oid(py_parent, &oid);
10571071
if (len == 0)
10581072
goto out;
@@ -1135,7 +1149,14 @@ Repository_create_commit_string(Repository *self, PyObject *args)
11351149
goto out;
11361150
}
11371151
for (; i < parent_count; i++) {
1138-
py_parent = PyList_GET_ITEM(py_parents, i);
1152+
py_parent =
1153+
#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION < 13
1154+
PyList_GetItem(py_parents, i);
1155+
#else
1156+
PyList_GetItemRef(py_parents, i);
1157+
#endif
1158+
if (py_parent == NULL)
1159+
goto out;
11391160
len = py_oid_to_git_oid(py_parent, &oid);
11401161
if (len == 0)
11411162
goto out;

0 commit comments

Comments
 (0)