@@ -247,14 +247,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
247247#endif
248248 if (!skip ) {
249249 if (i < nargs && i < max ) {
250- current_arg = PyTuple_GET_ITEM (args , i );
250+ current_arg = Py_NewRef ( PyTuple_GET_ITEM (args , i ) );
251251 }
252252 else if (nkwargs && i >= pos ) {
253- current_arg = _PyDict_GetItemStringWithError (kwargs , kwlist [i ]);
254- if (current_arg ) {
253+ int res = PyDict_GetItemStringRef (kwargs , kwlist [i ], & current_arg );
254+ if (res == 1 ) {
255255 -- nkwargs ;
256256 }
257- else if (PyErr_Occurred () ) {
257+ else if (res == -1 ) {
258258 return 0 ;
259259 }
260260 }
@@ -265,6 +265,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
265265 if (current_arg ) {
266266 PyObject * * p = va_arg (* p_va , PyObject * * );
267267 * p = current_arg ;
268+ Py_DECREF (current_arg );
268269 format ++ ;
269270 continue ;
270271 }
@@ -370,8 +371,11 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
370371 Py_ssize_t j ;
371372 /* make sure there are no arguments given by name and position */
372373 for (i = pos ; i < bound_pos_args && i < len ; i ++ ) {
373- current_arg = _PyDict_GetItemStringWithError (kwargs , kwlist [i ]);
374- if (unlikely (current_arg != NULL )) {
374+ int res = PyDict_GetItemStringRef (kwargs , kwlist [i ], & current_arg );
375+ if (res == 1 ) {
376+ Py_DECREF (current_arg );
377+ }
378+ else if (unlikely (res == 0 )) {
375379 /* arg present in tuple and in dict */
376380 PyErr_Format (PyExc_TypeError ,
377381 "argument for %.200s%s given by name ('%s') "
@@ -381,7 +385,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
381385 kwlist [i ], i + 1 );
382386 goto latefail ;
383387 }
384- else if (unlikely (PyErr_Occurred () != NULL )) {
388+ else if (unlikely (res == -1 )) {
385389 goto latefail ;
386390 }
387391 }
0 commit comments