@@ -1183,38 +1183,32 @@ lineiter_dealloc(lineiterator *li)
11831183 Py_TYPE (li )-> tp_free (li );
11841184}
11851185
1186+ static PyObject *
1187+ _source_offset_converter (int * value ) {
1188+ if (* value == -1 ) {
1189+ Py_RETURN_NONE ;
1190+ }
1191+ return PyLong_FromLong (* value );
1192+ }
1193+
11861194static PyObject *
11871195lineiter_next (lineiterator * li )
11881196{
11891197 PyCodeAddressRange * bounds = & li -> li_line ;
11901198 if (!_PyLineTable_NextAddressRange (bounds )) {
11911199 return NULL ;
11921200 }
1193- PyObject * start = NULL ;
1194- PyObject * end = NULL ;
1195- PyObject * line = NULL ;
1196- PyObject * result = PyTuple_New (3 );
1197- start = PyLong_FromLong (bounds -> ar_start );
1198- end = PyLong_FromLong (bounds -> ar_end );
1199- if (bounds -> ar_line < 0 ) {
1200- line = Py_NewRef (Py_None );
1201- }
1202- else {
1203- line = PyLong_FromLong (bounds -> ar_line );
1204- }
1205- if (result == NULL || start == NULL || end == NULL || line == NULL ) {
1206- goto error ;
1201+ int start = bounds -> ar_start ;
1202+ int line = bounds -> ar_line ;
1203+ // Merge overlapping entries:
1204+ while (_PyLineTable_NextAddressRange (bounds )) {
1205+ if (bounds -> ar_line != line ) {
1206+ _PyLineTable_PreviousAddressRange (bounds );
1207+ break ;
1208+ }
12071209 }
1208- PyTuple_SET_ITEM (result , 0 , start );
1209- PyTuple_SET_ITEM (result , 1 , end );
1210- PyTuple_SET_ITEM (result , 2 , line );
1211- return result ;
1212- error :
1213- Py_XDECREF (start );
1214- Py_XDECREF (end );
1215- Py_XDECREF (line );
1216- Py_XDECREF (result );
1217- return result ;
1210+ return Py_BuildValue ("iiO&" , start , bounds -> ar_end ,
1211+ _source_offset_converter , & line );
12181212}
12191213
12201214PyTypeObject _PyLineIterator = {
@@ -1290,14 +1284,6 @@ positionsiter_dealloc(positionsiterator* pi)
12901284 Py_TYPE (pi )-> tp_free (pi );
12911285}
12921286
1293- static PyObject *
1294- _source_offset_converter (int * value ) {
1295- if (* value == -1 ) {
1296- Py_RETURN_NONE ;
1297- }
1298- return PyLong_FromLong (* value );
1299- }
1300-
13011287static PyObject *
13021288positionsiter_next (positionsiterator * pi )
13031289{
0 commit comments