From e27c2abca1b87d4448310d7c26a1b6dcf993640e Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 13 Oct 2024 22:46:27 +0200 Subject: [PATCH 1/2] [mypyc] Replace deprecated _PyDict_GetItemStringWithError --- mypyc/lib-rt/getargs.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mypyc/lib-rt/getargs.c b/mypyc/lib-rt/getargs.c index 1bc2f5b02ba8..0f97758d6a57 100644 --- a/mypyc/lib-rt/getargs.c +++ b/mypyc/lib-rt/getargs.c @@ -250,11 +250,11 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, current_arg = 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], ¤t_arg); + if (res == 1) { --nkwargs; } - else if (PyErr_Occurred()) { + else if (res == -1) { return 0; } } @@ -370,8 +370,8 @@ 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], ¤t_arg); + if (unlikely(res == 0)) { /* arg present in tuple and in dict */ PyErr_Format(PyExc_TypeError, "argument for %.200s%s given by name ('%s') " @@ -381,7 +381,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; } } From ff0e537da92d4a5aa28a46031621de62545e8905 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 14 Oct 2024 04:44:42 +0200 Subject: [PATCH 2/2] Handle strong reference --- mypyc/lib-rt/getargs.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mypyc/lib-rt/getargs.c b/mypyc/lib-rt/getargs.c index 0f97758d6a57..4f2f8aa0be83 100644 --- a/mypyc/lib-rt/getargs.c +++ b/mypyc/lib-rt/getargs.c @@ -247,7 +247,7 @@ 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) { int res = PyDict_GetItemStringRef(kwargs, kwlist[i], ¤t_arg); @@ -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; } @@ -371,7 +372,10 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format, /* make sure there are no arguments given by name and position */ for (i = pos; i < bound_pos_args && i < len; i++) { int res = PyDict_GetItemStringRef(kwargs, kwlist[i], ¤t_arg); - if (unlikely(res == 0)) { + 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') "