@@ -247,14 +247,14 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
247
247
#endif
248
248
if (!skip ) {
249
249
if (i < nargs && i < max ) {
250
- current_arg = PyTuple_GET_ITEM (args , i );
250
+ current_arg = Py_NewRef ( PyTuple_GET_ITEM (args , i ) );
251
251
}
252
252
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 ) {
255
255
-- nkwargs ;
256
256
}
257
- else if (PyErr_Occurred () ) {
257
+ else if (res == -1 ) {
258
258
return 0 ;
259
259
}
260
260
}
@@ -265,6 +265,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
265
265
if (current_arg ) {
266
266
PyObject * * p = va_arg (* p_va , PyObject * * );
267
267
* p = current_arg ;
268
+ Py_DECREF (current_arg );
268
269
format ++ ;
269
270
continue ;
270
271
}
@@ -370,8 +371,11 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
370
371
Py_ssize_t j ;
371
372
/* make sure there are no arguments given by name and position */
372
373
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 )) {
375
379
/* arg present in tuple and in dict */
376
380
PyErr_Format (PyExc_TypeError ,
377
381
"argument for %.200s%s given by name ('%s') "
@@ -381,7 +385,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
381
385
kwlist [i ], i + 1 );
382
386
goto latefail ;
383
387
}
384
- else if (unlikely (PyErr_Occurred () != NULL )) {
388
+ else if (unlikely (res == -1 )) {
385
389
goto latefail ;
386
390
}
387
391
}
0 commit comments