@@ -94,22 +94,6 @@ framelocalsproxy_hasval(_PyInterpreterFrame *frame, PyCodeObject *co, int i)
9494 return true;
9595}
9696
97- static int
98- framelocalsproxy_is_first_occurrence (PyObject * seen , PyObject * name )
99- {
100- int found = PySet_Contains (seen , name );
101- if (found < 0 ) {
102- return -1 ;
103- }
104- if (found ) {
105- return 0 ;
106- }
107- if (PySet_Add (seen , name ) < 0 ) {
108- return -1 ;
109- }
110- return 1 ;
111- }
112-
11397static int
11498framelocalsproxy_getkeyindex (PyFrameObject * frame , PyObject * key , bool read , PyObject * * value_ptr )
11599{
@@ -396,28 +380,16 @@ framelocalsproxy_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
396380 if (names == NULL ) {
397381 return NULL ;
398382 }
399- // An inlined comprehension cell can share a name with a free var.
400- PyObject * seen = PySet_New (NULL );
401- if (seen == NULL ) {
402- Py_DECREF (names );
403- return NULL ;
404- }
405383
406384 for (int i = 0 ; i < co -> co_nlocalsplus ; i ++ ) {
407385 if (framelocalsproxy_hasval (frame -> f_frame , co , i )) {
408386 PyObject * name = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
409- int first = framelocalsproxy_is_first_occurrence (seen , name );
410- if (first < 0 ) {
411- goto error ;
412- }
413- if (first ) {
414- if (PyList_Append (names , name ) < 0 ) {
415- goto error ;
416- }
387+ if (PyList_Append (names , name ) < 0 ) {
388+ Py_DECREF (names );
389+ return NULL ;
417390 }
418391 }
419392 }
420- Py_DECREF (seen );
421393
422394 // Iterate through the extra locals
423395 if (frame -> f_extra_locals ) {
@@ -436,11 +408,6 @@ framelocalsproxy_keys(PyObject *self, PyObject *Py_UNUSED(ignored))
436408 }
437409
438410 return names ;
439-
440- error :
441- Py_DECREF (seen );
442- Py_DECREF (names );
443- return NULL ;
444411}
445412
446413static void
@@ -622,30 +589,18 @@ framelocalsproxy_values(PyObject *self, PyObject *Py_UNUSED(ignored))
622589 if (values == NULL ) {
623590 return NULL ;
624591 }
625- PyObject * seen = PySet_New (NULL );
626- if (seen == NULL ) {
627- Py_DECREF (values );
628- return NULL ;
629- }
630592
631593 for (int i = 0 ; i < co -> co_nlocalsplus ; i ++ ) {
632594 PyObject * value = framelocalsproxy_getval (frame -> f_frame , co , i );
633595 if (value ) {
634- PyObject * name = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
635- int first = framelocalsproxy_is_first_occurrence (seen , name );
636- if (first == 1 ) {
637- if (PyList_Append (values , value ) < 0 ) {
638- Py_DECREF (value );
639- goto error ;
640- }
596+ if (PyList_Append (values , value ) < 0 ) {
597+ Py_DECREF (value );
598+ Py_DECREF (values );
599+ return NULL ;
641600 }
642601 Py_DECREF (value );
643- if (first < 0 ) {
644- goto error ;
645- }
646602 }
647603 }
648- Py_DECREF (seen );
649604
650605 // Iterate through the extra locals
651606 if (frame -> f_extra_locals ) {
@@ -661,11 +616,6 @@ framelocalsproxy_values(PyObject *self, PyObject *Py_UNUSED(ignored))
661616 }
662617
663618 return values ;
664-
665- error :
666- Py_DECREF (seen );
667- Py_DECREF (values );
668- return NULL ;
669619}
670620
671621static PyObject *
@@ -677,37 +627,21 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
677627 if (items == NULL ) {
678628 return NULL ;
679629 }
680- PyObject * seen = PySet_New (NULL );
681- if (seen == NULL ) {
682- Py_DECREF (items );
683- return NULL ;
684- }
685630
686631 for (int i = 0 ; i < co -> co_nlocalsplus ; i ++ ) {
687632 PyObject * name = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
688633 PyObject * value = framelocalsproxy_getval (frame -> f_frame , co , i );
689634
690635 if (value ) {
691- int first = framelocalsproxy_is_first_occurrence (seen , name );
692- if (first == 1 ) {
693- PyObject * pair = _PyTuple_FromPairSteal (Py_NewRef (name ), value );
694- if (pair == NULL ) {
695- goto error ;
696- }
697- if (_PyList_AppendTakeRef ((PyListObject * )items , pair ) < 0 ) {
698- goto error ;
699- }
636+ PyObject * pair = _PyTuple_FromPairSteal (Py_NewRef (name ), value );
637+ if (pair == NULL ) {
638+ goto error ;
700639 }
701- else {
702- Py_DECREF (value );
703- if (first < 0 ) {
704- goto error ;
705- }
640+ if (_PyList_AppendTakeRef ((PyListObject * )items , pair ) < 0 ) {
641+ goto error ;
706642 }
707643 }
708644 }
709- Py_DECREF (seen );
710- seen = NULL ;
711645
712646 // Iterate through the extra locals
713647 if (frame -> f_extra_locals ) {
@@ -729,7 +663,6 @@ framelocalsproxy_items(PyObject *self, PyObject *Py_UNUSED(ignored))
729663 return items ;
730664
731665error :
732- Py_XDECREF (seen );
733666 Py_DECREF (items );
734667 return NULL ;
735668}
@@ -746,24 +679,11 @@ framelocalsproxy_length(PyObject *self)
746679 size += PyDict_Size (frame -> f_extra_locals );
747680 }
748681
749- PyObject * seen = PySet_New (NULL );
750- if (seen == NULL ) {
751- return -1 ;
752- }
753682 for (int i = 0 ; i < co -> co_nlocalsplus ; i ++ ) {
754683 if (framelocalsproxy_hasval (frame -> f_frame , co , i )) {
755- PyObject * name = PyTuple_GET_ITEM (co -> co_localsplusnames , i );
756- int first = framelocalsproxy_is_first_occurrence (seen , name );
757- if (first < 0 ) {
758- Py_DECREF (seen );
759- return -1 ;
760- }
761- else if (first ) {
762- size ++ ;
763- }
684+ size ++ ;
764685 }
765686 }
766- Py_DECREF (seen );
767687 return size ;
768688}
769689
0 commit comments