Skip to content

[mypyc] Replace deprecated _PyDict_GetItemStringWithError #17930

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

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions mypyc/lib-rt/getargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
#endif
if (!skip) {
if (i < nargs && i < max) {
current_arg = PyTuple_GET_ITEM(args, i);
current_arg = Py_NewRef(PyTuple_GET_ITEM(args, i));
}
else if (nkwargs && i >= pos) {
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (current_arg) {
int res = PyDict_GetItemStringRef(kwargs, kwlist[i], &current_arg);
if (res == 1) {
--nkwargs;
}
else if (PyErr_Occurred()) {
else if (res == -1) {
return 0;
}
}
Expand All @@ -265,6 +265,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
if (current_arg) {
PyObject **p = va_arg(*p_va, PyObject **);
*p = current_arg;
Py_DECREF(current_arg);
format++;
continue;
}
Expand Down Expand Up @@ -370,8 +371,11 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
Py_ssize_t j;
/* make sure there are no arguments given by name and position */
for (i = pos; i < bound_pos_args && i < len; i++) {
current_arg = _PyDict_GetItemStringWithError(kwargs, kwlist[i]);
if (unlikely(current_arg != NULL)) {
int res = PyDict_GetItemStringRef(kwargs, kwlist[i], &current_arg);
if (res == 1) {
Py_DECREF(current_arg);
}
else if (unlikely(res == 0)) {
/* arg present in tuple and in dict */
PyErr_Format(PyExc_TypeError,
"argument for %.200s%s given by name ('%s') "
Expand All @@ -381,7 +385,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
kwlist[i], i+1);
goto latefail;
}
else if (unlikely(PyErr_Occurred() != NULL)) {
else if (unlikely(res == -1)) {
goto latefail;
}
}
Expand Down
Loading