@@ -1728,23 +1728,22 @@ identify_unbound_names(PyThreadState *tstate, PyCodeObject *co,
1728
1728
assert (globalsns == NULL || PyDict_Check (globalsns ));
1729
1729
assert (builtinsns == NULL || PyDict_Check (builtinsns ));
1730
1730
assert (counts == NULL || counts -> total == 0 );
1731
+ struct co_unbound_counts unbound = {0 };
1731
1732
Py_ssize_t len = Py_SIZE (co );
1732
1733
for (int i = 0 ; i < len ; i ++ ) {
1733
1734
_Py_CODEUNIT inst = _Py_GetBaseCodeUnit (co , i );
1734
1735
if (inst .op .code == LOAD_ATTR ) {
1735
1736
int oparg = GET_OPARG (co , i , inst .op .arg );
1736
1737
int index = LOAD_ATTR_NAME_INDEX (oparg );
1737
1738
PyObject * name = GETITEM (co -> co_names , index );
1738
- if (counts != NULL ) {
1739
- if (PySet_Contains (attrnames , name )) {
1740
- if (_PyErr_Occurred (tstate )) {
1741
- return -1 ;
1742
- }
1743
- continue ;
1739
+ if (PySet_Contains (attrnames , name )) {
1740
+ if (_PyErr_Occurred (tstate )) {
1741
+ return -1 ;
1744
1742
}
1745
- counts -> total += 1 ;
1746
- counts -> numattrs += 1 ;
1743
+ continue ;
1747
1744
}
1745
+ unbound .total += 1 ;
1746
+ unbound .numattrs += 1 ;
1748
1747
if (PySet_Add (attrnames , name ) < 0 ) {
1749
1748
return -1 ;
1750
1749
}
@@ -1753,36 +1752,37 @@ identify_unbound_names(PyThreadState *tstate, PyCodeObject *co,
1753
1752
int oparg = GET_OPARG (co , i , inst .op .arg );
1754
1753
int index = LOAD_ATTR_NAME_INDEX (oparg );
1755
1754
PyObject * name = GETITEM (co -> co_names , index );
1756
- if (counts != NULL ) {
1757
- if (PySet_Contains (globalnames , name )) {
1758
- if (_PyErr_Occurred (tstate )) {
1759
- return -1 ;
1760
- }
1761
- continue ;
1755
+ if (PySet_Contains (globalnames , name )) {
1756
+ if (_PyErr_Occurred (tstate )) {
1757
+ return -1 ;
1762
1758
}
1763
- counts -> total += 1 ;
1764
- counts -> globals .total += 1 ;
1765
- counts -> globals .numunknown += 1 ;
1766
- if (globalsns != NULL && PyDict_Contains (globalsns , name )) {
1767
- if (_PyErr_Occurred (tstate )) {
1768
- return -1 ;
1769
- }
1770
- counts -> globals .numglobal += 1 ;
1771
- counts -> globals .numunknown -= 1 ;
1759
+ continue ;
1760
+ }
1761
+ unbound .total += 1 ;
1762
+ unbound .globals .total += 1 ;
1763
+ unbound .globals .numunknown += 1 ;
1764
+ if (globalsns != NULL && PyDict_Contains (globalsns , name )) {
1765
+ if (_PyErr_Occurred (tstate )) {
1766
+ return -1 ;
1772
1767
}
1773
- if ( builtinsns != NULL && PyDict_Contains ( builtinsns , name )) {
1774
- if ( _PyErr_Occurred ( tstate )) {
1775
- return -1 ;
1776
- }
1777
- counts -> globals . numbuiltin += 1 ;
1778
- counts -> globals . numunknown -= 1 ;
1768
+ unbound . globals . numglobal += 1 ;
1769
+ unbound . globals . numunknown -= 1 ;
1770
+ }
1771
+ if ( builtinsns != NULL && PyDict_Contains ( builtinsns , name )) {
1772
+ if ( _PyErr_Occurred ( tstate )) {
1773
+ return - 1 ;
1779
1774
}
1775
+ unbound .globals .numbuiltin += 1 ;
1776
+ unbound .globals .numunknown -= 1 ;
1780
1777
}
1781
1778
if (PySet_Add (globalnames , name ) < 0 ) {
1782
1779
return -1 ;
1783
1780
}
1784
1781
}
1785
1782
}
1783
+ if (counts != NULL ) {
1784
+ * counts = unbound ;
1785
+ }
1786
1786
return 0 ;
1787
1787
}
1788
1788
0 commit comments