@@ -1592,14 +1592,14 @@ initialize_locals(PyThreadState *tstate, PyFunctionObject *func,
1592
1592
continue ;
1593
1593
PyObject * varname = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
1594
1594
if (func -> func_kwdefaults != NULL ) {
1595
- PyObject * def = PyDict_GetItemWithError (func -> func_kwdefaults , varname );
1595
+ PyObject * def ;
1596
+ if (PyDict_GetItemRef (func -> func_kwdefaults , varname , & def ) < 0 ) {
1597
+ goto fail_post_args ;
1598
+ }
1596
1599
if (def ) {
1597
- localsplus [i ] = Py_NewRef ( def ) ;
1600
+ localsplus [i ] = def ;
1598
1601
continue ;
1599
1602
}
1600
- else if (_PyErr_Occurred (tstate )) {
1601
- goto fail_post_args ;
1602
- }
1603
1603
}
1604
1604
missing ++ ;
1605
1605
}
@@ -2401,13 +2401,9 @@ PyEval_GetBuiltins(void)
2401
2401
PyObject *
2402
2402
_PyEval_GetBuiltin (PyObject * name )
2403
2403
{
2404
- PyThreadState * tstate = _PyThreadState_GET ();
2405
- PyObject * attr = PyDict_GetItemWithError (PyEval_GetBuiltins (), name );
2406
- if (attr ) {
2407
- Py_INCREF (attr );
2408
- }
2409
- else if (!_PyErr_Occurred (tstate )) {
2410
- _PyErr_SetObject (tstate , PyExc_AttributeError , name );
2404
+ PyObject * attr ;
2405
+ if (PyDict_GetItemRef (PyEval_GetBuiltins (), name , & attr ) == 0 ) {
2406
+ PyErr_SetObject (PyExc_AttributeError , name );
2411
2407
}
2412
2408
return attr ;
2413
2409
}
@@ -2558,12 +2554,12 @@ static PyObject *
2558
2554
import_name (PyThreadState * tstate , _PyInterpreterFrame * frame ,
2559
2555
PyObject * name , PyObject * fromlist , PyObject * level )
2560
2556
{
2561
- PyObject * import_func = _PyDict_GetItemWithError (frame -> f_builtins ,
2562
- & _Py_ID (__import__ ));
2557
+ PyObject * import_func ;
2558
+ if (PyDict_GetItemRef (frame -> f_builtins , & _Py_ID (__import__ ), & import_func ) < 0 ) {
2559
+ return NULL ;
2560
+ }
2563
2561
if (import_func == NULL ) {
2564
- if (!_PyErr_Occurred (tstate )) {
2565
- _PyErr_SetString (tstate , PyExc_ImportError , "__import__ not found" );
2566
- }
2562
+ _PyErr_SetString (tstate , PyExc_ImportError , "__import__ not found" );
2567
2563
return NULL ;
2568
2564
}
2569
2565
@@ -2574,6 +2570,7 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
2574
2570
2575
2571
/* Fast path for not overloaded __import__. */
2576
2572
if (_PyImport_IsDefaultImportFunc (tstate -> interp , import_func )) {
2573
+ Py_DECREF (import_func );
2577
2574
int ilevel = PyLong_AsInt (level );
2578
2575
if (ilevel == -1 && _PyErr_Occurred (tstate )) {
2579
2576
return NULL ;
@@ -2587,7 +2584,6 @@ import_name(PyThreadState *tstate, _PyInterpreterFrame *frame,
2587
2584
}
2588
2585
2589
2586
PyObject * args [5 ] = {name , frame -> f_globals , locals , fromlist , level };
2590
- Py_INCREF (import_func );
2591
2587
PyObject * res = PyObject_Vectorcall (import_func , args , 5 , NULL );
2592
2588
Py_DECREF (import_func );
2593
2589
return res ;
0 commit comments