@@ -372,26 +372,26 @@ get_attrib_from_keywords(PyObject *kwds)
372
372
if (attrib_str == NULL ) {
373
373
return NULL ;
374
374
}
375
- PyObject * attrib = PyDict_GetItemWithError (kwds , attrib_str );
376
-
377
- if (attrib ) {
375
+ PyObject * attrib ;
376
+ if (PyDict_GetItemRef (kwds , attrib_str , & attrib ) == 0 ) {
377
+ attrib = PyDict_New ();
378
+ }
379
+ else if (attrib ) {
378
380
/* If attrib was found in kwds, copy its value and remove it from
379
381
* kwds
380
382
*/
381
383
if (!PyDict_Check (attrib )) {
382
384
Py_DECREF (attrib_str );
383
385
PyErr_Format (PyExc_TypeError , "attrib must be dict, not %.100s" ,
384
386
Py_TYPE (attrib )-> tp_name );
387
+ Py_DECREF (attrib );
385
388
return NULL ;
386
389
}
387
- attrib = PyDict_Copy (attrib );
390
+ Py_SETREF ( attrib , PyDict_Copy (attrib ) );
388
391
if (attrib && PyDict_DelItem (kwds , attrib_str ) < 0 ) {
389
392
Py_SETREF (attrib , NULL );
390
393
}
391
394
}
392
- else if (!PyErr_Occurred ()) {
393
- attrib = PyDict_New ();
394
- }
395
395
396
396
Py_DECREF (attrib_str );
397
397
@@ -1421,11 +1421,14 @@ _elementtree_Element_get_impl(ElementObject *self, PyObject *key,
1421
1421
{
1422
1422
if (self -> extra && self -> extra -> attrib ) {
1423
1423
PyObject * attrib = Py_NewRef (self -> extra -> attrib );
1424
- PyObject * value = Py_XNewRef (PyDict_GetItemWithError (attrib , key ));
1425
- Py_DECREF (attrib );
1426
- if (value != NULL || PyErr_Occurred ()) {
1424
+ PyObject * value ;
1425
+ if (PyDict_GetItemRef (attrib , key , & value ) != 0 ) {
1426
+ // found or error
1427
+ Py_DECREF (attrib );
1427
1428
return value ;
1428
1429
}
1430
+ // not found
1431
+ Py_DECREF (attrib );
1429
1432
}
1430
1433
1431
1434
return Py_NewRef (default_value );
@@ -3085,9 +3088,7 @@ makeuniversal(XMLParserObject* self, const char* string)
3085
3088
if (!key )
3086
3089
return NULL ;
3087
3090
3088
- value = Py_XNewRef (PyDict_GetItemWithError (self -> names , key ));
3089
-
3090
- if (value == NULL && !PyErr_Occurred ()) {
3091
+ if (PyDict_GetItemRef (self -> names , key , & value ) == 0 ) {
3091
3092
/* new name. convert to universal name, and decode as
3092
3093
necessary */
3093
3094
0 commit comments