@@ -1086,26 +1086,11 @@ dummy_func(
1086
1086
}
1087
1087
1088
1088
inst (LOAD_BUILD_CLASS , ( -- bc )) {
1089
- if (PyDict_CheckExact (BUILTINS ())) {
1090
- bc = _PyDict_GetItemWithError (BUILTINS (),
1091
- & _Py_ID (__build_class__ ));
1092
- if (bc == NULL ) {
1093
- if (!_PyErr_Occurred (tstate )) {
1094
- _PyErr_SetString (tstate , PyExc_NameError ,
1095
- "__build_class__ not found" );
1096
- }
1097
- ERROR_IF (true, error );
1098
- }
1099
- Py_INCREF (bc );
1100
- }
1101
- else {
1102
- bc = PyObject_GetItem (BUILTINS (), & _Py_ID (__build_class__ ));
1103
- if (bc == NULL ) {
1104
- if (_PyErr_ExceptionMatches (tstate , PyExc_KeyError ))
1105
- _PyErr_SetString (tstate , PyExc_NameError ,
1106
- "__build_class__ not found" );
1107
- ERROR_IF (true, error );
1108
- }
1089
+ ERROR_IF (_PyMapping_LookupItem (BUILTINS (), & _Py_ID (__build_class__ ), & bc ) < 0 , error );
1090
+ if (bc == NULL ) {
1091
+ _PyErr_SetString (tstate , PyExc_NameError ,
1092
+ "__build_class__ not found" );
1093
+ ERROR_IF (true, error );
1109
1094
}
1110
1095
}
1111
1096
@@ -1280,25 +1265,9 @@ dummy_func(
1280
1265
1281
1266
op (_LOAD_FROM_DICT_OR_GLOBALS , (mod_or_class_dict -- v )) {
1282
1267
PyObject * name = GETITEM (FRAME_CO_NAMES , oparg );
1283
- if (PyDict_CheckExact (mod_or_class_dict )) {
1284
- v = PyDict_GetItemWithError (mod_or_class_dict , name );
1285
- if (v != NULL ) {
1286
- Py_INCREF (v );
1287
- }
1288
- else if (_PyErr_Occurred (tstate )) {
1289
- Py_DECREF (mod_or_class_dict );
1290
- goto error ;
1291
- }
1292
- }
1293
- else {
1294
- v = PyObject_GetItem (mod_or_class_dict , name );
1295
- if (v == NULL ) {
1296
- if (!_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
1297
- Py_DECREF (mod_or_class_dict );
1298
- goto error ;
1299
- }
1300
- _PyErr_Clear (tstate );
1301
- }
1268
+ if (_PyMapping_LookupItem (mod_or_class_dict , name , & v ) < 0 ) {
1269
+ Py_DECREF (mod_or_class_dict );
1270
+ goto error ;
1302
1271
}
1303
1272
Py_DECREF (mod_or_class_dict );
1304
1273
if (v == NULL ) {
@@ -1310,28 +1279,14 @@ dummy_func(
1310
1279
goto error ;
1311
1280
}
1312
1281
else {
1313
- if (PyDict_CheckExact (BUILTINS ())) {
1314
- v = PyDict_GetItemWithError (BUILTINS (), name );
1315
- if (v == NULL ) {
1316
- if (!_PyErr_Occurred (tstate )) {
1317
- format_exc_check_arg (
1318
- tstate , PyExc_NameError ,
1319
- NAME_ERROR_MSG , name );
1320
- }
1321
- goto error ;
1322
- }
1323
- Py_INCREF (v );
1282
+ if (_PyMapping_LookupItem (BUILTINS (), name , & v ) < 0 ) {
1283
+ goto error ;
1324
1284
}
1325
- else {
1326
- v = PyObject_GetItem (BUILTINS (), name );
1327
- if (v == NULL ) {
1328
- if (_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
1329
- format_exc_check_arg (
1330
- tstate , PyExc_NameError ,
1331
- NAME_ERROR_MSG , name );
1332
- }
1333
- goto error ;
1334
- }
1285
+ if (v == NULL ) {
1286
+ format_exc_check_arg (
1287
+ tstate , PyExc_NameError ,
1288
+ NAME_ERROR_MSG , name );
1289
+ goto error ;
1335
1290
}
1336
1291
}
1337
1292
}
@@ -1381,19 +1336,14 @@ dummy_func(
1381
1336
/* Slow-path if globals or builtins is not a dict */
1382
1337
1383
1338
/* namespace 1: globals */
1384
- v = PyObject_GetItem ( GLOBALS (), name );
1339
+ ERROR_IF ( _PyMapping_LookupItem ( GLOBALS (), name , & v ) < 0 , error );
1385
1340
if (v == NULL ) {
1386
- ERROR_IF (!_PyErr_ExceptionMatches (tstate , PyExc_KeyError ), error );
1387
- _PyErr_Clear (tstate );
1388
-
1389
1341
/* namespace 2: builtins */
1390
- v = PyObject_GetItem ( BUILTINS (), name );
1342
+ ERROR_IF ( _PyMapping_LookupItem ( BUILTINS (), name , & v ) < 0 , error );
1391
1343
if (v == NULL ) {
1392
- if (_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
1393
- format_exc_check_arg (
1394
- tstate , PyExc_NameError ,
1395
- NAME_ERROR_MSG , name );
1396
- }
1344
+ format_exc_check_arg (
1345
+ tstate , PyExc_NameError ,
1346
+ NAME_ERROR_MSG , name );
1397
1347
ERROR_IF (true, error );
1398
1348
}
1399
1349
}
@@ -1466,25 +1416,9 @@ dummy_func(
1466
1416
assert (class_dict );
1467
1417
assert (oparg >= 0 && oparg < _PyFrame_GetCode (frame )-> co_nlocalsplus );
1468
1418
name = PyTuple_GET_ITEM (_PyFrame_GetCode (frame )-> co_localsplusnames , oparg );
1469
- if (PyDict_CheckExact (class_dict )) {
1470
- value = PyDict_GetItemWithError (class_dict , name );
1471
- if (value != NULL ) {
1472
- Py_INCREF (value );
1473
- }
1474
- else if (_PyErr_Occurred (tstate )) {
1475
- Py_DECREF (class_dict );
1476
- goto error ;
1477
- }
1478
- }
1479
- else {
1480
- value = PyObject_GetItem (class_dict , name );
1481
- if (value == NULL ) {
1482
- if (!_PyErr_ExceptionMatches (tstate , PyExc_KeyError )) {
1483
- Py_DECREF (class_dict );
1484
- goto error ;
1485
- }
1486
- _PyErr_Clear (tstate );
1487
- }
1419
+ if (_PyMapping_LookupItem (class_dict , name , & value ) < 0 ) {
1420
+ Py_DECREF (class_dict );
1421
+ goto error ;
1488
1422
}
1489
1423
Py_DECREF (class_dict );
1490
1424
if (!value ) {
@@ -1622,10 +1556,8 @@ dummy_func(
1622
1556
}
1623
1557
else {
1624
1558
/* do the same if locals() is not a dict */
1625
- ann_dict = PyObject_GetItem ( LOCALS (), & _Py_ID (__annotations__ ));
1559
+ ERROR_IF ( _PyMapping_LookupItem ( LOCALS (), & _Py_ID (__annotations__ ), & ann_dict ) < 0 , error );
1626
1560
if (ann_dict == NULL ) {
1627
- ERROR_IF (!_PyErr_ExceptionMatches (tstate , PyExc_KeyError ), error );
1628
- _PyErr_Clear (tstate );
1629
1561
ann_dict = PyDict_New ();
1630
1562
ERROR_IF (ann_dict == NULL , error );
1631
1563
err = PyObject_SetItem (LOCALS (), & _Py_ID (__annotations__ ),
0 commit comments