@@ -643,16 +643,12 @@ dummy_func(
643
643
inst (BINARY_SUBSCR_DICT , (unused /1 , dict , sub -- res )) {
644
644
DEOPT_IF (!PyDict_CheckExact (dict ));
645
645
STAT_INC (BINARY_SUBSCR , hit );
646
- res = PyDict_GetItemWithError (dict , sub );
647
- if (res == NULL ) {
648
- if (!_PyErr_Occurred (tstate )) {
649
- _PyErr_SetKeyError (sub );
650
- }
651
- DECREF_INPUTS ();
652
- ERROR_IF (true, error );
646
+ int rc = PyDict_GetItemRef (dict , sub , & res );
647
+ if (rc == 0 ) {
648
+ _PyErr_SetKeyError (sub );
653
649
}
654
- Py_INCREF (res ); // Do this before DECREF'ing dict, sub
655
650
DECREF_INPUTS ();
651
+ ERROR_IF (rc <= 0 , error ); // not found or error
656
652
}
657
653
658
654
inst (BINARY_SUBSCR_GETITEM , (unused /1 , container , sub -- unused )) {
@@ -1349,14 +1345,10 @@ dummy_func(
1349
1345
GOTO_ERROR (error );
1350
1346
}
1351
1347
if (v == NULL ) {
1352
- v = PyDict_GetItemWithError (GLOBALS (), name );
1353
- if (v != NULL ) {
1354
- Py_INCREF (v );
1355
- }
1356
- else if (_PyErr_Occurred (tstate )) {
1348
+ if (PyDict_GetItemRef (GLOBALS (), name , & v ) < 0 ) {
1357
1349
GOTO_ERROR (error );
1358
1350
}
1359
- else {
1351
+ if ( v == NULL ) {
1360
1352
if (PyMapping_GetOptionalItem (BUILTINS (), name , & v ) < 0 ) {
1361
1353
GOTO_ERROR (error );
1362
1354
}
@@ -1383,14 +1375,10 @@ dummy_func(
1383
1375
GOTO_ERROR (error );
1384
1376
}
1385
1377
if (v == NULL ) {
1386
- v = PyDict_GetItemWithError (GLOBALS (), name );
1387
- if (v != NULL ) {
1388
- Py_INCREF (v );
1389
- }
1390
- else if (_PyErr_Occurred (tstate )) {
1378
+ if (PyDict_GetItemRef (GLOBALS (), name , & v ) < 0 ) {
1391
1379
GOTO_ERROR (error );
1392
1380
}
1393
- else {
1381
+ if ( v == NULL ) {
1394
1382
if (PyMapping_GetOptionalItem (BUILTINS (), name , & v ) < 0 ) {
1395
1383
GOTO_ERROR (error );
1396
1384
}
@@ -1663,34 +1651,17 @@ dummy_func(
1663
1651
ERROR_IF (true, error );
1664
1652
}
1665
1653
/* check if __annotations__ in locals()... */
1666
- if (PyDict_CheckExact (LOCALS ())) {
1667
- ann_dict = _PyDict_GetItemWithError (LOCALS (),
1668
- & _Py_ID (__annotations__ ));
1669
- if (ann_dict == NULL ) {
1670
- ERROR_IF (_PyErr_Occurred (tstate ), error );
1671
- /* ...if not, create a new one */
1672
- ann_dict = PyDict_New ();
1673
- ERROR_IF (ann_dict == NULL , error );
1674
- err = PyDict_SetItem (LOCALS (), & _Py_ID (__annotations__ ),
1675
- ann_dict );
1676
- Py_DECREF (ann_dict );
1677
- ERROR_IF (err , error );
1678
- }
1654
+ ERROR_IF (PyMapping_GetOptionalItem (LOCALS (), & _Py_ID (__annotations__ ), & ann_dict ) < 0 , error );
1655
+ if (ann_dict == NULL ) {
1656
+ ann_dict = PyDict_New ();
1657
+ ERROR_IF (ann_dict == NULL , error );
1658
+ err = PyObject_SetItem (LOCALS (), & _Py_ID (__annotations__ ),
1659
+ ann_dict );
1660
+ Py_DECREF (ann_dict );
1661
+ ERROR_IF (err , error );
1679
1662
}
1680
1663
else {
1681
- /* do the same if locals() is not a dict */
1682
- ERROR_IF (PyMapping_GetOptionalItem (LOCALS (), & _Py_ID (__annotations__ ), & ann_dict ) < 0 , error );
1683
- if (ann_dict == NULL ) {
1684
- ann_dict = PyDict_New ();
1685
- ERROR_IF (ann_dict == NULL , error );
1686
- err = PyObject_SetItem (LOCALS (), & _Py_ID (__annotations__ ),
1687
- ann_dict );
1688
- Py_DECREF (ann_dict );
1689
- ERROR_IF (err , error );
1690
- }
1691
- else {
1692
- Py_DECREF (ann_dict );
1693
- }
1664
+ Py_DECREF (ann_dict );
1694
1665
}
1695
1666
}
1696
1667
0 commit comments