@@ -466,7 +466,7 @@ dict_keys_inorder(PyObject *dict, Py_ssize_t offset)
466466extern void _Py_set_localsplus_info (int , PyObject * , unsigned char ,
467467 PyObject * , PyObject * );
468468
469- static void
469+ static int
470470compute_localsplus_info (_PyCompile_CodeUnitMetadata * umd , int nlocalsplus ,
471471 PyObject * names , PyObject * kinds )
472472{
@@ -481,7 +481,11 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
481481 if (PyDict_Contains (umd -> u_fasthidden , k )) {
482482 kind |= CO_FAST_HIDDEN ;
483483 }
484- if (PyDict_GetItem (umd -> u_cellvars , k ) != NULL ) {
484+ PyObject * cell ;
485+ if (PyDict_GetItemRef (umd -> u_cellvars , k , & cell ) < 0 ) {
486+ return -1 ;
487+ }
488+ if (cell != NULL ) {
485489 kind |= CO_FAST_CELL ;
486490 }
487491 _Py_set_localsplus_info (offset , k , kind , names , kinds );
@@ -492,7 +496,11 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
492496 int numdropped = 0 ;
493497 pos = 0 ;
494498 while (PyDict_Next (umd -> u_cellvars , & pos , & k , & v )) {
495- if (PyDict_GetItem (umd -> u_varnames , k ) != NULL ) {
499+ PyObject * name ;
500+ if (PyDict_GetItemRef (umd -> u_varnames , k , & name ) < 0 ) {
501+ return -1 ;
502+ }
503+ if (name != NULL ) {
496504 // Skip cells that are already covered by locals.
497505 numdropped += 1 ;
498506 continue ;
@@ -512,6 +520,7 @@ compute_localsplus_info(_PyCompile_CodeUnitMetadata *umd, int nlocalsplus,
512520 assert (offset < nlocalsplus );
513521 _Py_set_localsplus_info (offset , k , CO_FAST_FREE , names , kinds );
514522 }
523+ return 0 ;
515524}
516525
517526static PyCodeObject *
@@ -556,7 +565,10 @@ makecode(_PyCompile_CodeUnitMetadata *umd, struct assembler *a, PyObject *const_
556565 if (localspluskinds == NULL ) {
557566 goto error ;
558567 }
559- compute_localsplus_info (umd , nlocalsplus , localsplusnames , localspluskinds );
568+ if (compute_localsplus_info (umd , nlocalsplus ,
569+ localsplusnames , localspluskinds ) < 0 ) {
570+ goto error ;
571+ }
560572
561573 struct _PyCodeConstructor con = {
562574 .filename = filename ,
0 commit comments