Commit f862ea6a authored by Stefan Behnel's avatar Stefan Behnel

streamline FetchStopIterationValue()

parent 5773ba74
......@@ -430,43 +430,41 @@ static int __Pyx_PyGen_FetchStopIterationValue(PyObject **pvalue) {
// most common case: plain StopIteration without or with separate argument
if (likely(et == PyExc_StopIteration)) {
if (!ev) {
Py_INCREF(Py_None);
value = Py_None;
}
#if PY_VERSION_HEX >= 0x030300A0
if (ev && Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
else if (Py_TYPE(ev) == (PyTypeObject*)PyExc_StopIteration) {
value = ((PyStopIterationObject *)ev)->value;
Py_INCREF(value);
Py_DECREF(ev);
Py_XDECREF(tb);
Py_DECREF(et);
*pvalue = value;
return 0;
}
#endif
if (!ev || !PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
// PyErr_SetObject() and friends put the value directly into ev
if (!ev) {
Py_INCREF(Py_None);
ev = Py_None;
} else if (unlikely(PyTuple_Check(ev))) {
// however, if it's a tuple, it is interpreted as separate constructor arguments (surprise!)
else if (unlikely(PyTuple_Check(ev))) {
// if it's a tuple, it is interpreted as separate constructor arguments (surprise!)
if (PyTuple_GET_SIZE(ev) >= 1) {
PyObject *value;
#if !CYTHON_COMPILING_IN_CPYTHON
value = PySequence_ITEM(ev, 0);
#else
value = PyTuple_GET_ITEM(ev, 0);
Py_INCREF(value);
#endif
Py_DECREF(ev);
ev = value;
} else {
Py_INCREF(Py_None);
value = Py_None;
}
Py_DECREF(ev);
ev = Py_None;
}
else if (!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) {
// 'steal' reference to ev
value = ev;
}
if (likely(value)) {
Py_XDECREF(tb);
Py_DECREF(et);
*pvalue = ev;
*pvalue = value;
return 0;
}
} else if (!PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment