Commit 72d0222b authored by Stefan Behnel's avatar Stefan Behnel

generalise dict iteration status flag (also used by the non-CPython/non-dict-type code)

parent f324eca3
...@@ -311,16 +311,16 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t ...@@ -311,16 +311,16 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* dict_or_iter, Py_ssize_t
//@requires: ObjectHandling.c::IterFinish //@requires: ObjectHandling.c::IterFinish
static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name, static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_dict, PyObject* method_name,
Py_ssize_t* p_orig_length, int* p_is_dict) { Py_ssize_t* p_orig_length, int* p_source_is_dict) {
is_dict = is_dict || likely(PyDict_CheckExact(iterable));
*p_source_is_dict = is_dict;
#if !CYTHON_COMPILING_IN_PYPY #if !CYTHON_COMPILING_IN_PYPY
if (is_dict || likely(PyDict_CheckExact(iterable))) { if (is_dict) {
*p_is_dict = 1;
*p_orig_length = PyDict_Size(iterable); *p_orig_length = PyDict_Size(iterable);
Py_INCREF(iterable); Py_INCREF(iterable);
return iterable; return iterable;
} }
#endif #endif
*p_is_dict = 0;
*p_orig_length = 0; *p_orig_length = 0;
if (method_name) { if (method_name) {
PyObject* iter; PyObject* iter;
...@@ -339,10 +339,10 @@ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_di ...@@ -339,10 +339,10 @@ static CYTHON_INLINE PyObject* __Pyx_dict_iterator(PyObject* iterable, int is_di
} }
static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* iter_obj, Py_ssize_t orig_length, Py_ssize_t* ppos, static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* iter_obj, Py_ssize_t orig_length, Py_ssize_t* ppos,
PyObject** pkey, PyObject** pvalue, PyObject** pitem, int is_dict) { PyObject** pkey, PyObject** pvalue, PyObject** pitem, int source_is_dict) {
PyObject* next_item; PyObject* next_item;
#if !CYTHON_COMPILING_IN_PYPY #if !CYTHON_COMPILING_IN_PYPY
if (is_dict) { if (source_is_dict) {
PyObject *key, *value; PyObject *key, *value;
if (unlikely(orig_length != PyDict_Size(iter_obj))) { if (unlikely(orig_length != PyDict_Size(iter_obj))) {
PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration"); PyErr_SetString(PyExc_RuntimeError, "dictionary changed size during iteration");
...@@ -395,7 +395,7 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* iter_obj, Py_ssize_t ori ...@@ -395,7 +395,7 @@ static CYTHON_INLINE int __Pyx_dict_iter_next(PyObject* iter_obj, Py_ssize_t ori
if (pitem) { if (pitem) {
*pitem = next_item; *pitem = next_item;
} else if (pkey && pvalue) { } else if (pkey && pvalue) {
if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, is_dict, is_dict, 1)) if (__Pyx_unpack_tuple2(next_item, pkey, pvalue, source_is_dict, source_is_dict, 1))
return -1; return -1;
} else if (pkey) { } else if (pkey) {
*pkey = next_item; *pkey = next_item;
......
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