@@ -1881,11 +1881,12 @@ chain_traverse(PyObject *op, visitproc visit, void *arg)
1881
1881
}
1882
1882
1883
1883
static inline PyObject *
1884
- chain_next_lock_held (PyObject * op )
1884
+ chain_next (PyObject * op )
1885
1885
{
1886
1886
chainobject * lz = chainobject_CAST (op );
1887
- PyObject * item ;
1887
+ PyObject * item = NULL ;
1888
1888
1889
+ Py_BEGIN_CRITICAL_SECTION (op );
1889
1890
/* lz->source is the iterator of iterables. If it's NULL, we've already
1890
1891
* consumed them all. lz->active is the current iterator. If it's NULL,
1891
1892
* we should grab a new one from lz->source. */
@@ -1894,41 +1895,38 @@ chain_next_lock_held(PyObject *op)
1894
1895
PyObject * iterable = PyIter_Next (lz -> source );
1895
1896
if (iterable == NULL ) {
1896
1897
Py_CLEAR (lz -> source );
1897
- return NULL ; /* no more input sources */
1898
+ goto exit ; /* no more input sources */
1898
1899
}
1899
1900
lz -> active = PyObject_GetIter (iterable );
1900
1901
Py_DECREF (iterable );
1901
1902
if (lz -> active == NULL ) {
1902
1903
Py_CLEAR (lz -> source );
1903
- return NULL ; /* input not iterable */
1904
+ goto exit ; /* input not iterable */
1904
1905
}
1905
1906
}
1906
1907
item = (* Py_TYPE (lz -> active )-> tp_iternext )(lz -> active );
1907
- if (item != NULL )
1908
- return item ;
1908
+ if (item != NULL ) {
1909
+ goto exit ;
1910
+ }
1909
1911
if (PyErr_Occurred ()) {
1910
1912
if (PyErr_ExceptionMatches (PyExc_StopIteration ))
1911
1913
PyErr_Clear ();
1912
- else
1913
- return NULL ; /* input raised an exception */
1914
+ else {
1915
+ goto exit ; /* input raised an exception */
1916
+ }
1914
1917
}
1915
1918
/* lz->active is consumed, try with the next iterable. */
1916
1919
Py_CLEAR (lz -> active );
1917
1920
}
1918
1921
/* Everything had been consumed already. */
1919
- return NULL ;
1920
- }
1921
1922
1922
- static PyObject *
1923
- chain_next (PyObject * op )
1924
- {
1925
- PyObject * result ;
1926
- Py_BEGIN_CRITICAL_SECTION (op );
1927
- result = chain_next_lock_held (op );
1923
+ exit :
1928
1924
Py_END_CRITICAL_SECTION ()
1929
- return result ;
1925
+
1926
+ return item ;
1930
1927
}
1931
1928
1929
+
1932
1930
PyDoc_STRVAR (chain_doc ,
1933
1931
"chain(*iterables)\n\
1934
1932
--\n\
0 commit comments