@@ -1491,7 +1491,6 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
1491
1491
int i , pos , len ;
1492
1492
int skip = 0 ;
1493
1493
Py_ssize_t nargs , nkwargs ;
1494
- PyObject * current_arg ;
1495
1494
freelistentry_t static_entries [STATIC_FREELIST_ENTRIES ];
1496
1495
freelist_t freelist ;
1497
1496
@@ -1621,17 +1620,17 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
1621
1620
return cleanreturn (0 , & freelist );
1622
1621
}
1623
1622
if (!skip ) {
1623
+ PyObject * current_arg ;
1624
1624
if (i < nargs ) {
1625
- current_arg = PyTuple_GET_ITEM (args , i );
1625
+ current_arg = Py_NewRef ( PyTuple_GET_ITEM (args , i ) );
1626
1626
}
1627
1627
else if (nkwargs && i >= pos ) {
1628
- current_arg = _PyDict_GetItemStringWithError (kwargs , kwlist [i ]);
1628
+ if (PyDict_GetItemStringRef (kwargs , kwlist [i ], & current_arg ) < 0 ) {
1629
+ return cleanreturn (0 , & freelist );
1630
+ }
1629
1631
if (current_arg ) {
1630
1632
-- nkwargs ;
1631
1633
}
1632
- else if (PyErr_Occurred ()) {
1633
- return cleanreturn (0 , & freelist );
1634
- }
1635
1634
}
1636
1635
else {
1637
1636
current_arg = NULL ;
@@ -1640,6 +1639,7 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
1640
1639
if (current_arg ) {
1641
1640
msg = convertitem (current_arg , & format , p_va , flags ,
1642
1641
levels , msgbuf , sizeof (msgbuf ), & freelist );
1642
+ Py_DECREF (current_arg );
1643
1643
if (msg ) {
1644
1644
seterror (i + 1 , msg , levels , fname , custom_msg );
1645
1645
return cleanreturn (0 , & freelist );
@@ -1710,8 +1710,12 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
1710
1710
Py_ssize_t j ;
1711
1711
/* make sure there are no arguments given by name and position */
1712
1712
for (i = pos ; i < nargs ; i ++ ) {
1713
- current_arg = _PyDict_GetItemStringWithError (kwargs , kwlist [i ]);
1713
+ PyObject * current_arg ;
1714
+ if (PyDict_GetItemStringRef (kwargs , kwlist [i ], & current_arg ) < 0 ) {
1715
+ return cleanreturn (0 , & freelist );
1716
+ }
1714
1717
if (current_arg ) {
1718
+ Py_DECREF (current_arg );
1715
1719
/* arg present in tuple and in dict */
1716
1720
PyErr_Format (PyExc_TypeError ,
1717
1721
"argument for %.200s%s given by name ('%s') "
@@ -1721,9 +1725,6 @@ vgetargskeywords(PyObject *args, PyObject *kwargs, const char *format,
1721
1725
kwlist [i ], i + 1 );
1722
1726
return cleanreturn (0 , & freelist );
1723
1727
}
1724
- else if (PyErr_Occurred ()) {
1725
- return cleanreturn (0 , & freelist );
1726
- }
1727
1728
}
1728
1729
/* make sure there are no extraneous keyword arguments */
1729
1730
j = 0 ;
@@ -1985,15 +1986,15 @@ find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key)
1985
1986
/* kwname == key will normally find a match in since keyword keys
1986
1987
should be interned strings; if not retry below in a new loop. */
1987
1988
if (kwname == key ) {
1988
- return kwstack [i ];
1989
+ return Py_NewRef ( kwstack [i ]) ;
1989
1990
}
1990
1991
}
1991
1992
1992
1993
for (i = 0 ; i < nkwargs ; i ++ ) {
1993
1994
PyObject * kwname = PyTuple_GET_ITEM (kwnames , i );
1994
1995
assert (PyUnicode_Check (kwname ));
1995
1996
if (_PyUnicode_EQ (kwname , key )) {
1996
- return kwstack [i ];
1997
+ return Py_NewRef ( kwstack [i ]) ;
1997
1998
}
1998
1999
}
1999
2000
return NULL ;
@@ -2013,7 +2014,6 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
2013
2014
PyObject * keyword ;
2014
2015
int i , pos , len ;
2015
2016
Py_ssize_t nkwargs ;
2016
- PyObject * current_arg ;
2017
2017
freelistentry_t static_entries [STATIC_FREELIST_ENTRIES ];
2018
2018
freelist_t freelist ;
2019
2019
PyObject * const * kwstack = NULL ;
@@ -2108,14 +2108,14 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
2108
2108
}
2109
2109
assert (!IS_END_OF_FORMAT (* format ));
2110
2110
2111
+ PyObject * current_arg ;
2111
2112
if (i < nargs ) {
2112
- current_arg = args [i ];
2113
+ current_arg = Py_NewRef ( args [i ]) ;
2113
2114
}
2114
2115
else if (nkwargs && i >= pos ) {
2115
2116
keyword = PyTuple_GET_ITEM (kwtuple , i - pos );
2116
2117
if (kwargs != NULL ) {
2117
- current_arg = PyDict_GetItemWithError (kwargs , keyword );
2118
- if (!current_arg && PyErr_Occurred ()) {
2118
+ if (PyDict_GetItemRef (kwargs , keyword , & current_arg ) < 0 ) {
2119
2119
return cleanreturn (0 , & freelist );
2120
2120
}
2121
2121
}
@@ -2133,6 +2133,7 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
2133
2133
if (current_arg ) {
2134
2134
msg = convertitem (current_arg , & format , p_va , flags ,
2135
2135
levels , msgbuf , sizeof (msgbuf ), & freelist );
2136
+ Py_DECREF (current_arg );
2136
2137
if (msg ) {
2137
2138
seterror (i + 1 , msg , levels , parser -> fname , parser -> custom_msg );
2138
2139
return cleanreturn (0 , & freelist );
@@ -2183,17 +2184,18 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs,
2183
2184
if (nkwargs > 0 ) {
2184
2185
/* make sure there are no arguments given by name and position */
2185
2186
for (i = pos ; i < nargs ; i ++ ) {
2187
+ PyObject * current_arg ;
2186
2188
keyword = PyTuple_GET_ITEM (kwtuple , i - pos );
2187
2189
if (kwargs != NULL ) {
2188
- current_arg = PyDict_GetItemWithError (kwargs , keyword );
2189
- if (!current_arg && PyErr_Occurred ()) {
2190
+ if (PyDict_GetItemRef (kwargs , keyword , & current_arg ) < 0 ) {
2190
2191
return cleanreturn (0 , & freelist );
2191
2192
}
2192
2193
}
2193
2194
else {
2194
2195
current_arg = find_keyword (kwnames , kwstack , keyword );
2195
2196
}
2196
2197
if (current_arg ) {
2198
+ Py_DECREF (current_arg );
2197
2199
/* arg present in tuple and in dict */
2198
2200
PyErr_Format (PyExc_TypeError ,
2199
2201
"argument for %.200s%s given by name ('%U') "
@@ -2248,7 +2250,6 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
2248
2250
int i , posonly , minposonly , maxargs ;
2249
2251
int reqlimit = minkw ? maxpos + minkw : minpos ;
2250
2252
Py_ssize_t nkwargs ;
2251
- PyObject * current_arg ;
2252
2253
PyObject * const * kwstack = NULL ;
2253
2254
2254
2255
assert (kwargs == NULL || PyDict_Check (kwargs ));
@@ -2343,11 +2344,11 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
2343
2344
2344
2345
/* copy keyword args using kwtuple to drive process */
2345
2346
for (i = Py_MAX ((int )nargs , posonly ); i < maxargs ; i ++ ) {
2347
+ PyObject * current_arg ;
2346
2348
if (nkwargs ) {
2347
2349
keyword = PyTuple_GET_ITEM (kwtuple , i - posonly );
2348
2350
if (kwargs != NULL ) {
2349
- current_arg = PyDict_GetItemWithError (kwargs , keyword );
2350
- if (!current_arg && PyErr_Occurred ()) {
2351
+ if (PyDict_GetItemRef (kwargs , keyword , & current_arg ) < 0 ) {
2351
2352
return NULL ;
2352
2353
}
2353
2354
}
@@ -2365,6 +2366,7 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
2365
2366
buf [i ] = current_arg ;
2366
2367
2367
2368
if (current_arg ) {
2369
+ Py_DECREF (current_arg );
2368
2370
-- nkwargs ;
2369
2371
}
2370
2372
else if (i < minpos || (maxpos <= i && i < reqlimit )) {
@@ -2382,17 +2384,18 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs,
2382
2384
if (nkwargs > 0 ) {
2383
2385
/* make sure there are no arguments given by name and position */
2384
2386
for (i = posonly ; i < nargs ; i ++ ) {
2387
+ PyObject * current_arg ;
2385
2388
keyword = PyTuple_GET_ITEM (kwtuple , i - posonly );
2386
2389
if (kwargs != NULL ) {
2387
- current_arg = PyDict_GetItemWithError (kwargs , keyword );
2388
- if (!current_arg && PyErr_Occurred ()) {
2390
+ if (PyDict_GetItemRef (kwargs , keyword , & current_arg ) < 0 ) {
2389
2391
return NULL ;
2390
2392
}
2391
2393
}
2392
2394
else {
2393
2395
current_arg = find_keyword (kwnames , kwstack , keyword );
2394
2396
}
2395
2397
if (current_arg ) {
2398
+ Py_DECREF (current_arg );
2396
2399
/* arg present in tuple and in dict */
2397
2400
PyErr_Format (PyExc_TypeError ,
2398
2401
"argument for %.200s%s given by name ('%U') "
@@ -2424,7 +2427,6 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs,
2424
2427
int i , posonly , minposonly , maxargs ;
2425
2428
int reqlimit = minkw ? maxpos + minkw : minpos ;
2426
2429
Py_ssize_t nkwargs ;
2427
- PyObject * current_arg ;
2428
2430
PyObject * const * kwstack = NULL ;
2429
2431
2430
2432
assert (kwargs == NULL || PyDict_Check (kwargs ));
@@ -2497,13 +2499,12 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs,
2497
2499
}
2498
2500
2499
2501
/* copy keyword args using kwtuple to drive process */
2500
- for (i = Py_MAX ((int )nargs , posonly ) -
2501
- Py_SAFE_DOWNCAST ( varargssize , Py_ssize_t , int ); i < maxargs ; i ++ ) {
2502
+ for (i = Py_MAX ((int )nargs , posonly ) - Py_SAFE_DOWNCAST ( varargssize , Py_ssize_t , int ); i < maxargs ; i ++ ) {
2503
+ PyObject * current_arg ;
2502
2504
if (nkwargs ) {
2503
2505
keyword = PyTuple_GET_ITEM (kwtuple , i - posonly );
2504
2506
if (kwargs != NULL ) {
2505
- current_arg = PyDict_GetItemWithError (kwargs , keyword );
2506
- if (!current_arg && PyErr_Occurred ()) {
2507
+ if (PyDict_GetItemRef (kwargs , keyword , & current_arg ) < 0 ) {
2507
2508
goto exit ;
2508
2509
}
2509
2510
}
@@ -2536,6 +2537,7 @@ _PyArg_UnpackKeywordsWithVararg(PyObject *const *args, Py_ssize_t nargs,
2536
2537
}
2537
2538
2538
2539
if (current_arg ) {
2540
+ Py_DECREF (current_arg );
2539
2541
-- nkwargs ;
2540
2542
}
2541
2543
else if (i < minpos || (maxpos <= i && i < reqlimit )) {
0 commit comments