@@ -466,7 +466,7 @@ dict_keys_inorder(PyObject *dict, Py_ssize_t offset)
466
466
extern void _Py_set_localsplus_info (int , PyObject * , unsigned char ,
467
467
PyObject * , PyObject * );
468
468
469
- static void
469
+ static int
470
470
compute_localsplus_info (_PyCompile_CodeUnitMetadata * umd , int nlocalsplus ,
471
471
PyObject * names , PyObject * kinds )
472
472
{
@@ -481,7 +481,11 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
481
481
if (PyDict_Contains (umd -> u_fasthidden , k )) {
482
482
kind |= CO_FAST_HIDDEN ;
483
483
}
484
- if (PyDict_GetItem (umd -> u_cellvars , k ) != NULL ) {
484
+ int has_cell = PyDict_Contains (umd -> u_cellvars , k );
485
+ if (has_cell < 0 ) {
486
+ return -1 ;
487
+ }
488
+ if (has_cell ) {
485
489
kind |= CO_FAST_CELL ;
486
490
}
487
491
_Py_set_localsplus_info (offset , k , kind , names , kinds );
@@ -492,7 +496,11 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
492
496
int numdropped = 0 ;
493
497
pos = 0 ;
494
498
while (PyDict_Next (umd -> u_cellvars , & pos , & k , & v )) {
495
- if (PyDict_GetItem (umd -> u_varnames , k ) != NULL ) {
499
+ int has_name = PyDict_Contains (umd -> u_varnames , k );
500
+ if (has_name < 0 ) {
501
+ return -1 ;
502
+ }
503
+ if (has_name ) {
496
504
// Skip cells that are already covered by locals.
497
505
numdropped += 1 ;
498
506
continue ;
@@ -512,6 +520,7 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
512
520
assert (offset < nlocalsplus );
513
521
_Py_set_localsplus_info (offset , k , CO_FAST_FREE , names , kinds );
514
522
}
523
+ return 0 ;
515
524
}
516
525
517
526
static PyCodeObject *
@@ -556,7 +565,10 @@ makecode(_PyCompile_CodeUnitMetadata *umd, struct assembler *a, PyObject *const_
556
565
if (localspluskinds == NULL ) {
557
566
goto error ;
558
567
}
559
- compute_localsplus_info (umd , nlocalsplus , localsplusnames , localspluskinds );
568
+ if (compute_localsplus_info (umd , nlocalsplus ,
569
+ localsplusnames , localspluskinds ) < 0 ) {
570
+ goto error ;
571
+ }
560
572
561
573
struct _PyCodeConstructor con = {
562
574
.filename = filename ,
0 commit comments